/* TwoFast Tools — shared styles
   Brand tokens, accessible base, mobile-first. */

:root {
  --bone:   #E6D7BE;
  --red:    #BA4026;
  --red-dk: #9A3420;
  --sienna: #D87D5B;
  --black:  #0D0D0D;
  --white:  #FFFFFF;
  --sienna-dk: #8E3F22; /* darker sienna for small text — meets WCAG AA 4.5:1 on bone and white */

  --font-display: "DM Serif Display", Georgia, serif;
  --font-body: "DM Sans", system-ui, -apple-system, sans-serif;
  /* Broad script coverage for student-entered words (Cyrillic, etc.) */
  --font-word: "DM Sans", system-ui, "Segoe UI", "Noto Sans", "Noto Sans CJK SC", "Noto Sans Arabic", sans-serif;

  --maxw: 40rem;
  --radius: 14px;
  --gap: 1rem;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bone);
  color: var(--black);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.page { max-width: var(--maxw); margin: 0 auto; padding: 1.25rem 1.25rem 3rem; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }

/* Roomier vertical rhythm on the input/confirm screens */
#screen-input, #screen-confirm { gap: 1.5rem; }
#saved-row { justify-content: center; }

/* Header */
.site-header { text-align: center; padding: 1.5rem 0 0.5rem; }
.site-header .tag {
  margin: 0; color: var(--sienna-dk); font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.8rem;
}
.site-header h1 {
  font-family: var(--font-display); color: var(--red);
  margin: 0.1rem 0 0; font-size: clamp(2rem, 8vw, 3rem); font-weight: 400;
}
.site-header p.sub { margin: 0.4rem 0 0; opacity: 0.85; }

/* Back link */
.backlink {
  display: inline-flex; align-items: center; gap: 0.4rem;
  color: var(--red-dk); text-decoration: none; font-weight: 500; padding: 0.5rem 0;
}
.backlink:hover { text-decoration: underline; }

