/* Schach-App – mobil zuerst, dunkles Design */
:root {
  --bg: #16181d;
  --bg2: #1f232a;
  --card: #252a33;
  --line: #343a46;
  --text: #e8eaed;
  --muted: #9aa3b2;
  --accent: #6aa84f;
  --accent2: #8fd16b;
  --danger: #e06c5f;
  --warn: #e8b34b;
  --radius: 14px;
  --light: #f0d9b5;
  --dark: #b58863;
  --sel: rgba(255, 235, 59, 0.55);
  --last: rgba(205, 210, 106, 0.55);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
[data-theme='gruen'] { --light: #eeeed2; --dark: #769656; }
[data-theme='blau'] { --light: #dee3e6; --dark: #8ca2ad; }
[data-theme='grau'] { --light: #d9d9d9; --dark: #8b8b8b; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  min-height: 100dvh;
  padding-bottom: var(--safe-bottom);
  overscroll-behavior-y: none;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 1.5rem; margin: 8px 0 14px; }
h2 { font-size: 1.1rem; margin: 22px 0 10px; color: var(--muted); font-weight: 600; }
h3 { font-size: 1rem; margin: 14px 0 8px; }
h3:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.up { color: var(--accent2); }
.down { color: var(--danger); }
small { display: block; }

/* Kopfzeile */
#header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + var(--safe-top)) 14px 8px;
  background: rgba(22, 24, 29, 0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
#header:empty { display: none; }
.logo { font-weight: 700; font-size: 1.15rem; display: flex; gap: 6px; align-items: center; }
.logo span { letter-spacing: 0.02em; }
.hd-right { display: flex; gap: 8px; align-items: center; }
.hd-rating { background: var(--card); border: 1px solid var(--line); padding: 4px 10px; border-radius: 99px; font-weight: 600; font-size: 0.9rem; }

main { max-width: 1200px; margin: 0 auto; padding: 12px 12px 30px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: 0.85rem; }
.btn.block { width: 100%; }
.btn.big { min-height: 54px; font-size: 1.05rem; margin-top: 14px; }
.icon-btn {
  min-width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 1.1rem; cursor: pointer;
}
.icon-btn:active { transform: scale(0.95); }
button.link { background: none; border: none; color: var(--text); font: inherit; text-align: left; padding: 12px 16px; cursor: pointer; }

/* Karten & Listen */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list .card { margin: 0; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; background: var(--bg2); font-size: 0.78rem; font-weight: 600; white-space: nowrap; }
.pill.go { background: var(--accent); color: #fff; }

/* Formulare */
label { display: block; margin: 10px 0; font-size: 0.9rem; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 11px 12px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
}
textarea { font-family: ui-monospace, monospace; font-size: 13px; }
.switch { display: flex; align-items: center; gap: 10px; color: var(--text); cursor: pointer; }
.switch input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); flex: none; }
.form-page { max-width: 640px; margin: 0 auto; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 42px; padding: 6px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.chip small { font-weight: 400; color: var(--muted); font-size: 0.7rem; }
.chip.active { border-color: var(--accent); background: rgba(106, 168, 79, 0.2); }
.levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.level {
  display: flex; flex-direction: column; align-items: center; padding: 8px 4px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text); font: inherit; cursor: pointer;
}
.level b { font-size: 1.3rem; }
.level span { font-size: 0.72rem; text-align: center; line-height: 1.15; min-height: 2.3em; display: flex; align-items: center; }
.level small { color: var(--muted); font-size: 0.68rem; }
.level.active { border-color: var(--accent); background: rgba(106, 168, 79, 0.2); }

/* Anmeldung */
.login { max-width: 400px; margin: 6vh auto 0; }
.login h1 { text-align: center; font-size: 2rem; margin: 0 0 16px; }
.login-logo { text-align: center; font-size: 4rem; line-height: 1; }
.tabs { display: flex; gap: 6px; margin-bottom: 6px; }
.tab { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); color: var(--muted); font: inherit; font-weight: 600; }
.tab.active { color: var(--text); border-color: var(--accent); }

/* Übersicht */
.hello { display: flex; justify-content: space-between; align-items: center; }
.big { font-size: 1.3rem; font-weight: 700; }
.elo-badge { display: flex; flex-direction: column; align-items: center; background: var(--bg2); border-radius: 12px; padding: 8px 14px; }
.elo-badge span { font-size: 1.5rem; font-weight: 800; color: var(--accent2); }
.elo-badge small { color: var(--muted); font-size: 0.7rem; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile {
  display: flex; flex-direction: column; gap: 2px; padding: 16px 14px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); min-height: 110px;
}
.tile.primary { background: linear-gradient(135deg, #4c8a36, #6aa84f); border-color: transparent; }
.tile .ti { font-size: 1.8rem; }
.tile small { color: var(--muted); font-size: 0.8rem; }
.tile.primary small { color: #e6f5dc; }
.row-links { display: flex; gap: 8px; margin-top: 14px; }
.row-links .btn { flex: 1; }

.grow { display: flex; align-items: center; gap: 10px; }
.gmain { flex: 1; min-width: 0; }
.gmain b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gright { text-align: right; }
.res { font-weight: 800; font-size: 1.05rem; }
.res.win { color: var(--accent2); }
.res.loss { color: var(--danger); }
.res.draw { color: var(--muted); }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 1px solid #000; flex: none; vertical-align: -2px; margin-right: 6px; }
.swatch.w { background: #f3f3f3; }
.swatch.b { background: #000; border-color: #888; }
.crow { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.crow .btns { display: flex; gap: 6px; flex-wrap: wrap; }

/* Seitenmenü */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 50; }
.drawer {
  position: absolute; right: 0; top: 0; bottom: 0; width: min(300px, 85vw); background: var(--bg2);
  display: flex; flex-direction: column; padding-top: var(--safe-top); overflow-y: auto; animation: slide 0.18s ease-out;
}
@keyframes slide { from { transform: translateX(100%); } }
.drawer a { padding: 13px 16px; border-bottom: 1px solid var(--line); }
.drawer-user { padding: 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; }
.drawer .ver { padding: 12px 16px; margin-top: auto; }

/* Toast & Dialog */
#toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bottom)); transform: translate(-50%, 140%);
  background: #333b48; color: #fff; padding: 10px 18px; border-radius: 12px; z-index: 100;
  transition: transform 0.25s, opacity 0.25s; opacity: 0; max-width: 90vw; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4); pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#toast.error { background: #8a3a32; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--bg2); border-radius: 18px; padding: 20px; width: min(420px, 100%); border: 1px solid var(--line); animation: pop 0.15s ease-out; }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } }
.modal h2 { margin: 0 0 8px; color: var(--text); font-size: 1.35rem; }
.modal-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-buttons .btn { flex: 1 1 auto; }
.modal-buttons .lvbtn { flex: 1 1 20%; }
.rating-change { font-size: 1.1rem; }
.rating-change.up b { color: var(--accent2); }
.rating-change.down b { color: var(--danger); }

/* ------------------------------------------------------------ Spielbildschirm */
.game { display: flex; flex-direction: column; gap: 8px; margin: -4px -4px 0; }
.board-col { display: flex; flex-direction: column; gap: 6px; }
.board-wrap { width: 100%; max-width: min(100%, calc(100dvh - 250px)); min-width: min(100%, 300px); margin: 0 auto; }
.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; touch-action: none; user-select: none;
  -webkit-user-select: none; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; container-type: size; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.last::before, .sq.sel::before, .sq.hint::before { content: ''; position: absolute; inset: 0; }
.sq.last::before { background: var(--last); }
.sq.sel::before { background: var(--sel); }
.sq.hint::before { background: rgba(80, 160, 255, 0.55); }
.sq.check { background: radial-gradient(circle, #ff3b30 0%, rgba(255, 59, 48, 0.6) 40%, transparent 75%), var(--dark); }
.sq.light.check { background: radial-gradient(circle, #ff3b30 0%, rgba(255, 59, 48, 0.6) 40%, transparent 75%), var(--light); }
.sq.target::after {
  content: ''; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: rgba(20, 30, 20, 0.35); pointer-events: none;
}
.sq.target-cap::after {
  content: ''; position: absolute; inset: 4%; border-radius: 50%; border: 5px solid rgba(20, 30, 20, 0.35); pointer-events: none;
}
.pc {
  position: relative; z-index: 2; font-size: 82cqh; line-height: 1; pointer-events: none;
  font-family: 'Segoe UI Symbol', 'Noto Sans Symbols 2', 'Noto Sans Symbols', 'Apple Symbols', 'DejaVu Sans', 'Arial Unicode MS', serif;
  transform: translateY(-2%);
}
.pc.w { color: #fff; -webkit-text-stroke: 1.2px #222; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45); paint-order: stroke fill; }
.pc.b { color: #1d1d1d; -webkit-text-stroke: 0.6px #000; text-shadow: 0 1px 1px rgba(255, 255, 255, 0.25); }
@supports not (font-size: 1cqh) { .pc { font-size: min(9.5vw, 56px); } }
.pc.ghost {
  position: fixed; left: 0; top: 0; z-index: 90; display: flex; align-items: center; justify-content: center;
  pointer-events: none; will-change: transform;
}
.co { position: absolute; font-size: 22cqh; font-weight: 700; z-index: 1; pointer-events: none; opacity: 0.85; }
.co.f { right: 4%; bottom: 1%; }
.co.r { left: 4%; top: 1%; }
.sq.light .co { color: var(--dark); }
.sq.dark .co { color: var(--light); }

.promo { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 10; display: flex; align-items: center; justify-content: center; }
.promo-box { display: flex; gap: 6px; background: var(--bg2); padding: 10px; border-radius: 14px; }
.promo-btn { width: 64px; height: 64px; border-radius: 10px; border: 1px solid var(--line); background: var(--light); cursor: pointer; container-type: size; display: flex; align-items: center; justify-content: center; }

.pbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px; min-height: 44px; }
.pinfo { min-width: 0; flex: 1; }
.pname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rating { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.captured { height: 20px; line-height: 20px; white-space: nowrap; overflow: hidden; }
.captured { display: flex; align-items: center; flex-wrap: nowrap; }
.captured .pc { display: inline-block; width: 13px; font-size: 16px; line-height: 20px; text-align: center; transform: none; -webkit-text-stroke-width: 0.5px; text-shadow: none; }
.captured .pc + .pc { margin-left: -1px; }
.adv { margin-left: 8px; color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.turn-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent2); margin-right: 6px; vertical-align: 2px; }
.clock {
  font: 700 1.35rem/1 ui-monospace, 'SF Mono', Menlo, monospace; padding: 8px 12px; border-radius: 10px;
  background: var(--bg2); color: var(--muted); min-width: 92px; text-align: center; font-variant-numeric: tabular-nums;
}
.clock.running { background: #f1f3f4; color: #111; }
.clock.running.low { background: var(--danger); color: #fff; }
.navrow { display: flex; gap: 6px; justify-content: center; }
.navrow .icon-btn { flex: 1; max-width: 70px; }

.side { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.status { background: var(--card); border-radius: 12px; padding: 10px 12px; border: 1px solid var(--line); }
.banner { background: #3a3320; border: 1px solid var(--warn); border-radius: 12px; padding: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions .btn { flex: 1 1 calc(50% - 6px); }

/* Zugliste: Hochformat = horizontales Band */
.movelist {
  display: flex; gap: 2px 10px; overflow-x: auto; white-space: nowrap; padding: 8px 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; scrollbar-width: thin; min-height: 42px;
}
.mrow { display: inline-flex; gap: 4px; align-items: baseline; }
.mrow .num { color: var(--muted); font-size: 0.85rem; }
.mv { padding: 2px 6px; border-radius: 6px; cursor: pointer; font-weight: 500; }
.mv.cur { background: var(--accent); color: #fff; }
.mv.empty { cursor: default; color: var(--muted); }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Bewertungsbalken */
.evalbar { position: relative; height: 26px; border-radius: 8px; background: #333; overflow: hidden; border: 1px solid var(--line); }
.evalfill { position: absolute; left: 0; top: 0; bottom: 0; width: 50%; background: #eee; transition: width 0.3s; }
.evaltxt { position: absolute; inset: 0; display: flex; align-items: center; padding: 0 8px; font-size: 0.8rem; font-weight: 600; color: #fff; mix-blend-mode: difference; white-space: nowrap; overflow: hidden; }

/* Querformat / Tablet: Zugliste an der Seite */
@media (min-width: 760px) and (min-aspect-ratio: 1/1), (min-width: 1000px) {
  .game { flex-direction: row; align-items: flex-start; gap: 16px; margin: 0; }
  .board-col { flex: 0 1 auto; width: min(calc(100dvh - 130px), 62vw); }
  .board-wrap { max-width: none; }
  .side { flex: 1; max-width: 380px; position: sticky; top: 70px; }
  .movelist {
    display: grid; grid-template-columns: 1fr; align-content: start; overflow-y: auto; overflow-x: hidden;
    white-space: normal; max-height: calc(100dvh - 380px); min-height: 160px;
  }
  .mrow { display: grid; grid-template-columns: 2.6em 1fr 1fr; }
  .actions .btn { flex: 1 1 calc(50% - 6px); }
}

/* Statistik */
.stat-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 12px 6px; }
.stat b { font-size: 1.6rem; color: var(--accent2); }
.stat small { color: var(--muted); font-size: 0.72rem; }
.chart { width: 100%; height: 200px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .lbl { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent2); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.chart .area { fill: rgba(143, 209, 107, 0.12); }
.chart .dot { fill: var(--accent2); }
.wdl { display: flex; height: 12px; border-radius: 6px; overflow: hidden; }
.wdl .w { background: var(--accent); }
.wdl .d { background: #777; }
.wdl .l { background: var(--danger); }
.hist-row { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.hist-row a { flex: 1; }
.ranking { padding: 4px 0; }
.rank-row { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.rank-row:last-child { border: none; }
.rank-row.me { background: rgba(106, 168, 79, 0.15); }
.rank-row .pos { width: 1.6em; color: var(--muted); font-weight: 700; }
.rank-row .nm { flex: 1; }

/* Lernen */
.pz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.pz { display: flex; align-items: center; justify-content: center; height: 44px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line); font-weight: 700; }
.pz.done { background: rgba(106, 168, 79, 0.35); border-color: var(--accent); }
.op-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border-radius: 10px; background: var(--bg2); }
.op-row.done { box-shadow: inset 3px 0 0 var(--accent); }
.op-row .swatch { margin-top: 4px; }
.rules p { margin: 6px 0; }
.rules ul { margin: 6px 0; padding-left: 20px; }
.captured .pc.b { color: #1d1d1d; -webkit-text-stroke: 0.7px #c8ccd4; }
.level.sf { border-style: dashed; }
.level.sf.active { border-style: solid; }
.invite-row { background: var(--bg2); border-radius: 10px; padding: 10px; }
.invite-row > div:first-child { flex: 1; min-width: 0; }
.invite-row input { font-size: 12px; padding: 6px 8px; margin-top: 6px; }
#header .muted.small { margin-left: auto; }
