/* ---------- Design-Tokens ---------- */
:root {
  --bg: #f3f0e8;
  --surface: #fffdf8;
  --ink: #1e1c17;
  --muted: #6d675b;
  --line: #e1dbcb;
  --accent: #2c6b5b;
  --accent-ink: #ffffff;
  --danger: #b0372d;
  --ok: #2c7a4b;

  --sq-light: #e8e2d2;
  --sq-dark: #6f8f8a;
  --hl-last: rgb(250 204 21 / .42);
  --hl-sel: rgb(37 99 235 / .45);
  --hl-move: rgb(20 40 60 / .28);
  --hl-hint: rgb(34 197 94 / .55);

  --radius: .85rem;
  --shadow: 0 1px 0 var(--line), 0 10px 28px rgb(30 25 10 / .10);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16150f;
    --surface: #1f1e17;
    --ink: #eee9dc;
    --muted: #a39d8d;
    --line: #34322a;
    --accent: #4aa38b;
    --accent-ink: #08130f;
    --danger: #ef7d71;
    --ok: #62c58a;
    --sq-light: #d7d1c1;
    --sq-dark: #5f7d78;
    --shadow: 0 1px 0 var(--line), 0 10px 28px rgb(0 0 0 / .45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
a { color: var(--accent); }
h1, h2 { line-height: 1.2; }
.muted { color: var(--muted); }
.noscript { padding: 1rem; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 1rem;
  padding: .55rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.15rem; color: inherit; text-decoration: none; white-space: nowrap; }
#nav { display: flex; gap: .2rem; overflow-x: auto; scrollbar-width: none; }
#nav::-webkit-scrollbar { display: none; }
#nav a {
  padding: .4rem .75rem; border-radius: .55rem;
  color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap;
}
#nav a:hover { background: var(--bg); color: var(--ink); }
#nav a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }

main { max-width: 1100px; margin: 0 auto; padding: 1rem; outline: none; }

/* ---------- Layout ---------- */
.layout { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr) 350px; align-items: start; }
}
.board-col { width: min(100%, calc(100vh - 10.5rem)); min-width: min(100%, 280px); margin-inline: auto; }
.panel { display: flex; flex-direction: column; gap: .9rem; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .9rem 1rem;
}
.card h2 { margin: 0 0 .6rem; font-size: 1rem; }
.card.error { border-color: var(--danger); }

/* ---------- Spielerleisten ---------- */
.bar { display: flex; align-items: center; gap: .55rem; min-height: 2.3rem; padding: .15rem .1rem; font-size: .95rem; }
.bar .name { font-weight: 600; }
.bar .sub { color: var(--muted); font-size: .85rem; }
.bar .caps { font-size: 1.05rem; letter-spacing: -.18em; color: var(--muted); font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Apple Symbols", "DejaVu Sans", sans-serif; }
.bar .adv { font-size: .8rem; color: var(--muted); }
.bar .clock {
  margin-left: auto; padding: .1rem .55rem; border-radius: .45rem;
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem;
  background: var(--surface); border: 1px solid var(--line);
}
.bar .clock.running { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.bar .clock.low { color: var(--danger); }
.bar .clock.running.low { background: var(--danger); border-color: var(--danger); color: #fff; }
.dot { width: .7rem; height: .7rem; border-radius: 50%; border: 1.5px solid var(--ink); }
.dot.w { background: #fff; }
.dot.b { background: #222; }
.bar.active .dot { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); }

/* ---------- Brett ---------- */
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  width: 100%;
  border-radius: 6px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  container-type: inline-size;
  box-shadow: var(--shadow);
}
.sq { position: relative; display: grid; place-items: center; }
.sq.light { background-color: var(--sq-light); }
.sq.dark { background-color: var(--sq-dark); }
.sq[data-p] { cursor: pointer; }
.sq.last::before, .sq.sel::before, .sq.hint::before { content: ""; position: absolute; inset: 0; }
.sq.last::before { background: var(--hl-last); }
.sq.hint::before { background: var(--hl-hint); }
.sq.sel::before { background: var(--hl-sel); }
.sq.check { background-image: radial-gradient(circle, rgb(220 38 38 / .9) 0, rgb(220 38 38 / .55) 38%, rgb(220 38 38 / 0) 72%); }
.sq.target { cursor: pointer; }
.sq.target::after { content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: var(--hl-move); }
.sq.target.capture::after { width: 90%; height: 90%; background: transparent; border: .8cqw solid var(--hl-move); }

.coord { position: absolute; font-size: max(9px, 1.7cqw); font-weight: 700; line-height: 1; opacity: .8; pointer-events: none; }
.coord.rank { top: 5%; left: 5%; }
.coord.file { bottom: 4%; right: 5%; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }

.pc, .pp, .ghost {
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Apple Symbols", "DejaVu Sans", sans-serif;
  line-height: 1;
}
.pc { position: relative; z-index: 1; font-size: 10.4cqw; pointer-events: none; }
.pc.dragging { opacity: .25; }
.pc.w, .pp.w, .ghost.w {
  color: #fff;
  text-shadow: -1px -1px 0 #1a1a1a, 1px -1px 0 #1a1a1a, -1px 1px 0 #1a1a1a, 1px 1px 0 #1a1a1a, 0 2px 3px rgb(0 0 0 / .35);
}
.pc.b, .pp.b, .ghost.b {
  color: #1b1b1b;
  text-shadow: 0 0 1px rgb(255 255 255 / .55), 0 2px 3px rgb(0 0 0 / .3);
}
.ghost { position: fixed; z-index: 50; transform: translate(-50%, -52%); pointer-events: none; filter: drop-shadow(0 6px 8px rgb(0 0 0 / .35)); }

.promo { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; background: rgb(0 0 0 / .45); }
.promo-box { display: flex; gap: .4rem; padding: .6rem; background: var(--surface); border-radius: .8rem; box-shadow: 0 10px 30px rgb(0 0 0 / .4); }
.pp { font-size: 11cqw; padding: .1em .15em; background: var(--sq-light); border: 2px solid transparent; border-radius: .5rem; cursor: pointer; }
.pp:hover, .pp:focus-visible { border-color: var(--accent); outline: none; }

/* ---------- Bedienelemente ---------- */
button, select, input, textarea { font: inherit; color: inherit; }
button {
  padding: .45rem .8rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  background: var(--surface);
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--bg); }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, black); }
button.danger { color: var(--danger); }
button:disabled { opacity: .45; cursor: not-allowed; }

