:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #d8dee8;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --ok: #067647;
  --warn: #b54708;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

input {
  min-width: 0;
}

button {
  border: 0;
  cursor: pointer;
}

.shell {
  display: grid;
  grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
  gap: 18px;
  height: 100vh;
  padding: 18px;
}

.left-pane {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  padding-right: 2px;
}

.app-header {
  display: flex;
  align-items: flex-start;
  flex: 0 0 auto;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 15px;
  line-height: 1.3;
}

.status-pill {
  flex: 0 0 auto;
  min-width: 72px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: #eef2f7;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.status-pill.connected {
  border-color: rgba(6, 118, 71, 0.25);
  background: #ecfdf3;
  color: var(--ok);
}

.status-pill.error {
  border-color: rgba(180, 35, 24, 0.25);
  background: #fef3f2;
  color: var(--danger);
}

.mini-status {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.mini-status.ok {
  color: var(--ok);
}

.mini-status.error {
  color: var(--danger);
}

.panel {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
}

.command-panel {
  overflow: hidden;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
}

.icon-button.listening {
  background: var(--danger);
}

.command-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 8px;
  padding: 12px;
}

.command-form input {
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
}

.command-form input:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(15, 118, 110, 0.18);
}

.command-form button,
.quick-commands button,
.ghost-button,
.system-page-button,
.config-form button {
  min-height: 36px;
  border-radius: 8px;
  padding: 0 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.hint {
  padding: 0 12px 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.quick-commands {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 12px 12px;
}

.quick-commands button,
.system-page-button {
  background: #eef8f6;
  color: var(--accent-dark);
}

.quick-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 36px;
}

.config-panel {
  flex: 0 0 auto;
}

.config-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
}

.ai-settings-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px;
}

.ai-render-progress {
  margin: 0 12px 12px;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 8px;
  padding: 10px;
  background: #f8fbfb;
}

.ai-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.ai-progress-head strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-progress-head span {
  flex: 0 0 auto;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.ai-progress-track {
  height: 8px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe8eb;
}

.ai-progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0f766e, #0284c7);
  transition: width 180ms ease;
}

.ai-progress-steps {
  display: grid;
  gap: 5px;
  margin: 10px 0 0;
  padding-left: 18px;
}

.ai-progress-steps li {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.ai-progress-steps li strong {
  color: var(--text);
}

.ai-progress-summary {
  margin-top: 8px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
}

.config-form input,
.ai-settings-form input {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--text);
}

.config-form input:focus,
.ai-settings-form input:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(15, 118, 110, 0.18);
}

.config-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.system-list {
  display: grid;
  gap: 10px;
  max-height: 190px;
  overflow: auto;
  padding: 12px;
}

.system-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.system-item strong {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
}

.system-heading {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--panel);
}

.system-heading strong {
  min-width: 0;
  margin-bottom: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.system-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.edit-system,
.delete-system {
  min-height: 28px;
  border-radius: 8px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 800;
}

.edit-system {
  border: 1px solid rgba(15, 118, 110, 0.24);
  background: #eef8f6;
  color: var(--accent-dark);
}

.delete-system {
  border: 1px solid rgba(180, 35, 24, 0.24);
  background: #fef3f2;
  color: var(--danger);
}

.system-pages {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.system-url {
  margin-top: 8px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-panel {
  display: flex;
  min-height: 0;
  flex: 1 0 220px;
  flex-direction: column;
}

.event-log {
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
  flex-direction: column-reverse;
  gap: 8px;
  margin: 0;
  overflow: auto;
  padding: 12px 12px 16px 28px;
}

.event-log li {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.event-log li strong {
  color: var(--text);
}

.event-log li.error {
  color: var(--danger);
}

.stage {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101828;
  box-shadow: var(--shadow);
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  padding: 12px 14px;
  color: #fff;
}

.stage-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stage-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 18px;
}

.stage-title {
  font-size: 16px;
  font-weight: 800;
}

.stage-url,
.frame-time {
  color: #cbd5e1;
  font-size: 12px;
  line-height: 1.4;
}

.stage-url {
  max-width: 72vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage:fullscreen {
  border: 0;
  border-radius: 0;
  width: 100vw;
  height: 100vh;
}

.stage.stage-expanded {
  position: fixed;
  inset: 0;
  z-index: 50;
  width: 100vw;
  height: 100vh;
  border: 0;
  border-radius: 0;
}

.stage:fullscreen .stage-url {
  max-width: 84vw;
}

.stage.stage-expanded .stage-url {
  max-width: 84vw;
}

.screen-frame {
  position: relative;
  display: grid;
  min-height: 0;
  flex: 1 1 auto;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px), #111827;
  background-size: 32px 32px;
}

.screen-frame::after {
  position: absolute;
  right: 22px;
  bottom: 14px;
  border-radius: 999px;
  padding: 5px 8px;
  background: rgba(15, 23, 42, 0.72);
  color: #e2e8f0;
  content: "滚轮滚动页面";
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.screen-frame:hover::after {
  opacity: 1;
}

.screen-scrollbar {
  position: absolute;
  top: 10px;
  right: 8px;
  bottom: 10px;
  z-index: 3;
  display: none;
  width: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  pointer-events: none;
}

.screen-scrollbar.visible {
  display: block;
}

.screen-scrollbar-thumb {
  width: 100%;
  min-height: 32px;
  border-radius: 999px;
  background: rgba(226, 232, 240, 0.72);
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.18);
}

#screenImage {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
}

#screenImage.ready {
  display: block;
}

.empty-screen {
  position: absolute;
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 8px;
  color: #dbeafe;
  text-align: center;
}

.empty-screen strong {
  font-size: 22px;
}

.empty-screen span {
  color: #cbd5e1;
}

@media (max-width: 960px) {
  .shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .left-pane {
    min-height: auto;
  }

  .stage {
    min-height: 60vh;
  }

  .stage-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stage-actions {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 520px) {
  .config-form {
    grid-template-columns: 1fr;
  }
}
