:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-soft: #f8f6ef;
  --surface-strong: #efeee6;
  --ink: #151711;
  --ink-soft: #3c4038;
  --muted: #74786e;
  --line: #e2ded3;
  --line-strong: #cbc5b7;
  --voice: #137461;
  --voice-soft: #e4f4ee;
  --voice-strong: #0d5b4d;
  --amber: #9a681c;
  --amber-soft: #fbedd2;
  --coral: #a94d43;
  --coral-soft: #f8e4df;
  --shadow: 0 20px 55px rgba(47, 43, 34, 0.09);
  --shadow-soft: 0 10px 26px rgba(47, 43, 34, 0.06);
  --radius: 8px;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.86), rgba(244, 241, 234, 0.96)),
    repeating-linear-gradient(90deg, rgba(21, 23, 17, 0.018) 0, rgba(21, 23, 17, 0.018) 1px, transparent 1px, transparent 12px);
  color: var(--ink);
  font-family: "Avenir Next", "SF Pro Text", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.42;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: 32px;
}

.voice-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.22fr) minmax(330px, 0.78fr);
  grid-template-areas:
    "topbar topbar"
    "stage captions"
    "memory memory"
    "history history";
  gap: 14px;
}

.topbar,
.metric-strip,
.stage,
.captions,
.memory-panel,
.history-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.topbar {
  grid-area: topbar;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  min-height: 88px;
  padding: 20px 22px;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid rgba(19, 116, 97, 0.18);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(255, 253, 248, 0.95), rgba(228, 244, 238, 0.82));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92), 0 8px 20px rgba(19, 116, 97, 0.09);
}

.brand-mark span {
  position: relative;
  width: 7px;
  height: 20px;
  border-radius: 999px;
  background: var(--voice);
  box-shadow: 0 0 0 1px rgba(13, 91, 77, 0.08);
}

.brand-mark span::before,
.brand-mark span::after {
  content: "";
  position: absolute;
  top: 4px;
  width: 7px;
  height: 12px;
  border-radius: 999px;
  background: rgba(19, 116, 97, 0.28);
}

.brand-mark span::before { left: -12px; }
.brand-mark span::after { right: -12px; background: rgba(154, 104, 28, 0.24); }
}

.eyebrow,
.stage-kicker {
  margin: 0 0 5px;
  color: var(--voice);
  font-size: 11px;
  font-weight: 720;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1;
  font-weight: 690;
  letter-spacing: 0;
}

.profile-summary {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

h2 {
  font-size: 13px;
  letter-spacing: 0;
}

h3 {
  margin: 0 0 10px;
  color: var(--voice);
  font-size: 12px;
  letter-spacing: 0;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
}

.pill,
.memory-status {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(248, 246, 239, 0.86);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 760;
  text-transform: lowercase;
}

.pill::before,
.memory-status::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 999px;
  background: var(--muted);
}

.memory-status::before {
  background: var(--voice);
}

.pill[data-state="connecting"] {
  color: var(--amber);
  border-color: rgba(159, 100, 0, 0.28);
  background: var(--amber-soft);
}

.pill[data-state="connecting"]::before {
  background: var(--amber);
}

.pill[data-state="active"] {
  color: var(--voice-strong);
  border-color: rgba(24, 113, 95, 0.28);
  background: var(--voice-soft);
}

.pill[data-state="active"]::before {
  background: var(--voice);
  box-shadow: 0 0 0 5px rgba(24, 113, 95, 0.12);
}

.pill[data-state="error"] {
  color: var(--coral);
  border-color: rgba(180, 73, 61, 0.28);
  background: var(--coral-soft);
}

.pill[data-state="error"]::before {
  background: var(--coral);
}

.metric-strip {
  grid-area: metrics;
  display: none;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  background: rgba(248, 250, 247, 0.92);
}

.metric-strip span {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 850;
  text-align: center;
}

.stage {
  grid-area: stage;
  min-height: 448px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 20px;
  padding: 44px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.96), rgba(250, 248, 241, 0.92)),
    var(--surface);
}

