/* Layout: Lernpult — Brett links (oben auf dem Handy), Erklärungen rechts, ruhige Turniertisch-Töne */
:root {
  --bg: #f2f4f1;
  --surface: #ffffff;
  --surface-2: #e8ece7;
  --ink: #1b2420;
  --muted: #56625c;
  --line: #d3dad5;
  --accent: #2f6b4f;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe2;
  --good: #2e7d4f;
  --good-soft: #d9f0e1;
  --bad: #b23a2e;
  --bad-soft: #f8dfdb;
  --warn-soft: #fbefcf;
  --sq-light: #ecdcbf;
  --sq-dark: #b08660;
  --sq-last: rgba(214, 178, 42, 0.45);
  --sq-sel: rgba(47, 107, 79, 0.55);
  --arrow: rgba(47, 107, 79, 0.85);
  --font-display: "Literata", Georgia, "Times New Roman", serif;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "Consolas", "Roboto Mono", monospace;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111613; --surface: #19201c; --surface-2: #222b26; --ink: #e5ebe7; --muted: #9eaba4; --line: #313b35;
    --accent: #6cbf92; --accent-ink: #0d1a13; --accent-soft: #1f3a2c; --good: #6cc98f; --good-soft: #193526;
    --bad: #f08a7c; --bad-soft: #3d1f1b; --warn-soft: #3a3118; --sq-light: #d9c7a6; --sq-dark: #94704f;
    --sq-last: rgba(222, 186, 60, 0.5); --sq-sel: rgba(108, 191, 146, 0.6); --arrow: rgba(66, 160, 110, 0.9);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111613; --surface: #19201c; --surface-2: #222b26; --ink: #e5ebe7; --muted: #9eaba4; --line: #313b35;
  --accent: #6cbf92; --accent-ink: #0d1a13; --accent-soft: #1f3a2c; --good: #6cc98f; --good-soft: #193526;
  --bad: #f08a7c; --bad-soft: #3d1f1b; --warn-soft: #3a3118; --sq-light: #d9c7a6; --sq-dark: #94704f;
  --sq-last: rgba(222, 186, 60, 0.5); --sq-sel: rgba(108, 191, 146, 0.6); --arrow: rgba(66, 160, 110, 0.9);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 16px; line-height: 1.55;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1, h2 { font-family: var(--font-display); font-weight: 700; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(1.45rem, 1.1rem + 1.4vw, 2rem); line-height: 1.2; }

/* Kopfzeile */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: 1120px; margin: 0 auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand { display: flex; align-items: center; gap: 8px; margin-right: auto; }
.brand-mark { width: 28px; height: 28px; fill: var(--accent); }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px; order: 3; width: 100%; }
.tab { flex: 1; border: 0; background: transparent; padding: 8px 12px; border-radius: 999px; font-weight: 700; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
@media (min-width: 720px) { .tabs { order: 0; width: auto; } .tab { flex: none; padding-inline: 18px; } }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--ink); stroke-width: 2; }
.icon-btn svg .fill { fill: var(--ink); stroke: none; }

.update-banner { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 8px 16px; background: var(--warn-soft); }

