:root {
  --ink: #1c1b19;
  --muted: #7d786f;
  --paper: #ffffff;
  --parch: #efe2c4;
  --parch-ink: #4a3424;
  --gold: #b8892f;
  --display: 'IM Fell English', 'Iowan Old Style', Georgia, serif;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--paper); color: var(--ink); }
body { font: 13px/1.4 var(--mono); overflow: hidden; -webkit-font-smoothing: antialiased; }

#stage { position: fixed; inset: 0; overflow: hidden; background: var(--paper); }
#c { display: block; image-rendering: pixelated; touch-action: none; outline: none; }

/* ---- HUD ---- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#place {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 2px;
  text-shadow: 0 0 6px #fff, 0 0 2px #fff;
}
#place b { font: 400 22px/1.1 var(--display); letter-spacing: 0.01em; }
#place span { color: var(--muted); font-size: 12px; }
#place.flash b { animation: ink 0.8s ease-out; }
@keyframes ink { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

#corner {
  position: absolute; top: max(14px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right));
  display: flex; align-items: center; gap: 12px; pointer-events: auto;
  text-shadow: 0 0 6px #fff, 0 0 2px #fff;
}
#secrets { color: var(--muted); font-variant-numeric: tabular-nums; }
#corner button {
  font: inherit; color: var(--muted); background: rgba(255, 255, 255, 0.8); border: 1px solid #d8d3c8;
  border-radius: 3px; padding: 3px 8px; cursor: pointer;
}
#corner button:hover, #corner button:focus-visible { color: var(--ink); border-color: var(--ink); }

#prompt {
  position: absolute; left: 50%; bottom: max(84px, calc(env(safe-area-inset-bottom) + 84px)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 5px 10px; border-radius: 2px; white-space: nowrap;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12); pointer-events: auto; cursor: pointer;
}
#say {
  position: absolute; left: 50%; bottom: max(22px, calc(env(safe-area-inset-bottom) + 18px)); transform: translateX(-50%);
  width: min(560px, calc(100vw - 32px));
  background: rgba(255, 255, 255, 0.94); border: 1px solid var(--ink); padding: 10px 14px 11px;
  font: 400 17px/1.35 var(--display); box-shadow: 3px 3px 0 rgba(28, 27, 25, 0.16);
}
#say b { display: block; font: 600 11px/1.2 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 4px; }

#ask {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); pointer-events: auto;
  background: #fff; border: 1px solid var(--ink); padding: 14px 16px; box-shadow: 4px 4px 0 rgba(28, 27, 25, 0.18);
  display: flex; flex-direction: column; gap: 8px; width: min(320px, calc(100vw - 32px));
}
#ask label { font: 400 18px/1.2 var(--display); }
#ask input { font: 15px var(--mono); padding: 6px 8px; border: 1px solid #bdb6a8; border-radius: 2px; outline: none; }
#ask input:focus { border-color: var(--ink); }

#found {
  position: absolute; left: 50%; top: max(64px, calc(env(safe-area-inset-top) + 56px)); transform: translateX(-50%);
  background: var(--parch); color: var(--parch-ink); border: 1px solid #c9b48a; padding: 7px 14px 8px;
  font: italic 400 16px/1.2 var(--display); white-space: nowrap; box-shadow: 2px 2px 0 rgba(74, 52, 36, 0.18);
  animation: found 3.6s ease forwards;
}
#found small { font: 11px var(--mono); font-style: normal; letter-spacing: 0.06em; text-transform: uppercase; margin-right: 8px; color: #8a6d48; }
@keyframes found { 0% { opacity: 0; transform: translate(-50%, -6px); } 10%, 82% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

/* ---- title card ---- */
#title {
  position: fixed; inset: 0; display: grid; align-items: center; justify-items: start; padding: 16px 16px 16px max(16px, 6vw);
  background: linear-gradient(to right, rgba(255, 255, 255, 0.97) 0%, rgba(255, 255, 255, 0.9) 30%, rgba(255, 255, 255, 0) 56%);
}
#title .card { text-align: left; }
#title .lede, #title .fine { margin-left: 0; }
#title.gone { opacity: 0; pointer-events: none; transition: opacity 0.6s ease; }
.card { max-width: 440px; text-align: center; }
.eyebrow { margin: 0 0 4px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.14em; font-size: 11px; }
#title h1 { margin: 0; font: 400 clamp(54px, 12vw, 84px)/0.95 var(--display); letter-spacing: -0.01em; }
.lede { font: 400 18px/1.4 var(--display); margin: 14px auto 16px; max-width: 380px; }
.keys { list-style: none; padding: 0; margin: 0 0 18px; color: var(--muted); display: grid; gap: 4px; }
@media (min-width: 561px) and (min-height: 521px) { .keys { justify-items: start; } }
kbd { font: 11px var(--mono); color: var(--ink); border: 1px solid #c8c2b6; border-bottom-width: 2px; border-radius: 3px; padding: 0 4px; background: #fff; }
#start {
  font: 400 20px/1 var(--display); color: #fff; background: var(--ink); border: 0; padding: 12px 22px 13px; cursor: pointer;
  box-shadow: 3px 3px 0 rgba(28, 27, 25, 0.2);
}
#start:hover, #start:focus-visible { background: #3a2f22; }
#start[disabled] { opacity: 0.4; cursor: wait; }
.loading { color: var(--muted); margin: 10px 0 0; min-height: 1.4em; }
.fine { color: var(--muted); font-size: 11px; line-height: 1.5; margin: 18px auto 0; max-width: 400px; }
.fine a { color: inherit; }

