/* Šahy — dětská online aplikace (play.html). Mobile-first, funguje i na PC. */

:root {
  --bg: #f2edff;
  --ink: #2b2149;
  --muted: #7a6fa3;
  --brand: #5b3df5;
  --brand-dark: #4527d8;
  --accent: #ffb521;
  --card: #ffffff;
  --danger: #e5484d;
  --ok: #30a46c;
  --sq-light: #f6e7c9;
  --sq-dark: #b8874f;
  --sq-sel: #ffd84d;
  --sq-move: rgba(91, 61, 245, 0.45);
  --sq-cap: rgba(229, 72, 77, 0.55);
  --sq-last: rgba(48, 164, 108, 0.4);
  --radius: 16px;
  --board-size: min(94vw, 58dvh, 560px);
}

/* Tmavý režim: přepíná JS atributem data-theme na <html> (uloženo v localStorage).
 * Paleta laděná na čitelnost: světlý text ≥ #b6abd6 na pozadích ≤ #2f2750. */
:root[data-theme="dark"] {
  --bg: #16121f;
  --ink: #f4f1fb;
  --muted: #b6abd6;
  --brand: #a290ff;
  --brand-dark: #4d3ab8;
  --accent: #ffc14d;
  --card: #251f3a;
  --danger: #ff8a8f;
  --ok: #4ade80;
  --sq-light: #cdb894;
  --sq-dark: #7d5c38;
  --sq-sel: #e8c243;
  --sq-move: rgba(162, 144, 255, 0.5);
  --sq-cap: rgba(255, 138, 143, 0.6);
  --sq-last: rgba(74, 222, 128, 0.35);
}
:root[data-theme="dark"] body {
  background-image: radial-gradient(circle at 15% 10%, #1f1834 0, transparent 40%),
                    radial-gradient(circle at 85% 90%, #2a2113 0, transparent 40%);
}
:root[data-theme="dark"] .btn { background: #352c58; color: var(--ink); }
:root[data-theme="dark"] .btn.primary { background: #6a55e6; color: #fff; box-shadow: 0 4px 0 var(--brand-dark); }
:root[data-theme="dark"] .btn.primary:active { box-shadow: 0 1px 0 var(--brand-dark); }
:root[data-theme="dark"] .btn.danger { background: #52252e; color: var(--danger); }
:root[data-theme="dark"] input { background: #1d172f; color: var(--ink); border-color: #4a3d80; }
:root[data-theme="dark"] input::placeholder { color: #8d81b5; }
:root[data-theme="dark"] .card { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); }
:root[data-theme="dark"] .menu-btn { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); }
:root[data-theme="dark"] .list-row { background: #2f2750; }
:root[data-theme="dark"] .list-row .sub { color: var(--muted); }
:root[data-theme="dark"] .bot-row.sel { background: #3d3268; }
:root[data-theme="dark"] .seg-btn { background: #1d172f; border-color: #4a3d80; color: var(--ink); }
:root[data-theme="dark"] .seg-btn.active { background: #3d3268; border-color: var(--brand); }
:root[data-theme="dark"] .hero h1 { text-shadow: 0 3px 0 #0b0813; }
:root[data-theme="dark"] .hero-piece { filter: drop-shadow(0 4px 0 #0b0813); }
:root[data-theme="dark"] .me-elo strong { text-shadow: none; }
:root[data-theme="dark"] .plate-clock { background: rgba(255, 255, 255, 0.1); }
:root[data-theme="dark"] .emoji-bar button { background: #352c58; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4); }
:root[data-theme="dark"] #toast { background: #f4f1fb; color: #16121f; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; } /* .screen má display:flex – hidden musí vyhrát */
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  background-image: radial-gradient(circle at 15% 10%, #e4dbff 0, transparent 40%),
                    radial-gradient(circle at 85% 90%, #ffe9c4 0, transparent 40%);
  color: var(--ink);
  min-height: 100dvh;
  touch-action: manipulation;
}

#app { max-width: 640px; margin: 0 auto; padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); }
.screen { display: flex; flex-direction: column; gap: 14px; animation: pop-in .18s ease-out; }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Hero + karty ─────────────────────────────────────────────────────── */
.hero { text-align: center; padding: 26px 0 6px; }
.hero.small { padding: 8px 0 0; }
.hero h1 { font-size: 44px; margin: 0; letter-spacing: 2px; color: var(--brand); text-shadow: 0 3px 0 #d9ceff; }
.hero.small h1 { font-size: 30px; }
.hero-piece { font-size: 72px; line-height: 1; filter: drop-shadow(0 4px 0 #d9ceff); }
.hero-piece-inline { color: var(--accent); }
.tagline { color: var(--muted); margin: 6px 0 0; font-weight: 600; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 4px 14px rgba(60, 30, 160, 0.10);
  display: flex; flex-direction: column; gap: 10px;
}
.card h3 { margin: 0; font-size: 16px; }

/* ── Tlačítka a inputy ────────────────────────────────────────────────── */
.btn {
  font: inherit; font-weight: 700; color: var(--ink);
  background: #eee9ff; border: none; border-radius: 12px;
  padding: 12px 16px; cursor: pointer; min-height: 44px;
  transition: transform .06s ease, filter .1s ease;
}
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--brand); color: #fff; box-shadow: 0 4px 0 var(--brand-dark); }
.btn.primary:active { box-shadow: 0 1px 0 var(--brand-dark); }
.btn.danger { background: #ffe5e5; color: var(--danger); }
.btn.big { font-size: 19px; padding: 14px 18px; }
.btn.tiny { min-height: 0; padding: 4px 8px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.back { font-size: 20px; padding: 8px 14px; flex: 0 0 auto; }
.btn:disabled { opacity: .45; cursor: default; }

input {
  font: inherit; font-size: 18px; padding: 12px 14px;
  border: 2px solid #d9ceff; border-radius: 12px; outline: none; width: 100%;
}
input:focus { border-color: var(--brand); }
.big-label { font-weight: 800; font-size: 16px; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.hint.center { text-align: center; }
.hint.warn { color: var(--danger, #c0392b); margin-top: 8px; }
.hint a { color: var(--brand); font-weight: 700; }

.screen-head { display: flex; align-items: center; gap: 10px; }
.screen-head h2 { margin: 0; font-size: 22px; }
.screen-head.slim { gap: 8px; }

/* ── Menu ─────────────────────────────────────────────────────────────── */
.me-card { flex-direction: row; align-items: center; justify-content: space-between; }
.me-right { display: flex; align-items: center; gap: 8px; }
.me-name { font-size: 18px; font-weight: 800; }
.me-elo { color: var(--muted); font-weight: 700; }
.me-elo strong { color: var(--accent); font-size: 20px; text-shadow: 0 1px 0 #c98f00; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.menu-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 18px 8px; font-size: 34px; background: var(--card);
  box-shadow: 0 4px 14px rgba(60, 30, 160, 0.10);
}
.menu-btn span { font-size: 15px; }

/* ── Lobby / seznamy ──────────────────────────────────────────────────── */
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 6px; font-weight: 800; text-align: center; }
.lobby-list, .table-list { display: flex; flex-direction: column; gap: 8px; }
.list-row {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: #f6f3ff; border: none; border-radius: 12px; padding: 12px 14px;
  font: inherit; color: var(--ink); cursor: pointer; min-height: 48px;
}
.list-row:active { transform: scale(0.98); }
.list-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.list-row .sub { color: var(--muted); font-size: 13px; font-weight: 400; }
.list-row .badge { flex: 0 0 auto; font-weight: 800; color: var(--brand); }
.list-row.mine { outline: 2px solid var(--accent); }
/* Upozornění: zvonek s bublinkou v me-card + seznam na vlastní obrazovce */
.bell { position: relative; font-size: 17px; overflow: visible; }
.notif-dot {
  position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: 11px; font-weight: 800; line-height: 1;
}
.notif-row { align-items: flex-start; cursor: default; }
.notif-row.unread { background: #ece6ff; outline: 2px solid var(--brand); }
.notif-row .grow { white-space: normal; overflow: visible; text-overflow: clip; font-weight: 400; }
.notif-row .ntext { font-weight: 700; }
.notif-row .nicon { flex: 0 0 auto; font-size: 20px; line-height: 1.3; }
.notif-row a { color: var(--brand); font-weight: 800; }
:root[data-theme="dark"] .notif-row.unread { background: #3d3268; }

.pulse { color: var(--ok); animation: pulse 1.6s infinite; font-size: 11px; vertical-align: middle; }
@keyframes pulse { 50% { opacity: .25; } }

.bot-list { display: flex; flex-direction: column; gap: 8px; }
.bot-row { justify-content: space-between; }
.list-group { font-size: 12px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 10px 2px 2px; }
.list-group:first-child { margin-top: 0; }
.bot-row.sel { outline: 3px solid var(--brand); background: #ece6ff; }
.seg { display: flex; gap: 6px; }
.seg-btn {
  flex: 1; font: inherit; font-weight: 700; padding: 10px 6px; min-height: 44px;
  border: 2px solid #d9ceff; background: #fff; border-radius: 12px; cursor: pointer;
}
.seg-btn.active { border-color: var(--brand); background: #ece6ff; }

/* ── Herní obrazovka ──────────────────────────────────────────────────── */
.game-screen { gap: 8px; }
.game-status { font-weight: 800; font-size: 15px; flex: 1; min-width: 0; }

.plate {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: 12px; padding: 8px 12px;
  width: var(--board-size); margin: 0 auto;
  box-shadow: 0 2px 8px rgba(60, 30, 160, 0.08);
  min-height: 40px;
}
.plate-dot { width: 10px; height: 10px; border-radius: 50%; background: #ccc; flex: 0 0 auto; }
.plate-dot.on { background: var(--ok); }
.plate-dot.turn { box-shadow: 0 0 0 3px rgba(48,164,108,.3); }
.plate-name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate-elo { color: var(--muted); font-size: 13px; font-weight: 700; flex: 0 0 auto; }
.plate-caps { margin-left: auto; font-size: 15px; letter-spacing: -2px; white-space: nowrap; overflow: hidden; }
.plate-clock {
  flex: 0 0 auto; font-variant-numeric: tabular-nums; font-weight: 900; font-size: 18px;
  background: rgba(127, 127, 127, 0.12); border-radius: 8px; padding: 3px 8px;
}
.plate-clock.turn { background: var(--brand); color: #fff; }
.plate-clock.low { background: var(--danger); color: #fff; animation: pulse 1s infinite; }

/* Eval bar analýzy v přehrávání (bílý podíl zleva) */
.ana-bar {
  position: relative; width: var(--board-size); margin: 0 auto; height: 18px;
  border-radius: 9px; overflow: hidden; background: #1c1c22;
  box-shadow: inset 0 0 0 1px rgba(127,127,127,.3);
}
.ana-fill { height: 100%; width: 50%; background: #f6f6f2; transition: width .25s ease; }
.ana-score {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 12px; font-weight: 900; color: #fff; mix-blend-mode: difference;
}
.ana-depth {
  position: absolute; right: 8px; top: 0; bottom: 0; display: grid; place-items: center;
  font-size: 11px; font-weight: 800; color: #fff; mix-blend-mode: difference;
}
.square.ai-from::before { content: ""; position: absolute; inset: 0; background: rgba(139, 116, 255, .4); z-index: 1; }
.square.ai-to::before { content: ""; position: absolute; inset: 0; background: rgba(139, 116, 255, .65); z-index: 1; }

#board-wrap { position: relative; width: var(--board-size); margin: 0 auto; }
#board {
  width: var(--board-size); height: var(--board-size);
  display: grid; grid-template: repeat(8, 1fr) / repeat(8, 1fr);
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 6px 18px rgba(60, 30, 160, 0.22);
  user-select: none;
}
.square { position: relative; display: grid; place-items: center; }
.square.light { background: var(--sq-light); }
.square.dark { background: var(--sq-dark); }
.square .piece {
  font-size: calc(var(--board-size) / 8 * 0.74);
  line-height: 1; cursor: pointer; z-index: 2;
  transition: transform .08s ease;
}
.square .piece.white { color: #fff; text-shadow: 0 0 3px #000, 0 2px 2px rgba(0,0,0,.5); }
.square .piece.black { color: #1c1c22; text-shadow: 0 0 2px #fff; }
.square.selected { background: var(--sq-sel); }
.square.selected .piece { transform: scale(1.12); }
.square.last::before {
  content: ""; position: absolute; inset: 0; background: var(--sq-last); z-index: 1;
}
.square.move::after {
  content: ""; position: absolute; width: 34%; height: 34%;
  border-radius: 50%; background: var(--sq-move); z-index: 1;
}
.square.capture::after {
  content: ""; position: absolute; inset: 6%;
  border: calc(var(--board-size) / 110) solid var(--sq-cap); border-radius: 50%; z-index: 1;
}
/* Souřadnice na desce: barva podle odstínu pole (na světlém tmavá, na tmavém
   světlá) — čitelné na obou a nezávislé na motivu (pole jsou dřevo v obou). */
.coord { position: absolute; font-size: calc(var(--board-size) / 8 * 0.2); font-weight: 800; opacity: .85; z-index: 1; }
.square.light .coord { color: #43301c; }
.square.dark .coord { color: #f2e6cc; }
.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 1px; right: 3px; }

/* Překryvy nad deskou */
.board-overlay {
  position: absolute; inset: 0; z-index: 10;
  display: grid; place-items: center;
  background: rgba(43, 33, 73, 0.55); border-radius: 12px;
  backdrop-filter: blur(2px);
}
.overlay-card {
  background: var(--card); border-radius: var(--radius); padding: 20px 24px;
  text-align: center; max-width: 86%;
  box-shadow: 0 10px 30px rgba(0,0,0,.3);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.overlay-card p { margin: 0; }
.overlay-card h3 { margin: 0; font-size: 24px; }
.room-code { font-size: 44px; font-weight: 900; letter-spacing: 10px; color: var(--brand); }
.end-emoji { font-size: 52px; line-height: 1; }
.end-elo { font-weight: 800; }
.end-elo .up { color: var(--ok); }
.end-elo .down { color: var(--danger); }
.overlay-buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* Létající emoji od soupeře */
#emoji-float { position: absolute; inset: 0; pointer-events: none; z-index: 9; overflow: hidden; }
.fly-emoji {
  position: absolute; font-size: 44px; animation: fly 1.6s ease-out forwards;
}
@keyframes fly {
  0% { opacity: 0; transform: translateY(20px) scale(.5); }
  20% { opacity: 1; transform: translateY(0) scale(1.15); }
  100% { opacity: 0; transform: translateY(-70px) scale(1); }
}

.moves-strip {
  width: var(--board-size); margin: 0 auto; min-height: 22px;
  overflow-x: auto; white-space: nowrap; font-size: 13px; color: var(--muted);
  display: flex; gap: 8px; align-items: center; scrollbar-width: none;
}
.moves-strip b { color: var(--ink); }

.game-actions { width: var(--board-size); margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.action-row { display: flex; gap: 8px; justify-content: center; align-items: center; }
.action-row .btn { flex: 1; max-width: 220px; }
.emoji-bar { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; }
.emoji-bar button {
  font-size: 22px; background: var(--card); border: none; border-radius: 10px;
  padding: 6px 10px; cursor: pointer; min-height: 40px;
  box-shadow: 0 2px 6px rgba(60,30,160,.1);
}
.emoji-bar button:active { transform: scale(1.2); }
.replay-nav { font-weight: 800; }
.replay-nav .btn { flex: 0 1 64px; }
.replay-nav .btn.active { background: var(--brand); color: #fff; }

/* ── Žebříček / moje hry ──────────────────────────────────────────────── */
.rank-num { font-weight: 900; width: 34px; text-align: center; flex: 0 0 auto; color: var(--muted); }
.rank-num.top { font-size: 20px; }
.rules-card p { margin: 4px 0; line-height: 1.5; }

.modal {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center;
  background: rgba(20, 12, 50, 0.6); backdrop-filter: blur(2px);
}
.tc-seg .seg-btn { min-width: 0; padding: 10px 4px; font-variant-numeric: tabular-nums; }
.challenge-btn { flex: 0 0 auto; font-size: 16px; background: transparent; border: none; cursor: pointer; padding: 6px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px;
  font-weight: 700; z-index: 100; max-width: 90vw; text-align: center;
  animation: pop-in .15s ease-out;
}

/* ── Širší obrazovky (PC / tablet) ────────────────────────────────────── */
@media (min-width: 700px) {
  :root { --board-size: min(60vw, 66dvh, 560px); }
  #app { max-width: 720px; }
  .menu-grid { grid-template-columns: repeat(4, 1fr); }
  .menu-btn { font-size: 40px; }
}
