/* Záplatris — MojeGalanterka.cz */
:root {
  --indigo: #4d51a6;
  --indigo-dark: #33356e;
  --coral: #e8735c;
  --coral-dark: #c9503a;
  --amber: #e0a838;
  --amber-dark: #b9861f;
  --teal: #3fa7a1;
  --teal-dark: #2c7d78;
  --cream: #f3f0fb;
  --ink: #34314f;
  --card: rgba(253, 251, 255, 0.94);
  --shadow: 0 8px 26px rgba(40, 32, 80, 0.22);
}

/* Barevné motivy prostředí (Část C3) — mění dílnu kolem, NE látky záplat
 * (ty mají vlastní volbu „Vzhled záplat"). Výchozí = Světlá dílna. */
html[data-theme="pulnoc"] {
  --indigo: #5d62c4;
  --indigo-dark: #23244d;
  --cream: #1d1b31;
  --ink: #eceafb;
  --card: rgba(38, 36, 64, 0.96);
  --shadow: 0 8px 26px rgba(0, 0, 0, 0.5);
}
html[data-theme="len"] {
  --indigo: #8a6f45;
  --indigo-dark: #5e4a2c;
  --cream: #f4efe3;
  --ink: #4a4234;
  --card: rgba(253, 250, 242, 0.95);
  --shadow: 0 8px 26px rgba(94, 74, 44, 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(--cream);
}

#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(51, 53, 110, 0.96), rgba(37, 38, 82, 0.94));
  box-shadow: 0 3px 12px rgba(20, 16, 50, 0.35);
  color: #f6f3ff;
}
.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.85rem;
  opacity: 0.92;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shop-top { color: #c9e0ff; text-decoration: none; font-weight: 700; font-size: 0.88rem; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.shop-top:hover { text-decoration: underline; }
.shop-link { cursor: pointer; }

.clocks { display: flex; gap: 6px; flex-shrink: 0; }
.clock-chip {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}
.clock-chip b { font-weight: 800; }

/* ---------- Herní plocha ---------- */
#gameArea {
  position: fixed;
  top: 44px; bottom: 92px; left: 0; right: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "board right";
  align-items: center;
  justify-items: center;
  gap: 8px;
  padding: 8px;
  overflow: hidden;
}
#sidePanelRight { grid-area: right; }
#boardWrap { grid-area: board; min-width: 0; min-height: 0; }
.side-panel { display: flex; flex-direction: column; align-items: center; gap: 8px; flex-shrink: 0; min-width: 0; }
.side-box {
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.side-label { font-size: 0.72rem; font-weight: 700; color: var(--indigo-dark); text-transform: uppercase; letter-spacing: 0.5px; }
.next-list { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.next-item canvas { background: rgba(77, 81, 166, 0.08); border-radius: 8px; }

#boardWrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#board {
  background: linear-gradient(160deg, #3a3d78, #262a52);
  border-radius: 10px;
  box-shadow: var(--shadow), inset 0 0 0 3px rgba(255, 255, 255, 0.08);
}

#pauseOverlay {
  /* rozměr nastavuje JS na velikost canvasu; centrujeme na střed boardWrapu,
     kde je i vycentrovaný canvas → overlay sedí přesně na hrací plochu */
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: none;
  align-items: center; justify-content: center;
  background: rgba(20, 18, 46, 0.72);
  border-radius: 10px;
  cursor: pointer;
  z-index: 15;
}
#pauseOverlay.show { display: flex; }
#idleOverlay {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: none;
  align-items: center; justify-content: center;
  background: rgba(20, 18, 46, 0.72);
  border-radius: 10px;
  z-index: 14;
  text-align: center;
  padding: 20px;
}
#idleOverlay.show { display: flex; }
.pause-card {
  color: #fff; text-align: center; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.pause-card i { font-size: 2rem; }
.idle-card {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; text-align: center; color: #fff; padding: 20px;
  max-width: 280px;
}
.idle-card h3 { margin: 0; font-size: 1.3rem; }
.idle-card span { margin: 0; font-size: 0.95rem; opacity: 0.9; }
.idle-card button {
  font-family: inherit; font-size: 1rem; font-weight: 700;
  padding: 10px 24px; margin-top: 4px;
  border-radius: 12px; border: none; cursor: pointer;
  background: var(--indigo); color: #fff;
  display: inline-flex; align-items: center; gap: 8px;
}
.idle-card button:active { transform: scale(0.96); }

/* ---------- Ovládací lišta ---------- */
#toolbar {
  position: fixed;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  max-width: 96vw;
}
#menuIdle, #menuPlaying {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 6px;
}
#menuPlaying { display: none; }
#toolbar button {
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-radius: 12px;
  white-space: nowrap;
  min-width: 48px;
  padding: 7px 9px;
  font-size: 0.7rem;
}
#toolbar button i { font-size: 1.15rem; }
#toolbar button:active, #toolbar button:hover { background: rgba(77, 81, 166, 0.12); }

.toolbar-divider {
  width: 1px;
  align-self: stretch;
  margin: 4px 2px;
  background: rgba(52, 49, 79, 0.15);
}
.round-btn {
  min-width: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 999px !important;
  background: rgba(77, 81, 166, 0.1) !important;
}
.round-btn i { font-size: 1.05rem; }
#btnStop i { color: var(--coral-dark); }

