:root {
  --bg0: #0c1218;
  --bg1: #121a22;
  --bg2: #1a2530;
  --line: rgba(232, 238, 244, 0.1);
  --text: #e8eef4;
  --muted: #8b9aab;
  --accent: #3d9b84;
  --accent-2: #c4a35a;
  --danger: #d66a6a;
  --ok: #6bcf8e;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --nav-h: 64px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(61, 155, 132, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(196, 163, 90, 0.12), transparent 50%),
    linear-gradient(180deg, #0a1016 0%, var(--bg0) 40%, #0e151c 100%);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  position: relative;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px;
  background: rgba(12, 18, 24, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--display);
  font-weight: 650;
  font-size: 1.25rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.model-switch select {
  appearance: none;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 28px 8px 12px;
  font-size: 0.78rem;
  font-weight: 500;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 55%, calc(100% - 10px) 55%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  max-width: 150px;
}

.main { padding: 16px; }

.hero-block { margin-bottom: 20px; }
.hero-block h1 {
  font-family: var(--display);
  font-size: 1.85rem;
  line-height: 1.15;
  margin: 0 0 8px;
  letter-spacing: -0.03em;
}
.hero-block p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.menu-list { display: grid; gap: 10px; }
.menu-item {
  display: block;
  text-decoration: none;
  color: inherit;
  background: linear-gradient(145deg, rgba(26, 37, 48, 0.95), rgba(18, 26, 34, 0.9));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.menu-item:active { transform: scale(0.98); }
.menu-item .kicker {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 6px;
  font-weight: 600;
}
.menu-item strong {
  display: block;
  font-size: 1.05rem;
  margin-bottom: 4px;
}
.menu-item span.desc {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}

.panel {
  background: rgba(18, 26, 34, 0.85);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.panel h2 {
  font-family: var(--display);
  font-size: 1.15rem;
  margin: 0 0 10px;
}

label.field {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}
select.input, textarea.input, input.input {
  width: 100%;
  background: var(--bg0);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-size: 1rem;
  margin-bottom: 12px;
}
textarea.input { min-height: 88px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 14px 16px;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary {
  background: linear-gradient(135deg, #2f8f79, #3d9b84 40%, #4aae90);
  color: #06110e;
}
.btn-secondary {
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--line);
}
.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 55%, transparent);
}
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--line);
}
.btn + .btn { margin-top: 8px; }
.btn:disabled { opacity: 0.55; cursor: wait; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--line);
  background: var(--bg0);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.8rem;
}
.chip.active {
  border-color: rgba(61, 155, 132, 0.5);
  color: var(--accent);
  background: rgba(61, 155, 132, 0.12);
}

.chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 52dvh;
  overflow-y: auto;
  padding: 4px 2px 8px;
  -webkit-overflow-scrolling: touch;
}
.bubble {
  max-width: 92%;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.bubble.user {
  align-self: flex-end;
  background: rgba(61, 155, 132, 0.2);
  border: 1px solid rgba(61, 155, 132, 0.35);
  border-bottom-right-radius: 6px;
}
.bubble.coach {
  align-self: stretch;
  background: rgba(196, 163, 90, 0.12);
  border: 1px solid rgba(196, 163, 90, 0.3);
  color: #e8d9b0;
  font-size: 0.85rem;
}
.bubble .who {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.7;
  margin-bottom: 4px;
}

.hint {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
  margin: 0 0 12px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.stat .n {
  font-family: var(--display);
  font-size: 1.35rem;
  display: block;
}
.stat .l {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table-list { display: grid; gap: 8px; }
.row-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--muted) 25%, transparent);
}
.row-item .meta { color: var(--muted); font-size: 0.78rem; }

.word-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 12px;
  max-height: 160px;
  overflow-y: auto;
}
.word-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(61, 155, 132, 0.12);
  border: 1px solid rgba(61, 155, 132, 0.25);
  color: #a8dccf;
}
.word-tag.new {
  background: rgba(196, 163, 90, 0.15);
  border-color: rgba(196, 163, 90, 0.35);
  color: #e8d9b0;
}
.word-remove {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  opacity: 0.65;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}
.word-remove:hover { opacity: 1; }
.hint-mini {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.reading-body {
  font-size: 1.05rem;
  line-height: 1.65;
  color: #dce5ee;
}
.audio-box {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg0);
  border-radius: 12px;
  border: 1px solid var(--line);
}
.audio-box audio { width: 100%; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: #1e2a36;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: .25s ease;
  z-index: 50;
  max-width: 90vw;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(480px, 100%);
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(10, 14, 18, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  z-index: 30;
}
.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 500;
}
.bottom-nav a .ico { font-size: 1.1rem; line-height: 1; }
.bottom-nav a.active { color: var(--accent); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 12px;
  font-size: 0.9rem;
}

@media (min-width: 481px) {
  .app-shell {
    box-shadow: 0 0 0 1px var(--line), 0 20px 60px rgba(0,0,0,.35);
  }
}

.review-box {
  background: var(--bg0);
  border: 1px solid rgba(196, 163, 90, 0.3);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}
.review-box pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: var(--font);
  font-size: 0.88rem;
  line-height: 1.5;
  color: #e8d9b0;
}
.call-item {
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
}
.call-item.is-error {
  border-color: rgba(214, 106, 106, 0.45);
}
.call-item summary {
  list-style: none;
  cursor: pointer;
  padding: 12px;
}
.call-item summary::-webkit-details-marker { display: none; }
.call-summary {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.88rem;
}
.call-body {
  border-top: 1px solid var(--line);
  padding: 10px 12px 12px;
  display: grid;
  gap: 10px;
}
.call-block {
  background: var(--bg0);
  border-radius: 10px;
  padding: 10px;
  border: 1px solid var(--line);
}
.call-block.err {
  border-color: rgba(214, 106, 106, 0.4);
  background: rgba(214, 106, 106, 0.08);
}
.call-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}
.call-block pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  color: #dce5ee;
  max-height: 280px;
  overflow: auto;
}
.badge-err {
  display: inline-block;
  background: rgba(214, 106, 106, 0.2);
  color: #f0a0a0;
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 0.68rem;
  font-weight: 700;
  margin-right: 4px;
}
.math-hud {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 12px;
}
.math-prompt {
  font-family: var(--display);
  font-size: 2.2rem;
  text-align: center;
  margin: 12px 0 8px;
  letter-spacing: -0.02em;
}
.math-answer {
  min-height: 2.4rem;
  text-align: center;
  font-family: var(--display);
  font-size: 1.8rem;
  color: var(--accent);
  border-bottom: 1px solid var(--line);
  margin: 0 auto 12px;
  max-width: 220px;
}
.math-feedback {
  text-align: center;
  min-height: 1.4rem;
  font-size: 0.9rem;
  margin-bottom: 10px;
  color: var(--muted);
}
.math-feedback.ok { color: #8ed9a0; }
.math-feedback.bad { color: #f0a0a0; }
.math-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 280px;
  margin: 0 auto 14px;
}
.math-key {
  border: 1px solid var(--line);
  background: var(--bg1);
  color: var(--text);
  border-radius: 12px;
  padding: 16px 0;
  font-size: 1.25rem;
  font-weight: 600;
  cursor: pointer;
}
.math-key:active { transform: scale(0.96); }
.math-key-wide { grid-column: span 2; }
.math-key-del { color: var(--muted); }