.wrap { max-width: 1120px; margin: 0 auto; padding-block: 20px 48px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.loading { color: var(--muted); }
.view { display: flex; flex-direction: column; gap: 18px; }
.list-head { display: grid; gap: 6px; max-width: 65ch; }
.lead { margin: 0; color: var(--muted); }
.help { margin: 6px 0 0; color: var(--muted); font-size: 0.92rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); font-weight: 700; text-align: center;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 0.92rem; }
.btn.big { min-height: 52px; font-size: 1.05rem; }
.back { align-self: flex-start; border: 0; background: none; color: var(--accent); font-weight: 700; padding: 4px 0; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--radius); }
.seg-btn { border: 0; background: transparent; padding: 8px 14px; border-radius: 7px; font-weight: 700; color: var(--muted); min-height: 40px; }
.seg-btn[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* Liste */
.list-tools { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.search { flex: 1 1 260px; }
.search input, .field select {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
}
.op-list { display: grid; gap: 22px; }
.op-group h2 { font-size: 1rem; color: var(--muted); font-family: var(--font-body); margin-bottom: 8px; letter-spacing: 0.02em; }
.op-cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.op-card {
  text-align: left; display: grid; gap: 4px; padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); min-width: 0;
}
.op-card:hover { border-color: var(--accent); }
.op-card .title { font-family: var(--font-display); font-weight: 700; font-size: 1.08rem; }
.op-card .sub { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 0.9rem; }
.side-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; font-weight: 700; padding: 2px 10px 2px 6px; border-radius: 999px; background: var(--surface-2); color: var(--ink); }
.side-badge::before { content: ""; width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--ink); }
.side-badge.w::before { background: #fafafa; }
.side-badge.b::before { background: #1d1d1d; }
.eco { font-family: var(--font-mono); font-size: 0.82rem; color: var(--muted); }
.mini-progress { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.mini-progress span { display: block; height: 100%; background: var(--accent); }

/* Studienansicht */
.study { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 900px) { .study { grid-template-columns: minmax(0, min(560px, 70vh)) minmax(0, 1fr); } }
.board-col { display: grid; gap: 12px; min-width: 0; }
.panel-col { display: grid; gap: 16px; min-width: 0; }
.op-head { display: grid; gap: 6px; }
.op-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.idea { margin: 0; max-width: 65ch; }
.block { display: grid; gap: 8px; }
.label { font-family: var(--font-body); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.hint-inline { text-transform: none; letter-spacing: 0; font-weight: 400; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px; font-size: 0.92rem; text-align: left; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.note { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-height: 64px; }
.note .mv { font-family: var(--font-display); font-weight: 700; }
.note p { margin: 0; }
.branch { background: var(--accent-soft); border-radius: var(--radius); padding: 12px 14px; }
.branch p { margin: 0; font-weight: 700; }
.branch .opts { display: grid; gap: 6px; }
.branch-opt { display: flex; gap: 10px; align-items: baseline; justify-content: space-between; text-align: left; padding: 8px 12px; border-radius: 8px; border: 1px solid transparent; background: var(--surface); }
.branch-opt[aria-pressed="true"] { border-color: var(--accent); }
.branch-opt .mv { font-family: var(--font-display); font-weight: 700; white-space: nowrap; }
.branch-opt .nm { color: var(--muted); font-size: 0.9rem; text-align: right; }

.movelist { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 2px 4px; font-variant-numeric: tabular-nums; }
.movelist li { display: inline-flex; align-items: baseline; gap: 2px; }
.movelist .num { color: var(--muted); font-size: 0.85rem; padding-left: 4px; }
.movelist button, .movelist .m { border: 0; background: none; padding: 2px 5px; border-radius: 5px; font-weight: 700; }
.movelist .future { color: var(--muted); font-weight: 400; opacity: 0.75; }
.movelist .cur { background: var(--accent); color: var(--accent-ink); }
.movelist .err { color: var(--bad); }

.controls { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.ctl { min-width: 52px; min-height: 46px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); font-size: 1.05rem; }
.ctl.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); min-width: 72px; }
.ctl:disabled { opacity: 0.4; cursor: default; }

/* Brett */
.board-host { width: 100%; max-width: 100%; }
.board { position: relative; width: 100%; aspect-ratio: 1; max-width: 100%; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); border-radius: 6px; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; box-shadow: 0 0 0 1px var(--line); }
.sq { position: relative; display: grid; place-items: center; }
.sq.l { background: var(--sq-light); }
.sq.d { background: var(--sq-dark); }
.sq.last::after, .sq.sel::after, .sq.ok::after, .sq.bad::after, .sq.hint::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.sq.last::after { background: var(--sq-last); }
.sq.sel::after { background: var(--sq-sel); }
.sq.hint::after { box-shadow: inset 0 0 0 4px var(--accent); background: rgba(47,107,79,.18); }
.sq.ok::after { background: rgba(46,160,90,.55); animation: flash .7s ease-out forwards; }
.sq.bad::after { background: rgba(200,50,40,.6); animation: flash .7s ease-out forwards; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
.sq .dot { position: absolute; width: 28%; height: 28%; border-radius: 50%; background: rgba(20, 40, 30, 0.32); pointer-events: none; }
.sq .ring { position: absolute; inset: 4%; border-radius: 50%; border: 4px solid rgba(20, 40, 30, 0.32); pointer-events: none; }
.sq .coord { position: absolute; font-size: clamp(9px, 2.2vw, 12px); font-weight: 700; pointer-events: none; line-height: 1; }
.sq .coord.f { right: 3px; bottom: 2px; }
.sq .coord.r { left: 3px; top: 3px; }
.sq.l .coord { color: #9a7650; }
.sq.d .coord { color: #f3e6cf; }
.piece { width: 88%; height: 88%; pointer-events: none; z-index: 1; }
.piece svg, .ghost svg { width: 100%; height: 100%; display: block; }
.ghost { position: absolute; z-index: 4; pointer-events: none; transform: translate(-50%, -50%) scale(1.12); }
.sq.dragfrom .piece { opacity: 0.3; }
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
.board.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@media (prefers-reduced-motion: reduce) { .board.shake, .sq.ok::after, .sq.bad::after { animation: none; } .sq.ok::after, .sq.bad::after { opacity: .5; } }

/* Training */
.setup { display: grid; gap: 18px; max-width: 560px; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
legend { font-weight: 700; margin-bottom: 6px; }
.target-fields { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; font-weight: 700; }
.due { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; color: var(--muted); }
.due strong { color: var(--ink); }
.variant-line { margin: 0; color: var(--muted); }
.score { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.score > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: grid; }
.score-num { font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.score-lbl { color: var(--muted); font-size: 0.82rem; }
.feedback { border-radius: var(--radius); padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); min-height: 72px; }
.feedback p { margin: 0; }
.feedback.good { background: var(--good-soft); border-color: transparent; }
.feedback.bad { background: var(--bad-soft); border-color: transparent; }
.feedback .mv { font-family: var(--font-display); font-weight: 700; }
.result { background: var(--accent-soft); border-radius: var(--radius); padding: 14px; }
.result p { margin: 0; }
.result .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* Statistik */
.totals { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); }
.total { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 2px; }
.total .n { font-family: var(--font-display); font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.total .t { color: var(--muted); font-size: 0.9rem; }
.st-list { display: grid; gap: 22px; }
.st-table { display: grid; gap: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.st-row { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) 64px; gap: 12px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); }
.st-row:first-child { border-top: 0; }
.st-row .nm { font-weight: 700; min-width: 0; }
.st-row .nm small { display: block; font-weight: 400; color: var(--muted); }
.st-bar { height: 8px; border-radius: 8px; background: var(--surface-2); overflow: hidden; }
.st-bar span { display: block; height: 100%; background: var(--accent); }
.st-row .lbl { font-size: 0.82rem; color: var(--muted); }
.st-row .pct { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.st-row .pct small { display: block; font-weight: 400; color: var(--muted); font-size: 0.78rem; }
.data-tools { display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 18px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.confirm { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; background: var(--bad-soft); padding: 10px 12px; border-radius: var(--radius); }
.export-text { width: 100%; min-height: 120px; font-family: var(--font-mono); font-size: 0.8rem; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; background: var(--surface); }
.btn:disabled { opacity: 0.45; cursor: default; border-color: var(--line); }

/* ---------- Version 1.1 ---------- */
.ver { font-size: 0.75rem; font-weight: 700; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 1px 8px; }
@media (max-width: 719px) { .tab { padding: 8px 4px; font-size: 0.9rem; } .tabs { gap: 2px; } }
.today-cta { display: grid; gap: 4px; max-width: 560px; }
.today-cta .btn.big { width: 100%; min-height: 60px; font-size: 1.15rem; }
.fq { display: inline-block; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.03em; padding: 0 6px; border-radius: 999px; vertical-align: 1px; margin-left: 2px; }
.fq.haupt { background: var(--accent-soft); color: var(--accent); }
.fq.neben { background: var(--surface-2); color: var(--muted); }
.chip[aria-pressed="true"] .fq { background: var(--accent-ink); color: var(--accent); }
.mode-badge { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.mode-badge:empty { display: none; }
.session-bar { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; color: var(--muted); font-size: 0.92rem; }
.session-bar strong { color: var(--ink); }
.session-bar .bar { flex: 1 1 120px; height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.session-bar .bar span { display: block; height: 100%; background: var(--accent); }
.warn-note { background: var(--warn-soft); border-radius: 6px; padding: 4px 8px; margin-top: 6px !important; }
.field input[type="text"], .field textarea { width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--surface); font-weight: 400; }
.field textarea { resize: vertical; }
.field-err { margin: -10px 0 0; color: var(--bad); font-size: 13px; min-height: 0; }
.field-err:empty { display: none; }
.ed-msg:empty { display: none; }
.ed-msg { color: var(--ink); background: var(--warn-soft); border-radius: var(--radius); padding: 8px 12px; margin: 0; }
.ed-lines { margin: 0; padding-left: 1.4em; display: grid; gap: 4px; }
.linkish { border: 0; background: none; padding: 0; text-align: left; color: var(--accent); font-family: var(--font-mono); font-size: 0.85rem; text-decoration: underline; text-underline-offset: 2px; }
.cu-card { cursor: default; }
.cu-card .row { margin-top: 6px; }
.cu-card .confirm { margin-top: 6px; }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 4px; max-width: 65ch; }
.empty p { margin: 0; }
#th-actions:empty { display: none; }

/* ---------- Version 1.2 ---------- */
.lv { display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; }
.lv-anfaenger { background: var(--good-soft); color: var(--good); }
.lv-fortgeschritten { background: var(--warn-soft); color: var(--ink); }
.lv-profi { background: var(--bad-soft); color: var(--bad); }
.pts { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.fq.eigen { background: var(--good-soft); color: var(--good); }
.movelist .ext { color: var(--good); text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px; }
.movelist .cur.ext { color: var(--accent-ink); }
.mini-field { display: inline-flex; gap: 6px; align-items: center; font-size: 0.9rem; color: var(--muted); font-weight: 700; }
.mini-field select, .stufe-field select, #tr-stufe { border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; background: var(--surface); font-weight: 400; min-height: 40px; }
.stufe-box { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.stufe-box:empty { display: none; }
.stufe-box .help { margin: 0; }
.stufe-field { display: inline-flex; gap: 8px; align-items: center; font-weight: 700; }
.imp-panel { display: grid; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; max-width: 720px; }
.imp-panel textarea { font-family: var(--font-mono); font-size: 0.85rem; }
#imp-msg ul { margin: 6px 0 0; padding-left: 1.2em; }
body.ed-extmode .ed-only { display: none !important; }
.ext-note { background: var(--accent-soft); border-radius: var(--radius); padding: 8px 12px; margin: 0; color: var(--ink); }