/* ---- the map ---- */
#map { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(28, 27, 25, 0.35); padding: 16px; }
.parchment {
  position: relative; width: min(760px, 100%); aspect-ratio: 6 / 5; max-height: calc(100vh - 32px);
  background: var(--parch); border: 1px solid #c9b48a; box-shadow: 6px 6px 0 rgba(74, 52, 36, 0.25);
  display: grid; place-items: center;
  background-image: radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, 0.35), transparent 60%), radial-gradient(ellipse at 80% 90%, rgba(120, 80, 30, 0.12), transparent 50%);
}
.parchment .blank { font: italic 400 20px var(--display); color: rgba(74, 52, 36, 0.5); }
#map-canvas { width: 100%; height: 100%; image-rendering: pixelated; }
.map-foot { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; font: italic 14px var(--display); color: var(--parch-ink); margin: 0; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; font: 18px var(--display); }

.keys--touch { display: none; }
@media (pointer: coarse) {
  .keys--desk { display: none; }
  .keys--touch { display: grid; }
}
@media (max-width: 560px) {
  #place { max-width: calc(100vw - 150px); }
  #place b { font-size: 18px; }
  #corner { flex-direction: column; align-items: flex-end; gap: 6px; }
  #secrets { font-size: 11px; }
  #say { font-size: 16px; }
  #prompt { bottom: 96px; max-width: calc(100vw - 32px); white-space: normal; text-align: center; }
}
@media (max-width: 560px), (max-height: 520px) {
  /* let the floating island show above the card */
  #title { align-items: end; justify-items: center; padding: 16px; background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.2) 30%, rgba(255, 255, 255, 0.95) 52%); }
  #title .card { text-align: center; }
  #title .lede, #title .fine { margin-left: auto; }
  #title h1 { font-size: 52px; }
  .lede { font-size: 16px; margin: 8px auto 10px; }
  .fine { margin-top: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  #place.flash b, #found { animation: none; }
}

/* the hidden attribute has to beat the display rules above */
#hud[hidden], #title[hidden], #map[hidden], #ask[hidden], #prompt[hidden], #say[hidden], #found[hidden], #map-canvas[hidden], #map-blank[hidden] { display: none; }
#ask .choices { display: grid; gap: 6px; }
#ask .choices button { font: 15px var(--display); text-align: left; background: #fff; border: 1px solid #c8c2b6; padding: 7px 10px; cursor: pointer; }
#ask .choices button:hover, #ask .choices button:focus-visible { border-color: var(--ink); background: #faf7f0; outline: none; }
