/* ============ 日本語スプリント ============ */

:root {
  --bg:        #f6f1e7;
  --panel:     #fffdf8;
  --ink:       #2a2723;
  --muted:     #6f6656;
  --line:      #e9e0d0;
  --accent:    #d9482f;
  --accent-soft: #f8e3de;
  --green:     #2f9e63;
  --red:       #d9482f;
  --shadow:    0 10px 30px rgba(80, 60, 30, .10), 0 2px 8px rgba(80, 60, 30, .06);
  --radius:    20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #17151b;
    --panel:     #211f27;
    --ink:       #ece7dd;
    --muted:     #8f8a96;
    --line:      #322f3b;
    --accent:    #ff6a4d;
    --accent-soft: #3a2622;
    --green:     #3fb877;
    --red:       #ff5c5c;
    --shadow:    0 10px 30px rgba(0, 0, 0, .45), 0 2px 8px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overscroll-behavior: none; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
               "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic Medium", Meiryo, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

.hidden { display: none !important; }

/* ---- home ---- */

#home {
  max-width: 460px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100dvh;
}

.home-header { text-align: center; padding-top: 12px; }

.home-header h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: .02em;
}

.home-header h1 span { color: var(--accent); }

.subtitle {
  margin-top: 4px;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .32em;
  color: var(--muted);
}

.lib-stats { margin-top: 10px; font-size: .82rem; color: var(--muted); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.field { display: flex; flex-direction: column; gap: 9px; }

.field-label {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-label small { text-transform: none; letter-spacing: 0; font-weight: 500; }

/* segmented control */

.seg {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 4px;
  gap: 4px;
}

.seg button {
  flex: 1;
  padding: 11px 6px;
  border-radius: 10px;
  font-size: .92rem;
  font-weight: 600;
  color: var(--muted);
  transition: background .15s, color .15s, box-shadow .15s;
}

.seg button.on {
  background: var(--panel);
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .10);
}

/* chips */

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

.chip {
  padding: 11px 16px;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: .88rem;
  font-weight: 600;
  color: var(--muted);
  transition: background .15s, color .15s, border-color .15s;
}

.chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* count stepper */

.count-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.step-btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 1.4rem;
  line-height: 1;
  color: var(--ink);
}

.step-btn:active { background: var(--accent-soft); }

.count-val {
  min-width: 2.4ch;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.count-presets { margin-left: auto; }

/* start */

#startBtn {
  margin-top: 2px;
  height: 56px;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .02em;
  box-shadow: 0 6px 18px rgba(217, 72, 47, .35);
  transition: transform .1s, opacity .15s;
}

#startBtn:active { transform: scale(.98); }

#startBtn:disabled { opacity: .45; box-shadow: none; cursor: default; }

.match-info { text-align: center; font-size: .8rem; color: var(--muted); min-height: 1.2em; }

.home-footer { text-align: center; font-size: .75rem; color: var(--muted); margin-top: auto; }

/* ---- sprint ---- */

#sprint {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  max-width: 640px;
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
}

.sprint-top { display: flex; align-items: center; gap: 14px; }

#quitBtn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  font-size: 1.05rem;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--panel);
  flex-shrink: 0;
}

.bar {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

#barFill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transition: width .3s ease;
}

.counter {
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* card */

.card-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .15s ease, transform .15s ease;
  min-height: 0;
}

.card-stage.swap { opacity: 0; transform: translateX(-14px); }

.card {
  perspective: 1400px;
  width: min(100%, 540px);
  height: min(100%, 420px);
  cursor: pointer;
  outline: none;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.2, .7, .3, 1);
}

.card-inner.no-anim { transition: none; }

.card.flipped .card-inner { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 30px 26px;
  text-align: center;
  overflow: hidden;
}

.face.back { transform: rotateY(180deg); }

.face-label {
  position: absolute;
  top: 18px;
  left: 0;
  right: 0;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--muted);
}

.face-main {
  font-size: clamp(1.7rem, 7.5vw, 2.6rem);
  font-weight: 700;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.face-main.long { font-size: clamp(1.15rem, 5vw, 1.7rem); }

.face-main[lang="ja"] { font-weight: 600; }

.face-sub {
  font-size: clamp(.95rem, 3.8vw, 1.15rem);
  color: var(--muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.face-sub:empty { display: none; }

.face-tag {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 88%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: .7rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 5px 12px;
}

/* bottom controls */

.sprint-bottom {
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.flip-hint {
  font-size: .8rem;
  color: var(--muted);
  transition: opacity .2s;
}

.answer-bar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  visibility: hidden; /* keeps the hidden buttons out of the tab order */
  transition: opacity .2s ease, transform .2s ease, visibility 0s linear .2s;
}

.answer-bar.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  visibility: visible;
  transition: opacity .2s ease, transform .2s ease;
}

.ans-btn {
  flex: 1;
  max-width: 240px;
  height: 64px;
  border-radius: 20px;
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  transition: transform .1s;
}

.ans-btn:active { transform: scale(.96); }

.ans-btn.correct { background: var(--green); box-shadow: 0 6px 18px rgba(47, 158, 99, .35); }

.ans-btn.wrong { background: var(--red); box-shadow: 0 6px 18px rgba(217, 72, 47, .3); }

/* ---- end overlay ---- */

.end-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}

.end-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  width: min(100%, 420px);
  max-height: 86dvh;
  overflow: auto;
  padding: 30px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.end-kicker { color: var(--accent); font-weight: 700; }

.end-score { font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }

.end-pct { color: var(--muted); font-size: .95rem; }

.wrong-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; text-align: left; }

.wrong-list:empty { display: none; }

.wrong-item {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
}

.wrong-item .wi-ja { font-weight: 600; }

.wrong-item .wi-en { font-size: .82rem; color: var(--muted); margin-top: 2px; }

.end-actions { display: flex; gap: 10px; margin-top: 12px; }

.end-actions button { flex: 1; height: 52px; border-radius: 15px; font-weight: 700; font-size: .98rem; }

.end-actions .primary { background: var(--accent); color: #fff; }

.end-actions .ghost { border: 1px solid var(--line); color: var(--ink); background: var(--panel); }

/* ---- fatal error ---- */

.fatal {
  position: fixed;
  inset: auto 16px 16px;
  background: var(--red);
  color: #fff;
  border-radius: 14px;
  padding: 14px 18px;
  font-size: .88rem;
  z-index: 20;
  box-shadow: var(--shadow);
}

/* wide screens: breathe a little */

@media (min-width: 700px) {
  .home-header h1 { font-size: 2.8rem; }
  .face-main { font-size: clamp(2rem, 4vw, 3rem); }
}
