:root {
  --bg0: #0f1419;
  --bg1: #1a222d;
  --bg2: #243040;
  --line: #314155;
  --text: #e8eef6;
  --muted: #8fa3b8;
  --accent: #5eb1ff;
  --ok: #3ecf8e;
  --bad: #f07178;
  --warn: #e6c07b;
  --focus: #5eb1ff;
  --radius: 14px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "Cascadia Code", "Consolas", "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, #1d3a55 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #1a4034 0%, transparent 50%),
    var(--bg0);
  min-height: 100vh;
}

button, input { font: inherit; }
button {
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  background: var(--bg2);
  color: var(--text);
  padding: 0.65rem 1rem;
  transition: background .15s, transform .1s;
}
button:hover { background: #2c3c50; }
button:active { transform: translateY(1px); }
button.primary {
  background: linear-gradient(180deg, #4f8cff, #2f6fe0);
  color: #fff;
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.05); }
button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}
button:disabled { opacity: .45; cursor: not-allowed; }

.app {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.brand {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: .02em;
}
.brand span { color: #7ec8ff; }
.stats {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: .85rem;
}
.stats b { color: var(--text); font-weight: 600; }

.panel {
  background: color-mix(in srgb, var(--bg1) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  backdrop-filter: blur(8px);
}

.hidden { display: none !important; }

h1, h2, h3 { margin: 0 0 .75rem; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }

.lesson-grid {
  display: grid;
  gap: .65rem;
  margin-top: 1rem;
}
.lesson {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  text-align: left;
  padding: .9rem 1rem;
  background: var(--bg2);
  border: 1px solid transparent;
}
.lesson:hover { border-color: #4a6a8a; }
.lesson .meta { color: var(--muted); font-size: .82rem; }
.lesson .title { font-weight: 600; }
.progress-pill {
  white-space: nowrap;
  font-size: .8rem;
  color: #b7d4f5;
  background: #24384f;
  padding: .25rem .55rem;
  border-radius: 999px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: 1rem;
}

.prompt {
  font-size: 1.2rem;
  line-height: 1.55;
  white-space: pre-wrap;
  margin: .5rem 0 1.25rem;
  min-height: 3.5rem;
}

.audio-row {
  display: flex;
  gap: .5rem;
  align-items: center;
  margin-bottom: 1rem;
}
.audio-btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: #27435f;
}
.audio-btn svg { width: 18px; height: 18px; fill: currentColor; }

.answer-box {
  display: grid;
  gap: .65rem;
}
.answer-box input[type="text"] {
  width: 100%;
  padding: .85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #121820;
  color: var(--text);
  outline: none;
  font-size: 1.15rem;
  font-family: var(--mono);
  text-align: center;
}
.answer-box input:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(94, 177, 255, .2);
}
.answer-box input.ok { border-color: var(--ok); }
.answer-box input.bad { border-color: var(--bad); }

.conj-grid {
  display: grid;
  gap: .55rem;
}
.conj-row {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: .55rem;
  align-items: center;
}
.conj-row label {
  color: var(--muted);
  font-family: var(--mono);
  font-size: .95rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: 1rem;
}

.feedback {
  margin-top: 1rem;
  padding: .85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #141c26;
  line-height: 1.5;
}
.feedback.ok { border-color: color-mix(in srgb, var(--ok) 55%, var(--line)); color: #b8f5d4; }
.feedback.bad { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); color: #ffc3c7; }
.feedback .ans {
  margin-top: .35rem;
  font-family: var(--mono);
  color: var(--text);
}

.bar {
  height: 6px;
  background: #1b2734;
  border-radius: 999px;
  overflow: hidden;
  margin: .75rem 0 1rem;
}
.bar > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3ecf8e, #5eb1ff);
  transition: width .25s ease;
}

.settings {
  display: grid;
  gap: .75rem;
  margin-top: 1rem;
}
.settings label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
}
.settings input[type="number"] {
  width: 5rem;
  padding: .4rem .55rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #121820;
  color: var(--text);
}

.done-card {
  text-align: center;
  padding: 2rem 1rem;
}
.done-card .big {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: .5rem;
}

.hist-sub {
  margin: 1.25rem 0 .55rem;
  font-size: 1rem;
  color: var(--muted);
  font-weight: 600;
}
.history-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .55rem;
  margin: .75rem 0 1rem;
}
.hist-stat {
  background: var(--bg2);
  border-radius: 12px;
  padding: .75rem .5rem;
  text-align: center;
}
.hist-stat b {
  display: block;
  font-size: 1.2rem;
  margin-bottom: .2rem;
}
.hist-stat span {
  color: var(--muted);
  font-size: .78rem;
}
.history-list {
  display: grid;
  gap: .45rem;
}
.hist-item {
  background: var(--bg2);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: .7rem .85rem;
}
.hist-item.ok { border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.hist-item.bad { border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.hist-title {
  font-size: .95rem;
  line-height: 1.4;
  margin-bottom: .2rem;
}
.hist-meta {
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.4;
}
.hist-empty {
  color: var(--muted);
  padding: .75rem 0;
  font-size: .9rem;
}

@media (max-width: 560px) {
  .history-summary { grid-template-columns: repeat(2, 1fr); }
}

.sync-banner {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  margin-bottom: .85rem;
  padding: .75rem .9rem;
  border-radius: 12px;
  background: #1c2e22;
  border: 1px solid #2f5a40;
  color: #c9f0d8;
  font-size: .9rem;
}
.sync-banner.install {
  background: #1a2838;
  border-color: #355577;
  color: #cfe3f8;
}
.sync-card {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 12px;
  background: var(--bg2);
  border: 1px solid var(--line);
}
.sync-card h3 {
  margin: 0 0 .4rem;
  font-size: 1.05rem;
}
.field {
  display: grid;
  gap: .35rem;
  margin: .75rem 0;
  color: var(--muted);
  font-size: .88rem;
}
.field input {
  width: 100%;
  padding: .7rem .8rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #121820;
  color: var(--text);
}
.checkline {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .75rem;
  color: var(--muted);
  font-size: .9rem;
}
.sync-msg {
  min-height: 1.2em;
  margin: .65rem 0 0;
  font-size: .88rem;
  color: #b7d4f5;
}
.sync-msg.err { color: #ffb4b8; }
.sync-msg.ok { color: #b8f5d4; }

.study-actions {
  position: sticky;
  bottom: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

@media (max-width: 560px) {
  .prompt { font-size: 1.05rem; }
  .conj-row { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .toolbar { gap: .45rem; }
  .toolbar button { flex: 1 1 calc(50% - .45rem); }
  .answer-box input[type="text"] {
    font-size: 1.05rem;
    padding: 1rem .85rem;
  }
  .audio-btn { min-height: 44px; }
  .actions button { min-height: 44px; }
}
