:root {
  --ink: #2C2311; --cream: #F9E4B3; --yellow: #FAD063; --ochre: #DAA533;
  --red: #A23D2D; --green: #66AB6E; --blue: #4982BA; --panel: #3b2f19;
}
@property --p { syntax: '<percentage>'; inherits: false; initial-value: 0%; }

* { box-sizing: border-box; margin: 0; }
html, body {
  height: 100%; overflow: hidden; background: var(--ink); color: var(--cream);
  font-family: "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

button {
  font: inherit; color: inherit; cursor: pointer; border: 0; border-radius: 18px;
  padding: .7em 1.1em; background: #4a3b1f; min-height: 64px; touch-action: manipulation;
}
button:disabled { opacity: .45; cursor: default; }
button:focus-visible { outline: 4px solid var(--yellow); outline-offset: 3px; }

.screen { position: fixed; inset: 0; }

/* ---------- menu ---------- */
#menu { overflow: auto; display: flex; justify-content: center; align-items: flex-start; padding: 4vh 4vw; }
.menu-inner { width: min(920px, 100%); display: flex; flex-direction: column; gap: 14px; }
h1 { font-size: clamp(40px, 6vw, 72px); color: var(--yellow); }
.sub { font-size: clamp(20px, 2.4vw, 28px); opacity: .9; }
h2 { font-size: 22px; margin-top: 14px; opacity: .85; font-weight: 600; }
h3 { font-size: 20px; margin-top: 8px; opacity: .85; font-weight: 600; }
.choices { display: flex; flex-wrap: wrap; gap: 12px; }
.choice { flex: 1 1 220px; font-size: 22px; text-align: left; background: var(--panel); }
.choice b { display: inline-block; min-width: 1.6em; color: var(--yellow); }
.choice small { display: block; font-size: 15px; opacity: .8; margin-top: 2px; }
.choice.selected { background: var(--yellow); color: var(--ink); }
.choice.selected b { color: var(--red); }
.big { font-size: 30px; font-weight: 700; background: var(--green); color: #fff; padding: .6em 1.4em; min-height: 84px; }
#startBtn { margin-top: 18px; align-self: flex-start; }
.secondary { background: #4a3b1f; color: var(--cream); }
.small { font-size: 18px; min-height: 52px; }
.accent { background: var(--blue); color: #fff; }
.status { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; }
#offlineStatus { font-size: 18px; opacity: .9; flex: 1 1 100%; }
.help { font-size: 16px; opacity: .7; }
.version { font-size: 14px; opacity: .55; }

/* ---------- stage ---------- */
#stage { background: #000; touch-action: none; }
#stage > video {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
  opacity: 0; pointer-events: none; transition: opacity .25s linear;
}
#stage > video.front { opacity: 1; }
/* everything drawn over the videos must sit above them (videos use z-index 1–2 for the crossfade) */
#placeholder, #target, #tapHint, #ripples, #errorMsg, #action { z-index: 3; }

/* Mode B: the boy doing the action, in his circle, at the same place as in the episode */
#action { position: absolute; inset: 0; pointer-events: none; }
#boyCircle {
  position: absolute; border-radius: 50%; overflow: hidden; background: #FBE2CB;
  border: 6px solid #fff; box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
}
#boyVid { width: 100%; height: 100%; object-fit: cover; transform: scale(1.16); }
#boyQ { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--red); }
#actionWord {
  position: absolute; transform: translateX(-50%); white-space: nowrap; font-weight: 800; color: var(--red);
  background: rgba(255, 255, 255, .92); border-radius: 999px; padding: .05em .55em; box-shadow: 0 3px 10px rgba(0, 0, 0, .25);
}
#actionSteps { position: absolute; transform: translateX(-50%); display: flex; gap: 12px; }
#actionSteps span { width: 22px; height: 22px; border-radius: 50%; background: rgba(255, 255, 255, .55); border: 3px solid #fff; }
#actionSteps span.on { background: var(--yellow); }

/* Ρέκο's reaction after a turn: soft stars around him, no sound */
#sparks { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 4; }
.spark {
  position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px; background: var(--yellow); opacity: 0;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  animation: spark 1s ease-out forwards;
}
@keyframes spark {
  0% { transform: translate(0, 0) scale(.4); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.1) rotate(90deg); opacity: 0; }
}

