/* Duhový běh (birthday-games) – styly
   Plátno má logické rozlišení 960×540; #stage se škáluje z JS a proměnná --u
   (pixely obrazovky na jeden logický pixel) škáluje i texty a tlačítka. */

:root {
  --u: 1;
  --accent1: #22b8cf;
  --accent2: #5c7cfa;
  --ink: #2b3a67;
  --font: "Comic Sans MS", "Chalkboard SE", "Comic Neue", "Trebuchet MS", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(160deg, #c5f6fa, #d3f9d8 50%, #fff3bf);
  font-family: var(--font), sans-serif;
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;   /* záloha pro prohlížeče bez dvh */
  height: 100dvh;
}

#stage {
  position: relative;
  width: 960px;
  height: 540px;
  overflow: hidden;
  border-radius: calc(14px * var(--u));
  box-shadow: 0 10px 40px rgba(40, 90, 150, .3);
  touch-action: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- Tlačítka vpravo nahoře ---------- */
#topbar {
  position: absolute;
  top: calc(10px * var(--u));
  right: calc(10px * var(--u));
  display: flex;
  gap: calc(8px * var(--u));
  z-index: 30;
}

.icon-btn {
  width: calc(44px * var(--u));
  height: calc(44px * var(--u));
  font-size: calc(22px * var(--u));
  line-height: 1;
  padding: 0;
  border: calc(3px * var(--u)) solid #fff;
  border-radius: 50%;
  background: rgba(255, 255, 255, .6);
  color: var(--ink);
  cursor: pointer;
  font-family: var(--font), sans-serif;
}
.icon-btn:hover { background: rgba(255, 255, 255, .9); }

/* ---------- Dotyková tlačítka ---------- */
.touch {
  position: absolute;
  bottom: calc(6px * var(--u));
  display: none;
  gap: calc(10px * var(--u));
  z-index: 10;
  touch-action: none;
}
#touch-left { left: calc(10px * var(--u)); }
#touch-right { right: calc(10px * var(--u)); }

/* Zobrazit na dotykových zařízeních, nebo jakmile se kdekoli dotkneme obrazovky */
@media (any-pointer: coarse) { .touch { display: flex; } }
body.touch-on .touch { display: flex; }

.tbtn {
  width: calc(96px * var(--u));
  height: calc(70px * var(--u));
  border: calc(3px * var(--u)) solid rgba(255, 255, 255, .9);
  border-radius: calc(20px * var(--u));
  background: rgba(51, 154, 240, .5);
  color: #fff;
  font-family: var(--font), sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  text-shadow: 0 1px 2px rgba(30, 60, 110, .6);
}
.tbtn b { font-size: calc(28px * var(--u)); line-height: 1; }
.tbtn span { font-size: calc(15px * var(--u)); margin-top: calc(2px * var(--u)); }
.tbtn.active { background: rgba(255, 169, 77, .85); transform: scale(.95); }
.tbtn-star { width: calc(130px * var(--u)); background: rgba(255, 190, 60, .5); }
/* Pan Tulíček (Dinosauří údolí) – jen když je zkrocený; když odpočívá, je tlačítko průhledné */
.tbtn-dino { display: none; background: rgba(81, 207, 102, .55); opacity: .45; }
body.has-buddy .tbtn-dino { display: flex; }
body.buddy-ready .tbtn-dino { opacity: 1; }

/* ---------- Překryvné obrazovky ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  font-size: calc(20px * var(--u));
  background: rgba(240, 250, 255, .35);
  animation: fade-in .35s ease-out both;
}
.overlay.hidden { display: none; }
#ov-gameover { animation-delay: .5s; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.06); } 100% { transform: scale(1); opacity: 1; } }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-8%) rotate(4deg); } }

.panel {
  background: rgba(255, 255, 255, .88);
  border: calc(4px * var(--u)) solid #fff;
  border-radius: calc(28px * var(--u));
  padding: calc(22px * var(--u)) calc(34px * var(--u));
  text-align: center;
  box-shadow: 0 calc(8px * var(--u)) calc(30px * var(--u)) rgba(60, 120, 200, .3);
  max-width: 92%;
  animation: pop .45s ease-out both;
}

h1, h2 { margin: 0 0 .3em; line-height: 1.1; }
h1 { font-size: 2.3em; }
h2 { font-size: 1.9em; }
.sub { margin: 0 0 .8em; }
.small { font-size: .75em; margin: .8em 0 0; opacity: .85; }

.rainbow-text {
  background: linear-gradient(90deg, #ff5e7e, #ffa94d, #ffd43b, #69db7c, #4dabf7, #9775fa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.help {
  list-style: none;
  margin: 0 auto 1em;
  padding: 0;
  display: grid;
  grid-template-columns: 5.4em 4.6em auto;   /* jedna mřížka pro všechny řádky */
  gap: .35em .5em;
  align-items: center;
  text-align: left;
  width: max-content;   /* max-width zajistí, že na úzkém displeji se dlouhé popisky zalomí */
  max-width: 100%;
}
.help li { display: contents; }
.help em { font-style: normal; font-size: .8em; opacity: .8; }

