/* Cívky — MojeGalanterka.cz */
:root {
  --wood: #8a5a3a;
  --wood-dark: #5c3a24;
  --linen: #f3ece0;
  --linen-edge: #e2d2b8;
  --ink: #3f2c20;
  --card: rgba(255, 251, 244, 0.96);
  --shadow: 0 8px 26px rgba(63, 44, 32, 0.22);
  --amber: #e0a838;
  --amber-dark: #b9861f;
  --teal: #3fa7a1;
  --teal-dark: #2c7d78;
  --coral: #e8735c;
  --coral-dark: #c9503a;
}

/* Barevné motivy prostředí (Část C3) — mění zásuvku a plátno kolem,
 * NE paletu přízí --y0..--y8 (ta je ve všech motivech stejná — hráč
 * musí barvy vždy spolehlivě rozlišit) ani bílou plochu cívek. */
html[data-theme="pulnoc"] {
  --wood: #b98a5c;
  --wood-dark: #7a5433;
  --linen: #262019;
  --linen-edge: #40352a;
  --ink: #f2e9dc;
  --card: rgba(45, 37, 29, 0.96);
  --shadow: 0 8px 26px rgba(0, 0, 0, 0.5);
}
html[data-theme="levandule"] {
  --wood: #7a6294;
  --wood-dark: #55416c;
  --linen: #f0ebf6;
  --linen-edge: #dccfe9;
  --ink: #3d2f4e;
  --card: rgba(252, 250, 255, 0.96);
  --shadow: 0 8px 26px rgba(85, 65, 108, 0.2);
}
:root { /* pokračování — paleta přízí (na motivu nezávislá) */

  /* Paleta přízí — musí být vzájemně dobře odlišitelné (až 9 barev) */
  --y0: #e8735c; /* korálová */
  --y1: #3fa7a1; /* petrolejová */
  --y2: #e0a838; /* medová */
  --y3: #4d51a6; /* indigová */
  --y4: #d15a8f; /* malinová */
  --y5: #7a8c3a; /* olivová */
  --y6: #8a5a3a; /* hnědá */
  --y7: #4a90c9; /* nebeská */
  --y8: #8a4fd1; /* fialová */
}

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

