/* ============================================================
   日语口语训练站 — 样式
   深色、克制、手机优先。日语字号要够大，练习时一眼能看清。
   ============================================================ */

:root {
  --bg:        #12141a;
  --bg-soft:   #1a1d26;
  --bg-raise:  #222633;
  --line:      #2e3340;
  --text:      #e6e8ee;
  --muted:     #8a90a2;
  --accent:    #e8a33d;
  --accent-dk: #b8792a;
  --good:      #4caf83;
  --slow:      #d9a441;
  --fail:      #d9534f;
  --radius:    14px;
  --font-ja:   "Yu Gothic UI", "Yu Gothic", "Hiragino Sans", "Meiryo",
               "Noto Sans JP", system-ui, sans-serif;
  --font-zh:   "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB",
               system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-zh);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------------- 顶栏 ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(18, 20, 26, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .04em;
  color: var(--accent);
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 4px;
  margin: 0 auto;
  background: var(--bg-soft);
  padding: 3px;
  border-radius: 999px;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 36px;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.tab.is-active { background: var(--bg-raise); color: var(--text); font-weight: 600; }
.tab:not(.is-active):hover { color: var(--text); }

.icon-btn {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 17px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  flex: 0 0 auto;
  transition: color .15s, border-color .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--muted); }

/* ---------------- 主区 ---------------- */

main {
  flex: 1;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 18px 16px 48px;
  padding-bottom: calc(48px + env(safe-area-inset-bottom));
}

.view { display: flex; flex-direction: column; gap: 16px; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-stats { justify-content: space-between; }
.row-controls { justify-content: flex-start; }

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 84px;
}
.stat-label { font-size: 11px; color: var(--muted); letter-spacing: .08em; }
.stat-value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

.muted { color: var(--muted); }
.hint { font-size: 13px; line-height: 1.55; margin: 6px 0 0; }
.label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

/* ---------------- 按钮 ---------------- */

