:root {
  color-scheme: light;
  --blue: #2f80d1;
  --blue-dark: #15579b;
  --sky: #d8eefc;
  --leaf: #4f9b6f;
  --sun: #f0b84f;
  --coral: #dc6f62;
  --ink: #1e2a35;
  --muted: #657380;
  --line: #d9e3ea;
  --panel: #ffffff;
  --bg: #f4f7f8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(216, 238, 252, 0.9), rgba(244, 247, 248, 0.8) 42%),
    var(--bg);
}

body.mobile-input-open {
  padding-bottom: 128px;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.stage-panel,
.control-panel {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(217, 227, 234, 0.9);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(36, 72, 105, 0.12);
}

.stage-panel {
  min-height: calc(100vh - 48px);
  padding: 24px;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue-dark);
  font-size: 13px;
  font-weight: 800;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 12px;
  font-size: 16px;
}

.session-meter {
  display: grid;
  place-items: center;
  min-width: 76px;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfd;
}

.session-meter span {
  color: var(--blue-dark);
  font-size: 24px;
  font-weight: 900;
}

.session-meter small {
  color: var(--muted);
  font-weight: 700;
}

.playroom {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 24px;
  align-items: center;
  margin: 28px 0;
  min-height: 340px;
  padding: 26px;
  border: 1px solid #cfe0ea;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.9)),
    repeating-linear-gradient(90deg, #e8f3f8 0 28px, #dff0f7 28px 56px);
}

.toy-gallery {
  position: relative;
  width: 240px;
  height: 280px;
  margin: auto;
}

.toy-gallery img {
  position: absolute;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 18px 18px rgba(39, 71, 100, 0.18));
}

.bluey-main {
  right: 0;
  bottom: 0;
  width: 190px;
  height: 240px;
}

.bluey-side {
  left: 0;
  bottom: 0;
  width: 128px;
  height: 166px;
  opacity: 0.95;
}

.toy-card {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: #0f4a33;
  background: #dff4e8;
  font-size: 13px;
  font-weight: 800;
}

#toyLine {
  min-height: 82px;
  margin: 18px 0;
  font-size: 28px;
  line-height: 1.35;
  font-weight: 850;
}

.line-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.line-meta span {
  padding: 7px 9px;
  border-radius: 6px;
  background: #eef4f7;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

audio {
  width: 100%;
  height: 38px;
}

.input-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 96px 96px;
  gap: 10px;
  align-items: center;
}

.input-row label {
  color: var(--muted);
  font-weight: 800;
}

.input-row input {
  min-width: 0;
  height: 46px;
  padding: 0 14px;
  border: 1px solid #c9d8e2;
  border-radius: 8px;
  background: #fff;
}

.input-row button,
.mode-button,
.prompt-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 850;
}

.input-row button {
  height: 46px;
  color: #fff;
  background: var(--blue-dark);
}

.voice-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  background: var(--leaf) !important;
}

.voice-button.listening {
  background: var(--coral) !important;
}

.voice-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.mic-icon {
  position: relative;
  width: 14px;
  height: 20px;
  border: 2px solid currentColor;
  border-radius: 8px;
}

.mic-icon::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 2px;
  height: 8px;
  transform: translateX(-50%);
  background: currentColor;
}

.mic-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -11px;
  width: 16px;
  height: 2px;
  transform: translateX(-50%);
  background: currentColor;
}

.voice-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.prompt-button {
  min-height: 36px;
  padding: 0 12px;
  color: #214258;
  background: #e9f2f6;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-button {
  min-height: 56px;
  padding: 10px;
  color: #234050;
  background: #edf4f7;
  text-align: left;
}

.mode-button.active {
  color: #fff;
  background: var(--blue);
}

.script-progress {
  display: grid;
  gap: 8px;
}

.script-step {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  padding: 9px;
  border: 1px solid #e0e9ef;
  border-radius: 8px;
  background: #f8fbfd;
}

.script-step.done {
  opacity: 0.62;
}

.script-step.active {
  border-color: #8fc1e7;
  background: #eaf5fc;
}

