/* WEFT component library — Constitution §5. Uses tokens only. */

/* Kill double-tap-to-zoom on every control. iOS Safari ignores user-scalable=no, so two quick taps
   on Tipp zoomed the page into the button area mid-game. manipulation keeps pan + pinch (so this is
   not an accessibility regression) and drops only the double-tap gesture and its 300ms delay. */
button,
a,
[role="button"],
input,
select,
label {
  touch-action: manipulation;
}

/* —— Button —— */
.weft-btn,
.btn-primary,
.btn-ghost {
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  /* Anchors styled as buttons kept the browser's underline — an underlined CTA reads as a link. */
  text-decoration: none;
  min-height: var(--touch-min);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  transition: filter var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    background var(--duration-fast) var(--ease-out);
}

.weft-btn:focus-visible,
.btn-primary:focus-visible,
.btn-ghost:focus-visible,
.weft-icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.weft-btn--primary,
.btn-primary {
  border: none;
  background: var(--accent);
  color: var(--selected-ink);
  width: 100%;
  font-size: var(--text-base);
  min-height: calc(var(--touch-min) + 4px);
  padding: var(--space-3) var(--space-6);
}

.weft-btn--primary:hover,
.btn-primary:hover { filter: brightness(1.08); }

.weft-btn--secondary {
  border: 1px solid var(--line-ui);
  background: var(--surface);
  color: var(--text);
}

/* In-game "Next" primary action (auto width, accent) */
.btn-next {
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  min-height: var(--touch-min);
  padding: var(--space-2) var(--space-5);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: linear-gradient(135deg,
    var(--accent),
    color-mix(in oklch, var(--accent) 70%, var(--word-4)));
  color: var(--selected-ink);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition: filter var(--duration-fast) var(--ease-out);
}
.btn-next:hover { filter: brightness(1.1); }
.btn-next:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* .btn-next is already inline-flex with a gap, so the icon needs sizing only. */
.btn-icon { font-size: 1.15em; line-height: 1; }

/* —— Icon glyphs ————————————————————————————————————————————————————————————
   UI symbols are inline SVG, not emoji (G4). The Archivo woff2 declares no unicode-range and
   carries no pictographs, so an emoji in markup always fell out of the stack onto whatever font
   the OS happened to offer — on Android that meant a different size, weight and baseline per
   glyph, which is the "damaged symbols" the owner saw in the simulator.

   Sizing in `em` (not px) is the whole point: every existing font-size rule on these icon spans —
   including the ones inside media queries, e.g. .app-nav-ico grows to --text-lg in the ≤720px tab
   bar — keeps working untouched. `fill: currentColor` likewise inherits the hover/active/pulse
   colour states the emoji never respected. */
.app-nav-ico svg,
.stat-ico svg,
.rail-ico svg,
.coach-icon svg,
.level-emoji svg,
.review-open-ico svg,
.btn-icon svg {
  width: 1em;
  height: 1em;
  display: block;
}

.weft-btn--ghost,
.btn-ghost {
  border: 1px solid var(--line-ui);
  background: transparent;
  color: var(--text-muted);
  font-weight: 500;
}

.weft-btn--ghost:hover,
.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--text);
}

.weft-btn--destructive {
  border: 1px solid color-mix(in oklch, var(--danger) 40%, var(--line-ui));
  background: transparent;
  color: var(--danger);
}

/* —— Icon button —— */
.weft-icon-btn,
.gear-btn {
  width: var(--touch-min);
  height: var(--touch-min);
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  border: 1px solid var(--line-ui);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text-muted);
  font-size: var(--text-lg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}

.weft-icon-btn:hover,
.gear-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* —— Select —— */
.weft-select,
.setup-field select {
  width: 100%;
  font: inherit;
  font-size: var(--text-sm);
  padding: var(--space-3);
  min-height: var(--touch-min);
  border: 1px solid var(--line-ui);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
}

/* —— Chip —— */
.weft-chip {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--chip-streak);
  color: var(--chip-streak-ink);
}

/* The streak rides in the header tools cluster next to two 44px pill buttons, so it matches their
   height and pill radius — one consistent row of controls instead of a stray short chip. */
.chip-streak {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  height: var(--touch-min);
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
  font-weight: 700;
  border-radius: var(--radius-pill);
  background: var(--chip-streak);
  color: var(--chip-streak-ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.weft-chip[hidden],
.chip-streak[hidden] { display: none !important; }

/* —— Card ——
   The solve panel is deliberately NOT in this group: it renders frameless like the Wörter/
   Fortschritt section views (see .solve-panel in ui-layout.css), not as a tinted card. */
.weft-card,
.setup-card,
.modal,
.word-rail {
  background: var(--surface);
  border: 1px solid var(--line-ui);
  border-radius: var(--radius-md);
  box-shadow: var(--elev-card);
}

.setup-card {
  padding: var(--space-6);
}

/* —— Progress —— */
.weft-progress,
.progress-bar {
  height: 8px;
  background: var(--line-ui);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.weft-progress__fill,
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-pill);
  width: 0%;
  transition: width var(--duration-normal) var(--ease-out);
}

/* —— Badge —— */
.weft-badge {
  font-family: var(--mono);
  font-size: var(--text-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-xs);
  background: var(--accent-soft);
  color: var(--accent);
}

/* —— Sheet (mobile learning panel — styled in Phase 2) —— */
.weft-sheet {
  background: var(--surface-raised);
  border: 1px solid var(--line-ui);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  box-shadow: var(--shadow-raised);
}

/* —— Toast (temporary alert boxes: tips, insights, share/feedback nudges) —— */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-4));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(420px, calc(100vw - 2 * var(--space-4)));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--line-ui);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-raised);
  font-size: var(--text-sm);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}
