/* =====================================================================
   Cyber Escape — Styles (walk-around escape room, Roblox-style)
   Touch-first; tuned for iPad. Bright, blocky, bouncy.
   ===================================================================== */

:root {
  --ink: #1f2547; --ink-soft: #555f8a; --card: #ffffff; --cream: #fff8ef;
  --purple: #7b5cff; --purple-d: #5a3fd6; --cyan: #21d4d4; --pink: #ff5fa2;
  --green: #2fd47a; --green-d: #18a85b; --red: #ff5470; --amber: #ffc23d; --blue: #3aa0ff;
  --shadow-3d: 0 6px 0; --radius: 22px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }   /* ensure hidden attr beats flex/grid display rules */
html, body { margin: 0; padding: 0; }
body {
  font-family: "Fredoka", system-ui, sans-serif; color: var(--ink);
  min-height: 100vh; line-height: 1.5; overflow-x: hidden; background: #8fd3ff;
}

.bg-sky { position: fixed; inset: 0; z-index: -3; background: linear-gradient(180deg, #7ec8ff 0%, #a9d8ff 45%, #d8b9ff 100%); }
.bg-clouds {
  position: fixed; inset: 0; z-index: -2; pointer-events: none;
  background:
    radial-gradient(60px 28px at 12% 20%, #fff, transparent 70%),
    radial-gradient(80px 34px at 80% 14%, #fff, transparent 70%),
    radial-gradient(50px 24px at 55% 30%, #fff, transparent 70%),
    radial-gradient(70px 30px at 30% 70%, rgba(255,255,255,.85), transparent 70%),
    radial-gradient(90px 38px at 88% 78%, rgba(255,255,255,.8), transparent 70%);
  animation: drift 30s linear infinite alternate;
}
@keyframes drift { from { transform: translateX(-20px);} to { transform: translateX(20px);} }

#app { max-width: 900px; margin: 0 auto; padding: clamp(12px,3vw,30px) 14px 88px; min-height: 100vh; display: flex; align-items: center; }
.screen { display: none; width: 100%; }
.screen.active { display: block; animation: pop .4s cubic-bezier(.2,1.4,.4,1); }
.screen#screen-game.active { display: flex; flex-direction: column; }
@keyframes pop { from { opacity:0; transform: translateY(14px) scale(.97);} to { opacity:1; transform:none;} }

.card { background: var(--card); border: 4px solid #fff; border-radius: var(--radius); padding: clamp(18px,4.5vw,36px); box-shadow: 0 14px 0 rgba(90,63,214,.25), 0 24px 50px rgba(31,37,71,.3); }
.hero { text-align: center; }

.badge { display: inline-block; font-weight: 600; font-size: 13px; padding: 7px 16px; border-radius: 999px; background: var(--amber); color: #6b4b00; box-shadow: 0 4px 0 #d99b00; margin-bottom: 16px; }
.title-pop { font-family: "Baloo 2", sans-serif; font-weight: 800; font-size: clamp(46px,13vw,84px); line-height: .92; margin: 6px 0 10px; color: var(--purple); -webkit-text-stroke: 3px #fff; text-shadow: 0 6px 0 var(--purple-d), 0 7px 0 var(--purple-d), 0 10px 14px rgba(0,0,0,.25); letter-spacing: 1px; }
.title-pop span { color: var(--pink); }
.title-pop.small { font-size: clamp(30px,8vw,46px); }
.subtitle { font-size: clamp(15px,3.4vw,20px); color: var(--purple-d); font-weight: 600; margin: 0 0 16px; }
.lede { font-size: clamp(15px,3vw,17px); margin: 0 auto 24px; max-width: 54ch; color: var(--ink); }
.fineprint { color: var(--ink-soft); font-size: 13px; margin-top: 14px; }
.section-title { font-family: "Baloo 2", sans-serif; font-size: clamp(22px,5vw,30px); margin: 0 0 6px; color: var(--purple-d); }
.muted { color: var(--ink-soft); margin-top: 0; }

/* buttons */
.btn { font-family: "Baloo 2", sans-serif; font-weight: 700; font-size: 16px; border: none; border-radius: 16px; padding: 13px 24px; cursor: pointer; color: #fff; transition: transform .08s, box-shadow .08s, filter .15s; position: relative; }
.btn-lg { font-size: 19px; padding: 16px 34px; }
.btn-sm { font-size: 14px; padding: 9px 16px; border-radius: 12px; }
.btn-primary { background: var(--purple); box-shadow: var(--shadow-3d) var(--purple-d); }
.btn-ghost { background: #eef0fb; color: var(--ink); box-shadow: var(--shadow-3d) #c7cbe6; }
.btn-danger { background: var(--red); box-shadow: var(--shadow-3d) #c0344a; }
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 currentColor; filter: brightness(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-bounce { animation: btnbob 1.6s ease-in-out infinite; }
@keyframes btnbob { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-4px);} }
.btn-bounce:active { animation: none; }
.actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }

/* forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-wide { grid-column: 1 / -1; }
.field > span { font-size: 14px; font-weight: 600; }
.field i { color: var(--pink); font-style: normal; }
.field input, .field select, .field textarea { font-family: inherit; font-size: 16px; color: var(--ink); background: var(--cream); border: 3px solid #e7e1f5; border-radius: 14px; padding: 12px 14px; width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--purple); box-shadow: 0 0 0 4px rgba(123,92,255,.18); }
.checkbox { display: flex; align-items: flex-start; gap: 10px; margin-top: 16px; font-size: 14px; color: var(--ink-soft); cursor: pointer; }
.checkbox input { margin-top: 3px; width: 20px; height: 20px; accent-color: var(--purple); flex-shrink: 0; }
.form-error { color: var(--red); font-size: 14px; margin-top: 12px; font-weight: 600; }

/* consent (PDPA) */
.consent-body { max-height: 46vh; overflow-y: auto; background: var(--cream); border: 3px solid #ece6fa; border-radius: 14px; padding: 14px 16px; margin: 14px 0; font-size: 14px; color: var(--ink); -webkit-overflow-scrolling: touch; }
.consent-body ol, .consent-body ul { margin: 0 0 12px; padding-left: 22px; }
.consent-body li { margin-bottom: 8px; }
.consent-body p { margin: 10px 0; }
.consent-body a { color: var(--purple-d); font-weight: 600; }

/* radio groups & Likert scales */
.radio-group, .likert { border: none; padding: 0; margin: 0 0 16px; }
.radio-group legend, .likert legend { font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 10px; padding: 0; }
.radio-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; cursor: pointer; font-size: 15px; }
.radio-row input { width: 20px; height: 20px; accent-color: var(--purple); flex-shrink: 0; }
.scale { display: flex; gap: 8px; flex-wrap: wrap; }
.scale label { cursor: pointer; position: relative; }
.scale input { position: absolute; opacity: 0; width: 0; height: 0; }
.scale span { display: grid; place-items: center; min-width: 46px; height: 46px; padding: 0 6px; border-radius: 12px; border: 3px solid #e7e1f5; background: var(--cream); font-family: "Baloo 2"; font-weight: 800; font-size: 16px; box-shadow: 0 4px 0 #e0daf2; transition: transform .08s; }
.scale label:active span { transform: translateY(3px); box-shadow: 0 1px 0 #e0daf2; }
.scale input:checked + span { background: var(--purple); color: #fff; border-color: var(--purple-d); box-shadow: 0 4px 0 var(--purple-d); }
.scale input:focus-visible + span { outline: 3px solid var(--cyan); }
.scale.yn span { min-width: 0; padding: 0 26px; }
.scale-ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-soft); margin-top: 4px; max-width: 290px; }

/* language select */
.lang-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 24px 0 6px; }
.lang-btn { font-size: 19px; padding: 18px 14px; }
.lang-btn.active { outline: 4px solid var(--cyan); outline-offset: 2px; }

/* avatar select */
.avatar-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; margin: 20px 0; }
.avatar-pick { background: var(--cream); border: 4px solid #ece6fa; border-radius: 18px; padding: 14px 6px 12px; cursor: pointer; text-align: center; transition: transform .12s, border-color .15s, box-shadow .15s; box-shadow: 0 5px 0 #ddd6f2; }
.avatar-pick:hover { transform: translateY(-4px); }
.avatar-pick .ava-emoji { font-size: clamp(34px,9vw,46px); display: block; line-height: 1; filter: drop-shadow(0 4px 3px rgba(0,0,0,.18)); }
.avatar-pick .ava-name { display: block; font-size: 12px; font-weight: 600; margin-top: 8px; }
.avatar-pick .ava-trait { display: block; font-size: 10.5px; color: var(--ink-soft); margin-top: 2px; }
.avatar-pick.selected { border-color: var(--purple); background: #f3eeff; box-shadow: 0 5px 0 var(--purple-d); transform: translateY(-4px) scale(1.04); }
.avatar-pick.selected .ava-emoji { animation: avahop .6s ease infinite; }
@keyframes avahop { 0%,100%{transform:translateY(0) rotate(-3deg);} 50%{transform:translateY(-6px) rotate(3deg);} }

/* level select */
.level-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 20px 0; }
.level-card { text-align: left; cursor: pointer; color: var(--ink); font-family: inherit; background: var(--cream); border: 4px solid #ece6fa; border-radius: 18px; padding: 20px; transition: transform .14s, border-color .15s, box-shadow .15s; box-shadow: 0 6px 0 #ddd6f2; }
.level-card:hover { transform: translateY(-5px); border-color: var(--cyan); box-shadow: 0 6px 0 #16b3b3; }
.level-icon { font-size: 40px; }
.level-card h3 { font-family: "Baloo 2"; margin: 8px 0 4px; font-size: 21px; color: var(--purple-d); }
.level-tag { display: inline-block; font-size: 12px; color: #0a6b6b; background: #c8f5f5; padding: 3px 11px; border-radius: 999px; margin: 0 0 10px; font-weight: 600; }
.level-card p { color: var(--ink-soft); font-size: 14px; margin: 6px 0; }
.level-cta { display: inline-block; margin-top: 8px; color: var(--purple); font-weight: 700; }

/* ===== GAME WORLD ===== */
.game-topbar { display: flex; justify-content: space-around; gap: 8px; background: #fff; border: 3px solid #fff; border-radius: 16px; padding: 8px 12px; box-shadow: 0 6px 0 rgba(90,63,214,.18); margin-bottom: 10px; }
.tb-item { display: flex; flex-direction: column; align-items: center; }
.tb-item span { font-size: 11px; color: var(--ink-soft); font-weight: 600; }
.tb-item b { font-family: "Baloo 2"; font-size: 18px; color: var(--purple-d); }

.objective { text-align: center; font-weight: 600; font-size: clamp(13px,3.4vw,15px); color: var(--purple-d); background: rgba(255,255,255,.7); border: 2px solid #fff; border-radius: 12px; padding: 7px 12px; margin-bottom: 10px; }

.world-wrap {
  position: relative; width: 100%;
  height: calc(100vh - 275px);        /* fill available height, fits without page scroll */
  height: calc(100dvh - 275px);       /* dvh = better on mobile Safari toolbars */
  max-height: 780px; min-height: 360px;
  border-radius: 20px; overflow: hidden; border: 4px solid #fff;
  box-shadow: 0 8px 0 rgba(90,63,214,.25); background: #2b2f5a;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
#world { display: block; width: 100%; height: 100%; touch-action: none; }

/* virtual joystick */
.joystick {
  position: absolute; left: 16px; bottom: 16px; width: 116px; height: 116px;
  border-radius: 50%; background: rgba(255,255,255,.18); border: 3px solid rgba(255,255,255,.55);
  touch-action: none; z-index: 6; backdrop-filter: blur(2px);
}
.joystick-thumb {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%; background: rgba(255,255,255,.9); border: 3px solid var(--purple);
  box-shadow: 0 4px 10px rgba(0,0,0,.3); transition: transform .03s linear;
}

/* interact button */
.interact-btn {
  position: absolute; right: 18px; bottom: 22px; z-index: 6;
  width: 92px; height: 92px; border-radius: 50%; border: 4px solid #fff;
  background: var(--green); color: #fff; font-size: 30px; cursor: pointer;
  box-shadow: 0 6px 0 var(--green-d); display: flex; flex-direction: column; align-items: center; justify-content: center;
  animation: ibob 1s ease-in-out infinite;
}
.interact-btn small { font-family: "Baloo 2"; font-size: 14px; font-weight: 800; }
.interact-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--green-d); }
@keyframes ibob { 0%,100%{transform:scale(1);} 50%{transform:scale(1.07);} }

.controls-hint { text-align: center; font-size: 12px; color: var(--ink-soft); margin: 8px 0 0; }

/* confetti */
.confetti-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 7; }
.confetti { position: absolute; top: -14px; width: 10px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(620px) rotate(620deg); opacity: .15; } }

/* puzzle modal */
.puzzle-modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(31,37,71,.55); backdrop-filter: blur(3px); overflow-y: auto; }
.puzzle-card { background: var(--card); border: 4px solid #fff; border-radius: 22px; padding: clamp(18px,4vw,28px); width: 100%; max-width: 560px; box-shadow: 0 16px 0 rgba(90,63,214,.3), 0 30px 60px rgba(0,0,0,.4); animation: pop .35s cubic-bezier(.2,1.4,.4,1); margin: auto; }
.puzzle-room { font-family: "Baloo 2"; font-weight: 800; font-size: clamp(16px,4vw,20px); color: #fff; background: var(--purple); display: inline-block; padding: 5px 16px; border-radius: 999px; box-shadow: 0 4px 0 var(--purple-d); margin-bottom: 14px; }
.puzzle-q { font-size: clamp(16px,3.8vw,19px); font-weight: 600; margin: 0 0 16px; }

.options { display: flex; flex-direction: column; gap: 11px; }
.option { display: flex; align-items: center; gap: 13px; text-align: left; cursor: pointer; background: #fff; border: 3px solid #e7e1f5; border-radius: 15px; padding: 13px 15px; font-family: inherit; font-size: 16px; color: var(--ink); font-weight: 500; box-shadow: 0 4px 0 #e0daf2; transition: transform .1s, border-color .15s, box-shadow .1s; }
.option:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--purple); }
.option:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #e0daf2; }
.option-key { flex-shrink: 0; width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-family: "Baloo 2"; font-weight: 800; background: var(--purple); color: #fff; }
.option.is-correct { border-color: var(--green); background: #e9fcf2; box-shadow: 0 4px 0 var(--green-d); }
.option.is-correct .option-key { background: var(--green); }
.option.is-wrong { border-color: var(--red); background: #ffeef1; box-shadow: 0 4px 0 #c0344a; }
.option.is-wrong .option-key { background: var(--red); }
.option:disabled { cursor: default; }

.feedback { margin-top: 16px; padding: 16px; border-radius: 16px; background: var(--cream); border: 3px solid #ece6fa; animation: pop .3s ease; }
.feedback-head { font-family: "Baloo 2"; font-weight: 800; font-size: 17px; margin-bottom: 6px; }
.feedback-head.ok { color: var(--green-d); }
.feedback-head.no { color: var(--red); }
.feedback-body { font-size: 15px; margin: 0 0 14px; }
.game-foot { margin-top: 14px; }
.hint-text { margin-top: 12px; color: #8a5a00; font-size: 14px; background: #fff3d6; border: 2px solid #ffdf99; padding: 10px 14px; border-radius: 12px; }

/* result */
.result-hero { position: relative; display: inline-block; }
.result-avatar { font-size: 74px; display: inline-block; animation: cheer .6s ease infinite; filter: drop-shadow(0 6px 5px rgba(0,0,0,.25)); }
@keyframes cheer { 0%,100%{transform:translateY(0) scale(1);} 50%{transform:translateY(-16px) scale(1.12);} }
.result-emoji { font-size: 54px; position: absolute; top: -8px; right: -28px; }
.result-stats { display: flex; justify-content: center; gap: 12px; margin: 22px 0 26px; flex-wrap: wrap; }
.divider { border: none; border-top: 3px dashed #e7e1f5; margin: 6px 0 18px; }
.stat { background: var(--cream); border: 3px solid #ece6fa; border-radius: 16px; padding: 14px 22px; min-width: 100px; box-shadow: 0 5px 0 #ddd6f2; }
.stat-num { display: block; font-family: "Baloo 2"; font-weight: 800; font-size: 26px; color: var(--purple-d); }
.stat-label { font-size: 12px; color: var(--ink-soft); font-weight: 600; }

/* stars */
.rating { display: flex; gap: 6px; }
.star { background: none; border: none; font-size: 34px; color: #dcd7ee; cursor: pointer; padding: 0; line-height: 1; transition: transform .1s, color .2s; }
.star:hover { transform: scale(1.2) rotate(-8deg); }
.star.on { color: var(--amber); text-shadow: 0 0 12px rgba(255,194,61,.6); }

/* admin */
.admin-stats { display: flex; gap: 12px; flex-wrap: wrap; margin: 18px 0; }
.admin-actions { justify-content: flex-start; }
.admin-table-wrap { overflow-x: auto; margin-top: 18px; border: 3px solid #ece6fa; border-radius: 14px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 820px; }
.admin-table th, .admin-table td { padding: 10px 12px; text-align: left; border-bottom: 2px solid #f0edf9; white-space: nowrap; }
.admin-table th { background: var(--cream); color: var(--purple-d); font-family: "Baloo 2"; font-size: 11px; text-transform: uppercase; }
.admin-table td.empty { color: var(--ink-soft); text-align: center; padding: 30px; }

/* sound toggle */
.sound-toggle { position: fixed; top: 12px; right: 12px; z-index: 50; width: 42px; height: 42px; border-radius: 50%; border: 3px solid #fff; background: var(--purple); color: #fff; font-size: 19px; cursor: pointer; box-shadow: 0 4px 0 var(--purple-d); }
.sound-toggle:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--purple-d); }

/* footer */
.site-foot { position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 9px 16px; font-size: 12px; color: var(--purple-d); background: rgba(255,255,255,.75); border-top: 3px solid #fff; backdrop-filter: blur(6px); }
.link-btn { background: none; border: none; color: var(--purple-d); cursor: pointer; font-size: 12px; text-decoration: underline; font-family: inherit; font-weight: 600; }

@media (max-width: 560px) {
  .form-grid, .level-grid { grid-template-columns: 1fr; }
  .avatar-grid { grid-template-columns: repeat(3,1fr); }
  .actions { justify-content: stretch; }
  .actions .btn { flex: 1; }
  .world-wrap { height: calc(100dvh - 300px); min-height: 320px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; } }