.step-dot {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  color: #fff;
  background: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.script-step.active .step-dot {
  background: var(--blue-dark);
}

.script-step.done .step-dot {
  background: var(--leaf);
}

.step-title {
  display: block;
  font-size: 13px;
  font-weight: 900;
}

.step-goal {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.library-stats,
.signal-list,
.decision-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.library-stats {
  grid-template-columns: 1fr 1fr;
}

.library-stats div,
.signal-list div,
.decision-list div {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  background: #f5f8fa;
}

.library-stats div {
  grid-template-columns: 42px minmax(0, 1fr);
}

dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

dd {
  margin: 0;
  font-weight: 800;
}

.candidate-panel {
  margin-top: 12px;
  padding: 10px;
  border: 1px solid #dfe9ef;
  border-radius: 8px;
  background: #fbfdfe;
}

.candidate-panel p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.candidate-panel ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.candidate-panel li {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 9px;
  border: 1px solid #e2ebf1;
  border-radius: 8px;
  background: #f6fafc;
  font-size: 13px;
  line-height: 1.4;
}

.candidate-panel li.selected {
  border-color: #8fc1e7;
  background: #eaf5fc;
}

.candidate-line {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.candidate-line strong {
  color: var(--blue-dark);
  font-size: 12px;
}

.candidate-line span,
.candidate-panel small {
  overflow-wrap: anywhere;
}

.candidate-panel small {
  color: var(--muted);
  font-weight: 750;
}

.log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 310px;
  overflow: auto;
  padding-right: 4px;
}

.log-entry {
  padding: 10px 12px;
  border-radius: 8px;
  background: #f4f8fa;
  font-size: 14px;
  line-height: 1.45;
}

.log-entry strong {
  display: block;
  margin-bottom: 4px;
  color: var(--blue-dark);
}

@media (max-width: 900px) {
  body {
    padding-bottom: 146px;
    background: linear-gradient(180deg, #d9effb 0, #f6f9fa 280px);
  }

  .app-shell {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100vw;
    gap: 12px;
    padding: 0 0 132px;
    overflow-x: hidden;
  }

  .stage-panel,
  .control-panel {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
    background: rgba(255, 255, 255, 0.92);
  }

  .stage-panel {
    min-height: auto;
    padding: 14px;
    width: 100%;
    max-width: 100vw;
  }

  .control-panel {
    gap: 14px;
    padding: 14px;
    width: 100%;
    max-width: 100vw;
  }

  .topbar {
    align-items: center;
  }

  .eyebrow {
    margin-bottom: 3px;
    font-size: 12px;
  }

  h1 {
    font-size: 24px;
  }

  .session-meter {
    min-width: 58px;
    min-height: 52px;
  }

  .session-meter span {
    font-size: 20px;
  }

  .playroom {
    grid-template-columns: 1fr;
    gap: 8px;
    min-height: auto;
    margin: 14px 0 12px;
    padding: 12px;
    width: 100%;
    max-width: 100%;
  }

  .toy-gallery {
    width: 100%;
    height: 172px;
    transform: none;
  }

  .bluey-main {
    left: 50%;
    right: auto;
    width: 142px;
    height: 176px;
    transform: translateX(-18%);
  }

  .bluey-side {
    left: calc(50% - 126px);
    width: 98px;
    height: 126px;
  }

  .toy-card {
    padding: 14px;
    min-width: 0;
    width: 100%;
  }

  #toyLine {
    min-height: 64px;
    margin: 12px 0;
    font-size: 22px;
  }

  .line-meta {
    margin-bottom: 10px;
  }

  .line-meta span {
    font-size: 12px;
  }

  audio {
    height: 34px;
  }

  .input-row {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 72px 72px;
    gap: 8px;
    align-items: center;
    width: 100%;
    max-width: 100vw;
    padding: 9px 10px max(9px, env(safe-area-inset-bottom));
    border-top: 1px solid #d7e3ea;
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 -10px 26px rgba(36, 72, 105, 0.14);
  }

  .input-row label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .input-row input {
    height: 48px;
    font-size: 16px;
    width: 100%;
  }

  .input-row button {
    height: 48px;
    min-width: 0;
    padding: 0 8px;
    position: relative;
    z-index: 101;
    -webkit-tap-highlight-color: transparent;
  }

  .voice-hint {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(68px + env(safe-area-inset-bottom));
    z-index: 99;
    margin: 0;
    padding: 7px 12px;
    width: 100%;
    max-width: 100vw;
    border-top: 1px solid #e1ebf1;
    background: rgba(246, 249, 250, 0.97);
    font-size: 12px;
  }

  .quick-prompts {
    flex-wrap: nowrap;
    overflow-x: auto;
    width: calc(100vw - 28px);
    margin: 8px 0 0;
    padding: 0 14px 6px;
    -webkit-overflow-scrolling: touch;
  }

  .prompt-button {
    flex: 0 0 auto;
    min-height: 38px;
    max-width: 240px;
    white-space: nowrap;
  }

  .mode-grid {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    width: calc(100vw - 28px);
    margin: 0;
    padding: 0 14px 6px;
    -webkit-overflow-scrolling: touch;
  }

  .mode-button {
    flex: 0 0 118px;
    min-height: 52px;
  }

  .script-progress {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    width: calc(100vw - 28px);
    margin: 0;
    padding: 0 14px 6px;
    -webkit-overflow-scrolling: touch;
  }

  .script-step {
    flex: 0 0 min(210px, calc(100vw - 56px));
  }

  .signal-list {
    grid-template-columns: 1fr;
  }

  .library-stats {
    grid-template-columns: 1fr 1fr;
  }

  .decision-list {
    grid-template-columns: 1fr;
  }

  .decision-list div {
    grid-template-columns: 70px minmax(0, 1fr);
    align-items: start;
  }

  .candidate-panel li {
    font-size: 12px;
  }

  .log {
    max-height: 220px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: 100%;
    max-width: 100vw;
    padding: 0 0 132px;
  }

  .stage-panel,
  .control-panel {
    padding: 12px;
  }

  .quick-prompts,
  .mode-grid,
  .script-progress {
    width: calc(100vw - 24px);
  }

  .topbar {
    align-items: center;
  }

  h1 {
    font-size: 22px;
  }

  #toyLine {
    font-size: 21px;
  }

  .status-pill {
    min-height: 28px;
    font-size: 12px;
  }
}
