/* ============================================================
   Schach — Gestaltung
   Dunkle, ruhige Oberfläche mit klassischem Brett.
   ============================================================ */

:root {
  --bg: #101319;
  --bg-soft: #161a22;
  --panel: #1a1f29;
  --panel-2: #212836;
  --line: #29303d;
  --text: #e9ecf3;
  --muted: #97a0b3;
  --accent: #8cb84a;
  --accent-dark: #6f9438;
  --accent-ink: #14200a;
  --danger: #dc5b4e;

  --sq-light: #ecedd4;
  --sq-dark: #779556;
  --hl-last: rgba(246, 214, 86, .45);
  --hl-sel: rgba(246, 214, 86, .62);
  --hl-check: rgba(232, 60, 50, .95);
  --hint: rgba(16, 24, 12, .26);

  --piece-w: #fbfbf7;
  --piece-w-line: #2f2d29;
  --piece-b: #33312d;
  --piece-b-line: #100f0e;

  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: radial-gradient(1200px 700px at 50% -220px, #1b2130 0%, var(--bg) 62%) fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overscroll-behavior: none;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.02em; }
h1 { font-size: 2.6rem; }
h2 { font-size: 1.5rem; }

button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }

/* ---------------- Kopfzeile ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px max(14px, env(safe-area-inset-left)) 10px max(14px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
  background: rgba(16, 19, 25, .8);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: none;
  border: 0;
  padding: 4px 6px;
  border-radius: 10px;
  font-weight: 650;
  font-size: 1.05rem;
  letter-spacing: -.01em;
}
.brand:hover { background: var(--panel); }
.brand-icon { width: 22px; height: 22px; color: var(--accent); }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: none;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--muted);
}
.icon-btn:hover { background: var(--panel); color: var(--text); }
.icon-btn svg { width: 21px; height: 21px; fill: currentColor; }
.icon-btn .ico-off { display: none; }
body.muted .icon-btn .ico-on { display: none; }
body.muted .icon-btn .ico-off { display: block; }

/* ---------------- Grundgerüst ---------------- */

#main {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 14px calc(20px + var(--safe-b));
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: fade .22s ease;
}
.screen[hidden] { display: none; }
.screen.form { max-width: 520px; width: 100%; margin: 0 auto; }
.screen.form h2 { margin-top: 4px; }

@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hero { text-align: center; margin: 6vh 0 2vh; }
.lead { color: var(--muted); margin: 8px 0 0; }

/* ---------------- Startseite ---------------- */

.mode-cards {
  display: grid;
  gap: 12px;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}

.mode-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  text-align: left;
  padding: 18px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color .16s, transform .16s, background .16s;
}
.mode-card:hover { border-color: var(--accent-dark); background: var(--panel-2); }
.mode-card:active { transform: scale(.99); }
.mode-icon {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: rgba(140, 184, 74, .13);
  color: var(--accent);
}
.mode-icon svg { width: 26px; height: 26px; fill: currentColor; }
.mode-text { display: flex; flex-direction: column; gap: 3px; }
.mode-text strong { font-size: 1.05rem; font-weight: 620; }
.mode-text small { color: var(--muted); font-size: .86rem; line-height: 1.35; }
.mode-arrow { color: var(--muted); font-size: 1.2rem; }

/* ---------------- Formulare ---------------- */

.back {
  align-self: flex-start;
  background: none;
  border: 0;
  color: var(--muted);
  padding: 6px 8px 6px 0;
  border-radius: 8px;
}
.back:hover { color: var(--text); }

.group {
  border: 0;
  padding: 0;
  margin: 0;
  max-width: 520px;
  width: 100%;
}
.group legend {
  padding: 0 0 10px;
  color: var(--muted);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  font-weight: 600;
}

