:root {
  color-scheme: dark;
  font: 16px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --night: #261c36;
  --plum: #342447;
  --paper: #fff4df;
  --sugar: #ffdda1;
  --muted: #e6d2df;
  --edge: clamp(16px, 2.8vw, 42px);
  --edge-t: max(var(--edge), env(safe-area-inset-top));
  --edge-r: max(var(--edge), env(safe-area-inset-right));
  --edge-b: max(var(--edge), env(safe-area-inset-bottom));
  --edge-l: max(var(--edge), env(safe-area-inset-left));
}

*, *::before, *::after { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--night); color: var(--paper); }
button { font: inherit; }
button:not(:disabled) { cursor: pointer; }
button:focus-visible { outline: 3px solid #fff0c5; outline-offset: 4px; }
button:disabled { opacity: .65; }

#hunt {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
  background:
    radial-gradient(ellipse at 62% 78%, #5d456d, transparent 68%),
    linear-gradient(160deg, #251b3c, #442d54);
}

body[data-mode="playing"] #game { cursor: grab; }
body[data-mode="playing"] #game:active { cursor: grabbing; }

.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  display: block;
  width: 1.25em;
  height: 1.25em;
  flex: none;
  pointer-events: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgb(26 15 43 / .38), transparent 22%, transparent 79%, rgb(26 15 43 / .42));
}

body[data-mode="title"] .vignette {
  background:
    linear-gradient(90deg, rgb(23 13 38 / .66), rgb(23 13 38 / .14) 57%, transparent),
    linear-gradient(180deg, rgb(26 15 43 / .44), transparent 28%);
}

.masthead {
  position: absolute;
  z-index: 3;
  top: var(--edge-t);
  right: var(--edge-r);
  left: var(--edge-l);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  width: 44px;
  aspect-ratio: 1;
  place-items: center;
  color: var(--sugar);
  background: #301e46;
  border: 1px solid #a67b9a;
  border-radius: 15px;
  box-shadow: 0 4px 12px rgb(22 12 38 / .32), inset 0 0 0 3px rgb(255 254 240 / .05);
  font-size: 20px;
}