select, input[type="text"], textarea {
  padding: .4rem .6rem; border: 1px solid var(--line); border-radius: .5rem; background: var(--surface);
}
textarea { width: 100%; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }

.btns { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.btns.nav button { min-width: 2.6rem; font-weight: 700; }
.field { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.field > span { color: var(--muted); font-size: .9rem; }
.check { display: inline-flex; align-items: center; gap: .35rem; cursor: pointer; }
.check input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
.row { display: flex; gap: .5rem; align-items: center; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: .6rem; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.status { margin: 0 0 .4rem; font-weight: 600; min-height: 1.5em; }
.status.over { color: var(--accent); }
.status.good { color: var(--ok); }
.status.bad { color: var(--danger); }

/* ---------- Zugliste ---------- */
.moves {
  position: relative;
  display: grid; grid-template-columns: 2.4rem 1fr 1fr;
  max-height: 13rem; overflow-y: auto;
  margin: .5rem 0; font-variant-numeric: tabular-nums;
}
.moves .n { color: var(--muted); padding: .2rem 0; }
.moves button.m { border: 0; background: none; text-align: left; padding: .15rem .45rem; border-radius: .35rem; }
.moves button.m:hover { background: var(--bg); }
.moves button.m[aria-current="true"] { background: var(--accent); color: var(--accent-ink); }

/* ---------- Analyse ---------- */
.evalhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.evaltext { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.evalbar { height: .85rem; border-radius: 99px; overflow: hidden; background: #26241d; }
.evalbar > i { display: block; height: 100%; width: 50%; background: #f4f1e8; transition: width .35s ease; }
.lines { margin-top: .6rem; display: grid; gap: .3rem; }
.line { display: grid; grid-template-columns: 4rem 1fr auto; gap: .5rem; align-items: baseline; text-align: left; padding: .35rem .5rem; }
.line b { font-variant-numeric: tabular-nums; }
.line span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line small { color: var(--muted); }

/* ---------- Puzzles / Eröffnungen / Online ---------- */
.plist { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.4rem, 1fr)); gap: .3rem; margin-top: .6rem; }
.plist button { padding: .3rem 0; }
.plist button[aria-current="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.plist button.done { border-color: var(--ok); color: var(--ok); }
.plist button.done[aria-current="true"] { color: var(--accent-ink); }

.olist { display: grid; gap: .3rem; max-height: 18rem; overflow-y: auto; }
.olist h3 { margin: .6rem 0 .1rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.olist button { text-align: left; display: flex; justify-content: space-between; gap: .5rem; }
.olist button small { color: var(--muted); }
.olist button[aria-current="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.olist button[aria-current="true"] small { color: inherit; opacity: .85; }
.theory { margin: .4rem 0 0; }
.linkbox { display: flex; gap: .4rem; margin-top: .5rem; }
.linkbox input { flex: 1; min-width: 0; }

/* ---------- Startseite ---------- */
.hero { padding: 2rem 0 1.2rem; }
.hero h1 { margin: 0 0 .3rem; font-size: clamp(1.8rem, 5vw, 2.6rem); }
.hero p { margin: 0; color: var(--muted); font-size: 1.1rem; }
.home-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.tile {
  display: flex; flex-direction: column; gap: .35rem;
  padding: 1.1rem; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow); }
.tile .icon { font-size: 1.8rem; }
.tile strong { font-size: 1.1rem; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 1.2rem; z-index: 100;
  transform: translate(-50%, 140%);
  max-width: min(90vw, 28rem);
  padding: .6rem 1rem;
  background: var(--ink); color: var(--bg);
  border-radius: .6rem;
  opacity: 0; transition: transform .25s ease, opacity .25s ease;
  pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

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