/* ---------- Nastavení (sheet) ---------- */
#sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: min(94vw, 440px);
  transform: translate(-50%, 105%);
  max-height: 82vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 30px rgba(20, 16, 50, 0.35);
  padding: 16px 18px calc(20px + env(safe-area-inset-bottom));
  z-index: 40;
  transition: transform 0.28s ease;
}
#sheet.show { transform: translate(-50%, 0); }
#sheet h2 { margin: 0 0 12px; display: flex; justify-content: space-between; align-items: center; font-size: 1.1rem; color: var(--indigo-dark); }
#sheet h2 button { border: none; background: none; font-size: 1.1rem; color: var(--ink); cursor: pointer; padding: 4px 8px; }
.sheet-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid rgba(52, 49, 79, 0.08); font-size: 1rem; }
.sheet-row:last-of-type { border-bottom: none; }
.sheet-col { flex-direction: column; align-items: stretch; gap: 4px; }
.sheet-row label { font-weight: 700; color: var(--indigo-dark); }
.sheet-hint { font-size: 0.78rem; color: rgba(52, 49, 79, 0.65); }
.sheet-stats { font-size: 0.85rem; text-align: right; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
  width: 100%;
}
.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: rgba(77, 81, 166, 0.08);
  border-radius: 12px;
  padding: 8px 6px;
  text-align: center;
}
.stat-label { font-size: 0.68rem; color: rgba(52, 49, 79, 0.65); line-height: 1.25; }
.stat-value { font-size: 1.15rem; font-weight: 800; color: var(--indigo-dark); }
#sheet select, #sheet input[type=checkbox] { font-size: 1rem; }
#sheet select { padding: 8px 10px; border-radius: 10px; border: 1px solid rgba(52, 49, 79, 0.2); background: var(--card); color: var(--ink); }
#sheet input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--indigo); }
.rules-btn, .install-btn {
  border: none; border-radius: 10px; padding: 8px 14px; font-weight: 700; cursor: pointer;
  background: var(--indigo); color: #fff; font-family: inherit; font-size: 0.9rem;
}
.sheet-help { margin-top: 6px; font-size: 0.9rem; color: rgba(52, 49, 79, 0.85); line-height: 1.6; }
.sheet-help p { margin: 4px 0; }
.sheet-promo, .end-promo {
  display: block; margin-top: 16px; padding: 10px 14px; border-radius: 12px;
  background: linear-gradient(135deg, #ece7fb, #e6f4f2);
  color: var(--indigo-dark); text-decoration: none; font-size: 1rem; line-height: 1.5; text-align: center;
}

/* ---------- Modály (pravidla, konec hry) ---------- */
#rulesModal, #endModal {
  position: fixed; inset: 0; z-index: 50;
  display: none; align-items: center; justify-content: center;
  background: rgba(20, 18, 46, 0.55);
  padding: 16px;
}
#rulesModal.show, #endModal.visible { display: flex; }
.rules-box, .end-box {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px 22px;
  width: 100%;
  max-height: 84vh;
  overflow-y: auto;
}
/* Modál konce partie je užší než pravidla — viz pokyny, Část F. */
.end-box { max-width: min(90vw, 400px); }
.rules-box { max-width: min(92vw, 430px); width: 100%; }
.rules-box h2, .end-box h2 { margin: 0 0 10px; display: flex; justify-content: space-between; align-items: center; color: var(--indigo-dark); font-size: 1.15rem; }
.rules-box h2 button { border: none; background: none; font-size: 1.1rem; color: var(--ink); cursor: pointer; }
.rules-box h3 { margin: 14px 0 4px; font-size: 0.95rem; color: var(--coral-dark); }
.rules-box p { margin: 4px 0; font-size: 0.92rem; line-height: 1.55; }
.rules-box table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 0.88rem; }
.rules-box th, .rules-box td { text-align: left; padding: 5px 8px; border-bottom: 1px solid rgba(52, 49, 79, 0.1); }
.end-box { text-align: center; }
.end-box p { font-size: 1rem; }
.end-box .btns { display: flex; gap: 10px; justify-content: center; margin: 14px 0 4px; margin-bottom: 1rem; }
.end-box .btns button {
  border: none; border-radius: 12px; padding: 10px 18px; font-weight: 700; cursor: pointer; font-family: inherit; flex: 1;
}

#endNew { background: var(--coral); color: #fff; }
#endClose { background: rgba(52, 49, 79, 0.1); color: var(--ink); }
#endShare { background: rgba(52, 49, 79, 0.1); color: var(--ink); width: 100%; }

@media (max-width: 700px) {
  #gameArea {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "right"
      "board";
  }
  .side-panel { flex-direction: row; justify-content: center; width: 100%; }
  .side-box { flex-direction: row; padding: 6px 10px; gap: 8px; }
  .next-list { flex-direction: row; gap: 6px; }
  #boardWrap { width: 100%; height: 100%; }
}

@media (max-width: 480px) {
  .brand .vs { display: none; }
  #gameArea { gap: 6px; }
  .side-box { padding: 6px 8px; }
  .side-label { font-size: 0.62rem; }
  #sheet input[type="checkbox"] { width: 28px; height: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  #sheet { transition: none; }
}
/* Čitelnost nočního motivu: nadpisy a popisky jely z --indigo-dark (tmavá na tmavé) */
html[data-theme="pulnoc"] #sheet h2,
html[data-theme="pulnoc"] .sheet-row label,
html[data-theme="pulnoc"] .rules-box h2,
html[data-theme="pulnoc"] .end-box h2 { color: #b9bdf3; }
html[data-theme="pulnoc"] .sheet-hint { color: rgba(236, 234, 251, 0.6); }
html[data-theme="pulnoc"] .stat-value { color: #c9ccf5; }
html[data-theme="pulnoc"] #sheet select { border-color: #4d5180; }

html[data-theme="pulnoc"] .side-label,
html[data-theme="pulnoc"] .sheet-help p 
	{ color: #b9bdf3; }