.stage-copy {
  width: min(100%, 520px);
  text-align: center;
}

.stage-title {
  color: var(--ink);
  font-size: 29px;
  font-weight: 680;
  line-height: 1.1;
}

.voice-orb {
  width: min(100%, 410px);
  aspect-ratio: 1.78;
  display: grid;
  place-items: center;
  border: 1px solid rgba(19, 116, 97, 0.16);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(228, 244, 238, 0.42)),
    var(--voice-soft);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.86), var(--shadow-soft);
}

.voice-meter {
  width: min(82%, 318px);
  height: 104px;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.voice-meter span {
  height: 24%;
  min-height: 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, #78d0ba, var(--voice));
  opacity: 0.5;
  transform-origin: center;
  transition: height 180ms ease, opacity 180ms ease, transform 180ms ease;
}

.voice-meter span:nth-child(2n) { height: 42%; }
.voice-meter span:nth-child(3n) { height: 68%; }
.voice-meter span:nth-child(5n) { height: 86%; }

.voice-meter[data-state="active"] span {
  animation: pulse 880ms ease-in-out infinite alternate;
  opacity: 0.92;
}

.voice-meter[data-state="active"] span:nth-child(2n) { animation-delay: 90ms; }
.voice-meter[data-state="active"] span:nth-child(3n) { animation-delay: 180ms; }
.voice-meter[data-state="active"] span:nth-child(5n) { animation-delay: 270ms; }

@keyframes pulse {
  from { transform: scaleY(0.55); }
  to { transform: scaleY(1.14); }
}

.primary-action {
  width: min(100%, 292px);
  min-height: 58px;
  border: 1px solid rgba(13, 91, 77, 0.22);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #17806a, var(--voice-strong));
  color: #ffffff;
  font-size: 16px;
  font-weight: 760;
  cursor: pointer;
  box-shadow: 0 16px 32px rgba(19, 116, 97, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 140ms ease, background 140ms ease, opacity 140ms ease, box-shadow 140ms ease;
}

.primary-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 36px rgba(19, 116, 97, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.primary-action:disabled { cursor: progress; opacity: 0.58; transform: none; }
.primary-action[data-state="active"] {
  border-color: rgba(169, 77, 67, 0.24);
  background: linear-gradient(180deg, #b95d52, var(--coral));
  box-shadow: 0 16px 32px rgba(169, 77, 67, 0.2);
}

.hint {
  min-height: 22px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.warning {
  width: min(100%, 460px);
  padding: 12px 14px;
  border: 1px solid rgba(180, 73, 61, 0.24);
  border-radius: 8px;
  background: var(--coral-soft);
  color: var(--coral);
  font-size: 13px;
}

.captions {
  grid-area: captions;
  display: grid;
  align-content: stretch;
  gap: 1px;
  overflow: hidden;
  background: var(--line);
}

.caption-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 18px;
  min-height: 154px;
  padding: 22px;
  background: rgba(255, 253, 248, 0.92);
}

.caption-label {
  padding-top: 3px;
  color: var(--voice);
  font-size: 11px;
  font-weight: 760;
}

.caption-text {
  min-height: 1.45em;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.46;
  white-space: pre-wrap;
  word-break: break-word;
}

.caption-support {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.38;
  overflow-wrap: anywhere;
}

.memory-panel,
.history-panel {
  padding: 0;
}

.memory-panel {
  grid-area: memory;
  display: block;
}

.history-panel {
  grid-area: history;
  max-height: 312px;
  overflow: auto;
}

.disclosure-panel summary {
  min-height: 60px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 16px 20px;
  cursor: pointer;
  list-style: none;
}

.disclosure-panel summary::-webkit-details-marker {
  display: none;
}

.disclosure-panel summary::after {
  content: "+";
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.72);
  color: var(--voice);
  font-size: 16px;
  font-weight: 750;
}

.disclosure-panel[open] summary::after {
  content: "-";
}

.disclosure-panel summary span {
  color: var(--ink);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0;
}

.disclosure-panel summary small {
  grid-column: 1;
  color: var(--muted);
  font-size: 12px;
}

.memory-panel[open] {
  display: block;
  padding: 0 22px 24px;
}

.history-panel[open] {
  padding: 0 22px 24px;
}

.memory-panel[open] > :not(summary),
.history-panel[open] > :not(summary) {
  width: min(100%, 640px);
  margin-left: auto;
  margin-right: auto;
}

.memory-panel[open] summary,
.history-panel[open] summary {
  margin: 0 -22px;
}

.panel-heading {
  grid-column: 1 / -1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.memory-panel > .panel-heading > div:first-child,
.history-panel > .panel-heading > div:first-child {
  display: none;
}

.memory-panel > .panel-heading,
.history-panel > .panel-heading {
  justify-content: flex-end;
}

.panel-heading p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.secondary-action {
  min-width: 64px;
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.76);
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}

.secondary-action:hover {
  border-color: rgba(24, 113, 95, 0.42);
  color: var(--voice);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.profile-grid label,
.field-block {
  display: grid;
  gap: 7px;
}

.field-block {
  margin-bottom: 14px;
}

.profile-grid span,
.field-block span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.profile-grid b {
  color: var(--ink);
  font-weight: 850;
}

input[type="text"],
select,
.field-block textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 11px 12px;
  background: rgba(248, 246, 239, 0.76);
  color: var(--ink);
  outline: none;
}

select {
  min-height: 40px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--voice);
}

.field-block textarea {
  min-height: 104px;
  resize: vertical;
}

input[type="text"]:focus,
select:focus,
.field-block textarea:focus {
  border-color: rgba(24, 113, 95, 0.62);
  box-shadow: 0 0 0 3px rgba(24, 113, 95, 0.1);
}

.memory-section {
  min-width: 0;
  padding-top: 16px;
  margin-top: 4px;
  border-top: 1px solid var(--line);
}

.compact-list,
.action-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.compact-list li,
.action-list li {
  min-width: 0;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.action-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.action-list strong,
.action-list small {
  display: block;
}

.action-list strong {
  font-size: 13px;
}

.action-list small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.micro-action {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(24, 113, 95, 0.3);
  border-radius: var(--radius);
  background: var(--voice-soft);
  color: var(--voice);
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}

.empty-row {
  color: var(--muted) !important;
}

.history-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.history-role {
  display: block;
  margin-bottom: 4px;
  color: var(--voice);
  font-size: 11px;
  font-weight: 760;
}

.history-text {
  color: var(--ink);
  font-size: 13px;
  overflow-wrap: anywhere;
}

audio {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 900px) {
  .app-shell {
    padding: 18px;
  }

  .voice-panel {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "stage"
      "captions"
      "memory"
      "history";
  }

  .memory-panel {
    display: block;
  }

  .memory-panel[open] {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 20px;
  }

  .status-row {
    justify-content: flex-start;
    flex-wrap: wrap;
    white-space: normal;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 8px;
  }

  .topbar,
  .metric-strip,
  .stage,
  .memory-panel,
  .history-panel {
    padding: 14px;
  }

  .brand-cluster {
    align-items: flex-start;
    gap: 12px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  h1 {
    font-size: 26px;
    line-height: 1.04;
  }

  .metric-strip {
    grid-template-columns: 1fr;
  }

  .stage {
    min-height: 348px;
    gap: 16px;
  }

  .stage-title {
    font-size: 24px;
  }

  .voice-orb {
    aspect-ratio: 1.38;
  }

  .voice-meter {
    width: 84%;
    height: 112px;
    gap: 6px;
  }

  .caption-row {
    grid-template-columns: 1fr;
    min-height: 122px;
    gap: 8px;
    padding: 18px;
  }

  .profile-grid {
    grid-template-columns: 1fr;
  }

  .button-row {
    justify-content: flex-start;
  }

  .memory-panel[open],
  .history-panel[open] {
    padding: 0 16px 18px;
  }

  .memory-panel[open] summary,
  .history-panel[open] summary {
    margin: 0 -16px;
  }

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