#placeholder { position: absolute; pointer-events: none; overflow: hidden; }
#placeholder.card { background: #23402c; }
#placeholder.card::after {
  content: ""; position: absolute; left: 3%; bottom: 6%; width: 3%; aspect-ratio: 1; background: var(--yellow);
  animation: slide 4s linear infinite;
}
@keyframes slide { to { left: 94%; } }
#phLabel {
  position: absolute; left: 0; right: 0; top: 10%; text-align: center; color: #fff;
  font-size: clamp(28px, 4.5vw, 60px); font-weight: 700; text-shadow: 0 2px 8px #000;
}
#phNote {
  position: absolute; left: 0; right: 0; top: 24%; text-align: center; color: #fff;
  font-size: clamp(16px, 1.8vw, 24px); opacity: .85;
}
#phDragon {
  position: absolute; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 40% 35%, #ffe28a, var(--yellow) 55%, var(--ochre));
  color: var(--ink); font-weight: 800; font-size: clamp(18px, 2.4vw, 34px);
  box-shadow: 0 0 0 6px rgba(162, 61, 45, .8);
}

#target {
  position: absolute; border-radius: 50%; pointer-events: none;
  border: 8px solid rgba(250, 208, 99, .95);
  box-shadow: 0 0 24px 8px rgba(250, 208, 99, .55), inset 0 0 24px rgba(250, 208, 99, .4);
  animation: breathe 2.6s ease-in-out infinite;
}
#tapHint {
  --s: clamp(90px, 11vw, 150px);
  position: absolute; left: 50%; bottom: 7%; width: var(--s); height: var(--s); margin-left: calc(var(--s) / -2);
  border-radius: 50%; border: 8px solid rgba(249, 228, 179, .85); pointer-events: none;
  animation: breathe 2.6s ease-in-out infinite;
}
#tapHint::after { content: ""; position: absolute; inset: 28%; border-radius: 50%; background: rgba(249, 228, 179, .85); }
#target.hint, #tapHint.hint { animation: breathe-strong 1.3s ease-in-out infinite; border-width: 12px; }
#target.pop, #tapHint.pop { animation: pop .4s ease-out forwards; }
@keyframes breathe { 0%, 100% { transform: scale(1); opacity: .75; } 50% { transform: scale(1.06); opacity: 1; } }
@keyframes breathe-strong { 0%, 100% { transform: scale(1); opacity: .85; } 50% { transform: scale(1.15); opacity: 1; } }
@keyframes pop { to { transform: scale(1.35); opacity: 0; } }

#ripples { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.ripple {
  position: absolute; width: 90px; height: 90px; margin: -45px 0 0 -45px; border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, .7); animation: ripple .55s ease-out forwards;
}
@keyframes ripple { from { transform: scale(.3); opacity: .9; } to { transform: scale(1.3); opacity: 0; } }

#soundNote {
  position: absolute; left: 50%; top: 3%; transform: translateX(-50%); z-index: 6; max-width: 80%;
  padding: 12px 20px; border-radius: 14px; background: rgba(44, 35, 17, .92); color: var(--cream);
  border: 2px solid var(--ochre); font-size: 20px; text-align: center;
}
#errorMsg {
  position: absolute; left: 5%; right: 5%; bottom: 8%; padding: 16px 20px; border-radius: 14px;
  background: rgba(162, 61, 45, .92); color: #fff; font-size: 20px; text-align: center;
}

