:root {
  color-scheme: light dark;
  --bg: #f5f1e8;
  --ink: #1f2326;
  --muted: #66707c;
  --line: #d7d2c6;
  --panel: #ffffff;
  --accent: #146c94;
  --accent-strong: #0f5676;
  --accent-soft: #dff2f6;
  --gold: #e4a11b;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(23, 29, 36, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(20, 108, 148, 0.11), transparent 42%),
    linear-gradient(315deg, rgba(228, 161, 27, 0.14), transparent 40%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(100%, 360px);
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.auth-logo {
  width: 76px;
  height: 76px;
  border-radius: 18px;
}

.auth-card h1 {
  margin: 2px 0 0;
  font-size: 28px;
  letter-spacing: 0;
}

.auth-card p {
  margin: 0;
  color: var(--muted);
}

.auth-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.auth-field input {
  height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font-size: 18px;
}

.auth-error {
  min-height: 18px;
  color: var(--danger) !important;
  font-size: 13px;
}

.app {
  width: min(1220px, calc(100% - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
}

.toolbar,
.panel {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  gap: 16px;
  padding: 14px;
  border-radius: 8px;
}

.brand {
  min-width: 230px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: 0;
}

.statusbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 8px 14px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.6);
  font-size: 12px;
  color: var(--muted);
}

.statusbar p {
  margin: 0;
}

.statusbar .quiet-note {
  color: var(--accent-strong);
  font-weight: 700;
}

.statusbar .cost-note {
  font-variant-numeric: tabular-nums;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.status-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #7a8088;
  box-shadow: 0 0 0 4px rgba(122, 128, 136, 0.14);
}

.status-dot.live {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(20, 108, 148, 0.16);
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(180, 35, 24, 0.16);
}

.controls {
  display: flex;
  align-items: end;
  justify-content: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.text-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.text-entry textarea {
  min-height: 48px;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 16px;
  line-height: 1.35;
}

.text-entry button {
  align-self: stretch;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
}

button {
  min-width: 76px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: #9aa5b1;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

button.primary:hover:not(:disabled) {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

button.stop {
  border-color: var(--danger);
  background: var(--danger);
  color: white;
}

button[aria-pressed="true"] {
  border-color: var(--gold);
  background: #fff5d6;
}

.icon-button {
  width: 150px;
  padding: 0 12px;
  font-size: 20px;
  line-height: 1;
}

#clearButton {
  width: 116px;
}

#sessionButton {
  width: 94px;
}

.target-selector {
  width: 292px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.target-pill {
  position: relative;
  min-width: 0;
  padding: 0 12px 0 28px;
  font-weight: 750;
  white-space: nowrap;
}

.target-pill::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: transparent;
  transform: translateY(-50%);
}

.target-pill[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.target-pill[aria-pressed="true"]::before {
  background: currentColor;
}

.workspace {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  min-height: 0;
}

.panel {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-height: 0;
  border-radius: 8px;
  overflow: hidden;
}

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

.panel-title span {
  font-weight: 750;
}

.button-row {
  display: flex;
  gap: 8px;
}

.meter {
  height: 8px;
  background: #e4e6e8;
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transition: width 90ms linear;
}

.audio-state {
  height: 8px;
  overflow: hidden;
  color: transparent;
  background: #e4e6e8;
}

.audio-state.live {
  background: linear-gradient(90deg, var(--accent), var(--gold));
}

textarea {
  width: 100%;
  height: 100%;
  min-height: 520px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 22px;
  background: var(--panel);
  color: var(--ink);
  font-size: 20px;
  line-height: 1.55;
}

@media (min-width: 1060px) {
  .toolbar {
    grid-template-columns: minmax(260px, 1fr) auto;
  }

  .controls {
    justify-content: flex-end;
  }
}

@media (max-width: 860px) {
  .app {
    width: min(100% - 20px, 1220px);
    margin: 10px auto;
  }

  .toolbar,
  .text-entry,
  .workspace {
    display: grid;
    grid-template-columns: 1fr;
  }

  .controls {
    justify-content: stretch;
  }

  .field,
  .target-selector,
  button {
    width: 100%;
  }

  .target-selector {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .icon-button,
  #clearButton,
  #sessionButton {
    width: 100%;
  }

  .action-row {
    width: 100%;
  }

  .action-row .icon-button,
  .action-row #clearButton {
    width: 100%;
    min-width: 0;
  }

  .button-row {
    width: 100%;
  }

  button {
    height: 44px;
  }

  #sessionButton {
    height: 52px;
    font-weight: 700;
  }

  textarea {
    min-height: 180px;
    padding: 16px;
    font-size: 18px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151513;
    --ink: #f0f1ec;
    --muted: #a6aca4;
    --line: #383a35;
    --panel: #20231f;
    --accent-soft: #163845;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  }

  .toolbar,
  .panel,
  .auth-card {
    background: rgba(32, 35, 31, 0.9);
  }

  button[aria-pressed="true"] {
    background: #3a2d0d;
  }

}
