:root {
  --bg0: #0f1218;
  --bg1: #1a2333;
  --bg2: #0b0f15;
  --ink: #edf2ff;
  --muted: #8ea2c9;
  --line: #2f3f5f;
  --good: #58f8a5;
  --warn: #ffb347;
  --danger: #ff4365;
  --accent: #67d7ff;
  --card-bg: linear-gradient(160deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
  --panel-bg: #111a2a;
  --pill-bg: rgba(255, 255, 255, 0.04);
  --control-bg: rgba(15, 22, 35, 0.88);
  --ghost-bg: rgba(255, 255, 255, 0.03);
  --history-bg: rgba(0, 0, 0, 0.2);
  --speak-half-bg: linear-gradient(to top, rgba(8, 12, 18, 0.95), rgba(8, 12, 18, 0.4), transparent);
  --upper-height: 50dvh;
  --cta-height: 50dvh;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg0: #edf5ff;
    --bg1: #dcecff;
    --bg2: #c7ddf9;
    --ink: #0f1b2e;
    --muted: #4e6487;
    --line: #a7bddb;
    --card-bg: linear-gradient(160deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.64));
    --panel-bg: #f3f8ff;
    --pill-bg: rgba(255, 255, 255, 0.82);
    --control-bg: rgba(255, 255, 255, 0.9);
    --ghost-bg: rgba(15, 27, 46, 0.04);
    --history-bg: rgba(255, 255, 255, 0.75);
    --speak-half-bg: linear-gradient(to top, rgba(233, 242, 255, 0.96), rgba(233, 242, 255, 0.72), transparent);
  }
}

body[data-theme="dark"] {
  --bg0: #0f1218;
  --bg1: #1a2333;
  --bg2: #0b0f15;
  --ink: #edf2ff;
  --muted: #8ea2c9;
  --line: #2f3f5f;
  --card-bg: linear-gradient(160deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
  --panel-bg: #111a2a;
  --pill-bg: rgba(255, 255, 255, 0.04);
  --control-bg: rgba(15, 22, 35, 0.88);
  --ghost-bg: rgba(255, 255, 255, 0.03);
  --history-bg: rgba(0, 0, 0, 0.2);
  --speak-half-bg: linear-gradient(to top, rgba(8, 12, 18, 0.95), rgba(8, 12, 18, 0.4), transparent);
}

body[data-theme="light"] {
  --bg0: #edf5ff;
  --bg1: #dcecff;
  --bg2: #c7ddf9;
  --ink: #0f1b2e;
  --muted: #4e6487;
  --line: #a7bddb;
  --card-bg: linear-gradient(160deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.64));
  --panel-bg: #f3f8ff;
  --pill-bg: rgba(255, 255, 255, 0.82);
  --control-bg: rgba(255, 255, 255, 0.9);
  --ghost-bg: rgba(15, 27, 46, 0.04);
  --history-bg: rgba(255, 255, 255, 0.75);
  --speak-half-bg: linear-gradient(to top, rgba(233, 242, 255, 0.96), rgba(233, 242, 255, 0.72), transparent);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100dvh;
  padding-bottom: var(--cta-height);
  overflow: hidden;
  color: var(--ink);
  font-family: "Space Grotesk", sans-serif;
  background: radial-gradient(circle at 20% 10%, var(--bg1) 0%, var(--bg0) 40%, var(--bg2) 100%);
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 80% 20%, rgba(103, 215, 255, 0.16), transparent 35%),
    radial-gradient(circle at 10% 80%, rgba(88, 248, 165, 0.12), transparent 40%);
}

.app {
  position: relative;
  z-index: 40;
  max-width: 980px;
  margin: 0 auto;
  height: var(--upper-height);
  padding: 10px 14px;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  grid-column: 1 / -1;
}

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

.account-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

h1,
h2,
p {
  margin: 0;
}

.label {
  color: var(--muted);
  font-size: 0.92rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(1.4rem, 2.4vw, 1.9rem);
}

.stat-pill {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  text-align: right;
  background: var(--pill-bg);
}

.stat-pill p:last-child {
  font-size: 1.15rem;
  font-weight: 700;
}

.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  background: var(--card-bg);
  backdrop-filter: blur(4px);
  min-height: 0;
  overflow: hidden;
}

.main-state {
  display: grid;
  gap: 8px;
  align-content: start;
  grid-template-rows: auto auto auto minmax(2.4em, auto);
}

.big-number {
  font-family: "IBM Plex Mono", monospace;
  font-size: clamp(1.75rem, 3.2vw, 2.45rem);
  font-weight: 700;
}

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

input,
button {
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 8px 10px;
  font: inherit;
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--control-bg);
}

input {
  flex: 1;
  min-width: 170px;
}

button {
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: #4d6797;
}