html, body {
  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, 58, 36, 0.96), rgba(63, 44, 32, 0.94));
  box-shadow: 0 3px 12px rgba(40, 26, 16, 0.35);
  color: #fdf6ec;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 {
  margin: 0; font-size: 1.2rem; letter-spacing: 1.5px; font-weight: 800;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.35); white-space: nowrap;
}
.brand .vs { font-size: 0.82rem; opacity: 0.92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shop-top { color: #f0d9b8; text-decoration: none; font-weight: 700; font-size: 0.85rem; white-space: nowrap; }
.shop-top:hover { text-decoration: underline; }

/* HUD vpravo nahoře: čas partie + aktuální level (level jen v režimu Výzva) */
.hud { display: flex; align-items: center; gap: 7px; white-space: nowrap; font-size: 0.84rem; font-weight: 700; }
.hud span { background: rgba(0, 0, 0, 0.24); border-radius: 999px; padding: 3px 10px; }
.hud #hudLevel { background: rgba(224, 168, 56, 0.30); }
.hud #hudTime i { margin-right: 5px; opacity: 0.85; font-size: 0.78rem; }
@media (max-width: 420px) { .hud { font-size: 0.78rem; } .hud span { padding: 3px 8px; } }

.status-chip {
  position: fixed; top: 52px; left: 50%; transform: translateX(-50%); z-index: 19;
  background: var(--card); padding: 7px 16px; border-radius: 999px; box-shadow: var(--shadow);
  font-weight: 700; font-size: 0.92rem; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- Toolbar (plovoucí karta) ---------- */
#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.72rem; font-weight: 700; padding: 6px 10px; 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.15rem; }
#toolbar button:hover { background: rgba(138, 90, 58, 0.14); }
#toolbar button:active { transform: scale(0.94); }
#toolbar button:disabled { opacity: 0.35; cursor: default; }
.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(--coral-dark); color: #fff; font-size: 0.62rem; font-weight: 800;
  line-height: 15px; text-align: center;
}

/* ---------- Herní plocha ---------- */
#stage {
  position: fixed; inset: 0; padding-top: 88px; padding-bottom: 66px;
  display: flex; align-items: center; justify-content: center;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
#board {
  --tw: 46px;     /* šířka cívky */
  --segh: 30px;   /* výška jednoho pruhu příze */
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: center;
  gap: 10px 6px; max-width: 96vw; padding: 10px 5px;
}
/* Zmenšení na mobilu, ať se deska vejde na displej (třídy nastavuje render()
 * v main.js podle počtu cívek a jejich kapacity — režim Výzva). */
@media (max-width: 699px) {
  #board.board-tight { --tw: 38px; }   /* 10+ cívek na desce */
  #board.board-cap5  { --segh: 26px; } /* kapacita 5 segmentů */
  #board.board-cap6  { --segh: 23px; } /* kapacita 6 segmentů */
}

.tube-wrap { display: flex; flex-direction: column; align-items: center; }
.tube {
  /* --tw a --segh dědí z #board (tam je i mobilní zmenšení pro režim Výzva) */
  --okraj: 8px;   /* výška dřevěného okraje cívky */
  width: var(--tw);
  /* Pevná výška: všechny cívky (plné i prázdné) stejně vysoké —
     2 okraje + kapacita × výška segmentu + 2×2px rámeček (border-box). */
  height: calc(2 * var(--okraj) + var(--cap, 4) * var(--segh) + 4px);
  display: flex; flex-direction: column-reverse;
  border: 2px solid rgba(63,44,32,0.18);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;                 /* prázdná plocha mezi okraji je bílá */
  box-shadow: var(--shadow);
  padding: var(--okraj) 0;          /* místo pro okraje; po stranách bez odsazení */
  gap: 0;                           /* segmenty navazují přímo na sebe */
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}
/* Okraje cívky mimo tok flexu — drží nahoře a dole bez ohledu na počet segmentů */
.tube::before, .tube::after {
  content: ""; position: absolute; left: 0; width: 100%; height: var(--okraj);
  background: var(--wood); box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.tube::before { bottom: 0; }
.tube::after  { top: 0; }
.tube.selected {
  transform: translateY(-10px);
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(224,168,56,0.35), var(--shadow);
}
.tube.hint-from { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(63,167,161,0.35), var(--shadow); }
.tube.hint-to { border-color: var(--coral); box-shadow: 0 0 0 3px rgba(232,115,92,0.35), var(--shadow); }
.tube.disabled { cursor: default; }

.segment {
  width: 100%; height: var(--segh, 30px); border-radius: 0; position: relative; overflow: hidden;
  box-shadow: inset 0 2px 3px rgba(255,255,255,0.35), inset 0 -3px 4px rgba(0,0,0,0.18);
  animation: seg-in 0.18s ease;
}
.segment::after {
  content: ""; position: absolute; inset: 0;
  background-image: repeating-linear-gradient(115deg, rgba(255,255,255,0.16) 0 3px, transparent 3px 9px);
}
@keyframes seg-in { from { transform: scaleY(0.3); opacity: 0.3; } to { transform: scaleY(1); opacity: 1; } }
.segment.leaving { animation: seg-out 0.16s ease forwards; }
@keyframes seg-out { to { transform: scaleY(0.2); opacity: 0; } }

.tube-empty-slot { flex: 1; min-height: 30px; }

@media (min-width: 700px) {
  #board { --tw: 54px; --segh: 34px; }
}

/* ---------- Panel deadlocku ---------- */
#deadlock {
  position: fixed; inset: 0; z-index: 45; display: none; align-items: center; justify-content: center;
  background: rgba(63, 44, 32, 0.55); padding: 20px;
}
#deadlock.open { display: flex; }
#deadlock .box {
  background: var(--card); border-radius: 18px; padding: 22px 20px; max-width: 340px; width: 100%;
  text-align: center; box-shadow: var(--shadow);
}
#deadlock .box h2 { margin: 0 0 8px; font-size: 1.15rem; }
#deadlock .box p { margin: 0 0 14px; opacity: 0.85; font-size: 0.92rem; }
#deadlock .box .actions { display: flex; gap: 8px; }
#deadlock .box button {
  flex: 1; padding: 11px; border-radius: 10px; border: none; font-weight: 700; cursor: pointer;
  background: var(--teal); color: #fff;
}
#deadlock .box button.secondary { background: var(--wood); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; top: 94px; left: 50%; transform: translateX(-50%) translateY(-10px);
  background: rgba(63,44,32,0.92); color: #fff; padding: 8px 16px; border-radius: 10px;
  font-size: 0.85rem; font-weight: 600; z-index: 45; opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Nastavení (sheet) ---------- */
#sheet {
  position: fixed; z-index: 30; left: 50%; bottom: 0; width: min(94vw, 440px);
  transform: translate(-50%, 110%);
  background: var(--card); border-radius: 20px 20px 0 0; box-shadow: 0 -8px 30px rgba(63,44,32,0.3);
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 82vh; overflow-y: auto; transition: transform 0.24s ease;
}
#sheet.open { transform: translate(-50%, 0); }
#sheet h2 { margin: 0 0 6px; font-size: 1.15rem; display: flex; justify-content: space-between; align-items: center; }
#sheet h2 button { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--ink); }
.sheet-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid rgba(63,44,32,0.1); font-size: 1rem;
}
.sheet-row:last-child { border-bottom: none; }
.sheet-row.sheet-col { flex-direction: column; align-items: flex-start; gap: 9px; }
.sheet-row label { font-weight: 600; }
.sheet-row select {
  padding: 7px 10px; border-radius: 8px; border: 1px solid rgba(63,44,32,0.2); font-size: 0.9rem;
}
.sheet-row.sheet-col select { width: 100%; }
.sheet-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--wood); }
.diff-desc { margin: -3px 0 0; font-size: 0.8rem; opacity: 0.75; line-height: 1.4; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.stats-grid .stat { background: rgba(138,90,58,0.1); border-radius: 10px; padding: 8px; text-align: center; }
.stats-grid .stat b { display: block; font-size: 1.2rem; }
.stats-grid .stat span { font-size: 0.7rem; opacity: 0.75; }

.rules-btn, .install-btn, .sheet-link-btn {
  font-family: inherit; font-size: 0.85rem; font-weight: 700; padding: 8px 14px;
  border: none; border-radius: 10px; cursor: pointer; color: #fff;
}
.install-btn, .rules-btn { background: linear-gradient(135deg, var(--wood), var(--wood-dark)); }
 .install-btn:active, .rules-btn:active { transform: scale(0.96); }

.sheet-help { font-size: 0.9rem; color: var(--ink); opacity: 0.85; line-height: 1.5; margin-top: 8px; }
.sheet-help p { margin: 5px 0; display: flex; align-items: flex-start; gap: 8px; }
.sheet-help i { color: var(--wood); width: 18px; text-align: center; margin-top: 2px; }

.end-promo, .sheet-promo {
  display: block; margin-top: 16px; padding: 10px 14px; border-radius: 12px;
  background: linear-gradient(120deg, rgba(224,168,56,0.18), rgba(63,167,161,0.16));
  text-align: center; text-decoration: none; font-weight: 700; color: var(--wood-dark);
}
.end-promo:hover, .sheet-promo:hover { text-decoration: underline; }

/* ---------- Modál pravidel ---------- */
#rulesModal {
  position: fixed; inset: 0; z-index: 55; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(63,44,32,0.5); opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
#rulesModal.visible { opacity: 1; pointer-events: auto; }
.rules-box {
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 22px 24px;
  max-width: min(92vw, 430px); width: 100%; max-height: calc(100vh - 60px); overflow-y: auto;
  text-align: left; transform: translateY(12px); transition: transform 0.2s ease;
}
#rulesModal.visible .rules-box { transform: translateY(0); }
.rules-box h2 { margin: 0 0 10px; font-size: 1.15rem; color: var(--wood-dark); display: flex; align-items: center; justify-content: space-between; }
.rules-box h2 button { border: none; background: transparent; font-size: 1.1rem; cursor: pointer; color: var(--ink); padding: 4px 8px; border-radius: 8px; }
.rules-box h3 { font-size: 0.98rem; margin: 14px 0 4px; color: var(--wood-dark); }
.rules-box p, .rules-box li { font-size: 0.9rem; line-height: 1.55; margin: 4px 0; }
.rules-box ul { margin: 4px 0; padding-left: 20px; }
.rules-box .rule-note { background: rgba(224,168,56,0.16); border-radius: 10px; padding: 8px 12px; margin-top: 10px; font-size: 0.86rem; }

/* ---------- Konec hry (vyřešeno) ---------- */
#endModal {
  position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center;
  background: rgba(63,44,32,0.55); padding: 20px;
}
#endModal.visible { display: flex; }
#endModal .end-box { background: var(--card); border-radius: 18px; padding: 24px 22px; max-width: min(90vw, 400px); width: 100%; text-align: center; box-shadow: var(--shadow); }
#endModal h2 { margin: 0 0 6px; font-size: 1.4rem; }
#endModal p { margin: 0 0 14px; opacity: 0.85; }
#endModal .btns { display: flex; gap: 8px; }
#endModal .btns button { flex: 1; padding: 11px; border-radius: 10px; border: none; font-weight: 700; cursor: pointer; color: #fff; }

#endNew {background: var(--teal); }
#endClose { background:var(--wood); }
#endShare, #deadlockShare { background:var(--wood); width: 100%; }

@media (pointer: coarse), (max-width: 560px) {
  #sheet { padding: 18px 20px calc(20px + env(safe-area-inset-bottom)); }
  #sheet h2 { font-size: 1.3rem; }
  .sheet-row { font-size: 1.1rem; padding: 13px 0; }
  .sheet-row select { font-size: 1.05rem; padding: 9px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .segment, .tube { animation: none !important; transition: none !important; }
}
