/* Paintbrush Island: HUD and overlays. The 3D scene is drawn by three.js underneath. */

/* The fonts ship with the game (fonts/, SIL Open Font License: fonts/OFL-*.txt), so no page asks
   another server for them: a child's visit reaches nobody but this site. */
@font-face { font-family: 'Baloo 2'; font-style: normal; font-weight: 400 800; font-display: swap; src: url('../fonts/Baloo2.woff2') format('woff2'); }
@font-face { font-family: 'Andika'; font-style: normal; font-weight: 400; font-display: swap; src: url('../fonts/Andika-Regular.woff2') format('woff2'); }
@font-face { font-family: 'Andika'; font-style: normal; font-weight: 700; font-display: swap; src: url('../fonts/Andika-Bold.woff2') format('woff2'); }

:root {
  --ink: #2E2A47;
  --muted: #6F6A86;
  --card: #FFFFFF;
  --line: #EDE7F6;
  --tile-shadow: #DCD4EE;
  --accent: #13A391; --accent-d: #0D7F71;  /* teal green, as in the reading game: no orange */
  --teal: #2BB5A0;  --teal-d: #1F9482;
  --sun: #FFC93C;   --sun-d: #E0AA1A;
  --grape: #9B5DE5; --grape-d: #7F44C8;
  --green-d: #3FB549;
  --radius: 22px;
  --tile: clamp(46px, 11vw, 66px);
  --font-ui: 'Baloo 2', 'Nunito', 'Trebuchet MS', system-ui, sans-serif;
  --font-read: 'Andika', 'Comic Sans MS', 'Trebuchet MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0f1a2b; }
body {
  font-family: var(--font-ui);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid #4CC9F0; outline-offset: 3px; }
[hidden] { display: none !important; }

#scene { position: fixed; inset: 0; }
#scene canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* ---------- HUD ---------- */

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

.hud-top {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 12px; right: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.hud-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12), 0 6px 16px rgba(0, 0, 0, 0.18);
  font-size: 22px;
  display: grid; place-items: center;
  text-decoration: none;
  flex: none;
}
.hud-btn.small { width: 40px; height: 40px; font-size: 18px; }
.hud-btn:active { transform: translateY(2px); }
.hud-settings { position: absolute; right: 12px; bottom: max(96px, calc(env(safe-area-inset-bottom) + 96px)); }
.hud-region {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  padding: 6px 16px;
  display: flex; flex-direction: column; align-items: center; line-height: 1.15;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  min-width: 150px;
}
.hud-region-name { font-weight: 800; font-size: 17px; }
.hud-region-progress { font-weight: 700; font-size: 13px; color: var(--muted); }
.hud-pill {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 800; font-size: 18px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  white-space: nowrap;
}
.hud-pill.bump { animation: bump 0.45s; }
@keyframes bump { 40% { transform: scale(1.25) rotate(-4deg); } }

.hud-bottom {
  position: absolute;
  left: 12px; right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.island-meter {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  padding: 8px 14px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  font-weight: 800; font-size: 14px;
  width: min(420px, 100%);
}
.island-meter-bar { flex: 1; height: 12px; background: #EFE9F8; border-radius: 999px; overflow: hidden; }
.island-meter-bar > i { display: block; height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #FF8FAB, #FFC93C, #5FD068, #13A391, #4CC9F0, #9B5DE5); transition: width 0.6s; }
.island-meter-pct { min-width: 38px; text-align: right; }
.hint {
  margin: 0;
  background: rgba(46, 42, 71, 0.85);
  color: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 700; font-size: 15px;
  text-align: center;
  max-width: 100%;
  transition: opacity 0.3s;
}
.hint.off { opacity: 0; }

.paint-btn {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: max(96px, calc(env(safe-area-inset-bottom) + 96px));
  border: 0;
  border-radius: 999px;
  padding: 16px 30px;
  font: 800 24px/1 var(--font-ui);
  color: #fff;
  background: var(--accent);
  box-shadow: 0 6px 0 var(--accent-d), 0 10px 24px rgba(0, 0, 0, 0.25);
  animation: pulse 1.4s ease-in-out infinite;
}
.paint-btn:active { transform: translate(-50%, 3px); box-shadow: 0 3px 0 var(--accent-d); }
@keyframes pulse { 50% { transform: translateX(-50%) scale(1.06); } }

.joystick {
  position: absolute;
  left: max(20px, env(safe-area-inset-left));
  bottom: max(84px, calc(env(safe-area-inset-bottom) + 84px));
  width: 130px; height: 130px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  border: 3px solid rgba(255, 255, 255, 0.6);
  touch-action: none;
}
.joystick-knob {
  position: absolute; left: 50%; top: 50%;
  width: 58px; height: 58px; margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}
.joystick.off { display: none; }

/* ---------- overlays ---------- */

.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(15, 26, 43, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 20;
  overflow-y: auto;
}
#start { background: linear-gradient(180deg, rgba(15, 26, 43, 0.75), rgba(15, 26, 43, 0.35)); }
.card {
  width: min(560px, 100%);
  background: var(--card);
  border-radius: 28px;
  padding: 24px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  text-align: center;
  animation: card-in 0.3s ease;
}
@keyframes card-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } }
.logo { font-size: 72px; line-height: 1; }
h1 { margin: 6px 0 4px; font-size: clamp(34px, 9vw, 52px); font-weight: 800; line-height: 1.05; }
h2 { margin: 0 0 12px; font-size: 26px; font-weight: 800; }
.tagline { margin: 0 0 10px; font-size: 18px; font-weight: 700; color: var(--muted); }
.who { margin: 0; font-weight: 800; font-size: 20px; }
.loading { margin: 6px 0 14px; color: var(--muted); font-weight: 700; }
.small { margin: 12px 0 0; font-size: 14px; color: var(--muted); font-weight: 600; }
.small a { color: var(--grape-d); }

.btn {
  font: 800 20px/1.1 var(--font-ui);
  padding: 15px 28px;
  border-radius: 999px;
  border: 0;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 5px 0 var(--accent-d);
  min-height: 56px;
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--accent-d); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.big { font-size: 24px; padding: 18px 36px; }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: 0 5px 0 var(--tile-shadow); }
.actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 12px; }