/* Cards (hub) */
.cards { display: grid; gap: var(--gap); grid-template-columns: 1fr; margin-top: 1.5rem; }
@media (min-width: 30rem) { .cards { grid-template-columns: 1fr 1fr; } }
.card {
  display: flex; flex-direction: column; gap: 0.35rem;
  background: var(--white); border: 2px solid transparent; border-radius: var(--radius);
  padding: 1.25rem; text-decoration: none; color: var(--black);
  box-shadow: 0 1px 3px rgba(13,13,13,0.08);
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
a.card:hover, a.card:focus-visible {
  border-color: var(--red); transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(13,13,13,0.12);
}
.card .icon { font-size: 1.75rem; }
.card h2 { margin: 0; font-size: 1.25rem; font-family: var(--font-display); font-weight: 400; }
.card p { margin: 0; opacity: 0.8; font-size: 0.95rem; }
.card.soon { opacity: 0.6; }

/* Activity-code labels (hub cards + tool pages) */
.codes-label {
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  font-size: 0.7rem; color: var(--sienna-dk); margin-right: 0.4rem;
}
.card p.codes { margin-top: 0.55rem; font-size: 0.8rem; opacity: 0.85; }
.guide-codes { margin: 0; text-align: center; font-size: 0.8rem; opacity: 0.7; }
.card .badge {
  align-self: flex-start; margin-top: 0.25rem; font-size: 0.7rem;
  text-transform: uppercase; letter-spacing: 0.06em; background: var(--bone);
  color: var(--red); padding: 0.15rem 0.5rem; border-radius: 999px; font-weight: 700;
}

/* Buttons */
.btn {
  font: inherit; font-weight: 700; cursor: pointer; border-radius: 999px;
  padding: 0.85rem 1.5rem; border: 2px solid var(--red);
  background: var(--red); color: var(--white); min-height: 48px;
  transition: background .15s ease, transform .05s ease;
}
.btn:hover { background: var(--red-dk); border-color: var(--red-dk); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: transparent; color: var(--red-dk); border-color: var(--red-dk); }
.btn.secondary:hover { background: rgba(186,64,38,0.08); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Form */
.field-label { font-weight: 700; display: block; margin-bottom: 0.4rem; }
.hint { font-size: 0.9rem; opacity: 0.75; margin: 0.25rem 0 0; }
textarea.words-input {
  width: 100%; min-height: 9rem; resize: vertical;
  font-family: var(--font-word); font-size: 1.1rem; line-height: 1.6;
  padding: 0.85rem; border-radius: var(--radius); border: 2px solid rgba(13,13,13,0.5);
  background: var(--white); color: var(--black);
}
textarea.words-input:focus-visible,
input.letters-input:focus-visible { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(186,64,38,0.25); }

/* Confirm list */
.count { font-weight: 700; }
.chips { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chips li {
  display: inline-flex; align-items: center; gap: 0.4rem; background: var(--white);
  border: 1px solid rgba(13,13,13,0.15); border-radius: 999px;
  padding: 0.4rem 0.5rem 0.4rem 0.9rem; font-family: var(--font-word); font-size: 1.05rem;
}
.chips button.remove {
  border: none; background: var(--bone); color: var(--red-dk); width: 1.6rem; height: 1.6rem;
  border-radius: 999px; cursor: pointer; font-size: 1.1rem; line-height: 1;
  display: grid; place-items: center;
}
.chips button.remove:hover { background: var(--red); color: var(--white); }

/* Mode selector */
fieldset.modes { border: none; padding: 0; margin: 0; }
fieldset.modes legend { font-weight: 700; margin-bottom: 0.4rem; padding: 0; }
.seg { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.seg label {
  flex: 1 1 auto; text-align: center; cursor: pointer; border: 2px solid rgba(13,13,13,0.5);
  border-radius: var(--radius); padding: 0.6rem 0.75rem; background: var(--white); font-weight: 500;
}
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg label:has(input:checked) { border-color: var(--red); background: rgba(186,64,38,0.06); font-weight: 700; }
.seg label:focus-within { outline: 3px solid var(--black); outline-offset: 2px; }

/* Inline controls */
.row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.stepper { display: inline-flex; align-items: center; gap: 0.5rem; }
.stepper button {
  width: 2.4rem; height: 2.4rem; border-radius: 999px; cursor: pointer;
  border: 2px solid var(--red); background: var(--white); color: var(--red);
  font-size: 1.25rem; font-weight: 700;
}
.stepper output { min-width: 1.5rem; text-align: center; font-weight: 700; font-size: 1.1rem; }
input.letters-input {
  font-family: var(--font-word); font-size: 1.05rem; padding: 0.6rem 0.75rem;
  border-radius: var(--radius); border: 2px solid rgba(13,13,13,0.5); background: var(--white); width: 100%;
}

/* Drill stage */
.stage {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 1rem; min-height: 52dvh; width: 100%;
  border-radius: var(--radius); padding: 1rem; cursor: pointer;
}
.stage.passive { cursor: default; }
.stage.is-paused { opacity: 0.55; }
.stage.is-done .word { color: var(--red); }
.stage .word {
  font-family: var(--font-word); font-weight: 700;
  font-size: clamp(2.5rem, 14vw, 6rem); line-height: 1.05; color: var(--black); word-break: break-word;
}
.stage .word-set { display: flex; flex-direction: column; gap: 0.5rem; }
.stage .word-set .word { font-size: clamp(1.75rem, 9vw, 4rem); }
.stage .letter {
  font-family: var(--font-word); font-weight: 700;
  font-size: clamp(5rem, 30vw, 12rem); color: var(--red);
}
.tap-hint { text-align: center; font-size: 0.95rem; opacity: 0.65; margin: 1.5rem 0 0; }
.progress { text-align: center; font-size: 0.95rem; opacity: 0.8; margin: 0; }
.controls { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; margin-top: 0.5rem; }
.error { color: var(--red-dk); font-weight: 700; }

/* Timer — setup choices */
.chip-choices { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.choice {
  font: inherit; font-weight: 700; cursor: pointer; border-radius: 999px;
  padding: 0.55rem 1.1rem; min-height: 44px;
  border: 2px solid rgba(13,13,13,0.5); background: var(--white); color: var(--black);
}
.choice.is-on { border-color: var(--red); background: rgba(186,64,38,0.06); color: var(--red); }
.choice:focus-visible { outline: 3px solid var(--black); outline-offset: 2px; }
#ramp-opts .opt-row { justify-content: space-between; }
#speed-choices .choice { flex: 1 1 auto; min-width: 2.75rem; text-align: center; }
.scale-ends { display: flex; justify-content: space-between; margin: 0; font-size: 0.8rem; opacity: 0.7; }

/* Timer — run screen */
.timer-stage {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 1.25rem; min-height: 52dvh; width: 100%;
  border-radius: var(--radius); padding: 1rem;
}
.timer-stage.is-paused { opacity: 0.55; }
.round-label {
  margin: 0; font-weight: 700; color: var(--sienna-dk);
  text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.95rem;
}
.time-display {
  font-family: var(--font-word); font-weight: 700; line-height: 1;
  font-size: clamp(4rem, 22vw, 9rem); color: var(--black);
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1;
  text-align: center; min-width: 5ch; /* keep the box width stable so digits don't shift */
}
.timer-stage.is-done .time-display { color: var(--red); }
.time-bar {
  width: min(100%, 22rem); height: 0.5rem; border-radius: 999px;
  background: rgba(13,13,13,0.12); overflow: hidden;
}
.time-bar span { display: block; height: 100%; width: 100%; background: var(--red); border-radius: 999px; transition: width 0.2s linear; }
@media (prefers-reduced-motion: reduce) { .time-bar span { transition: none; } }

/* Screen switching — show one screen at a time.
   Sections live inside .page, so target them there (not body > section).
   Input/confirm stay flex so the .stack gap survives. */
.page > section { display: none; }
[data-screen="input"]   #screen-input,
[data-screen="confirm"] #screen-confirm,
[data-screen="setup"]   #screen-setup { display: flex; }
[data-screen="drill"]   #screen-drill,
[data-screen="run"]     #screen-run { display: block; }

/* Utilities */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

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