/* Čtverečky (Dots and Boxes) — MojeGalanterka.cz
 * Vizuální motiv: vyšívací plátno (aida) — tečky jako dírky ve tkanině,
 * tahy jako stehy nití, hotový čtvereček se "vyšije" křížkem (X) v barvě hráče. */
:root {
  --linen: #f3e9d8;
  --linen-edge: #e4d3b4;
  --wood: #5c4130;
  --wood-dark: #3f2c20;
  --thread1: #c1443a;
  --thread1-dark: #93342c;
  --thread2: #2c7a72;
  --thread2-dark: #1e5750;
  --gold: #cf9a3e;
  --card: rgba(255, 251, 244, 0.95);
  --ink: #3f2c20;
  --shadow: 0 8px 26px rgba(63, 44, 32, 0.24);
}

/* Barevné motivy prostředí (Část C3) — mění plátno a dílnu kolem,
 * NE barvy nití hráčů (ty mají vlastní volbu „Barvy nití"). */
html[data-theme="soumrak"] {
  --linen: #2b2420;
  --linen-edge: #423830;
  --wood: #a57d54;
  --wood-dark: #7c5a39;
  --card: rgba(46, 40, 36, 0.96);
  --ink: #f0e8dc;
  --shadow: 0 8px 26px rgba(0, 0, 0, 0.5);
}
html[data-theme="mata"] {
  --linen: #e7efe6;
  --linen-edge: #cfe0cd;
  --wood: #44604f;
  --wood-dark: #2e4436;
  --card: rgba(250, 253, 249, 0.95);
  --ink: #2e3b33;
  --shadow: 0 8px 26px rgba(46, 68, 54, 0.22);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  margin: 0;
  padding: 0;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink);
  background: var(--linen);
}

#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
}

/* ---------- Horní lišta ---------- */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: linear-gradient(180deg, rgba(92, 65, 48, 0.96), rgba(63, 44, 32, 0.94));
  box-shadow: 0 3px 12px rgba(30, 20, 12, 0.35);
  color: #fbf3e6;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 2px;
  font-weight: 800;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}