#teacherBtn {
  position: absolute; top: 10px; right: 10px; z-index: 5; width: 72px; height: 72px; min-height: 0; padding: 0;
  border-radius: 50%; background: rgba(0, 0, 0, .35); font-size: 34px; opacity: .35;
}
#teacherBtn.holding {
  opacity: 1; animation: hold 1s linear forwards;
  background: conic-gradient(var(--yellow) var(--p), rgba(0, 0, 0, .5) 0);
}
@keyframes hold { to { --p: 100%; } }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: 3vh 3vw; background: rgba(20, 15, 6, .82);
}
#end { background: rgba(20, 15, 6, .6); }
.panel {
  background: var(--ink); border: 3px solid var(--ochre); border-radius: 24px; padding: 24px;
  max-height: 94vh; overflow: auto; display: flex; flex-direction: column; gap: 12px;
}
.panel.wide { width: min(1000px, 96vw); }
.row { display: flex; flex-wrap: wrap; gap: 12px; }
.row > button { flex: 1 1 180px; font-size: 22px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.grid button { font-size: 19px; text-align: left; background: var(--panel); }
.grid button.current { background: var(--yellow); color: var(--ink); }
#tVolume { width: 100%; height: 48px; accent-color: var(--yellow); }
.endTitle { font-size: clamp(36px, 5vw, 64px); color: var(--yellow); font-weight: 800; text-align: center; }
.round { width: 160px; height: 160px; border-radius: 50%; font-size: 64px; padding: 0; }

@media (prefers-reduced-motion: reduce) {
  #target, #tapHint, #target.hint, #tapHint.hint { animation: fade 2.6s ease-in-out infinite; }
  @keyframes fade { 0%, 100% { opacity: .7; } 50% { opacity: 1; } }
}

/* ---------- Mode C: small games ---------- */
#game { position: absolute; inset: 0; z-index: 3; background: #1b1508; }
#gVid, #gPic { position: absolute; object-fit: contain; }
#gUi { position: absolute; inset: 0; pointer-events: none; }
#gUi > * { pointer-events: auto; }
#gUi > .gRing, #gUi > .gDrop, #gUi > .gStop, #gUi > .gWordBadge, #gUi > .gBar, #gUi > .gDots, #gUi > .gPrompt,
#gUi > .gColLines, #gUi > .gGhost { pointer-events: none; }
#gHub {
  position: absolute; inset: 0; display: grid; grid-template-columns: repeat(4, min(21vw, 33vh)); gap: 2.4vmin;
  padding: 4vmin 4vw; align-content: center; justify-content: center; overflow: auto;
}
#gHub.many { grid-template-columns: repeat(5, min(16.5vw, 31vh)); }   /* 9–10 games: two rows of five */
@media (max-aspect-ratio: 1/1) {   /* phone or board held upright: three big cards a row, scroll */
  #gHub, #gHub.many { grid-template-columns: repeat(3, 28vw); align-content: start; }
}
.gHubCard {
  background: var(--panel); border-radius: 22px; padding: 1.2vmin; min-height: 0; display: flex; flex-direction: column;
  gap: 1vmin; color: var(--cream); font-size: clamp(16px, min(1.9vw, 3.2vh), 30px); font-weight: 700; text-align: center;
}
.gHubPic { width: 100%; aspect-ratio: 1; border-radius: 16px; background-repeat: no-repeat; background-color: #fff; }
.gCard {
  position: absolute; padding: 0; min-height: 0; border-radius: 24px; background: #fff; border: 6px solid #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35); overflow: hidden; touch-action: none;
}
.gCard.round { border-radius: 50%; }
.gCard .pic { position: absolute; inset: 0; background-repeat: no-repeat; }
.gCard .word {
  position: absolute; left: 0; right: 0; bottom: 0; background: rgba(255, 255, 255, .92); color: var(--red);
  font-weight: 800; text-align: center; padding: .1em 0;
}
.gCard.right { border-color: var(--yellow); box-shadow: 0 0 0 10px rgba(250, 208, 99, .85), 0 6px 18px rgba(0, 0, 0, .35); }
.gCard.dragging { z-index: 2; box-shadow: 0 16px 40px rgba(0, 0, 0, .5); }
.wiggle { animation: wiggle .5s ease-in-out; }
@keyframes wiggle { 0%, 100% { translate: 0; } 20% { translate: -12px; } 40% { translate: 12px; } 60% { translate: -8px; } 80% { translate: 8px; } }
#game .scan { outline: 10px solid var(--blue); outline-offset: 6px; }
.gPrompt {
  position: absolute; border-radius: 50%; border: 8px solid #fff; background-color: #fff; background-repeat: no-repeat;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
}
.gWordBadge {
  position: absolute; transform: translateX(-50%); white-space: nowrap; font-weight: 800; color: var(--red);
  background: rgba(255, 255, 255, .94); border-radius: 999px; padding: .05em .6em; box-shadow: 0 3px 10px rgba(0, 0, 0, .25);
}
.gDots { position: absolute; left: 50%; bottom: 7%; transform: translateX(-50%); display: flex; gap: 2.4vmin; }
.gDots span { width: 6vmin; height: 6vmin; border-radius: 50%; border: 6px solid #fff; background: rgba(255, 255, 255, .3); }
.gDots span.on { background: var(--yellow); }
.gRing { position: absolute; border-radius: 50%; border: 8px solid var(--yellow); box-shadow: 0 0 24px 8px rgba(250, 208, 99, .6); }
.gDrop { position: absolute; border-radius: 50%; border: 6px dashed rgba(255, 255, 255, .9); }
.gBar { position: absolute; left: 8%; right: 8%; bottom: 5%; height: 3vmin; border-radius: 999px; background: rgba(255, 255, 255, .35); }
.gBar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 999px; background: var(--yellow); }
.gStop { position: absolute; bottom: 9%; transform: translateX(-50%); font-weight: 800; color: #fff; text-shadow: 0 2px 6px #000; font-size: 3.2vmin; }
.gFlap { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 1vmin; pointer-events: none; }
.gFlap .pic { width: 100%; border-radius: 50%; border: 6px solid #fff; background-repeat: no-repeat; animation: breathe 2.6s ease-in-out infinite; }
.gFlap span { font-weight: 800; color: var(--red); background: rgba(255, 255, 255, .94); border-radius: 999px; padding: .05em .6em; font-size: 3.4vmin; }
.gFlap.flying .pic { animation: none; opacity: .5; }
#gEnd {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5;
  background: var(--ink); border: 3px solid var(--ochre); border-radius: 24px; padding: 24px; display: flex; flex-direction: column; gap: 16px;
}

.gSeekWord { transform: translateX(-50%); }
.gAsk {
  position: absolute; left: 50%; top: 3%; transform: translateX(-50%); display: flex; align-items: center; gap: 2vmin;
  pointer-events: none; white-space: nowrap;
}
.gAskFace { border-radius: 50%; border: 4px solid #fff; background-color: #fff; background-repeat: no-repeat; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); }
.gAsk span { font-weight: 800; color: var(--red); background: rgba(255, 255, 255, .94); border-radius: 999px; padding: .05em .6em; }

/* ---------- colouring ---------- */
.gColCanvas { position: absolute; background: #fff; border-radius: 8px; box-shadow: 0 6px 24px rgba(0, 0, 0, .45); touch-action: none; }
.gColLines { position: absolute; -webkit-user-drag: none; }
.gSwatch, .gTool { position: absolute; padding: 0; min-height: 0; touch-action: none; }
.gSwatch {
  border-radius: 50%; border: 5px solid rgba(255, 255, 255, .8); box-shadow: 0 4px 12px rgba(0, 0, 0, .45);
  transition: transform .15s;
}
.gSwatch.on { transform: scale(1.12); border: 6px solid #fff; box-shadow: 0 0 0 6px var(--ink), 0 0 0 11px #fff, 0 6px 16px rgba(0, 0, 0, .5); }
.gTool { border-radius: 22px; background: var(--panel); color: var(--cream); font-weight: 800; line-height: 1; }
.gGhost { position: absolute; border-radius: 50%; border: 5px solid #fff; box-shadow: 0 10px 28px rgba(0, 0, 0, .5); opacity: .92; }
#gEnd.low { top: auto; bottom: 2.5%; transform: translateX(-50%); flex-direction: row; align-items: center; padding: 12px 18px; white-space: nowrap; width: max-content; max-width: 96vw; }
#gEnd.low .row { flex-wrap: nowrap; }
#gEnd.low #gMore { order: -2; }
#gEnd.low #gSave { order: -1; }
#gEnd.low #gAgain { background: #4a3b1f; color: var(--cream); }
#gEnd.low .endTitle { margin: 0 8px 0 4px; font-size: clamp(28px, 3.4vw, 46px); }
@media (max-width: 700px) {   /* phone held upright: end buttons wrap under the title */
  #gEnd.low { flex-direction: column; white-space: normal; width: 94vw; }
  #gEnd.low .row { flex-wrap: wrap; }
}