.level-list { display: grid; gap: 8px; }
.level {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 13px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: left;
  transition: border-color .14s, background .14s;
}
.level:hover { background: var(--panel-2); }
.level.is-active { border-color: var(--accent); background: rgba(140, 184, 74, .1); }
.level-pips { display: flex; gap: 3px; }
.level-pips i {
  width: 5px; height: 16px;
  border-radius: 2px;
  background: var(--line);
  display: block;
}
.level.is-active .level-pips i.on { background: var(--accent); }
.level-pips i.on { background: #46505f; }
.level-name { font-weight: 560; }
.level-elo { color: var(--muted); font-size: .82rem; }

.seg {
  display: grid;
  grid-auto-flow: column;
  gap: 6px;
  padding: 5px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.seg.wrap { grid-auto-flow: row; grid-template-columns: repeat(4, 1fr); }
.seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 8px;
  background: none;
  border: 0;
  border-radius: 9px;
  color: var(--muted);
  font-size: .92rem;
  transition: background .14s, color .14s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.dotw, .dotb { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dotw { background: #f4f4ee; }
.dotb { background: #2f2e2b; box-shadow: inset 0 0 0 1px #55534e; }

.primary {
  padding: 14px 20px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 12px;
  font-weight: 640;
  max-width: 520px;
  width: 100%;
  transition: filter .14s, transform .1s;
}
.primary:hover { filter: brightness(1.07); }
.primary:active { transform: scale(.99); }
.primary.small { width: auto; padding: 11px 16px; }
.primary:disabled { opacity: .5; cursor: default; }

.ghost {
  padding: 12px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
}
.ghost:hover { background: var(--panel-2); }
.ghost.wide { max-width: 520px; width: 100%; }

/* ---------------- Einladung ---------------- */

.linkbox {
  display: flex;
  gap: 8px;
  max-width: 520px;
  width: 100%;
}
.linkbox input {
  flex: 1;
  min-width: 0;
  padding: 13px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-size: .92rem;
}
.linkbox input:focus { outline: 2px solid var(--accent-dark); outline-offset: -1px; }

.waiting {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--muted);
  padding: 16px 0;
}
.spinner {
  width: 17px; height: 17px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Partie-Layout ---------------- */

.game { gap: 16px; }

@media (min-width: 900px) {
  .game {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 22px;
  }
  .panel { width: 300px; flex: none; position: sticky; top: 78px; }
}

.board-col {
  width: 100%;
  max-width: min(620px, calc(100dvh - 250px));
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
}
.who { display: flex; align-items: center; gap: 9px; min-width: 0; }
.avatar {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  flex: none;
  font-size: 15px;
}
.avatar.w { background: #f2f2ec; border-color: #d6d6cc; }
.avatar.b { background: #2b2a27; border-color: #454340; }
.name { font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.name .sub { color: var(--muted); font-weight: 400; font-size: .85rem; }

.captured {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1px;
  flex: 1;
  min-width: 0;
  min-height: 20px;
}
.captured svg { width: 19px; height: 19px; margin-right: -6px; opacity: .78; }
.captured .adv { color: var(--muted); font-size: .8rem; margin-left: 11px; font-variant-numeric: tabular-nums; }

.clock {
  font-variant-numeric: tabular-nums;
  font-size: 1.22rem;
  font-weight: 620;
  letter-spacing: .01em;
  padding: 5px 12px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  flex: none;
}
.clock.running { background: var(--panel-2); color: var(--text); border-color: #3a4453; }
.clock.low { color: var(--danger); border-color: rgba(220, 91, 78, .5); }

/* ---------------- Brett ---------------- */

.board-wrap { position: relative; width: 100%; }

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.squares {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
}

.sq { position: relative; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }

.sq.last::before,
.sq.sel::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--hl-last);
}
.sq.sel::before { background: var(--hl-sel); }

.sq.check::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, var(--hl-check) 0%, rgba(232, 60, 50, .62) 40%, rgba(232, 60, 50, 0) 72%);
  pointer-events: none;
}

.sq .hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.sq .hint::before {
  content: '';
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: var(--hint);
}
.sq.hint-cap .hint::before {
  width: 100%;
  height: 100%;
  background: none;
  border: 7px solid var(--hint);
  border-radius: 50%;
}
.sq.target::before {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .55);
}

.coord {
  position: absolute;
  font-size: clamp(8px, 1.7vw, 11px);
  font-weight: 620;
  opacity: .62;
  pointer-events: none;
}
.coord.f { right: 3px; bottom: 1px; }
.coord.r { left: 3px; top: 1px; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }

.pieces { position: absolute; inset: 0; pointer-events: none; }

.piece {
  position: absolute;
  top: 0; left: 0;
  width: 12.5%;
  height: 12.5%;
  transition: transform .17s cubic-bezier(.22, .68, .35, 1);
  will-change: transform;
}
.piece.dragging { transition: none; z-index: 12; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .45)); }
.piece.ghost { opacity: .32; }
.piece svg { width: 100%; height: 100%; display: block; }

.pc .s {
  fill: var(--piece-w);
  stroke: var(--piece-w-line);
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.pc .eye { fill: var(--piece-w-line); }
.pc.b .s { fill: var(--piece-b); stroke: var(--piece-b-line); }
.pc.b .eye { fill: #b9b6b0; }
.pc .line { fill: none; }

/* Umwandlungsauswahl */
.promo {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 16, .55);
  backdrop-filter: blur(1.5px);
  z-index: 20;
}
.promo .choices {
  position: absolute;
  width: 12.5%;
  display: flex;
  flex-direction: column;
  background: var(--sq-light);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
.promo .choices.up { flex-direction: column-reverse; }
.promo .choice { aspect-ratio: 1; border: 0; background: none; padding: 6%; }
.promo .choice:hover { background: rgba(140, 184, 74, .38); }
.promo .choice svg { width: 100%; height: 100%; }

/* ---------------- Seitenspalte ---------------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-weight: 560;
  font-size: .95rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-head .badge {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}
.panel-head .badge.off { background: #4a5364; }

.moves-wrap {
  overflow-y: auto;
  max-height: 152px;   /* auf dem Handy bleiben die Schaltflächen sichtbar */
  min-height: 92px;
  scrollbar-width: thin;
}
@media (min-width: 900px) { .moves-wrap { max-height: 46vh; } }

.moves {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
  font-variant-numeric: tabular-nums;
}
.moves tr:nth-child(odd) { background: rgba(255, 255, 255, .018); }
.moves td { padding: 5px 8px; }
.moves td.n { color: var(--muted); width: 34px; text-align: right; font-size: .84rem; }
.moves td.m { cursor: pointer; border-radius: 6px; }
.moves td.m:hover { background: var(--panel-2); }
.moves td.m.now { background: rgba(140, 184, 74, .17); color: #cfe4a8; }
.moves .empty { color: var(--muted); padding: 14px; text-align: center; font-size: .88rem; }

.offer-bar {
  padding: 11px 13px;
  background: rgba(140, 184, 74, .1);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: .9rem;
}
.offer-bar[hidden] { display: none; }
.offer-bar button {
  padding: 6px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: .85rem;
}
.offer-bar button:hover { border-color: var(--accent-dark); }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
}
.ctrl {
  flex: 1 1 auto;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: .87rem;
  color: var(--text);
  white-space: nowrap;
  transition: border-color .14s, background .14s;
}
.ctrl:hover { border-color: #3d4757; background: #262e3d; }
.ctrl:disabled { opacity: .42; cursor: default; }
.ctrl svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ctrl.danger:hover { border-color: rgba(220, 91, 78, .6); color: #ffb3aa; }

/* ---------------- Dialog & Hinweis ---------------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, .68);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 20px;
  animation: fade .18s ease;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}
.modal-card h3 { font-size: 1.35rem; margin-bottom: 6px; }
.modal-card p { color: var(--muted); margin: 0 0 20px; }
.modal-actions { display: grid; gap: 8px; }
.modal-actions .primary, .modal-actions .ghost { max-width: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 11px;
  z-index: 70;
  box-shadow: var(--shadow);
  font-size: .9rem;
  animation: toastin .2s ease;
}
.toast[hidden] { display: none; }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
