/* Structure shared by the three directions. Each direction sets the tokens and the look. */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.shell {
  max-width: 460px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0 16px; }
.brand { color: inherit; text-decoration: none; font-family: var(--font-display); font-size: 1.25rem; }
.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: none; padding: 8px 10px; font-size: 0.95rem; color: var(--muted); }
.tabs button[aria-current="page"] { color: var(--ink); }

main { flex: 1; display: flex; flex-direction: column; }
main > section { flex: 1; display: flex; flex-direction: column; }

/* Practise */
.count { margin: 0 0 12px; font-size: 0.9rem; color: var(--muted); }
#study { flex: 1; display: flex; flex-direction: column; }
.card { position: relative; touch-action: pan-y; user-select: none; cursor: pointer; }
.card.is-revealed { cursor: default; }
.kind { margin: 0; display: flex; gap: 10px; font-size: 0.85rem; color: var(--muted); }
.front { margin: 0; overflow-wrap: anywhere; }
.back { margin: 0; }
.example { margin: 8px 0 0; font-style: italic; color: var(--muted); }
.flag { margin: 16px 0 0; font-size: 0.85rem; }

.actions { margin-top: auto; padding-top: 20px; display: grid; gap: 12px; }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rate button, .reveal, form button[type="submit"], .done button { min-height: 52px; }
.fix { justify-self: center; border: 0; background: none; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; padding: 8px; font-size: 0.9rem; }
.swipe-hint { display: none; }

.card { transition: transform 260ms ease, opacity 260ms ease; }
.card.fly-left { transform: translateX(-120%) rotate(-8deg); opacity: 0; }
.card.fly-right { transform: translateX(120%) rotate(8deg); opacity: 0; }

.done { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.done h1 { margin: 0; }
.done p { margin: 0 0 16px; color: var(--muted); }

/* Add */
#add h1 { margin: 0 0 16px; }
form { display: grid; gap: 18px; }
fieldset.seg { border: 0; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
fieldset.seg legend { padding: 0; margin-bottom: 6px; font-size: 0.9rem; color: var(--muted); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: grid; place-items: center; min-height: 44px; font-size: 0.85rem; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 0.9rem; color: var(--muted); }
.field em { font-style: normal; opacity: 0.8; }
.field input, .field textarea, .field select { width: 100%; padding: 12px; min-height: 48px; }
textarea { resize: vertical; }

/* Progress */
.example-note { margin: 0 0 20px; padding: 10px 12px; font-size: 0.9rem; }
#progress h1, #progress h2 { margin: 0; }
#progress h2 { margin-top: 28px; }
.sub { margin: 4px 0 12px; font-size: 0.9rem; color: var(--muted); }
.chart { position: relative; margin: 0; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-family: var(--font-body); }
.chart .line { fill: none; stroke: var(--chart); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--chart); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: crosshair; }
.tip { position: absolute; width: 150px; padding: 6px 8px; font-size: 0.8rem; background: var(--ink); color: var(--bg); border-radius: 6px; pointer-events: none; }

.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.bars li { display: grid; grid-template-columns: 92px 1fr 42px; align-items: center; gap: 10px; font-size: 0.9rem; }
.bar-track { height: 12px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--chart); border-radius: 0 4px 4px 0; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }

.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); margin: 0; padding: 10px 16px; background: var(--ink); color: var(--bg); border-radius: 8px; font-size: 0.9rem; }

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
}