.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: 17px;
  text-align: left;
}
.row input { width: 26px; height: 26px; accent-color: var(--teal); }

/* ---------- challenge ---------- */

.challenge-card { padding: 16px 16px 18px; }
.challenge-top { display: flex; align-items: center; justify-content: space-between; }
.challenge-title { font-weight: 800; font-size: 22px; }
.instruction { margin: 4px 0 8px; color: var(--muted); font-weight: 700; font-size: 16px; }
.stage { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 6px 0; }

.picture { font-size: clamp(80px, 22vw, 120px); line-height: 1.1; filter: drop-shadow(0 8px 14px rgba(46, 42, 71, 0.14)); }
.picture.grey { filter: grayscale(1) opacity(0.55); }

.word-big {
  font: 700 clamp(44px, 14vw, 80px)/1.1 var(--font-read);
  letter-spacing: 0.04em;
  background: #F2FAF7;
  padding: 6px 24px;
  border-radius: var(--radius);
  border: 0;
}
.word-big .g { display: inline-block; transition: color 0.15s, transform 0.15s; }
.word-big .g.hi { color: var(--accent); transform: translateY(-6px) scale(1.12); }

.slots, .tray { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; width: 100%; }
.tray { gap: 10px; min-height: calc(var(--tile) * 1.15 + 12px); }
.slot, .tile {
  width: var(--tile); height: calc(var(--tile) * 1.15);
  border-radius: 14px;
  padding: 0;
  font: 700 calc(var(--tile) * 0.52) var(--font-read);
  color: var(--ink);
  display: grid; place-items: center;
}
.slot { border: 3px dashed #D9D1EA; background: #FBF9FF; }
.slot.filled { border-style: solid; border-color: transparent; background: #fff; box-shadow: 0 4px 0 var(--tile-shadow); }
.slot.filled.vowel, .tile.vowel { color: var(--accent); }
.slot.good { background: #E8FBEA; box-shadow: 0 4px 0 var(--green-d); }
.slot.bad { background: #FFECEC; box-shadow: 0 4px 0 #F0B4B4; }
.slot.hi { border-color: var(--accent); background: #E4F6F1; }
.tile { border: 0; background: #fff; box-shadow: 0 4px 0 var(--tile-shadow), 0 6px 14px rgba(46, 42, 71, 0.08); transition: transform 0.1s, opacity 0.2s; }
.tile:active { transform: translateY(3px); }
.tile.used { opacity: 0; pointer-events: none; transform: scale(0.6); }

.choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: 100%; }
.choice {
  border-radius: var(--radius);
  background: #fff;
  border: 0;
  box-shadow: 0 5px 0 var(--tile-shadow), 0 6px 14px rgba(46, 42, 71, 0.08);
  font-size: clamp(40px, 12vw, 64px);
  line-height: 1;
  padding: 14px 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  transition: transform 0.1s, background 0.2s;
}
.choice.word { font: 700 clamp(22px, 7vw, 34px)/1.1 var(--font-read); padding: 18px 6px; }
.choice:active { transform: translateY(3px); }
.choice.veiled { background: #F6F2FC; border: 3px dashed #D9D1EA; box-shadow: none; color: #C9BFE0; cursor: default; }
.choice.veiled:active { transform: none; }
.reveal-btn { background: var(--grape); box-shadow: 0 5px 0 var(--grape-d); align-self: center; }
.reveal-btn:active { box-shadow: 0 2px 0 var(--grape-d); }
.choice.right { background: #E8FBEA; box-shadow: 0 5px 0 var(--green-d); }
.choice.wrong { background: #FFECEC; box-shadow: 0 5px 0 #F0B4B4; opacity: 0.6; }

.tools { display: flex; gap: 10px; justify-content: center; padding-top: 10px; }
.tool {
  border: 0;
  background: #F2FAF7;
  border-radius: 999px;
  padding: 10px 16px;
  font: 800 16px var(--font-ui);
  box-shadow: 0 4px 0 var(--tile-shadow);
  display: flex; align-items: center; gap: 6px;
  min-height: 46px;
}
.tool:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--tile-shadow); }

.shake { animation: shake 0.5s; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); } 40%, 60% { transform: translateX(6px); }
}
.pop { animation: pop 0.5s; }
@keyframes pop { 40% { transform: scale(1.22); } }

.cheer {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  pointer-events: none;
  font-size: clamp(110px, 30vw, 180px);
  opacity: 0; z-index: 30;
}
.cheer.show { animation: cheer 1s ease-out; }
@keyframes cheer {
  0% { opacity: 0; transform: scale(0.4) rotate(-10deg); }
  30% { opacity: 1; transform: scale(1.1) rotate(4deg); }
  70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.2) translateY(-30px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
/* Feedback for grown-ups (the same as the reading game's, which it opens, marked as from the island): a small round bug button in the bottom right corner of every screen. It opens
   on a press and hold (js/hold.js); a tap only shows the hint above it, so there is little in it for a child. */
.report-tab { position: fixed; right: max(6px, env(safe-area-inset-right)); bottom: max(6px, env(safe-area-inset-bottom)); z-index: 30;
  width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.92); box-shadow: 0 8px 24px rgba(46, 42, 71, 0.12);
  font-size: 21px; line-height: 44px; text-align: center; cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.report-tab { color: #77737F; } /* a plain grey line drawing of a bug, like Eyewire II's toolbar icons: nothing in it to tempt a child */
.report-tab svg { display: block; margin: 11px auto; }
.report-tab.holding { background: #2E2A47; color: #fff; transition: background-color 1s linear, color 1s linear; }
.report-tab[hidden] { display: none; }
.report-tab::before { content: attr(data-hint); position: absolute; right: 0; bottom: calc(100% + 8px); white-space: nowrap; padding: 6px 10px; border-radius: 10px;
  background: var(--ink); color: #fff; font: 700 13px/1.2 inherit; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.report-tab.hinting::before { opacity: 1; }