button:disabled,
input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.primary {
  background: linear-gradient(120deg, #4ecfff, #4d9df7);
  color: #001126;
  border-color: #78d7ff;
  font-weight: 700;
}

.speak-cta {
  width: 100%;
  height: 100%;
  border: 1px solid #8ce8ff;
  border-radius: 0;
  background: linear-gradient(120deg, #6be8ff, #49b8ff);
  color: #001126;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
  min-height: 72px;
  box-shadow: 0 6px 24px rgba(73, 184, 255, 0.35), 0 0 0 2px rgba(255, 255, 255, 0.08) inset;
}

.speak-cta:hover {
  border-color: #b9f2ff;
}

.speak-half {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--cta-height);
  min-height: 0;
  border-top: 1px solid rgba(185, 242, 255, 0.5);
  background: var(--speak-half-bg);
  backdrop-filter: blur(4px);
}

.ghost {
  background: var(--ghost-bg);
}

button.danger {
  border-color: var(--danger);
  color: #ffdbe2;
}

body[data-theme="light"] button.danger {
  background: rgba(200, 32, 62, 0.2);
  border-color: #b01f3e;
  color: #7a0f24;
}

.icon-btn {
  width: 44px;
  min-width: 44px;
  padding: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.status-line {
  color: var(--muted);
  min-height: 1.2em;
  font-size: 1rem;
  overflow-wrap: anywhere;
  line-height: 1.25;
  overflow: visible;
  flex: 1 0 100%;
  min-width: 0;
  display: block;
  margin-top: 4px;
}

.session-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.mono {
  font-family: "IBM Plex Mono", monospace;
  font-size: 1.2rem;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.ratio-wrap {
  margin-top: 8px;
}

.ratio-buttons {
  margin-top: 6px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.ratio-buttons button {
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  font-weight: 700;
  border-color: var(--line);
}

.ratio-buttons button.active {
  border-color: var(--good);
  box-shadow: 0 0 0 1px var(--good) inset;
  background: rgba(88, 248, 165, 0.2);
  color: var(--ink);
}

.ratio-buttons button.danger {
  border-color: var(--danger);
  background: rgba(255, 67, 101, 0.22);
  color: #ffdbe2;
}

body[data-theme="light"] .ratio-buttons button {
  background: rgba(15, 27, 46, 0.08);
}

body[data-theme="light"] .ratio-buttons button.active {
  background: rgba(17, 150, 92, 0.18);
}

body[data-theme="light"] .ratio-buttons button.danger {
  background: rgba(200, 32, 62, 0.2);
  color: #7a0f24;
}

.history {
  max-height: none;
  overflow: hidden;
  display: grid;
  gap: 6px;
}

.history-item {
  font-family: "IBM Plex Mono", monospace;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 8px;
  background: var(--history-bg);
  font-size: 0.98rem;
}

.menu-panel {
  position: fixed;
  z-index: 80;
  left: 50%;
  top: 68px;
  transform: translateX(-50%);
  width: min(980px, calc(100vw - 20px));
  max-height: none;
  overflow: hidden;
  display: grid;
  gap: 10px;
  background: var(--panel-bg);
  backdrop-filter: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

.menu-block {
  display: grid;
  gap: 6px;
}

.session-card {
  align-content: start;
}

.burn-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 25% 20%, rgba(255, 71, 34, 0.8), transparent 30%),
    radial-gradient(circle at 75% 50%, rgba(255, 180, 50, 0.7), transparent 34%),
    radial-gradient(circle at 50% 80%, rgba(180, 15, 0, 0.8), transparent 40%),
    rgba(20, 3, 0, 0.82);
  animation: flame 1.2s infinite alternate;
}

.burn-panel {
  width: min(92vw, 500px);
  border: 1px solid #ff8a50;
  background: rgba(20, 5, 0, 0.86);
  border-radius: 12px;
  padding: 18px;
  display: grid;
  gap: 12px;
}

.hidden {
  display: none;
}

@keyframes flame {
  from {
    filter: saturate(1) brightness(1);
  }
  to {
    filter: saturate(1.3) brightness(1.14);
  }
}

@media (max-width: 680px) {
  :root {
    --upper-height: 66.666dvh;
    --cta-height: 33.334dvh;
  }

  body {
    padding-bottom: var(--cta-height);
  }

  .app {
    padding: 8px 8px 6px;
    gap: 8px;
    height: var(--upper-height);
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) minmax(0, 1fr);
  }

  .top-bar {
    grid-column: 1;
    gap: 8px;
  }

  .card {
    padding: 8px;
  }

  .main-state,
  .session-card {
    gap: 6px;
    align-content: start;
  }

  .main-state .entry-row {
    flex-wrap: nowrap;
    align-items: center;
  }

  .status-line {
    font-size: 0.95rem;
    min-height: 1.2em;
    flex: 1;
    margin-top: 0;
    display: flex;
    align-items: center;
  }

  .big-number {
    font-size: clamp(1.45rem, 6.4vw, 2rem);
  }

  .top-actions {
    gap: 8px;
  }

  .stat-pill {
    padding: 8px 10px;
  }

  .account-title-row h1 {
    font-size: 1.45rem;
  }

  .menu-panel {
    top: 58px;
    width: calc(100vw - 14px);
    max-height: none;
    overflow: hidden;
    gap: 8px;
  }

  .history {
    max-height: none;
  }

  .metrics {
    grid-template-columns: 1fr 1fr;
    margin-top: 4px;
    gap: 6px;
  }

  .label {
    font-size: 0.82rem;
  }

  input,
  button {
    padding: 8px 10px;
    font-size: 1rem;
  }

  .speak-half {
    min-height: 0;
  }

  .speak-cta {
    font-size: clamp(1.35rem, 6vw, 2rem);
  }
}