.brand-copy { display: grid; line-height: 1.15; text-shadow: 0 1px 6px #231234, 0 1px 12px #231234; }
.brand-copy strong { font: 700 1.02rem/1.15 Georgia, Cambria, serif; }
.brand-copy small {
  margin-top: 5px;
  color: #ffebd6;
  font-size: .61rem;
  font-weight: 750;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.top-actions { display: flex; gap: 8px; pointer-events: auto; }
.icon-button {
  display: grid;
  width: 48px;
  height: 48px;
  padding: 0;
  place-items: center;
  color: var(--paper);
  border: 1px solid #ad8da6;
  border-radius: 15px;
  background: #322245;
  box-shadow: 0 4px 12px rgb(22 12 38 / .27), inset 0 0 0 3px rgb(255 254 240 / .04);
}

.icon-button:hover { background: #4b3260; }
.icon-button .icon, .primary-button .icon, .timer-display .icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#mute-button .sound-icon,
#mute-button[aria-pressed="true"] .mute-icon { display: none; }
#mute-button[aria-pressed="true"] .sound-icon { display: block; }
#pause-button { display: none; }
body[data-mode="playing"] #pause-button { display: grid; }
body:not([data-mode="title"]):not([data-mode="playing"]) .top-actions { visibility: hidden; }

.screen {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: none;
  padding: max(calc(var(--edge-t) + 47px), 64px) var(--edge-r) var(--edge-b) var(--edge-l);
}

body[data-mode="title"] #title-screen,
body[data-mode="paused"] #pause-screen,
body[data-mode="won"] #win-screen,
body[data-mode="error"] #error-screen { display: grid; }

.screen-title { align-items: center; justify-items: start; }
.card {
  position: relative;
  width: 100%;
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  border: 1px solid #b78e9d;
  border-radius: 27px;
  background:
    radial-gradient(ellipse at 100% 0%, rgb(171 102 124 / .30), transparent 56%),
    linear-gradient(135deg, #3c294f, #2c2043 82%);
  box-shadow: 0 20px 50px rgb(18 10 35 / .42), inset 0 0 0 4px rgb(255 235 220 / .05);
}

.title-card {
  max-width: 494px;
  padding: clamp(25px, 3.05vw, 45px);
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 10px;
  color: var(--sugar);
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .19em;
  text-transform: uppercase;
}

.sugar-diamond {
  display: inline-block;
  width: 7px;
  height: 7px;
  flex: none;
  transform: rotate(45deg);
  border-radius: 1px;
  background: #ffd07c;
  box-shadow: 0 0 9px #ffbb71;
}

h1, h2 {
  margin: 0;
  color: var(--paper);
  font-family: Georgia, Cambria, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: -.055em;
}

h1 { font-size: clamp(2.7rem, 5.05vw, 4.2rem); line-height: .98; text-shadow: 0 3px #613747; }
.title-pre { display: block; margin-bottom: .06em; font-size: .57em; letter-spacing: -.045em; }
.title-main { display: block; color: #ffe2a5; }
.lede { max-width: 37ch; margin: 18px 0 0; color: #f7e6eb; line-height: 1.52; }
.lede strong { color: #ffdf96; }

.title-tokens { display: flex; gap: 7px; margin: 22px 0 18px; user-select: none; }
.title-tokens > span {
  display: grid;
  width: 43px;
  aspect-ratio: 1;
  place-items: center;
  color: #452437;
  border: 1px solid #ffe1a5;
  border-radius: 9px;
  background: linear-gradient(160deg, #ffedc6 4%, #edaf69 98%);
  box-shadow: 0 3px 0 #a66b59, inset 0 0 0 2px rgb(128 65 63 / .15);
  font: 900 1.28rem/1 Georgia, Cambria, serif;
}

.title-tokens .title-star {
  margin-left: 5px;
  color: #ffdf9a;
  background: #72445b;
  border-color: #d18e86;
  box-shadow: 0 3px 0 #51304e, inset 0 0 0 2px rgb(255 222 190 / .09);
}

.title-star .icon { width: .95em; height: .95em; }
.title-controls {
  padding-top: 12px;
  margin: 0 0 18px;
  color: #f1dfe9;
  border-top: 1px solid #8c6784;
  font-size: .79rem;
  line-height: 1.55;
}

.title-controls p { margin: 0 0 2px; }
.title-controls kbd {
  padding: 1px 5px;
  color: var(--paper);
  border: 1px solid #946f91;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #4c345f;
  font: 750 .67rem/1.4 system-ui, sans-serif;
  white-space: nowrap;
}

.title-controls [aria-hidden="true"] { margin-inline: 2px; color: var(--sugar); }
.title-controls .touch-instructions { display: none; }
.noscript { color: var(--muted); font-size: .8rem; }

.primary-button {
  display: flex;
  width: 100%;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 17px;
  color: #39223b;
  text-align: left;
  border: 1px solid #ffedb5;
  border-radius: 12px;
  background: linear-gradient(145deg, #ffe5a9, #ffc379);
  box-shadow: 0 4px 0 #9a6354, inset 0 0 0 2px rgb(255 249 217 / .29);
  font-weight: 850;
}

.primary-button:hover:not(:disabled) { background: linear-gradient(145deg, #ffefbe, #ffd098); }
.primary-button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #9a6354; }
.secondary-button {
  display: block;
  min-height: 44px;
  width: 100%;
  margin-top: 10px;
  color: var(--paper);
  border: 1px solid #a982a1;
  border-radius: 10px;
  background: #49335d;
  font-size: .86rem;
  font-weight: 700;
}

.secondary-button:hover { background: #5a3e70; }

#hud {
  position: absolute;
  z-index: 2;
  display: none;
  gap: 8px;
  align-items: stretch;
  top: var(--edge-t);
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}

body[data-mode="playing"] #hud { display: flex; }
.hud-panel {
  color: var(--paper);
  background: #302143;
  border: 1px solid #a785a2;
  border-radius: 16px;
  box-shadow: 0 6px 20px rgb(20 10 35 / .26), inset 0 0 0 3px rgb(244 224 235 / .045);
}

.progress-card {
  display: grid;
  grid-template-columns: minmax(0, auto) auto;
  align-items: center;
  gap: 5px 8px;
  padding: 8px 10px 10px;
}

.hud-heading {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  padding-inline: 1px;
  color: #f0d9e8;
  font-size: .57rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: .12em;
  text-transform: uppercase;
}

#letter-count { color: #ffe4a7; font-variant-numeric: tabular-nums; white-space: nowrap; }
.letter-slots { display: flex; gap: 4px; padding: 0; margin: 0; list-style: none; }
.letter-slots li, .star-slot {
  display: grid;
  width: 32px;
  height: 34px;
  place-items: center;
  color: #e5cadd;
  border: 1px dashed #997997;
  border-radius: 7px;
  background: #442e57;
  font: 700 1.05rem/1 Georgia, Cambria, serif;
}

.star-slot { color: #f8d88e; }
.star-slot .icon { width: 17px; height: 17px; }
.letter-slots [data-collected="true"], .star-slot[data-collected="true"] {
  color: #4d2b42;
  border: 1px solid #ffe0a1;
  background: linear-gradient(150deg, #ffedbe, #f6b96e);
  box-shadow: 0 0 13px rgb(255 196 119 / .36);
  animation: found .36s ease-out;
}

@keyframes found {
  40% { transform: scale(1.16); }
}

.guide-card { display: flex; align-items: center; padding: 7px 10px; gap: 10px; }
.timer-display { display: flex; align-items: center; gap: 4px; font-weight: 760; }
.timer-display .icon { width: 15px; height: 15px; color: #f1c887; }
#timer { min-width: 5ch; font-size: .8rem; font-variant-numeric: tabular-nums; }
.compass-display {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 9px;
  color: #efd9e9;
  border-left: 1px solid #7d6086;
  font-size: .55rem;
  font-weight: 790;
  line-height: 1.15;
  letter-spacing: .075em;
  text-transform: uppercase;
}

.compass-dial {
  display: grid;
  width: 29px;
  height: 29px;
  place-items: center;
  border: 1px solid #997497;
  border-radius: 50%;
  background: #452f58;
}

#compass-needle { width: 24px; height: 24px; color: #ffdb85; }
#compass[data-active="false"] #compass-needle { opacity: .38; }

#joystick {
  position: absolute;
  z-index: 2;
  bottom: max(29px, calc(env(safe-area-inset-bottom) + 18px));
  left: max(23px, calc(env(safe-area-inset-left) + 11px));
  display: none;
  width: 112px;
  height: 112px;
  place-items: center;
  border: 1px solid rgb(255 230 201 / .68);
  border-radius: 50%;
  background: rgb(47 30 66 / .49);
  box-shadow: 0 3px 18px rgb(25 12 42 / .28);
  touch-action: none;
  user-select: none;
}

.joystick-ring, .joystick-knob { grid-area: 1 / 1; border-radius: 50%; pointer-events: none; }
.joystick-ring { width: 81%; height: 81%; border: 1px dashed rgb(255 235 219 / .56); }
.joystick-knob {
  width: 45px;
  height: 45px;
  background: #ffe1a4;
  border: 2px solid #fff0d0;
  box-shadow: 0 3px 8px rgb(32 14 48 / .36), inset 0 0 0 3px #eab57c;
}

.field-note {
  position: absolute;
  z-index: 1;
  right: var(--edge-r);
  bottom: var(--edge-b);
  display: none;
  align-items: center;
  gap: 9px;
  margin: 0;
  color: #fff2d6;
  text-shadow: 0 1px 5px #2a173c, 0 1px 11px #2a173c;
  font-size: .66rem;
  font-weight: 790;
  letter-spacing: .12em;
  text-transform: uppercase;
  pointer-events: none;
}

body[data-mode="playing"] .field-note { display: flex; }

.screen-modal {
  align-items: center;
  justify-items: center;
  background: rgb(26 16 41 / .34);
}

.modal-card { max-width: 423px; padding: 28px; text-align: center; }
.modal-card .eyebrow { justify-content: center; margin: 12px 0 7px; }
.modal-card h2 { font-size: clamp(2rem, 4vw, 3.1rem); line-height: 1.04; }
.modal-card .lede { margin: 10px auto 19px; font-size: .92rem; }
#error-heading:focus { outline: none; }
.medallion {
  display: grid;
  width: 55px;
  height: 55px;
  margin: 0 auto;
  place-items: center;
  color: #ffdb95;
  border: 1px solid #d2a079;
  border-radius: 17px;
  background: #5a3b5e;
  box-shadow: 0 0 23px rgb(255 179 103 / .15), inset 0 0 0 3px rgb(255 221 185 / .1);
  font-size: 24px;
}

.win-card[data-perfect="true"] .medallion {
  color: #79454b;
  border-color: #ffedb6;
  background: linear-gradient(150deg, #fff0c5, #ffc37e);
  box-shadow: 0 0 24px rgb(255 183 110 / .33), inset 0 0 0 3px rgb(255 245 192 / .65);
}

.win-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 16px; }
.win-stats div { padding: 8px 4px; border: 1px solid #8b688b; border-radius: 11px; background: #39284e; }
.win-stats dt { color: #efdbeb; font-size: .6rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.win-stats dd { margin: 2px 0 0; color: var(--paper); font-size: 1.05rem; font-weight: 780; font-variant-numeric: tabular-nums; }
#win-star[data-collected="true"] { color: #ffe1a0; }
.replay-note { margin: 13px 0 0; color: #e8d6e7; font-size: .74rem; }

@media (any-pointer: coarse) {
  body[data-mode="playing"] #joystick { display: grid; }
  .title-controls .keyboard-instructions { display: none; }
  .title-controls .touch-instructions { display: block; }
}

@media (max-width: 760px) {
  body[data-mode="playing"] .brand { visibility: hidden; }
  #hud { left: var(--edge-l); transform: none; }
}

@media (max-width: 540px) {
  body[data-mode="title"] .vignette {
    background: linear-gradient(180deg, rgb(23 13 38 / .30), transparent 29%, rgb(23 13 38 / .54) 100%);
  }

  .screen-title { align-items: end; justify-items: center; }
  .title-card { padding: 20px 21px; border-radius: 22px; }
  .title-card .eyebrow { font-size: .58rem; margin-bottom: 7px; }
  h1 { font-size: clamp(2.45rem, 10.6vw, 3.35rem); }
  .title-card .lede { margin-top: 11px; font-size: .84rem; }
  .title-tokens { gap: 5px; margin: 13px 0 12px; }
  .title-tokens > span { width: 32px; border-radius: 6px; font-size: .95rem; }
  .title-controls { padding-top: 8px; margin-bottom: 11px; font-size: .73rem; }
  .primary-button { min-height: 47px; font-size: .91rem; }
  .modal-card { padding: 20px; border-radius: 22px; }
  body[data-mode="won"] #win-screen { align-items: end; }
  .brand-mark { width: 38px; border-radius: 12px; font-size: 17px; }
  .brand-copy strong { font-size: .91rem; }
  .brand-copy small { font-size: .55rem; }
  .icon-button { width: 43px; height: 43px; border-radius: 13px; }
  .top-actions { gap: 5px; }
  #hud {
    top: var(--edge-t);
    flex-direction: column;
    gap: 5px;
    align-items: flex-start;
  }
  .progress-card { padding: 6px 7px 7px; gap: 5px 5px; border-radius: 12px; }
  .letter-slots { gap: 3px; }
  .letter-slots li, .star-slot { width: 24px; height: 26px; border-radius: 5px; font-size: .89rem; }
  .star-slot .icon { width: 14px; height: 14px; }
  .guide-card { padding: 4px 7px; border-radius: 11px; gap: 7px; }
  .compass-display { padding-left: 6px; }
  .compass-dial { width: 24px; height: 24px; }
  #compass-needle { width: 21px; height: 21px; }
  .field-note { max-width: 128px; gap: 7px; font-size: .57rem; }
}

@media (max-height: 520px) and (min-width: 541px) {
  :root { --edge: 12px; }
  .title-card { max-width: 460px; padding: 15px 23px; }
  h1 { font-size: 2.9rem; }
  .title-card .lede, .title-tokens { margin-top: 9px; }
  .title-tokens { margin-bottom: 9px; }
  .title-tokens > span { width: 29px; font-size: .85rem; }
  .title-controls { padding-top: 5px; margin-bottom: 7px; }
  .primary-button { min-height: 43px; }
  .modal-card { padding: 13px 22px; }
  .modal-card .medallion { width: 34px; height: 34px; border-radius: 10px; font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .letter-slots [data-collected="true"], .star-slot[data-collected="true"] { animation: none; }
}
