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

:root {
  --bg: #fdf6ec;
  --card: #ffffff;
  --ink: #2d2a32;
  --muted: #8b8698;
  --accent: #7c5cff;
  --accent-soft: #ece6ff;
  --good: #22b573;
  --bad: #ff5a5f;
  --warn: #ffb020;
  --ring-track: #efe8db;
  --shadow: 0 6px 24px rgba(60, 40, 120, 0.12);
  --radius: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a24;
    --card: #2a2735;
    --ink: #f3f0fa;
    --muted: #a49fb5;
    --accent: #9d85ff;
    --accent-soft: #3a3352;
    --ring-track: #3a3646;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  }
}

html, body { height: 100%; }

body {
  font-family: "Fredoka", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 900px;
  margin: 0 auto;
  padding: 12px 16px;
  gap: 10px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.brand {
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
}

.player {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(0.85rem, 3vw, 1rem);
}

.nick {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 4px 12px;
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  max-width: 44vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scorebox { font-weight: 600; white-space: nowrap; }
.scorebox.best { color: var(--muted); }

/* ---------- Realm chips ---------- */
.realms {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.realms::-webkit-scrollbar { display: none; }

.realm-chip {
  flex: 0 0 auto;
  border: 2px solid transparent;
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
}
.realm-chip:active { transform: scale(0.94); }
.realm-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---------- Stage: timer + card ---------- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 8px 0;
}

/* Landscape / wide screens: timer beside the card */
@media (min-width: 640px) and (orientation: landscape), (min-width: 820px) {
  .stage { flex-direction: row; }
}

.timer-wrap {
  position: relative;
  width: clamp(110px, 22vmin, 160px);
  height: clamp(110px, 22vmin, 160px);
  flex: 0 0 auto;
}

.timer-ring { width: 100%; height: 100%; transform: rotate(-90deg); }

.ring-bg {
  fill: none;
  stroke: var(--ring-track);
  stroke-width: 10;
}

.ring-fg {
  fill: none;
  stroke: var(--good);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 326.7;  /* 2πr, r=52 */
  stroke-dashoffset: 0;
}

.timer-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.timer-emoji { font-size: clamp(1.6rem, 6vmin, 2.4rem); line-height: 1.1; }
.timer-secs { font-size: clamp(1.1rem, 4vmin, 1.5rem); font-weight: 700; }

.timer-wrap.urgent { animation: pulse 0.5s infinite alternate; }
@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

/* ---------- Sentence card ---------- */
.card {
  position: relative; /* anchors the docked pause button */
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(18px, 4vw, 32px);
  padding-right: clamp(34px, 6vw, 48px); /* room for the docked pause button */
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.realm-label {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 8px;
  padding: 2px 10px;
  font-weight: 600;
  text-transform: capitalize;
}

.streak-label { margin-left: auto; font-weight: 600; color: var(--warn); }

.zh-toggle {
  border: 2px solid var(--ring-track);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 2px 10px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  touch-action: manipulation;
}
.zh-toggle.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.translation {
  font-size: clamp(0.85rem, 3vw, 1rem);
  color: var(--muted);
  line-height: 1.6;
}

.sentence {
  font-size: clamp(1.15rem, 4.5vw, 1.6rem);
  line-height: 2;
  word-break: normal;
  overflow-wrap: break-word;
}

.blank {
  display: inline-block;
  border: none;
  border-bottom: 3px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  text-align: center;
  outline: none;
  padding: 0 2px;
  margin: 0 2px;
  border-radius: 4px 4px 0 0;
  min-width: 3.5ch;
  transition: background 0.15s, border-color 0.15s;
}
.blank:focus { background: var(--accent-soft); }
.blank.ok { color: var(--good); border-bottom-color: var(--good); }
.blank.nope { color: var(--bad); border-bottom-color: var(--bad); animation: shake 0.35s; }
.blank.fixed { color: var(--warn); border-bottom-color: var(--warn); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

.card-actions { display: flex; justify-content: center; }

.check-btn {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 12px 40px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s, opacity 0.12s;
  touch-action: manipulation;
}
.check-btn:active { transform: scale(0.95); }
.check-btn:disabled { opacity: 0.45; cursor: default; }

.feedback {
  min-height: 1.6em;
  text-align: center;
  font-weight: 600;
  font-size: 1.05rem;
}
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding-bottom: 6px;
}
kbd {
  background: var(--card);
  border-radius: 5px;
  padding: 1px 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  font-family: inherit;
}

/* ---------- Pause button (docked to the card's right edge) ---------- */
.pause-btn {
  position: absolute;
  right: -22px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid var(--accent-soft);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.12s;
  touch-action: manipulation;
}
.pause-btn:active { transform: translateY(-50%) scale(0.9); }

/* While paused: freeze the look and hide the sentence (and its hint) so the
   clock can't be beaten by reading with the timer stopped. */
body.paused .sentence,
body.paused .translation { filter: blur(9px); pointer-events: none; user-select: none; }
body.paused .timer-wrap { opacity: 0.55; }
body.paused .pause-btn { background: var(--accent); border-color: var(--accent); }

/* ---------- Loading overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 40, 0.55);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.overlay.show { display: flex; }

.overlay-box {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 36px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 84vw;
}

.spinner { font-size: 2.4rem; animation: bounce 0.9s infinite alternate; }
@keyframes bounce {
  from { transform: translateY(0) rotate(-8deg); }
  to { transform: translateY(-10px) rotate(8deg); }
}

/* ---------- Account modal ---------- */
.acct-box { max-width: min(420px, 88vw); }
.acct-box h2 { font-size: 1.25rem; }

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

.id-chip {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.5px;
  user-select: all;
  word-break: break-all;
}

.copy-btn {
  border: none;
  background: var(--card);
  box-shadow: var(--shadow);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
}

.acct-hint { font-size: 0.9rem; color: var(--muted); line-height: 1.5; }

/* Chinese sub-line shown under English UI text, smaller and muted. */
.zh-sub {
  display: block;
  font-size: 0.82em;
  font-weight: 500;
  color: var(--muted);
  margin-top: 3px;
  line-height: 1.5;
}
.retry-btn .zh-sub { color: rgba(255, 255, 255, 0.85); margin-top: 1px; }
.acct-plan { font-size: 0.9rem; font-weight: 600; color: var(--accent); min-height: 1.2em; }

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

.login-input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 0.95rem;
  border: 2px solid var(--ring-track);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
}
.login-input:focus { border-color: var(--accent); }

.login-err { color: var(--bad); font-size: 0.85rem; min-height: 1.2em; font-weight: 600; }

.retry-btn {
  font-family: inherit;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 30px;
  cursor: pointer;
}
.hidden { display: none; }

/* ---------- Confetti + score float ---------- */
#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
}

.score-float {
  position: fixed;
  z-index: 101;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--good);
  pointer-events: none;
  animation: floatUp 1.1s ease-out forwards;
}
@keyframes floatUp {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-70px) scale(1.3); }
}

/* Narrow screens: keep the docked pause button inside the viewport */
@media (max-width: 700px) {
  .pause-btn { right: -10px; width: 62px; height: 62px; font-size: 1.7rem; }
}

/* Small phones portrait: tighten paddings */
@media (max-width: 380px) {
  .app { padding: 8px 10px; }
  .card { padding: 16px 14px; }
}
