/* ============================================================
   Kouzelná výprava — UI vrstva nad Three.js scénou
   Tablet-first, velké dotykové plochy (min 88×88 px), žádný text
   nutný ke čtení v dětském flow (ikony + hlas).
   ============================================================ */
:root {
  --font: 'Baloo 2', 'Segoe UI', Arial, sans-serif;
  --ink: #3a3352;
  --ink-soft: #6a6288;
  --cream: #fffaf0;
  --sun: #ffd166;
  --sun-dark: #e0a832;
  --coral: #ff9776;
  --coral-dark: #cc6547;
  --leaf: #7bd389;
  --leaf-dark: #4f9c5c;
  --sky: #bfe6ff;
  --berry: #b48ae6;
  --shadow: 0 8px 24px rgba(58, 51, 82, 0.22);
  --btn-size: clamp(64px, 9vmin, 96px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  font-family: var(--font); color: var(--ink); background: var(--sky);
  touch-action: none; -webkit-user-select: none; user-select: none; overscroll-behavior: none;
}
#game { position: fixed; inset: 0; overflow: hidden; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#ui { position: absolute; inset: 0; pointer-events: none; }
#ui > * { pointer-events: none; }
#ui .screen { position: absolute; inset: 0; }
#ui button, #ui .tappable { pointer-events: auto; }
#fade { position: absolute; inset: 0; background: #fff7e6; opacity: 0; pointer-events: none; transition: opacity 0.35s ease; z-index: 50; }
#fade.on { opacity: 1; pointer-events: auto; }

/* ---------- Načítání ---------- */
#loading {
  position: fixed; inset: 0; z-index: 100; background: linear-gradient(180deg, #cfeeff, #ffe9f3);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; font-size: 22px;
  transition: opacity 0.5s ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
.loading-fox { width: 80px; height: 80px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffb36b, #f07b2a);
  box-shadow: 0 6px 0 rgba(0,0,0,0.08); animation: bob 1.1s ease-in-out infinite; }
.loading-bar { width: min(320px, 70vw); height: 18px; border-radius: 12px; background: rgba(255,255,255,0.7); overflow: hidden; border: 3px solid #fff; }
#loading-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--sun), var(--coral)); transition: width 0.2s ease; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }


/* ---------- Tlačítka ---------- */
.btn {
  font-family: var(--font); font-weight: 700; border: none; cursor: pointer; color: #fff;
  border-radius: 999px; padding: 0 clamp(20px, 3vmin, 34px); height: var(--btn-size); min-width: var(--btn-size);
  font-size: clamp(20px, 3.2vmin, 30px); display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  background: var(--leaf); box-shadow: 0 6px 0 var(--leaf-dark), var(--shadow);
  transition: transform 0.08s ease, box-shadow 0.08s ease; text-shadow: 0 1px 0 rgba(0,0,0,0.12);
}
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--leaf-dark); }
.btn.coral { background: var(--coral); box-shadow: 0 6px 0 var(--coral-dark), var(--shadow); }
.btn.coral:active { box-shadow: 0 1px 0 var(--coral-dark); }
.btn.sun { background: var(--sun); color: var(--ink); box-shadow: 0 6px 0 var(--sun-dark), var(--shadow); text-shadow: none; }
.btn.sun:active { box-shadow: 0 1px 0 var(--sun-dark); }
.btn.big { height: calc(var(--btn-size) * 1.4); font-size: clamp(28px, 5vmin, 44px); padding: 0 clamp(36px, 6vmin, 64px); }
.btn.round { width: var(--btn-size); padding: 0; border-radius: 50%; }
.btn.ghost { background: rgba(255,255,255,0.9); color: var(--ink); box-shadow: 0 6px 0 rgba(0,0,0,0.12), var(--shadow); text-shadow: none; }
.btn.ghost:active { box-shadow: 0 1px 0 rgba(0,0,0,0.12); }
.btn svg { width: 55%; height: 55%; }
.btn.round svg { width: 56%; height: 56%; }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.btn.wiggle { animation: wiggle 0.6s ease-in-out; }
@keyframes wiggle { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }

/* ---------- HUD ---------- */
.hud { position: absolute; top: calc(12px + var(--safe-top)); left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: flex-start; }
.hud .left, .hud .right { display: flex; gap: 12px; }

/* ---------- Dialogová bublina ---------- */
.dialogue {
  position: absolute; left: 50%; bottom: calc(18px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px);
  width: min(880px, 94vw); background: #fff; border-radius: 30px; padding: 14px 18px; display: flex; align-items: center; gap: 16px;
  box-shadow: var(--shadow); border: 5px solid var(--sun); opacity: 0; transition: opacity 0.25s ease, transform 0.25s ease; pointer-events: none;
}
.dialogue.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.dialogue .avatar { width: clamp(64px, 11vmin, 104px); height: clamp(64px, 11vmin, 104px); border-radius: 50%; object-fit: cover; object-position: center 20%; border: 4px solid var(--sun); background: #fff3d6; flex-shrink: 0; }
.dialogue .text { flex: 1; font-size: clamp(19px, 3vmin, 28px); line-height: 1.3; font-weight: 600; }
.dialogue .next { flex-shrink: 0; }
.dialogue.top { top: calc(90px + var(--safe-top)); bottom: auto; transform: translateX(-50%) translateY(-20px); }
.dialogue.top.show { transform: translateX(-50%) translateY(0); }
.dialogue.compact { width: auto; max-width: 94vw; }

/* ---------- Panely ---------- */
.panel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(0.9); width: min(760px, 92vw); max-height: 92vh; overflow: hidden;
  background: var(--cream); border-radius: 36px; padding: clamp(18px, 3vmin, 32px); text-align: center; box-shadow: 0 16px 48px rgba(58,51,82,0.3);
  border: 6px solid var(--sun); opacity: 0; transition: opacity 0.3s ease, transform 0.3s cubic-bezier(.34,1.56,.64,1); pointer-events: none;
}
.panel.show { opacity: 1; transform: translate(-50%, -50%) scale(1); pointer-events: auto; }
.panel h2 { margin: 0 0 8px; font-size: clamp(26px, 4.4vmin, 40px); }
.panel p { margin: 6px 0; font-size: clamp(18px, 2.6vmin, 24px); }
.panel .row { display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; margin-top: 14px; }
.panel .scroll { overflow-y: auto; max-height: calc(92vh - 230px); pointer-events: auto; touch-action: pan-y; }

/* Odměna */
.reward { display: flex; align-items: center; justify-content: center; gap: 24px; margin: 10px 0; flex-wrap: wrap; }
.reward .card { background: #fff; border-radius: 24px; padding: 12px; box-shadow: var(--shadow); border: 4px solid #fff; animation: popin 0.6s cubic-bezier(.34,1.56,.64,1); }
.reward .card img, .reward .card canvas { width: clamp(120px, 22vmin, 200px); height: clamp(120px, 22vmin, 200px); object-fit: contain; display: block; }
.reward .card .label { font-weight: 700; font-size: clamp(16px, 2.4vmin, 22px); margin-top: 6px; }
@keyframes popin { 0% { transform: scale(0.3) rotate(-8deg); opacity: 0; } 100% { transform: scale(1) rotate(0); opacity: 1; } }

/* ---------- Splash ---------- */
.splash-title { position: absolute; top: 9vh; left: 0; right: 0; text-align: center; pointer-events: none; }
.splash-title h1 { margin: 0; font-size: clamp(44px, 9vmin, 96px); color: #fff; letter-spacing: 1px;
  text-shadow: 0 4px 0 var(--sun-dark), 0 10px 24px rgba(58,51,82,0.3); -webkit-text-stroke: 2px rgba(120,70,20,0.35); }
.splash-title h2 { margin: 4px 0 0; font-size: clamp(18px, 3vmin, 28px); color: var(--ink); font-weight: 600; }
.splash-actions { position: absolute; bottom: 10vh; left: 0; right: 0; display: flex; justify-content: center; }
.age-pick { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; }
.age-pick .q { font-size: clamp(26px, 4.5vmin, 42px); font-weight: 700; color: #fff; text-shadow: 0 3px 0 rgba(58,51,82,0.3); }
.age-pick .row { display: flex; gap: 20px; }
.age-pick .btn { flex-direction: column; height: auto; padding: 14px 26px; line-height: 1.1; }
.age-pick .btn small { font-size: 0.55em; opacity: 0.9; }

/* ---------- Character Creator ---------- */
.creator-steps { position: absolute; top: calc(14px + var(--safe-top)); left: 50%; transform: translateX(-50%); display: flex; gap: 10px; }
.creator-steps .dot { width: 16px; height: 16px; border-radius: 50%; background: rgba(255,255,255,0.7); border: 3px solid #fff; }
.creator-steps .dot.active { background: var(--coral); transform: scale(1.25); }
.creator-steps .dot.done { background: var(--leaf); }
.creator-bottom { position: absolute; left: 0; right: 0; bottom: calc(14px + var(--safe-bottom)); display: flex; align-items: center; justify-content: center; gap: 14px; padding: 0 12px; }
.carousel { display: flex; gap: 14px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 10px 6px; max-width: min(1100px, 76vw); pointer-events: auto; touch-action: pan-x; scrollbar-width: none; }
.carousel::-webkit-scrollbar { display: none; }
.option {
  flex: 0 0 auto; width: clamp(88px, 14vmin, 130px); height: clamp(88px, 14vmin, 130px); border-radius: 28px; border: 5px solid #fff; background: rgba(255,255,255,0.9);
  box-shadow: 0 6px 0 rgba(0,0,0,0.1); display: flex; align-items: center; justify-content: center; scroll-snap-align: center; padding: 0; cursor: pointer; transition: transform 0.12s ease;
  font-family: var(--font); font-size: clamp(18px, 2.6vmin, 24px); font-weight: 700; color: var(--ink); overflow: hidden; position: relative;
}
.option canvas, .option img { width: 100%; height: 100%; object-fit: contain; }
.option.selected { border-color: var(--coral); transform: scale(1.1); box-shadow: 0 0 0 5px rgba(255,151,118,0.35), 0 6px 0 rgba(0,0,0,0.1); }
.option.locked { opacity: 0.45; filter: grayscale(1); }
.option.locked::after { content: ''; position: absolute; inset: 0; background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><rect x='5' y='10' width='14' height='11' rx='3' fill='%233a3352'/><path d='M8 10V7a4 4 0 0 1 8 0v3' stroke='%233a3352' stroke-width='2.5' fill='none'/></svg>") center/40% no-repeat; }
.option .swatch { width: 62%; height: 62%; border-radius: 50%; border: 4px solid rgba(0,0,0,0.08); }
.creator-name { position: absolute; left: 50%; bottom: calc(110px + var(--safe-bottom)); transform: translateX(-50%); font-size: clamp(24px, 4vmin, 38px); font-weight: 700; color: #fff; text-shadow: 0 3px 0 rgba(58,51,82,0.35); }

/* ---------- Album ---------- */
.album-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 10px; }
.album-card { background: #fff; border-radius: 24px; padding: 8px; border: 4px solid #fff; box-shadow: var(--shadow); cursor: pointer; pointer-events: auto; transition: transform 0.15s ease; }
.album-card:active { transform: scale(0.95); }
.album-card img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; }
.album-card.locked img { filter: brightness(0) opacity(0.15); }
.album-card .label { font-weight: 700; font-size: clamp(14px, 2vmin, 20px); margin-top: 4px; }
.album-card.locked .label { color: #bbb; }
.album-card.selected { transform: scale(1.06); border-color: var(--sun); }
@media (max-width: 800px) { .album-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; } }

/* ---------- Rodičovská zóna ---------- */
.gate-q { font-size: clamp(40px, 8vmin, 72px); font-weight: 800; margin: 6px 0; letter-spacing: 2px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 340px; margin: 10px auto; }
.keypad .btn { height: 64px; min-width: 0; font-size: 26px; }
.parent-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 6px; border-bottom: 2px dashed #eadfc8; font-size: clamp(17px, 2.4vmin, 22px); }
.parent-row .btn { height: 52px; font-size: 18px; padding: 0 16px; }
.parent-row .btn.off { opacity: 0.45; }
.seg { display: flex; gap: 6px; }
.seg .btn { height: 52px; font-size: 18px; padding: 0 16px; background: #e8e2d6; color: var(--ink); box-shadow: 0 4px 0 #cfc7b8; text-shadow: none; }
.seg .btn.on { background: var(--coral); color: #fff; box-shadow: 0 4px 0 var(--coral-dark); }
.progress-list { display: flex; gap: 6px; flex-wrap: wrap; }
.progress-list span { padding: 4px 10px; border-radius: 12px; background: #e8e2d6; font-size: 15px; }
.progress-list span.done { background: var(--leaf); color: #fff; }
.small { font-size: 15px; color: var(--ink-soft); }

/* ---------- Hlavolam ---------- */
.task-hint { position: absolute; top: calc(90px + var(--safe-top)); left: 50%; transform: translateX(-50%); background: rgba(255,255,255,0.92); padding: 10px 22px; border-radius: 22px;
  font-size: clamp(17px, 2.6vmin, 24px); font-weight: 700; box-shadow: var(--shadow); white-space: nowrap; max-width: 94vw; overflow: hidden; text-overflow: ellipsis; opacity: 0; transition: opacity 0.3s; }
.task-hint.show { opacity: 1; }
.hidden { display: none !important; }

/* ---------- Nízké displeje (telefon na šířku) ---------- */
@media (max-height: 520px) {
  :root { --btn-size: 60px; }
  .dialogue { padding: 8px 12px; gap: 10px; border-width: 4px; border-radius: 22px; bottom: calc(8px + var(--safe-bottom)); }
  .dialogue .avatar { width: 52px; height: 52px; }
  .dialogue .text { font-size: 17px; }
  .dialogue.top { top: calc(70px + var(--safe-top)); }
  .panel { padding: 12px 16px; border-radius: 24px; }
  .panel h2 { font-size: 22px; margin-bottom: 4px; }
  .reward .card img, .reward .card canvas { width: 96px; height: 96px; }
  .creator-bottom { bottom: calc(6px + var(--safe-bottom)); }
  .option { width: 74px; height: 74px; border-radius: 18px; }
  .creator-steps .dot { width: 12px; height: 12px; }
  .task-hint { top: calc(70px + var(--safe-top)); }
  .album-grid { gap: 8px; }
  .album-card { padding: 4px; }
}

/* ---------- Na výšku (mobil/tablet portrait) ---------- */
@media (orientation: portrait) {
  .age-pick .row { flex-wrap: wrap; justify-content: center; }
  .age-pick .btn.big { padding: 10px 22px; font-size: clamp(24px, 7vw, 40px); }
  .splash-title h1 { font-size: clamp(38px, 11vw, 80px); }
  .carousel { max-width: 62vw; }
  .album-grid { grid-template-columns: repeat(2, 1fr); }
  .panel { width: min(760px, 94vw); }
  .dialogue { width: 94vw; }
  .dialogue .text { font-size: clamp(17px, 4.2vw, 24px); }
}
