/* Design tokens as CSS custom properties so the study/manage/stats pages share one
   palette. Dark mode follows the OS setting rather than an in-app toggle. */
:root {
  --bg: #fdfdfc;
  --fg: #1b1b18;
  --muted: #6b6b63;
  --accent: #c1440e;
  --card: #ffffff;
  --border: #e4e2dc;
  --ok: #2f6f4f;
  --bad: #a63328;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b18;
    --fg: #f0eee6;
    --muted: #9a978c;
    --accent: #e8642c;
    --card: #26261f;
    --border: #3a3a32;
    --ok: #7fbf9a;
    --bad: #e88b80;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main {
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.5rem 1rem calc(3rem + env(safe-area-inset-bottom));
}

.page-head h1 {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.head-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

/* --- sign in --- */

body.centred {
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.signin {
  width: min(22rem, 100%);
  text-align: center;
}

.signin h1 {
  margin: 0 0 1.5rem;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.signin form {
  display: grid;
  gap: 0.6rem;
}

.signin button {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.signin button:disabled {
  opacity: 0.6;
  cursor: default;
}

.signin .msg {
  margin-top: 1rem;
}

.sub {
  margin: 0.25rem 0 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* --- add form --- */

.add {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 0.75rem;
}

.add .wide {
  grid-column: span 2;
}

/* A labelled field: the label sits above its input and the pair spans the row. */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.field span {
  font-size: 0.8rem;
  color: var(--muted);
}

input,
select,
textarea,
button {
  font: inherit;
  padding: 0.6rem 0.7rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  max-width: 100%;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button[type="submit"] {
  grid-column: span 2;
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

button[type="submit"]:hover {
  filter: brightness(1.08);
}

.msg {
  margin: 0 0 1rem;
  font-size: 0.9rem;
}
.msg.ok {
  color: var(--ok);
}
.msg.bad {
  color: var(--bad);
}
.msg.warn {
  color: var(--fg);
}

/* An action offered inside a message — looks like a link, behaves like a button. */
.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

/* --- bulk import --- */

.import {
  margin: 0.5rem 0 0;
}

.import summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
}

.import form {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* Monospace because line NUMBERS are the error currency here — "line 3" should mean
   the third thing you can count, in even rows. */
.import textarea {
  font: 0.88rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}

/* The form is single-column; the shared span-2 rule for submit buttons would drag a
   phantom second column into the grid. */
.import button[type="submit"] {
  grid-column: auto;
}

.import-result {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
}

.import-result p {
  margin: 0 0 0.35rem;
}

.import-result ul {
  margin: 0 0 0.5rem;
  padding-left: 1.25rem;
}

.import-errors li {
  color: var(--bad);
}

.import-conflicts li {
  color: var(--muted);
}

/* --- study batches (manage page) --- */

.batches {
  margin: 0.5rem 0 0;
}

.batches summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
}

.batches form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.batch-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.batch-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.6rem;
  font-size: 0.9rem;
}

.batch-stats {
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

/* --- edit / delete --- */

.dialog-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-top: 1.25rem;
}

/* Same idiom as the study screen's miss button: outlined in the danger colour, never
   filled — destructive should be visible, not loud. */
.danger {
  background: none;
  border-color: var(--bad);
  color: var(--bad);
  cursor: pointer;
}

#edit h2 {
  margin-bottom: 1rem;
}

/* --- toolbar --- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 1.5rem 0 0.5rem;
}

.toolbar input {
  flex: 1 1 12rem;
}

.toolbar select {
  flex: 0 1 auto;
  padding: 0.5rem 0.6rem;
  font-size: 0.87rem;
}

.count {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}

/* --- card list --- */

.cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  padding: 0.7rem 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.es {
  font-weight: 600;
}

.en {
  color: var(--muted);
}

.es::after {
  content: "·";
  color: var(--border);
  margin: 0 0.45rem;
}

.example {
  margin: 0.3rem 0 0;
  font-size: 0.87rem;
  color: var(--muted);
  font-style: italic;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.3rem;
  flex-shrink: 0;
}

.badge,
.tag,
.pos,
.source {
  font-size: 0.72rem;
  padding: 0.12rem 0.45rem;
  border-radius: 0.3rem;
  white-space: nowrap;
}

.badge {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* Grammar, not theme — deliberately styled differently from tags so the two kinds of
   label never get read as the same thing. */
.pos {
  background: var(--fg);
  color: var(--bg);
  opacity: 0.65;
}

/* An unfilled classification. Visible enough to notice while scrolling, quiet enough
   not to look like an error — it's a small job outstanding, not a fault. */
.pos.missing {
  background: none;
  color: var(--muted);
  border: 1px dashed var(--muted);
  opacity: 0.8;
}

.tag {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
}

.source {
  color: var(--muted);
  border: 1px dashed var(--border);
}

.score {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.card {
  cursor: pointer;
}

.card:hover,
.card:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.empty {
  color: var(--muted);
  padding: 1.5rem 0;
  text-align: center;
  cursor: default;
}

/* --- card detail --- */

dialog {
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--card);
  color: var(--fg);
  padding: 1.25rem;
  max-width: min(38rem, 92vw);
  width: 100%;
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.5);
}

dialog h2 {
  margin: 0;
  font-size: 1.25rem;
}

dialog h3 {
  margin: 1.5rem 0 0.5rem;
  font-size: 0.95rem;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(5.5rem, 1fr));
  gap: 0.5rem;
  margin: 1rem 0;
}

.tile {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem;
  text-align: center;
}

.tile strong {
  display: block;
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
}

.tile span {
  font-size: 0.7rem;
  color: var(--muted);
}

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 1rem;
  margin: 0;
  font-size: 0.85rem;
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  margin: 0;
}

.history {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.history th,
.history td {
  text-align: left;
  padding: 0.25rem 0.5rem 0.25rem 0;
  border-bottom: 1px solid var(--border);
}

.history th {
  color: var(--muted);
  font-weight: 500;
}

.history .hit td:nth-child(2) {
  color: var(--ok);
}

.history .miss td:nth-child(2) {
  color: var(--bad);
}

.close {
  margin-top: 1.25rem;
  cursor: pointer;
}

@media (max-width: 30rem) {
  .add {
    grid-template-columns: 1fr;
  }
  .add input,
  .add button {
    grid-column: span 1;
  }
  .card {
    flex-direction: column;
    gap: 0.5rem;
  }
  .meta {
    justify-content: flex-start;
  }
}

/* --- study --- */

/* The hidden attribute must always win, even over classes that set display (like
   .answer's grid below). Without this, giving an element a display rule silently
   breaks every `hidden` toggle on it. */
[hidden] {
  display: none !important;
}

/* The nav pair (page link + sign out) in either page's header. */
.head-actions {
  display: flex;
  gap: 1rem;
  align-items: baseline;
}

/* The study page fills the viewport so the answer buttons land in the thumb zone;
   the safe-area padding keeps them clear of the iPhone home indicator. */
main.study {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
}

#stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.study-card {
  flex: 1;
  min-height: 40vh;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  /* No double-tap-to-zoom: rapid taps on the card and buttons are the whole game. */
  touch-action: manipulation;
}

.study-card .badge {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
}

/* A requeued miss coming round again — quieter than NEW on purpose. */
.badge.again {
  background: var(--muted);
}

.prompt {
  margin: 0;
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  font-weight: 600;
  text-align: center;
  overflow-wrap: anywhere;
}

/* The first-person line under a verb: "tengo" beneath "tener", "I have" under "have". */
.yo-line {
  margin: 0;
  font-size: clamp(1rem, 4vw, 1.4rem);
  color: var(--muted);
  text-align: center;
}

.answer {
  display: grid;
  gap: 0.6rem;
  text-align: center;
}

.answer .prompt {
  color: var(--accent);
}

@media (prefers-reduced-motion: no-preference) {
  .answer {
    animation: reveal 0.15s ease-out;
  }
  @keyframes reveal {
    from {
      opacity: 0;
      transform: translateY(4px);
    }
  }
}

.hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.study-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.study-actions button {
  min-height: 3.25rem;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

#btn-show {
  grid-column: span 2;
}

#btn-show,
#btn-got {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

#btn-miss {
  background: none;
  border-color: var(--bad);
  color: var(--bad);
}

.study-actions button:disabled {
  opacity: 0.45;
  cursor: default;
}

#tally,
#empty {
  text-align: center;
  padding: 2rem 0;
}

/* --- stats page --- */

/* Both charts are plain divs: each column is a fixed-height track filled from the
   bottom, its height set inline by stats.js as a percentage of the tallest column —
   CSS can't know the max. Every colour is an existing token, so dark mode needs
   nothing extra. */

.stats h2 {
  font-size: 1rem;
  margin: 1.75rem 0 0.6rem;
}

.boxbar {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.5rem;
}

.box-col {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 9rem;
  text-align: center;
  gap: 0.3rem;
}

.box-col strong {
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.box-fill {
  background: var(--accent);
  border-radius: 0.3rem 0.3rem 0 0;
}

/* "new" is the unstudied pile — muted, apart from the graded boxes, the same
   muted-vs-accent split the badges already use. */
.box-fill.new {
  background: var(--muted);
}

.box-col span {
  font-size: 0.7rem;
  color: var(--muted);
}

.daybars {
  display: grid;
  grid-template-columns: repeat(30, 1fr);
  gap: 2px;
  height: 7rem;
  border-bottom: 1px solid var(--border);
}

.day {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.day .hit {
  background: var(--ok);
}

.day .miss {
  background: var(--bad);
}

.daybars-range {
  display: flex;
  justify-content: space-between;
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}