.brand .vs {
  font-size: 0.85rem;
  opacity: 0.92;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand .vs b.you { color: #f2b8a4; }
.brand .vs b.foe { color: #9fdcd4; }
.brand a, .shop-top { color: #f0dcc0; text-decoration: none; font-weight: 700; font-size: 0.88rem; white-space: nowrap; }
.brand a:hover, .shop-top:hover { text-decoration: underline; }
.shop-top { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.shop-link { cursor: pointer; }
.end-promo, .sheet-promo {
  display: block;
  margin-top: 16px;
  padding: 10px 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, #f3e6cd, #e6f0ee);
  color: var(--wood-dark);
  text-decoration: none;
  font-size: 1rem;
  line-height: 1.5;
}
.sheet-promo { text-align: center; margin-top: 14px; }

.install-btn, .rules-btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 9px 16px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--thread2), var(--thread2-dark));
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.install-btn:active, .rules-btn:active { transform: scale(0.96); }

.end-promo b, .sheet-promo b { color: var(--wood); }
.end-promo:hover, .sheet-promo:hover { box-shadow: 0 3px 12px rgba(92, 65, 48, 0.25); }

.clocks { display: flex; gap: 6px; flex-shrink: 0; }
.clock-chip {
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid transparent;
  white-space: nowrap;
}
#clockHuman.active { border-color: var(--thread1); background: rgba(193, 68, 58, 0.35); }
#clockAI.active { border-color: var(--thread2); background: rgba(44, 122, 114, 0.35); }

/* ---------- Stavový a skóre řádek ---------- */
.status-chip {
  position: fixed;
  top: 54px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  width: max-content;
  max-width: min(92vw, 640px);
  padding: 7px 16px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 0.98rem;
  font-weight: 600;
  text-align: center;
}
.status-chip.thinking { background: #f7ecd8; color: #8a5a17; }
.status-chip.won { background: #e6f4ee; color: #226349; }
.status-chip.lost { background: #fbe9e7; color: #97362f; }
.status-chip.p1turn { background: #f7e3de; color: var(--thread1-dark); box-shadow: var(--shadow), 0 0 0 2px var(--thread1) inset; }
.status-chip.p2turn { background: #dcefec; color: var(--thread2-dark); box-shadow: var(--shadow), 0 0 0 2px var(--thread2) inset; }

.score-chip {
  position: fixed;
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 19;
  width: max-content;
  max-width: min(92vw, 640px);
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(255, 251, 244, 0.85);
  box-shadow: 0 4px 14px rgba(63, 44, 32, 0.16);
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
  color: var(--wood-dark);
}
.score-chip b { color: var(--thread1-dark); }

/* ---------- Hrací plocha (vyšívací plátno) ---------- */
#boardWrap {
  position: fixed;
  inset: 0;
  padding-top: 128px;
  padding-bottom: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}
#boardFrame {
  background: linear-gradient(155deg, #caa876, #a9824f);
  border-radius: 22px;
  padding: 14px;
  box-shadow: 0 10px 30px rgba(63, 44, 32, 0.3);
}
#board {
  display: block;
  background: var(--linen);
  border-radius: 12px;
  touch-action: manipulation;
}
#board .dot { fill: var(--wood); }
#board .dot-ring { fill: none; stroke: var(--linen-edge); stroke-width: 2; }
#board .guide { stroke: #d6c39c; stroke-width: 2.5; stroke-linecap: round; opacity: 0.65; }
#board .hit { stroke: transparent; fill: none; cursor: pointer; }
#board .hit:hover ~ .guide,
#board .edge-g:hover .guide { stroke: var(--gold); opacity: 1; stroke-width: 4; }
#board .thread { stroke-linecap: round; opacity: 0; transition: opacity 0.15s ease; }
#board .drawn .thread { opacity: 1; }
#board .drawn .guide { opacity: 0; }
#board .thread.p1 { stroke: var(--thread1); }
#board .thread.p2 { stroke: var(--thread2); }
#board .box-fill { opacity: 0; transition: opacity 0.25s ease; }
#board .box-fill.shown { opacity: 1; }
#board .box-x { stroke-linecap: round; }
#board .box-x.p1 { stroke: var(--thread1); }
#board .box-x.p2 { stroke: var(--thread2); }
#board .box-bg.p1 { fill: rgba(193, 68, 58, 0.12); }
#board .box-bg.p2 { fill: rgba(44, 122, 114, 0.12); }
#board .edge-g.hinted .guide { stroke: var(--gold); opacity: 1; stroke-width: 5; animation: pulseHint 0.5s ease-in-out infinite alternate; }
@keyframes pulseHint { from { opacity: 0.6; } to { opacity: 1; } }

/* ---------- Spodní panel nástrojů ---------- */
#toolbar {
  position: fixed;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  gap: 6px;
  padding: 8px;
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
}
#toolbar button {
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 9px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 56px;
  white-space: nowrap;
}
#toolbar button i { font-size: 1.2rem; }
.icon-badge { position: relative; display: inline-block; }
.icon-badge .badge {
  position: absolute;
  top: -6px;
  right: -12px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--thread2-dark);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 15px;
  text-align: center;
}
#toolbar button:disabled .badge { background: #b7a88f; }
#toolbar button:hover { background: rgba(92, 65, 48, 0.1); }
#toolbar button:active { transform: scale(0.94); }
#toolbar button:disabled { opacity: 0.4; cursor: default; }

/* ---------- Nastavení (sheet) ---------- */
#sheet {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 105%);
  width: min(94vw, 440px);
  background: var(--card);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 30px rgba(30, 20, 12, 0.3);
  padding: 16px 18px calc(16px + env(safe-area-inset-bottom));
  transition: transform 0.3s cubic-bezier(0.4, 1.1, 0.5, 1);
  max-height: 78vh;
  overflow-y: auto;
}
#sheet.open { transform: translate(-50%, 0); }
#sheet h2 {
  margin: 0 0 10px;
  font-size: 1.2rem;
  color: var(--wood-dark);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#sheetClose {
  border: none;
  background: #f0e4cf;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  cursor: pointer;
  color: var(--ink);
}
.sheet-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px dashed #e4d3b4;
  font-size: 1rem;
}
.sheet-row:last-child { border-bottom: none; }
.sheet-row.sheet-col { flex-direction: column; align-items: flex-start; gap: 9px; }
.sheet-hint { font-size: 0.82rem; color: #967a5c; margin: -4px 0 2px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 34px;
  height: 30px;
  border-radius: 8px;
  border: 2px solid rgba(63, 44, 32, 0.2);
  cursor: pointer;
  padding: 0;
}
.swatch.sel {
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 2px #fff;
  transform: scale(1.08);
}
.sheet-row label { font-weight: 600; }
.sheet-row select {
  font-family: inherit;
  font-size: 1rem;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1.5px solid #d8c39e;
  background: var(--card);
  color: var(--ink);
}
.sheet-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--thread2-dark);
}
.sheet-stats { display: flex; gap: 12px; font-size: 0.98rem; flex-wrap: wrap; justify-content: flex-end; }
.sheet-stats b { color: var(--wood-dark); }
.sheet-help { font-size: 0.9rem; color: #7a6349; line-height: 1.45; margin-top: 10px; }
.sheet-help i { color: var(--thread2-dark); width: 20px; text-align: center; }

/* ---------- Konec partie / pravidla ---------- */
#endModal, #rulesModal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(40, 28, 18, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 16px;
}
#endModal.visible, #rulesModal.visible { opacity: 1; pointer-events: auto; }
.end-box {
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 14px 44px rgba(30, 18, 10, 0.4);
  padding: 26px 30px;
  text-align: center;
  max-width: min(90vw, 400px);
  width: 100%;
  transform: translateY(12px);
  transition: transform 0.25s ease;
}
.rules-box {
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 14px 44px rgba(30, 18, 10, 0.4);
  padding: 22px 26px;
  max-width: min(92vw, 430px);
  width: 100%;
  max-height: 82vh;
  overflow-y: auto;
  transform: translateY(12px);
  transition: transform 0.25s ease;
  text-align: left;
}
#endModal.visible .end-box, #rulesModal.visible .rules-box { transform: translateY(0); }
.end-box h2 { margin: 0 0 6px; font-size: 1.3rem; color: var(--wood-dark); }
.end-box p { margin: 0 0 16px; font-size: 0.95rem; color: #7a6349; }
.end-box .btns { display: flex; gap: 10px; margin-bottom: 1rem; }
.end-box .btns button { flex: 1; } /* Nová hra + Zavřít půl na půl, Sdílet samo přes celou šířku (Část F) */
.end-box button {
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 700;
  padding: 9px 18px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
	flex: 1;
}

#endNew { background: linear-gradient(135deg, var(--wood), var(--wood-dark)); color: #fff; }
#endClose { background: #f0e4cf; color: var(--ink); }
#endShare { background: #f0e4cf; color: var(--ink); width: 100%; }

.end-box button:active { transform: scale(0.96); }
.rules-box h2 { margin: 0 0 12px; font-size: 1.25rem; color: var(--wood-dark); display: flex; justify-content: space-between; align-items: center; }
.rules-box h3 { margin: 14px 0 4px; font-size: 1.02rem; color: var(--thread1-dark); }
.rules-box p, .rules-box li { margin: 0 0 8px; font-size: 0.98rem; line-height: 1.5; color: var(--ink); }
.rules-box ul { margin: 4px 0; padding-left: 20px; }
.rules-box table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 0.92rem; }
.rules-box th, .rules-box td { text-align: left; padding: 4px 6px; border-bottom: 1px dashed #e4d3b4; }
.rules-box .rule-note { background: #f3e9d8; border-radius: 10px; padding: 8px 12px; margin-top: 10px; font-size: 0.9rem; }
#rulesClose {
  border: none;
  background: #f0e4cf;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  cursor: pointer;
  color: var(--ink);
  flex-shrink: 0;
}

/* ---------- Mobil ---------- */
@media (max-width: 560px) {
  #topbar { padding: 8px 10px; }
  .brand { gap: 8px; }
  .brand h1 { font-size: 1rem; letter-spacing: 1px; }
  .brand .vs { display: none; }
  .hide-sm { display: none; }
  .shop-top { font-size: 0.72rem; }
  .clock-chip { font-size: 0.72rem; padding: 3px 7px; }
  .clocks { gap: 4px; }
  .status-chip { top: 50px; }
  .score-chip { top: 90px; font-size: 0.78rem; }
  #boardWrap { padding-top: 118px; }
  #boardFrame { padding: 8px; border-radius: 16px; }
}

@media (pointer: coarse), (max-width: 560px) {
  .status-chip { font-size: 0.95rem; padding: 8px 15px; }
  .score-chip { font-size: 0.85rem; padding: 6px 14px; }

  #toolbar { gap: 4px; padding: 8px 6px; }
  #toolbar button { min-width: 58px; font-size: 0.82rem; padding: 8px 8px; }
  #toolbar button i { font-size: 1.25rem; }

  #sheet { padding: 18px 20px calc(20px + env(safe-area-inset-bottom)); }
  #sheet h2 { font-size: 1.3rem; }
  #sheetClose { width: 38px; height: 38px; font-size: 1.05rem; }
  .sheet-row { font-size: 1.12rem; padding: 14px 0; }
  .sheet-row select { font-size: 1.05rem; padding: 10px 14px; }
  .sheet-row input[type="checkbox"] { width: 28px; height: 28px; }
  .swatch { width: 42px; height: 36px; }
  .sheet-stats { font-size: 1.02rem; gap: 12px; }
  .sheet-help { font-size: 1.02rem; line-height: 1.55; }
  .sheet-promo { font-size: 1.05rem; padding: 14px 16px; }

  .end-box { padding: 26px 24px; }
  .end-box h2 { font-size: 1.35rem; }
  .end-box p { font-size: 1rem; }
  .end-box button { font-size: 1.05rem; padding: 12px 22px; }
  .end-promo { font-size: 1.05rem; }
}

@media (prefers-reduced-motion: reduce) {
  #sheet, #endModal, .end-box, #rulesModal, .rules-box, #board .thread, #board .box-fill { transition: none !important; }
  #board .edge-g.hinted .guide { animation: none; }
}
/* Čitelnost nočního motivu: povrchy jedou z var(--card), pevné odstíny dorovnat */
html[data-theme="soumrak"] .sheet-hint { color: rgba(240, 232, 220, 0.65); }
html[data-theme="soumrak"] #sheet h2,
html[data-theme="soumrak"] .sheet-help p
 { color: var(--wood); }
html[data-theme="soumrak"] #sheetClose { color: var(--wood-dark); }
