/* Fonts live in fonts/ (SIL Open Font License, see the OFL files there), so the game never waits on the network.
   Each font is split by alphabet the way Google Fonts serves it; the browser only fetches the parts a page uses. */
@font-face { font-family: "Patrick Hand"; font-display: swap; src: url(../fonts/patrick-hand-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Patrick Hand"; font-display: swap; src: url(../fonts/patrick-hand-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Patrick Hand"; font-display: swap; src: url(../fonts/patrick-hand-vietnamese.woff2) format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB; }
@font-face { font-family: "Caveat Brush"; font-display: swap; src: url(../fonts/caveat-brush-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Caveat Brush"; font-display: swap; src: url(../fonts/caveat-brush-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }

:root {
  --paper-color: #f7f0de;
  --ink: #4a2f1c;
  --purple: #7b5aa6;
  --purple-dark: #5a3270;
  --gold: #e9b23f;
  --green: #6f9e58;
  --edge: rgba(120, 90, 60, 0.45);
  --font: "Patrick Hand", "Comic Sans MS", cursive;
  --title: "Caveat Brush", "Patrick Hand", cursive;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #e9dfc6;
  font-family: var(--font);
  color: var(--ink);
}
#game { display: block; position: fixed; inset: 0; touch-action: none; }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

/* a hand-painted paper card */
.panel {
  background-color: var(--paper-color);
  background-image: var(--paper);
  border: 2px solid var(--edge);
  border-radius: 18px 26px 16px 28px / 26px 16px 28px 18px;
  box-shadow: 0 6px 24px rgba(90, 60, 30, 0.18), inset 0 0 40px rgba(200, 170, 120, 0.25);
}

.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(120, 140, 160, 0.25);
  backdrop-filter: blur(2px);
  /* (the safe areas keep panels out from under a phone's notch when the game fills the screen, as in the iOS app) */
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  z-index: 10;
}

h1, h2 { font-family: var(--title); font-weight: normal; margin: 0; color: var(--purple-dark); }
h1 { font-size: 52px; text-align: center; line-height: 1; }
h2 { font-size: 38px; }
h3 { margin: 14px 0 6px; font-size: 20px; font-weight: normal; color: var(--purple-dark); }
h3 small { font-size: 15px; color: #8a6a4a; }
.sub { text-align: center; margin: 4px 0 10px; font-size: 20px; color: #8a6a4a; }

button {
  font-family: var(--font);
  font-size: 17px;
  color: var(--ink);
  cursor: pointer;
  border: 2px solid var(--edge);
  background: #fffaf0;
  border-radius: 12px 16px 12px 16px / 16px 12px 16px 12px;
  padding: 6px 12px;
  transition: transform 0.1s, box-shadow 0.1s;
}
/* only where there's a real mouse: on touch screens a hover sticks after the tap */
@media (hover: hover) {
  button:hover:not(:disabled) { transform: translateY(-2px) rotate(-0.5deg); box-shadow: 0 4px 10px rgba(90, 60, 30, 0.15); }
}
button:disabled { cursor: default; opacity: 0.75; }
button.big {
  display: block; width: 100%;
  margin-top: 14px;
  font-size: 26px;
  font-family: var(--title);
  background: var(--purple);
  color: #fff;
  border-color: var(--purple-dark);
}

/* ---------- title page ---------- */
#title { background: radial-gradient(ellipse at 50% 40%, rgba(205, 182, 230, 0.35), rgba(120, 140, 160, 0.3) 75%); }
.title-panel { width: min(520px, 100%); max-height: 100%; overflow: auto; padding: 18px 30px 28px; text-align: center; }
#titleArt { display: block; width: min(440px, 100%); height: auto; margin: 0 auto -18px; }
h1.logo {
  font-size: 96px;
  letter-spacing: 1px;
  color: var(--purple-dark);
  text-shadow: 2px 3px 0 #e2d2f2, 4px 6px 0 rgba(123, 90, 166, 0.25), 0 0 22px rgba(233, 178, 63, 0.35);
  transform: rotate(-2deg);
  animation: logo-bob 5s ease-in-out infinite;
}
@keyframes logo-bob { 0%, 100% { transform: rotate(-2deg) translateY(0); } 50% { transform: rotate(-1deg) translateY(-4px); } }
.tagline { font-size: 22px; color: #8a6a4a; margin: 6px 0 18px; }
.title-buttons { max-width: 380px; margin: 0 auto; }
#continueText { font-size: 20px; margin: 0; }
#continueBtn { margin-top: 8px; }
/* a phone on its side: smaller art so both buttons fit without scrolling */
@media (max-height: 500px) {
  .title-panel { padding: 8px 24px 14px; }
  #titleArt { width: min(280px, 100%); margin-bottom: -12px; }
  h1.logo { font-size: 60px; }
  .tagline { font-size: 18px; margin: 2px 0 8px; }
  #continueText { font-size: 17px; }
  .title-buttons button.big { padding-top: 8px; padding-bottom: 8px; }
}
button.big.quiet { background: #fffaf0; color: var(--purple-dark); border-color: var(--edge); font-size: 22px; }

/* ---------- creator ---------- */
.creator-panel { width: min(940px, 100%); max-height: 100%; overflow: auto; padding: 22px 26px; position: relative; }
.creator-title { text-align: center; margin-bottom: 8px; }
.back-btn { position: absolute; top: 16px; left: 18px; }
.creator-grid { display: grid; grid-template-columns: 280px 1fr; gap: 22px; }
.preview-col { text-align: center; }
#preview {
  width: 260px; height: 300px;
  background: radial-gradient(ellipse at 50% 60%, rgba(180, 210, 160, 0.45), rgba(255, 255, 255, 0) 70%);
  border-radius: 50%;
}
#perk { font-size: 18px; padding: 8px 6px; }
#perk strong { color: var(--purple-dark); }
.choices { display: flex; gap: 8px; flex-wrap: wrap; }
.choice { display: flex; flex-direction: column; align-items: center; padding: 3px 8px 5px; font-size: 16px; min-width: 84px; }
.choice canvas { width: 62px; height: 72px; }
.swatch.selected { outline: 3px solid var(--purple); outline-offset: 2px; }
.selected:not(.swatch) { border-color: var(--purple) !important; background: #efe4fa !important; box-shadow: 0 0 0 3px rgba(123, 90, 166, 0.25); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.swatches { display: flex; gap: 7px; flex-wrap: wrap; }
.swatch { width: 32px; height: 32px; padding: 0; border-radius: 50% 45% 52% 48%; }
.fancy-hair { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 8px; }
.fancy-hair:empty { display: none; }
.fancy-swatch { display: flex; flex-direction: column; align-items: center; padding: 0; background: none; border: none; box-shadow: none; }
.fancy-swatch .swatch { pointer-events: none; }
.fancy-swatch .price { font-size: 13px; color: #a0701c; display: flex; align-items: center; gap: 2px; }
.outfits { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.outfit { display: flex; flex-direction: column; align-items: center; padding: 4px 6px 6px; position: relative; }
.outfit canvas { width: 64px; height: 76px; }
.outfit-name { font-size: 16px; line-height: 1.1; text-align: center; }
.outfit .price { font-size: 15px; margin-top: 2px; color: #a0701c; display: flex; align-items: center; gap: 3px; }
.outfit .price.free { color: #4f8a44; }
.outfit.fancy { background: linear-gradient(160deg, #fffaf0, #fbf0d4); }
.outfit.fancy::after { content: "✦ fancy"; position: absolute; top: 3px; right: 6px; font-size: 12px; color: #b58a2a; }
#nameInput {
  font-family: var(--font); font-size: 22px; color: var(--ink);
  width: 100%; padding: 6px 12px;
  border: 2px solid var(--edge); border-radius: 12px;
  background: #fffaf0;
}
#coinSummary { margin-top: 12px; font-size: 18px; }

/* ---------- coins & gems ---------- */
.coin-icon {
  display: inline-block; width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff2b0 0 18%, #f6d36b 30%, #e9b23f 70%, #c48a2c 100%);
  vertical-align: -4px; margin-right: 5px;
}
.coin-icon.small { width: 15px; height: 15px; vertical-align: -2px; margin-right: 3px; }
.gem-icon { display: inline-block; width: 13px; height: 13px; transform: rotate(45deg); margin: 0 5px 0 4px; border-radius: 2px; box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.5); }
.muted { color: #9a8a76; font-size: 15px; }

/* ---------- HUD ---------- */
/* fades out of the way when you stand behind it (Game.peekHud) */
#hud, #objective, #effects, #quickbar { transition: opacity 0.25s; }
#hud.peek, #objective.peek, #effects.peek, #quickbar.peek { opacity: 0.25; }
#hud { position: fixed; top: 14px; left: 14px; padding: 10px 16px; font-size: 20px; min-width: 190px; z-index: 5; }
.hud-name { font-family: var(--title); font-size: 24px; color: var(--purple-dark); }
.hud-row { display: flex; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.hud-broom { font-size: 16px; color: #6b5a48; }
#objective { position: fixed; top: 14px; right: 14px; max-width: 340px; padding: 10px 16px; font-size: 18px; z-index: 5; }
#objective .label { display: inline-block; background: var(--gold); color: #fff; border-radius: 8px; padding: 0 8px; margin-right: 4px; font-size: 15px; }
#controls {
  position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%);
  background: rgba(255, 250, 236, 0.85); border: 1.5px solid var(--edge); border-radius: 14px;
  padding: 4px 14px; font-size: 16px; white-space: nowrap; z-index: 5;
}
#controls b { background: var(--purple); color: #fff; padding: 0 6px; border-radius: 5px; font-weight: normal; }
#toast {
  position: fixed; left: 50%; bottom: 56px; transform: translateX(-50%);
  max-width: min(620px, calc(100% - 32px)); padding: 12px 20px; font-size: 20px; text-align: center; z-index: 6;
  animation: pop 0.25s ease-out;
}
@keyframes pop { from { transform: translateX(-50%) translateY(10px) scale(0.96); } }

/* ---------- shop ---------- */
.shop-panel { width: min(680px, 100%); max-height: 100%; overflow: auto; padding: 22px 26px; position: relative; }
.close { position: absolute; top: 12px; right: 14px; font-size: 18px; padding: 2px 10px; }
.talk { font-size: 19px; margin: 6px 0 10px; }
.talk .who { color: var(--purple-dark); }
.coins-line { font-size: 20px; margin-bottom: 10px; display: flex; align-items: center; gap: 2px; }
.store-row {
  display: grid; grid-template-columns: 56px 1fr 140px; align-items: center; gap: 12px;
  padding: 8px 12px; margin-bottom: 8px;
  border: 2px solid rgba(120, 90, 60, 0.25); border-radius: 14px 18px 14px 18px;
  background: rgba(255, 252, 244, 0.7);
}
.store-row.equipped { border-color: var(--purple); background: #f3ebfb; }
.store-row canvas { justify-self: center; }
.store-row button { font-size: 17px; line-height: 1.1; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; }
.store-row button.cant { background: #f1e8d8; color: #9a8268; }
.store-row button small { width: 100%; font-size: 13px; }
.row-name { font-family: var(--title); font-size: 22px; color: var(--purple-dark); }
.hud-pack { margin-left: 12px; font-size: 15px; }
.hud-pack.full { color: #c0392b; font-weight: bold; }
.store-row.store-header { padding-top: 10px; border-bottom: none; background: none; }
/* the salon's Big Mirror (openSalon): stays in view while you scroll down the list to try things on */
.store-row.store-mirror { grid-template-columns: 150px 1fr 140px; position: sticky; top: -22px; z-index: 2; background: #fbf3ff; border-color: #c9a6e6; box-shadow: 0 6px 10px -8px rgba(60, 30, 80, 0.45); }
@media (max-width: 600px) {
  .store-row.store-mirror { grid-template-columns: 84px 1fr; gap: 4px 10px; }
  .store-row.store-mirror canvas { width: 84px; height: auto; }
  .store-row.store-mirror button { grid-column: 1 / -1; }
}
.energy-tag { font-family: var(--font); font-size: 14px; background: #dff0d4; color: #3f7a3a; border-radius: 6px; padding: 0 6px; vertical-align: 3px; }

/* conversations */
#dialog { position: fixed; left: 50%; bottom: 60px; transform: translateX(-50%); width: min(640px, calc(100% - 32px)); z-index: 12; }
.dialog-panel { padding: 16px 22px; }
.dialog-name { font-family: var(--title); font-size: 26px; color: var(--purple-dark); }
.dialog-text { font-size: 20px; margin: 6px 0 12px; line-height: 1.35; }
.dialog-buttons { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.dialog-buttons button:not(:last-child) { background: var(--purple); color: #fff; border-color: var(--purple-dark); }

/* energy + quickbar */
.energy-row { gap: 6px; margin-top: 4px; }
.energy-label { font-size: 15px; color: #6b5a48; }
.energy-bar { flex: 1; min-width: 80px; height: 10px; border-radius: 6px; background: rgba(120, 90, 60, 0.15); overflow: hidden; }
#foodFill, #restFill { height: 100%; width: 100%; background: #6fae5a; border-radius: 6px; transition: width 0.3s, background 0.3s; }
#energyNum { font-size: 15px; min-width: 24px; text-align: right; }
#quickbar { position: fixed; right: 14px; bottom: 12px; display: flex; gap: 6px; z-index: 5; }
.slot {
  position: relative; width: 46px; height: 46px; display: flex; align-items: center; justify-content: center;
  background: rgba(255, 250, 236, 0.9); border: 1.5px solid var(--edge); border-radius: 12px;
}
.slot span { position: absolute; right: 3px; bottom: 0; font-size: 15px; font-weight: bold; color: var(--ink); }
.map-panel { width: auto; max-width: calc(100% - 32px); text-align: center; }
#mapCanvas { border-radius: 12px; border: 2px solid var(--edge); max-width: 100%; }
.map-tabs { justify-content: center; }
.broom-card {
  display: grid; grid-template-columns: 120px 1fr 130px; align-items: center; gap: 12px;
  padding: 10px 12px; margin-bottom: 8px;
  border: 2px solid rgba(120, 90, 60, 0.25); border-radius: 14px 18px 14px 18px;
  background: rgba(255, 252, 244, 0.7);
}
.broom-card.equipped { border-color: var(--purple); background: #f3ebfb; }
.broom-name { font-family: var(--title); font-size: 24px; color: var(--purple-dark); }
.ability { font-size: 16px; color: #6b5a48; }
.speed { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.bar { flex: 1; height: 9px; border-radius: 6px; background: rgba(120, 90, 60, 0.15); overflow: hidden; }
.bar div { height: 100%; background: linear-gradient(90deg, #8fc1d9, var(--purple)); border-radius: 6px; }
.broom-card button { font-size: 18px; line-height: 1.1; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; }
.broom-card button.cant { background: #f1e8d8; color: #9a8268; }
.broom-card button small { width: 100%; font-size: 13px; }
.hint { text-align: center; color: #8a6a4a; margin: 10px 0 0; }
.loading-panel { padding: 22px 34px; font-family: var(--title); font-size: 34px; color: var(--purple-dark); }

@media (max-width: 760px) {
  .creator-grid { grid-template-columns: 1fr; }
  h1.logo { font-size: 72px; }
  .creator-title { margin-top: 30px; }
  .outfits { grid-template-columns: repeat(2, 1fr); }
  .broom-card { grid-template-columns: 1fr; text-align: center; }
  #controls { white-space: normal; width: calc(100% - 32px); text-align: center; }
  #objective { top: auto; bottom: 100px; right: 16px; left: 16px; max-width: none; }
}

/* ---------- effects, fade ---------- */
#effects { position: fixed; top: 236px; left: 14px; display: flex; flex-direction: column; gap: 4px; z-index: 5; }
.effect { background: rgba(255, 250, 236, 0.92); border: 1.5px solid var(--edge); border-radius: 10px; padding: 2px 10px; font-size: 16px; }
.effect.low { background: #fde2dc; border-color: #d6493f; color: #8a2a20; }
#fade { position: fixed; inset: 0; background: #1a1a30; z-index: 20; animation: fadeout 0.9s ease-in forwards; pointer-events: none; }
@keyframes fadeout { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- tailor ---------- */
.tailor-panel { width: min(900px, 100%); }
.tailor-grid { display: grid; grid-template-columns: 240px 1fr; gap: 18px; }
.tailor-preview { text-align: center; }
#tailorPreview { width: 220px; height: 250px; background: radial-gradient(ellipse at 50% 60%, rgba(230, 210, 240, 0.6), rgba(255, 255, 255, 0) 70%); border-radius: 40%; }
#tailorSelected { font-size: 18px; min-height: 48px; }
#tailorAction { font-size: 22px; padding: 6px; }
#tailorAction.cant { background: #c9b8d8; border-color: #a08ab5; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tab { font-size: 17px; padding: 4px 12px; }
.cloth-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; max-height: 52vh; overflow: auto; padding: 2px; }
.cloth-card { display: flex; flex-direction: column; align-items: center; padding: 4px 4px 6px; position: relative; }
.cloth-card canvas { width: 80px; height: 96px; }
.cloth-card .price { font-size: 14px; color: #a0701c; display: flex; align-items: center; gap: 3px; }
.cloth-card .price.free { color: #4f8a44; }
.cloth-card.wearing { border-color: #4f8a44; background: #eef7e6; }
.cloth-card.fancy::after { content: "✦"; position: absolute; top: 2px; right: 6px; font-size: 13px; color: #b58a2a; }
.quest-note { margin-top: 10px; padding: 8px; border: 2px dashed var(--edge); border-radius: 12px; font-size: 16px; text-align: left; }
.quest-note button { margin-top: 6px; }
.quest-row { padding: 8px 12px; margin-bottom: 8px; border: 2px solid rgba(120, 90, 60, 0.25); border-radius: 14px; background: rgba(255, 252, 244, 0.7); }
.quest-row.done { opacity: 0.6; }
.have { color: #3f7a3a; }
.need { color: #b5473a; }
@media (max-width: 760px) { .tailor-grid { grid-template-columns: 1fr; } }

/* ---------- touch screens (body.touch, see js/touch.js) ---------- */
.touch-only { display: none; }
body:not(.touch) #touch { display: none; }
#touch, #touch * { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* no double-tap zoom on panel buttons */
.overlay, #dialog { touch-action: manipulation; }
#touch button {
  position: fixed; z-index: 8; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 250, 236, 0.88); border: 2px solid var(--edge);
  border-radius: 50% 46% 52% 48%; box-shadow: 0 3px 10px rgba(90, 60, 30, 0.18);
}
#touch button:active { transform: scale(0.92); background: #efe4fa; }
#touchMenu { position: fixed; z-index: 8; top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 8px; }
#touchMenu button { position: static; width: 48px; height: 48px; font-size: 24px; }
#touchUse {
  right: calc(18px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
  width: 84px; height: 84px; font-size: 38px; flex-direction: column; opacity: 0.6;
}
#touchUse.ready { opacity: 1; border-color: var(--purple); background: #f6effc; box-shadow: 0 0 0 4px rgba(123, 90, 166, 0.25), 0 3px 10px rgba(90, 60, 30, 0.18); }
#touchUseLabel {
  position: absolute; bottom: 100%; right: 0; margin-bottom: 6px; max-width: 150px;
  font-size: 15px; line-height: 1.1; text-align: right; color: var(--ink);
  background: rgba(255, 250, 236, 0.92); border-radius: 8px; padding: 2px 8px;
}
#touchUseLabel:empty { display: none; }
#touchBroom { right: calc(114px + env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom)); width: 60px; height: 60px; font-size: 30px; }
#touchJump { right: calc(186px + env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom)); width: 60px; height: 60px; font-size: 30px; }
#touchBroom.flying { background: #e6f0fa; border-color: #7f8fd9; }
/* the arrow pad in the bottom-left corner: hold an arrow to walk, press between two to go diagonally */
#dpad {
  position: fixed; z-index: 8;
  left: calc(14px + env(safe-area-inset-left)); bottom: calc(14px + env(safe-area-inset-bottom));
  width: 156px; height: 156px; border-radius: 50%;
  background: rgba(255, 250, 236, 0.28); border: 2px dashed rgba(120, 90, 60, 0.3);
}
.dpadArrow {
  position: absolute; width: 54px; height: 54px; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 250, 236, 0.88); border: 2px solid var(--edge);
  border-radius: 46% 52% 48% 50%; box-shadow: 0 3px 10px rgba(90, 60, 30, 0.18);
}
.dpadArrow svg { width: 26px; height: 26px; fill: var(--purple); }
.dpadArrow[data-dir="up"] { left: 51px; top: 2px; }
.dpadArrow[data-dir="down"] { left: 51px; bottom: 2px; }
.dpadArrow[data-dir="down"] svg { transform: rotate(180deg); }
.dpadArrow[data-dir="left"] { top: 51px; left: 2px; }
.dpadArrow[data-dir="left"] svg { transform: rotate(-90deg); }
.dpadArrow[data-dir="right"] { top: 51px; right: 2px; }
.dpadArrow[data-dir="right"] svg { transform: rotate(90deg); }
.dpadArrow.on { background: #efe4fa; border-color: var(--purple); transform: scale(0.92); }
/* after a quick tap you keep walking: the arrow stays lit and glows */
#dpad.latched .dpadArrow.on { background: #e4d4f7; box-shadow: 0 0 0 4px rgba(123, 90, 166, 0.3), 0 3px 10px rgba(90, 60, 30, 0.18); }
#dpadHub { position: absolute; left: 66px; top: 66px; width: 24px; height: 24px; border-radius: 50%; background: rgba(120, 90, 60, 0.18); pointer-events: none; }
body.touch .touch-only { display: block; }
body.touch #controls, body.touch #quickbar, body.touch .hint { display: none !important; }
body.touch .close { font-size: 22px; padding: 6px 14px; }
body.touch .dialog-panel { position: relative; padding-right: 60px; }
body.touch .dialog-buttons button { padding: 10px 16px; font-size: 19px; }
/* a slim HUD; tap it to see everything */
body.touch #hud { top: calc(10px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left)); padding: 6px 12px; font-size: 17px; min-width: 0; width: 176px; }
body.touch #hud:not(.open) .hud-name, body.touch #hud:not(.open) #hudGems, body.touch #hud:not(.open) .hud-broom:not(#hudTime) { display: none; }
body.touch #hud:not(.open) .energy-word { display: none; }
body.touch .energy-bar { min-width: 60px; }
body.touch #hudTime { font-size: 14px; }
body.touch #hud.open { width: auto; max-width: calc(100% - 90px); z-index: 9; }
body.touch #objective {
  top: calc(10px + env(safe-area-inset-top)); left: 200px; right: 72px; bottom: auto;
  max-width: 420px; margin: 0 auto; padding: 6px 12px; font-size: 15px; line-height: 1.2;
}
body.touch #effects { top: calc(118px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left)); }
body.touch #toast { bottom: calc(150px + env(safe-area-inset-bottom)); font-size: 18px; }
/* phones held upright: the goal goes under the HUD */
@media (max-width: 600px) {
  body.touch #objective { top: calc(142px + env(safe-area-inset-top)); left: 10px; max-width: none; }
  body.touch #effects { top: calc(210px + env(safe-area-inset-top)); }
}
/* phones held sideways: the menu buttons go in a row along the top */
@media (max-height: 500px) {
  #touchMenu { flex-direction: row; }
  body.touch #objective { right: 300px; }
  body.touch #effects { top: calc(112px + env(safe-area-inset-top)); }
}

/* ---------- the mailbox (mail.js) ---------- */
.mail-panel { width: min(720px, 100%); }
.mail-note { margin: 0 0 10px; padding: 8px 12px; border-radius: 12px; background: #fff4cf; border: 2px dashed #e0b84a; font-size: 18px; }
.mail-list { display: flex; flex-direction: column; gap: 6px; max-height: 56vh; overflow: auto; padding: 2px; }
.mail-row { display: grid; grid-template-columns: 40px 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; text-align: left; padding: 6px 10px; }
.mail-row .mail-stamp { grid-row: span 2; }
.mail-row.unread { background: #fffbe8; border-color: var(--gold); }
.mail-row.unread .mail-from { font-weight: bold; }
.mail-from { font-size: 19px; color: var(--purple-dark); }
.mail-snip { font-size: 15px; color: #7a6a56; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mail-stamp { display: inline-flex; align-items: center; justify-content: center; width: 54px; height: 62px; font-size: 30px;
  border: 3px dotted rgba(255, 255, 255, 0.95); outline: 2px solid rgba(120, 90, 60, 0.35); border-radius: 4px; box-shadow: 1px 2px 0 rgba(80, 50, 30, 0.2); }
.mail-stamp.small { width: 34px; height: 40px; font-size: 19px; border-width: 2px; }
.mail-stamp.empty { background: rgba(120, 90, 60, 0.08); color: #b8a68e; border-color: transparent; outline-style: dashed; box-shadow: none; }
.mail-paper { position: relative; padding: 16px 20px 12px; margin-bottom: 10px; border-radius: 6px 10px 8px 12px; font-size: 19px; line-height: 1.4;
  background: repeating-linear-gradient(#fffdf6 0 29px, #e8ddc8 29px 30px); border: 1.5px solid rgba(120, 90, 60, 0.3); box-shadow: 2px 3px 0 rgba(80, 50, 30, 0.12); }
.mail-paper > .mail-stamp { float: right; margin: 0 0 8px 12px; transform: rotate(4deg); }
.mail-meta { font-size: 15px; color: #8a7a64; margin-bottom: 6px; }
.mail-paper p { margin: 6px 0; }
.mail-sign { text-align: right; font-family: var(--title); font-size: 24px; color: var(--purple-dark); clear: both; }
.mail-oops { background: #fde2dc; border-radius: 10px; padding: 6px 10px; font-size: 17px; margin-bottom: 8px; }
.mail-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.mail-buttons .big { font-size: 19px; }
.mail-buttons .cant { background: #f1e8d8; color: #9a8268; }
.mail-people { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; max-height: 56vh; overflow: auto; padding: 2px; }
.mail-person { font-size: 17px; line-height: 1.2; padding: 8px; }
.mail-choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; margin: 6px 0 10px; }
.mail-choice { text-align: left; font-size: 18px; }
.mail-gift { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 18px; margin-bottom: 6px; }
.mail-gift select { font-family: var(--font); font-size: 17px; padding: 3px 6px; border-radius: 8px; max-width: 100%; }
.mail-album { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; margin-bottom: 10px; }
.mail-album-slot { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: 14px; }
.mail-album-slot.empty small { color: #b8a68e; }

/* ---------- the sticker album (stickers.js) ---------- */
#stickerBtn { position: fixed; right: 14px; bottom: 66px; z-index: 5; width: 54px; height: 54px; padding: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; background: rgba(255, 250, 236, 0.92); }
#stickerBtn canvas { width: 40px; height: 40px; }
#stickerBtnCount { position: absolute; right: -4px; bottom: -4px; min-width: 20px; padding: 0 4px; border-radius: 10px; background: var(--purple); color: #fff; font-size: 13px; line-height: 20px; }
#stickerBtn.bump { animation: stkBump 0.5s ease-out; }
@keyframes stkBump { 40% { transform: scale(1.25) rotate(-8deg); } }
body.touch #stickerBtn { display: none; }
#stickerPop { position: fixed; left: 50%; top: 70px; z-index: 40; display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  max-width: min(460px, calc(100% - 32px)); padding: 12px 18px; pointer-events: none; }
.stk-pop-art canvas { width: 96px; height: 96px; display: block; }
.stk-pop-text { font-size: 18px; flex: 1; min-width: 160px; }
.stk-pop-title { font-family: var(--title); font-size: 26px; color: var(--purple-dark); }
.stk-pop-notes { flex-basis: 100%; font-size: 16px; padding: 6px 10px; border-radius: 10px; background: #fff4cf; }
.sticker-panel { width: min(760px, 100%); }
.stk-cover { font-family: var(--title); font-size: 26px; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2); padding: 6px 14px; border-radius: 10px 16px 10px 16px; }
#stickerGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; max-height: 50vh; overflow: auto; padding: 4px;
  background: repeating-linear-gradient(45deg, #fbf5e6 0 12px, #f7efdc 12px 24px); border-radius: 12px; }
.stk-slot { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; background: transparent; border: 0; box-shadow: none; position: relative; }
.stk-slot canvas { width: 76px; height: 76px; }
.stk-slot small { font-size: 13px; line-height: 1.1; color: #6b5a48; text-align: center; }
.stk-slot.selected small { color: var(--purple-dark); font-weight: bold; }
.stk-empty { width: 70px; height: 70px; margin: 3px; border-radius: 50%; border: 2.5px dashed rgba(120, 90, 60, 0.35); display: flex; align-items: center; justify-content: center;
  font-family: var(--title); font-size: 30px; color: #c4b49c; }
.stk-slot.bonus::after { content: "⭐"; position: absolute; top: 2px; right: 8px; font-size: 13px; }
.stk-slot.shiny canvas, .stk-pop-art.shiny canvas { animation: stkShine 2.4s ease-in-out infinite; }
@keyframes stkShine { 0%, 100% { filter: brightness(1) saturate(1); } 50% { filter: brightness(1.18) saturate(1.3) drop-shadow(0 0 4px rgba(255, 230, 140, 0.9)); } }

/* ---------- the camera and the photo scrapbook (camera.js) ---------- */
#camFlash { position: fixed; inset: 0; background: #fffdf5; z-index: 19; pointer-events: none; animation: camflash 0.4s ease-out forwards; }
@keyframes camflash { from { opacity: 0.95; } to { opacity: 0; } }
.scrap-panel { width: min(820px, 100%); }
#scrapHead { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
#scrapHead .talk { flex-basis: 100%; }
#scrapHead .polaroid { max-width: 240px; }
.scrap-msg { flex-basis: 100%; margin: 0; padding: 6px 10px; border-radius: 10px; background: #fff4cf; }
#scrapGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 16px 12px; max-height: 58vh; overflow: auto; padding: 12px 8px;
  margin-top: 8px; background: repeating-linear-gradient(45deg, #fbf5e6 0 12px, #f7efdc 12px 24px); border-radius: 12px; }
.polaroid { background: #fffdf8; padding: 8px 8px 6px; box-shadow: 0 3px 10px rgba(90, 60, 30, 0.22); border-radius: 3px; display: flex; flex-direction: column; gap: 4px; transform: rotate(-1.2deg); }
.polaroid:nth-child(even) { transform: rotate(1.3deg); }
.polaroid:nth-child(3n) { transform: rotate(-0.4deg); }
.polaroid.new { transform: rotate(-2deg); outline: 3px dashed var(--gold); outline-offset: 3px; }
.polaroid img { width: 100%; height: auto; aspect-ratio: 8 / 5; display: block; background: #e8e0cc; }
.polaroid .cap { font-family: var(--title); font-size: 19px; line-height: 1.1; color: var(--ink); word-break: break-word; min-height: 1.1em; }
.polaroid small { font-size: 13px; color: #8a6a4a; }
.polaroid .cap-input { font-family: var(--title); font-size: 18px; width: 100%; box-sizing: border-box; padding: 2px 4px; border: 2px solid var(--edge); border-radius: 6px; }
.pol-btns { display: flex; gap: 6px; justify-content: flex-end; }
.pol-btns button { font-size: 15px; padding: 2px 8px; }

/* ---------- music (music.js): a panel at the bottom, so you can watch everybody dance ---------- */
#tunes { position: fixed; z-index: 10; left: 50%; transform: translateX(-50%);
  bottom: max(10px, env(safe-area-inset-bottom)); width: min(440px, calc(100vw - 20px)); }
#tunes.hidden { display: none; }
.tunes-panel { position: relative; padding: 12px 16px 10px; max-height: calc(100vh - 30px); overflow-y: auto; }
.tunes-panel h2 { font-size: 30px; margin-right: 36px; }
.tunes-msg { margin: 4px 0 6px; min-height: 1.3em; }
#tunesLanes { display: block; width: 100%; height: auto; max-height: 34vh; border-radius: 12px; background: rgba(255, 252, 244, 0.7); border: 1.5px solid var(--edge); }
.tunes-pads { display: flex; gap: 8px; margin-top: 8px; }
.tunes-pad { flex: 1; height: 58px; font-size: 26px; color: #fff; border: 2px solid rgba(60, 40, 70, 0.35); border-radius: 14px; touch-action: none; user-select: none; -webkit-user-select: none; }
.tunes-pad:active { transform: scale(0.94); filter: brightness(1.15); }
.tunes-insts { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.tunes-inst { display: flex; flex-direction: column; align-items: center; padding: 4px 6px; min-width: 70px; }
.tunes-inst small { font-size: 13px; line-height: 1.1; }
.tunes-inst.selected { background: var(--purple); color: #fff; border-color: var(--purple-dark); }
.tunes-songs { display: flex; flex-direction: column; gap: 6px; }
.tunes-song { text-align: left; padding: 6px 10px; line-height: 1.2; }
.tunes-song small { font-size: 14px; opacity: 0.85; }
.tunes-song.locked { border: 1.5px dashed var(--edge); border-radius: 12px; opacity: 0.7; }
.tunes-stars { color: #e8a32e; letter-spacing: 1px; }
.tunes-result { text-align: center; }
.tunes-big-stars { font-size: 44px; color: #e8a32e; letter-spacing: 4px; line-height: 1.1; }
.tunes-big-stars span { color: #cfc2b0; }
.tunes-result .dialog-buttons { justify-content: center; }
.tunes-score { margin: 0 0 6px; }
@media (max-height: 520px) { .tunes-pad { height: 46px; } #tunesLanes { max-height: 30vh; } .tunes-panel h2 { font-size: 24px; } }