kbd {
  display: inline-block;
  min-width: 1.8em;
  padding: .1em .45em;
  border-radius: .4em;
  background: #fff;
  border: 2px solid #a5d8ff;
  border-bottom-width: 4px;
  text-align: center;
  font-family: var(--font), sans-serif;
  font-size: .95em;
}
.help kbd { justify-self: center; }
kbd.wide { font-size: .7em; padding: .3em .5em; }

.big-btn {
  font-family: var(--font), sans-serif;
  font-size: 1.3em;
  padding: .45em 1.5em;
  border: none;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(90deg, var(--accent1), var(--accent2));
  box-shadow: 0 .25em 0 #3b5bdb;
  cursor: pointer;
}
.big-btn:hover { filter: brightness(1.08); }
.big-btn:active { transform: translateY(.15em); box-shadow: 0 .1em 0 #3b5bdb; }

/* Panel s portrétem z konfigurace hry (např. betuska.svg) */
.with-portrait { display: flex; align-items: center; gap: 1em; text-align: center; }
.with-portrait > div { min-width: 0; }
.portrait {
  height: calc(250px * var(--u));
  width: auto;
  flex: none;
  filter: drop-shadow(0 calc(4px * var(--u)) calc(6px * var(--u)) rgba(30, 60, 110, .25));
}
.portrait-small { height: calc(190px * var(--u)); }

/* Výběr levelu */
.link-btn {
  font-family: var(--font), sans-serif;
  font-size: .75em;
  margin-top: .6em;
  padding: .25em .9em;
  border: 2px solid #a5d8ff;
  border-radius: 999px;
  background: rgba(255, 255, 255, .7);
  color: var(--ink);
  cursor: pointer;
}
.link-btn:hover { background: #fff; }
.levels-panel { max-height: 94%; overflow-y: auto; }
.pass-input {
  font-family: var(--font), sans-serif;
  font-size: 1.1em;
  width: 9em;
  padding: .3em .6em;
  border: 3px solid #a5d8ff;
  border-radius: .6em;
  text-align: center;
  -webkit-user-select: text;
  user-select: text;
}
.small-btn { font-size: 1em; padding: .3em 1.1em; margin-left: .4em; }
.err { color: #e03131; min-height: 1.2em; margin: .4em 0 0; font-size: .85em; }
.levels-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .45em;
  margin: .4em 0 .2em;
}
.lvl-btn {
  font-family: var(--font), sans-serif;
  font-size: .8em;
  display: grid;
  grid-template-columns: 2em 1fr 1.4em;
  align-items: center;
  gap: .3em;
  padding: .45em .6em;
  border: 3px solid #fff;
  border-radius: .8em;
  background: linear-gradient(90deg, #e7f5ff, #f3f0ff);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.lvl-btn b { font-size: 1.3em; text-align: center; }
.lvl-btn i { font-style: normal; text-align: center; }
.lvl-btn.done { background: linear-gradient(90deg, #d3f9d8, #fff3bf); }
.lvl-btn:hover:not(:disabled) { filter: brightness(1.05); border-color: #ffd43b; }
.lvl-btn:disabled { opacity: .45; cursor: default; }

/* Kartička levelu */
.card {
  text-align: center;
  background: rgba(255, 255, 255, .9);
  padding: 1em 2.4em;
  border-radius: 1.4em;
  border: .2em solid #fff;
  box-shadow: 0 .4em 1.5em rgba(60, 120, 200, .35);
  animation: pop .5s ease-out both;
}
.card-level { font-size: 1.3em; color: var(--accent2); }
.card-name { font-size: 2.6em; margin: .1em 0; }
.card-go { font-size: 1.6em; color: #f08c00; min-height: 1.3em; margin-top: .2em; }
.card-hint { font-size: .85em; opacity: .85; min-height: 1.2em; }

/* Slavnostní obrazovka – přes plátno s konfetami a jednorožci */
#ov-victory { background: transparent; align-items: flex-start; padding-top: calc(36px * var(--u)); }
.victory { background: rgba(255, 255, 255, .82); }
.cake { font-size: 2.6em; line-height: 1; animation: bob 1.6s ease-in-out infinite; }
.birthday {
  font-size: 2.1em;
  background: linear-gradient(90deg, #ff5e7e, #ff9f43, #f7c600, #3fbf6f, #3b9bf0, #8f5cf7);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.score-line { font-size: 1.3em; margin: .2em 0 .6em; }
.bonus-q { font-weight: bold; color: #e8590c; margin: 0 0 .5em; }
.btn-row { display: flex; gap: .6em; justify-content: center; flex-wrap: wrap; }
.dedication { font-size: 1.05em; font-style: italic; margin: .1em auto .5em; max-width: 30em; overflow-wrap: anywhere; white-space: pre-line; }
.create-own { display: inline-block; text-decoration: none; }
.create-own[hidden] { display: none; }
.dedication[hidden] { display: none; }

/* Upozornění na otočení zařízení (jen mobil na výšku) */
#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: linear-gradient(160deg, #c5f6fa, #d3f9d8 50%, #fff3bf);
  color: var(--ink);
  font-size: 26px;
  text-align: center;
}
.rotate-icon { font-size: 80px; animation: rotate-hint 2s ease-in-out infinite; }
@keyframes rotate-hint { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (any-pointer: coarse) {
  #rotate { display: flex; }
}

/* ---------- Smazání hry (#smazat=<token>) – přes celou obrazovku, bez škálování plátna ---------- */
.delete-screen {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  font-size: 20px;
  background: linear-gradient(160deg, #c5f6fa, #d3f9d8 50%, #fff3bf);
}
.delete-screen.hidden { display: none; }
.delete-screen .panel { max-width: 34em; }
.delete-screen .btn-row { align-items: center; }
.delete-screen .link-btn { margin-top: 0; font-size: .9em; }
.danger-btn { background: linear-gradient(90deg, #ff6b6b, #e03131); box-shadow: 0 .25em 0 #a51111; }
.danger-btn:active { box-shadow: 0 .1em 0 #a51111; }
.danger-btn:disabled { opacity: .6; cursor: wait; }

/* ---------- Mobil a tablet (body.touch-ui nastavuje game.js) ----------
   Hra vyplní celou obrazovku a tlačítka mají skutečnou velikost v pixelech
   (ne zmenšenou podle škálování plátna), aby se dobře trefovala palcem. */
body.touch-ui #stage { border-radius: 0; box-shadow: none; }
body.touch-ui .touch { display: flex; }

body.touch-ui .tbtn {
  --b: clamp(80px, 22vmin, 124px);
  width: var(--b);
  height: var(--b);
  border-radius: 50%;
  border-width: 3px;
  background: rgba(51, 154, 240, .4);
  box-shadow: 0 4px 12px rgba(30, 60, 110, .25);
}
body.touch-ui .tbtn b { font-size: calc(var(--b) * .38); }
body.touch-ui .tbtn span { font-size: calc(var(--b) * .16); margin-top: 2px; }
body.touch-ui .tbtn.active { background: rgba(255, 169, 77, .8); transform: scale(.92); }
body.touch-ui .tbtn-dino { background: rgba(81, 207, 102, .5); }
body.touch-ui .tbtn-star {
  --b: clamp(100px, 29vmin, 156px);
  background: rgba(255, 190, 60, .5);
}

/* Skok nad Skrč v levém rohu, velká Hvězda v pravém; respektuje výřezy displeje */
body.touch-ui #touch-left {
  flex-direction: column-reverse;   /* Skok nahoře, Skrč dole */
  gap: 12px;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
}
body.touch-ui #touch-right {
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
}

body.touch-ui #topbar {
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  gap: 10px;
}
body.touch-ui .icon-btn {
  width: max(50px, calc(44px * var(--u)));
  height: max(50px, calc(44px * var(--u)));
  font-size: 24px;
  border-width: 3px;
}

/* Na nízkém displeji (telefon na šířku) trochu menší obrázek na úvodní obrazovce */
@media (max-height: 480px) {
  .portrait { height: calc(210px * var(--u)); }
  .panel { padding: calc(14px * var(--u)) calc(24px * var(--u)); }
}

/* Herní tlačítka jen během hraní (na úvodní obrazovce, kartičce apod. by překážela) */
body.touch-ui:not([data-state="play"]) .touch { display: none; }
body.touch-ui .big-btn { font-size: 1.5em; padding: .5em 1.8em; }

/* Nápověda: na dotyku ukázat ⭐ místo mezerníku a skrýt klávesové zkratky */
.touch-only { display: none; }
body.touch-ui .touch-only { display: inline-block; }
body.touch-ui .desk-only { display: none; }