.btn {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  min-height: 44px;
  transition: filter .15s, background .15s, border-color .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #1a1206; font-weight: 700; }
.btn-primary:hover:not(:disabled) { background: #f0ae4d; }

.btn-ghost { background: var(--bg-soft); color: var(--text); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-raise); border-color: var(--muted); }

.btn-sm { min-height: 38px; padding: 7px 12px; font-size: 13px; }

.btn-huge {
  min-height: 62px;
  font-size: 17px;
  width: 100%;
  border-radius: 12px;
}

.btn-danger { color: var(--fail); border-color: #4a2b2b; }
.btn-danger:hover:not(:disabled) { background: #2a1a1a; }

.btn-rate {
  flex: 1;
  min-height: 54px;
  font-size: 15px;
  font-weight: 600;
  background: var(--bg-raise);
  color: var(--text);
  border: 1px solid var(--line);
}
.btn-rate.good:hover { border-color: var(--good); color: var(--good); }
.btn-rate.slow:hover { border-color: var(--slow); color: var(--slow); }
.btn-rate.fail:hover { border-color: var(--fail); color: var(--fail); }

.kbd {
  font-size: 11px;
  font-family: var(--font-zh);
  padding: 1px 6px;
  border: 1px solid currentColor;
  border-radius: 4px;
  opacity: .55;
  font-weight: 400;
}

/* ---------------- 抢答舞台 ---------------- */

.stage {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 20px;
  min-height: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
}

.stage-scene {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .12em;
  min-height: 18px;
}

.stage-prompt {
  font-size: clamp(24px, 6vw, 34px);
  font-weight: 700;
  line-height: 1.45;
  font-family: var(--font-ja);
  word-break: break-word;
  max-width: 100%;
}

.stage-timer {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-height: 20px;
  letter-spacing: .06em;
}
.stage-timer.is-over { color: var(--fail); font-weight: 700; }

.answer {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: fade-in .18s ease;
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.answer-ja {
  font-family: var(--font-ja);
  font-size: clamp(20px, 5vw, 27px);
  font-weight: 700;
  line-height: 1.55;
  color: var(--accent);
  padding: 14px 16px;
  background: rgba(232, 163, 61, .08);
  border: 1px solid rgba(232, 163, 61, .25);
  border-radius: 10px;
}

.answer-alts {
  font-family: var(--font-ja);
  font-size: 14px;
  color: var(--muted);
  line-height: 1.7;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.answer-note {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  text-align: left;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
  border-left: 2px solid var(--line);
}

.rate-row { display: flex; gap: 10px; width: 100%; }

.empty {
  text-align: center;
  padding: 44px 16px;
  color: var(--text);
}
.empty p { margin: 6px 0; }

/* ---------------- 面板 / 输入 ---------------- */

.panel {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.input, .select, textarea {
  font: inherit;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  min-height: 44px;
  outline: none;
  transition: border-color .15s;
  width: 100%;
}
.input:focus, .select:focus, textarea:focus { border-color: var(--accent); }

textarea {
  resize: vertical;
  font-family: var(--font-zh);
  line-height: 1.6;
  min-height: 84px;
}

.select { cursor: pointer; width: auto; min-width: 120px; }

.row-controls > .btn { flex: 0 0 auto; }
.row-controls > .input { flex: 1 1 200px; width: auto; }

/* ---------------- 自言自语 ---------------- */

.status {
  font-size: 13px;
  color: var(--muted);
  min-height: 20px;
}
.status.is-error { color: var(--fail); }

.results {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  cursor: pointer;
  transition: border-color .15s;
  text-align: left;
}
.result-card:hover { border-color: var(--muted); }
.result-card.is-selected { border-color: var(--accent); background: rgba(232, 163, 61, .06); }

.result-check {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin-top: 3px;
  accent-color: var(--accent);
  pointer-events: none;
}

.result-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 7px; }

.result-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.pill {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--bg-raise);
  color: var(--muted);
  letter-spacing: .04em;
  border: 1px solid var(--line);
}
.pill-polite { color: #79b8ff; border-color: #26405e; }
.pill-cushion { color: var(--accent); border-color: #5c4420; }
.pill-casual { color: var(--good); border-color: #23492f; }
.pill-rescue { color: var(--fail); border-color: #4a2b2b; }

.result-ja {
  font-family: var(--font-ja);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.55;
  color: var(--text);
  word-break: break-word;
}

.result-chunk {
  font-family: var(--font-ja);
  font-size: 13px;
  color: var(--accent);
}

.result-note { font-size: 12.5px; color: var(--muted); line-height: 1.55; }

/* ---------------- 句块本 ---------------- */

.book-meta { font-size: 12px; letter-spacing: .04em; }

.book-list { display: flex; flex-direction: column; gap: 10px; }

.book-item {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.book-item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.book-item-ja {
  font-family: var(--font-ja);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.55;
  word-break: break-word;
}

.book-item-zh { font-size: 13px; color: var(--muted); }

.book-item-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: var(--muted);
  padding-top: 4px;
  border-top: 1px dashed var(--line);
}

.book-item-foot .spacer { flex: 1; }

.mini-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}
.mini-btn:hover { color: var(--fail); background: #2a1a1a; }

.srs-badge {
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.srs-badge.due { color: var(--accent); border-color: #5c4420; }
.srs-badge.new { color: #79b8ff; border-color: #26405e; }
.srs-badge.weak { color: var(--fail); border-color: #4a2b2b; }

/* ---------------- 弹窗 ---------------- */

.dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg-soft);
  color: var(--text);
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 64px);
}
.dialog::backdrop { background: rgba(0, 0, 0, .65); backdrop-filter: blur(3px); }

.dialog-inner {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  max-height: calc(100dvh - 64px);
}
.dialog h2 { margin: 0; font-size: 18px; }
.dialog h3 { margin: 0; font-size: 14px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.dialog hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; width: 100%; }
.dialog-actions { justify-content: flex-end; }

/* ---------------- 手机 ---------------- */

@media (max-width: 560px) {
  main { padding: 12px 12px 40px; }

  .brand { display: none; }
  .tabs { margin: 0 auto; }

  .row-stats { gap: 8px; }
  .stat { min-width: 0; flex: 1; padding: 7px 10px; }
  .stat-value { font-size: 15px; }
  .row-stats .btn { flex-basis: 100%; }

  .stage { min-height: 340px; padding: 20px 14px; }

  .tab { padding: 7px 11px; font-size: 13px; }

  .book-item-foot { font-size: 11px; }
}

/* ---------------- 语音 ---------------- */

.voice-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.voice-status {
  font-size: 12px;
  color: var(--muted);
  min-height: 16px;
}
.voice-status.is-error { color: var(--fail); }
.voice-status.is-ok { color: var(--good); }

.rec-bar {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.rec-bar audio {
  width: 100%;
  height: 36px;
  filter: invert(.88) hue-rotate(180deg);
}

.rec-bar .row { justify-content: center; }

.rec-info {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-height: 16px;
  text-align: center;
}
.rec-info.is-warn { color: var(--fail); font-weight: 600; }

.rec-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-rec-active {
  border-color: var(--fail) !important;
  color: var(--fail) !important;
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .45; }
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  cursor: pointer;
  min-height: 32px;
}
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); }

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  min-height: 34px;
}
.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  min-height: 24px;
}
.label-inline { color: var(--muted); white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; min-width: 38px; text-align: right; }

.speak-btn {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, border-color .15s;
  padding: 0;
}
.speak-btn:hover { color: var(--accent); border-color: var(--accent); }
.speak-btn.is-speaking { color: var(--accent); border-color: var(--accent); }

@media (max-width: 560px) {
  .voice-row .btn { flex: 1 1 auto; }
  .voice-status { flex-basis: 100%; text-align: center; }
}

/* ---------------- 这句话自然吗 ---------------- */

.nat-result {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.verdict {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
}

.verdict-badge {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  letter-spacing: .04em;
  white-space: nowrap;
}

.verdict-summary {
  font-size: 14.5px;
  line-height: 1.55;
  padding-top: 3px;
}

.verdict-natural { border-color: #23492f; background: rgba(76, 175, 131, .07); }
.verdict-natural .verdict-badge { color: var(--good); border: 1px solid #23492f; background: rgba(76, 175, 131, .12); }

.verdict-slight { border-color: #5c4420; background: rgba(217, 164, 65, .07); }
.verdict-slight .verdict-badge { color: var(--slow); border: 1px solid #5c4420; background: rgba(217, 164, 65, .12); }

.verdict-unnatural { border-color: #4a2b2b; background: rgba(217, 83, 79, .07); }
.verdict-unnatural .verdict-badge { color: var(--fail); border: 1px solid #4a2b2b; background: rgba(217, 83, 79, .12); }

.issues { display: flex; flex-direction: column; gap: 10px; }

.issue {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-left: 3px solid var(--slow);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.issue-part {
  font-family: var(--font-ja);
  font-size: 15px;
  font-weight: 600;
  color: var(--slow);
  word-break: break-word;
}

.issue-problem { font-size: 14px; line-height: 1.55; }

.issue-why { font-size: 12.5px; color: var(--muted); line-height: 1.55; }

.rewrites { display: flex; flex-direction: column; gap: 10px; }

.rewrite-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.nat-extra {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
  border-left: 2px solid var(--line);
}

.section-title {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .1em;
  margin: 4px 0 -4px;
}

/* ---------------- 口令闸门 ---------------- */

.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

/* .gate 用了 display:flex，hidden 属性会失效，必须显式覆盖 */
.gate[hidden] { display: none; }

.gate-card {
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.gate-brand {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .08em;
}

.gate-card p { margin: 0; font-size: 13px; }
.gate-card .input { text-align: center; font-size: 16px; }

.gate-msg {
  min-height: 20px;
  font-size: 13px;
  color: var(--fail);
  line-height: 1.5;
}

.btn-block { width: 100%; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}