.toast.toast-in { opacity: 1; transform: translateY(0); }
.toast-badge {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}
.toast-text { line-height: 1.4; }
.toast-actions { display: flex; gap: var(--space-2); align-self: flex-end; }
.toast-action {
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: var(--space-1) var(--space-3);
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--selected-ink);
  cursor: pointer;
}
.toast-action.toast-action--ghost {
  background: transparent;
  border: 1px solid var(--line-ui);
  color: var(--text-muted);
}
@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity var(--duration-fast) var(--ease-out); transform: none; }
  .toast.toast-in { transform: none; }
}

/* —— Desktop left-rail modules (streak / goal / mastery / gallery) —— */
.rail-h { margin: 0 0 var(--space-3); font-size: var(--text-xs);
  letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-muted);
  font-weight: var(--weight-bold); }
.streak-top { display: flex; align-items: center; gap: var(--space-3); }
.streak-flame { font-size: 30px; filter: drop-shadow(0 0 8px color-mix(in oklab, var(--brand-pop) 35%, transparent)); }
.streak-num { font-size: var(--text-2xl); font-weight: 800; line-height: 1; color: var(--gold-text); }
.streak-sub { font-size: var(--text-xs); color: var(--text-muted); }
.week { display: flex; gap: var(--space-1); margin-top: var(--space-3); }
.day { flex: 1; text-align: center; }
.day-dot { display: grid; place-items: center; width: 24px; height: 24px; margin: 0 auto var(--space-1);
  border-radius: 50%; font-size: 11px; font-weight: 700; background: var(--surface-raised);
  border: 1px solid var(--line-ui); color: var(--text-muted); }
.day-dot.on { background: color-mix(in oklab, var(--brand-pop) 30%, var(--surface));
  border-color: var(--gold-text); color: var(--gold-text); }
.day-dot.today { box-shadow: 0 0 0 2px var(--accent); }
.day-name { font-size: 9px; color: var(--text-muted); }
.ring-row { display: flex; align-items: center; gap: var(--space-4); }
.goal-ring { position: relative; width: 76px; height: 76px; border-radius: 50%;
  background: conic-gradient(var(--brand-pop) calc(var(--pct) * 1%), var(--line-ui) 0);
  display: grid; place-items: center; flex: none; }
.goal-ring::before { content: ""; position: absolute; width: 58px; height: 58px;
  border-radius: 50%; background: var(--surface); }
.goal-ring span { position: relative; font-weight: 800; font-size: var(--text-sm); }
.goal-meta { font-size: var(--text-sm); color: var(--text-muted); margin: 0; }
.mastery-lbl { font-size: var(--text-sm); font-weight: 600; }
.mastery-lbl b { color: var(--gold-text); }
.mastery-bar { height: 10px; border-radius: var(--radius-pill); background: var(--surface-raised);
  overflow: hidden; margin: var(--space-2) 0; }
.mastery-bar > i { display: block; height: 100%;
  background: linear-gradient(90deg, var(--accent), color-mix(in oklab, var(--accent) 60%, var(--brand-pop))); }
.mastery-meta { display: flex; justify-content: space-between; font-size: var(--text-xs); color: var(--text-muted); }
.gallery-chips { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.g-chip { font-family: var(--mono); font-size: var(--text-xs); font-weight: 600;
  padding: var(--space-1) var(--space-2); border-radius: var(--radius-pill); cursor: pointer;
  border: 1px solid var(--line-ui); background: var(--surface-raised); color: var(--text); }
.g-chip:hover { border-color: var(--accent); }
.gallery-empty { font-size: var(--text-xs); color: var(--text-muted); }

/* —— Persistent reveal card (Wortkarte). Shown on every viewport now: on mobile it is THE reveal
   surface below the board (solved slots no longer expand in place); on desktop it keeps its
   right-column spot via a grid-area. Reuses the existing .lesson-* recap styles. —— */
.wortkarte-card { display: none; }
.wortkarte-card:not(:empty):not([hidden]) { display: block; margin-top: var(--space-4); }
/* Mobile: hide the empty grammar placeholder — coach + status teach until first solve (2026 UX). */
@media (max-width: 720px) {
  .wortkarte-card.wortkarte-card--idle { display: none !important; }
}
.rail-grammar-hint { margin: 0; color: var(--text-muted); font-size: var(--text-sm); line-height: 1.4; }
.wortkarte-card .lesson-head { display: flex; align-items: center; gap: var(--space-2); margin: 0 0 var(--space-2); }
.wortkarte-card .lesson-word { font-family: var(--mono); font-size: var(--text-lg); font-weight: 600; }

/* Save failure remains in the page flow; never cover the puzzle or dismiss unsaved state. */
.storage-notice:not([hidden]) { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 12px 0; padding: 14px; border: 1px solid currentColor; border-radius: 12px; background: var(--surface); color: var(--text); }
.storage-notice p { flex: 1 1 240px; margin: 0; line-height: 1.5; }
.storage-notice button { min-height: 44px; padding: 8px 14px; color: inherit; background: transparent; border: 1px solid currentColor; border-radius: 8px; cursor: pointer; }
.storage-notice button:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }
