/* Vlník — MojeGalanterka.cz
 * Vizuální motiv: jehlice táhne přízi po plátně (mřížce) a sbírá barevná
 * klubíčka. Vlastní paleta a motivy, nezávislé na ostatních hrách v sérii.
 * Barevné motivy: ranní (výchozí), půlnoční, mátová, terakotová.
 * Přepínají se atributem <html data-theme="…">. */
:root {
  --bg1: #f4ecd8;                 /* plátno na vyšívání — teplý len */
  --bg2: #e7dcc0;
  --ink: #3a3226;
  --card: rgba(253, 250, 242, 0.95);
  --topbar1: rgba(122, 90, 48, 0.97);   /* dřevěná dílna */
  --topbar2: rgba(92, 66, 32, 0.95);
  --topbar-ink: #fbf3e2;
  --accent: #c98c28;              /* medová hořčice */
  --accent-dark: #a06f1e;
  --needle: #c9ccd1;               /* jehlice je vždy ocelová, napříč motivy */
  --needle-dark: #8d919a;
  --shadow: 0 8px 26px rgba(60, 45, 20, 0.22);
  --promo1: #f6efe0;
  --promo2: #f0e6d3;
  --grid-dot: rgba(122, 90, 48, 0.12);
}
html[data-theme="pulnoc"] {
  --bg1: #2b2a3a;
  --bg2: #1d1c28;
  --ink: #e9e6f0;
  --card: rgba(40, 39, 52, 0.95);
  --topbar1: rgba(20, 19, 28, 0.97);
  --topbar2: rgba(13, 12, 19, 0.95);
  --topbar-ink: #f0edf8;
  --accent: #d9b34a;
  --accent-dark: #b8943a;
  --shadow: 0 8px 26px rgba(0, 0, 0, 0.5);
  --promo1: #302f40;
  --promo2: #383650;
  --grid-dot: rgba(230, 225, 245, 0.08);
}
html[data-theme="terakota"] {
  --bg1: #f3ded1;
  --bg2: #e6c3ac;
  --ink: #432a1f;
  --card: rgba(253, 246, 240, 0.95);
  --topbar1: rgba(155, 74, 42, 0.97);
  --topbar2: rgba(122, 55, 30, 0.95);
  --topbar-ink: #fbeee6;
  --accent: #c25a34;
  --accent-dark: #9c4527;
  --shadow: 0 8px 26px rgba(90, 45, 20, 0.25);
  --promo1: #f7e9df;
  --promo2: #f0d9c8;
  --grid-dot: rgba(122, 55, 30, 0.12);
}

* { 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(--bg2);
}

/* ---------- 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, var(--topbar1), var(--topbar2));
  box-shadow: 0 3px 12px rgba(15, 20, 28, 0.35);
  color: var(--topbar-ink);
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  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.85rem;
  opacity: 0.92;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand a, .shop-top { color: var(--topbar-ink); text-decoration: none; font-weight: 700; font-size: 0.88rem; white-space: nowrap; opacity: 0.92; }
.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, var(--promo1), var(--promo2));
  color: var(--ink);
  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: var(--accent);
  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(--accent-dark); }
.end-promo:hover, .sheet-promo:hover { box-shadow: 0 3px 12px rgba(45, 35, 20, 0.2); }

/* ---------- HUD skóre nad hrou ---------- */
.score-hud {
  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: 700;
  text-align: center;
}
.score-hud b { color: var(--accent-dark); }

/* ---------- Herní plocha (čtvercová mřížka) ---------- */
#gameWrap {
  position: fixed;
  inset: 0;
  padding-top: 96px;
  padding-bottom: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
#gameFrame {
  background: linear-gradient(155deg, var(--topbar1), var(--topbar2));
  border-radius: 22px;
  padding: 10px;
  box-shadow: 0 10px 30px rgba(20, 26, 36, 0.35);
  position: relative;
}
#game {
  display: block;
  border-radius: 14px;
  background: var(--bg1);
  touch-action: none;
}

#pauseOverlay, #startOverlay {
  position: absolute;
  inset: 10px;
  border-radius: 14px;
  background: rgba(28, 22, 14, 0.6);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  text-align: center;
  padding: 20px;
}
#pauseOverlay.visible, #startOverlay.visible { display: flex; }
#pauseOverlay h3, #startOverlay h3 { margin: 0; font-size: 1.3rem; }
#pauseOverlay p, #startOverlay p { margin: 0; font-size: 0.95rem; opacity: 0.9; max-width: 260px; }
#startOverlay button, #pauseOverlay button {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 10px 20px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
#startOverlay button:active, #pauseOverlay button:active { transform: scale(0.96); }

/* ---------- 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: 8px;
  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.82rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 64px;
  white-space: nowrap;
}
#toolbar button i { font-size: 1.25rem; }
#toolbar button:hover { background: rgba(58, 50, 38, 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(15, 20, 28, 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;
  color: var(--ink);
}
#sheet.open { transform: translate(-50%, 0); }
#sheet h2 {
  margin: 0 0 10px;
  font-size: 1.2rem;
  color: var(--ink);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#sheetClose {
  border: none;
  background: rgba(58, 50, 38, 0.08);
  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 rgba(122, 90, 48, 0.2);
  font-size: 1rem;
}
.sheet-row:last-child { border-bottom: none; }
.sheet-row.sheet-col { flex-direction: column; align-items: flex-start; gap: 6px; }
.sheet-hint { font-size: 0.86rem; opacity: 0.75; }
.sheet-row label { font-weight: 600; }
.sheet-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}
.sheet-row select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(125, 125, 125, 0.4);
  background: var(--card);
  color: var(--ink);
}
.color-swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.color-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.08);
  cursor: pointer;
  padding: 0;
  position: relative;
  box-shadow: inset 0 -2px 3px rgba(0,0,0,0.12), inset 0 2px 2px rgba(255,255,255,0.5);
  transition: transform 0.12s ease;
}
.color-swatch:hover { transform: scale(1.08); }
.color-swatch.selected {
  border-color: var(--accent-dark);
  box-shadow: inset 0 -2px 3px rgba(0,0,0,0.12), inset 0 2px 2px rgba(255,255,255,0.5), 0 0 0 2px #fff, 0 0 0 4px var(--accent-dark);
}
.color-swatch.selected::after {
  content: "\2713";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(0,0,0,0.55);
  font-size: 0.95rem;
  font-weight: 700;
}
.sheet-stats { display: flex; gap: 12px; font-size: 0.98rem; flex-wrap: wrap; justify-content: flex-end; }
.sheet-stats b { color: var(--accent-dark); }
.sheet-help { font-size: 0.9rem; opacity: 0.8; line-height: 1.45; margin-top: 10px; }
.sheet-help i { color: var(--accent-dark); width: 20px; text-align: center; }

/* ---------- Konec hry / pravidla ---------- */
#endModal, #rulesModal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 24, 14, 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(15, 18, 26, 0.4);
  padding: 26px 30px;
  text-align: center;
  max-width: min(90vw, 400px);
  width: 100%;
  transform: translateY(12px);
  transition: transform 0.25s ease;
  color: var(--ink);
}
.rules-box {
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 14px 44px rgba(15, 18, 26, 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;
  color: var(--ink);
}
#endModal.visible .end-box, #rulesModal.visible .rules-box { transform: translateY(0); }
.end-box h2 { margin: 0 0 6px; font-size: 1.3rem; color: var(--ink); }
.end-box p { margin: 0 0 16px; font-size: 0.95rem; opacity: 0.8; }
.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: var(--accent); color: #fff; }
#endClose { background: rgba(58, 50, 38, 0.08); color: var(--ink); }
#endShare { background: rgba(58, 50, 38, 0.08); 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(--ink); display: flex; justify-content: space-between; align-items: center; }
.rules-box h3 { margin: 14px 0 4px; font-size: 1.02rem; color: var(--accent-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; }
.rule-note { font-style: italic; opacity: 0.75; }

#rulesClose {
  border: none;
  background: rgba(58, 50, 38, 0.08);
  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: 0.98rem; letter-spacing: 0.5px; }
  .brand .vs { display: none; }
  .hide-sm { display: none; }
  .shop-top { font-size: 0.72rem; }
  .score-hud { top: 50px; font-size: 0.88rem; padding: 6px 14px; }
  #gameWrap { padding-top: 92px; }
}

@media (pointer: coarse), (max-width: 560px) {
  #toolbar { gap: 5px; padding: 8px 6px; }
  #toolbar button { min-width: 66px; font-size: 0.85rem; padding: 8px 10px; }
  #toolbar button i { font-size: 1.3rem; }

  #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 input[type="checkbox"] { width: 28px; height: 28px; }
  .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 { transition: none !important; }
}
