/* Lanternbrook UI. Pixel-bordered panels, a notebook journal, big touch targets.
   Everything sits outside the canvas's way: the HUD is one slim bar, sheets slide up. */
:root {
  --ink: #2a1f2d; --ink2: #4a3a40; --paper: #f7ecd3; --paper2: #efdfba; --line: #d8c59a; --red: #c8553d;
  --gold: #e7b84c; --green: #5c9a5a; --blue: #4f7cac; --hud: rgba(42, 31, 45, .88);
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --hand: "Bradley Hand", "Segoe Print", "Chalkboard SE", "Comic Neue", "Marker Felt", cursive;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #3079bd; color: var(--ink); font-family: var(--sans);
  overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; touch-action: none; }
canvas#world { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; cursor: grab; }
canvas#world.dragging { cursor: grabbing; }
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
.ico { display: inline-block; width: 24px; height: 24px; }
.ico canvas, canvas.pix { image-rendering: pixelated; image-rendering: crisp-edges; width: 100%; height: 100%; display: block; }

/* ---------- pixel buttons ---------- */
.btn { min-width: 44px; min-height: 44px; padding: 0 10px; border: 0; border-radius: 0; cursor: pointer; position: relative;
  background: #f4e2b8; color: var(--ink); font-weight: 700;
  box-shadow: inset -2px -3px 0 #d3b77c, inset 2px 2px 0 #fff6dc, 0 0 0 2px var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:active { transform: translateY(1px); box-shadow: inset 2px 2px 0 #d3b77c, 0 0 0 2px var(--ink); }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.btn.text { min-height: 40px; font-size: 15px; }
.btn.wide { min-height: 48px; padding: 0 20px; font-size: 17px; }
.btn.danger { background: #f2c6c2; box-shadow: inset -2px -3px 0 #d99a92, inset 2px 2px 0 #fff0ee, 0 0 0 2px var(--ink); }
.btn.small { min-width: 36px; min-height: 36px; }

/* ---------- HUD ---------- */
#hud { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  padding: calc(6px + var(--sat)) calc(8px + var(--sar)) 6px calc(8px + var(--sal)); background: var(--hud);
  box-shadow: 0 2px 0 rgba(0,0,0,.25); pointer-events: auto; }
#logo { height: 22px; flex: 0 1 auto; min-width: 0; }
#logo canvas { height: 100%; width: auto; image-rendering: pixelated; }
#progress { display: flex; gap: 6px; margin-left: auto; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px 3px 5px; background: rgba(255,255,255,.12); color: #f7ecd3; font-size: 14px; font-variant-numeric: tabular-nums; border-radius: 2px; }
.pill .ico { width: 18px; height: 18px; }
#hud nav { display: flex; gap: 8px; }
#badge { position: absolute; top: -4px; right: -4px; width: 12px; height: 12px; background: var(--red); box-shadow: 0 0 0 2px var(--ink); }
@media (max-width: 420px) { #logo { display: none; } #progress { margin-left: 0; } #hud nav { margin-left: auto; } }

/* ---------- bubbles + toast ---------- */
#bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.bubble { position: absolute; left: 0; top: 0; max-width: min(240px, 70vw); padding: 7px 10px 8px; background: #fffaf0; color: var(--ink);
  font-size: 14px; line-height: 1.3; box-shadow: 0 0 0 2px var(--ink), 3px 3px 0 2px rgba(0,0,0,.25); transform: translate(-50%, -100%);
  transition: opacity .4s; will-change: transform; }
.bubble::after { content: ""; position: absolute; left: var(--tail, 50%); bottom: -8px; width: 8px; height: 8px; background: #fffaf0;
  box-shadow: 2px 0 0 var(--ink), 0 2px 0 var(--ink), -2px 0 0 var(--ink); transform: translateX(-50%); clip-path: polygon(0 0, 100% 0, 50% 100%); }
.bubble.label { background: #2a1f2d; color: #f7ecd3; font-family: var(--serif); font-style: italic; }
.bubble.label::after { background: #2a1f2d; }
.bubble .who { display: block; font-size: 11px; font-weight: 700; color: var(--red); letter-spacing: .02em; }
.bubble.fade { opacity: 0; }
#toast { position: fixed; left: 50%; bottom: calc(14px + var(--sab)); transform: translate(-50%, 20px); z-index: 12; pointer-events: none;
  max-width: min(440px, calc(100vw - 24px)); opacity: 0; transition: opacity .35s, transform .35s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.toastcard { display: flex; gap: 10px; align-items: center; background: var(--paper); padding: 10px 14px; box-shadow: 0 0 0 2px var(--ink), 4px 4px 0 2px rgba(0,0,0,.25); }
.toastcard .ico { width: 34px; height: 34px; flex: none; }
.toastcard b { display: block; font-size: 13px; color: var(--red); text-transform: uppercase; letter-spacing: .06em; }
.toastcard span { font-size: 15px; line-height: 1.3; }
#tip { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--sab)); z-index: 11; display: flex; align-items: center; gap: 10px;
  background: var(--hud); color: #f7ecd3; padding: 6px 6px 6px 14px; font-size: 15px; box-shadow: 0 0 0 2px #f7ecd3; max-width: calc(100vw - 24px); }
#tip .btn { flex: none; }

/* ---------- sheets (journal, settings) ---------- */
.sheet { position: fixed; z-index: 20; left: 50%; bottom: 0; transform: translateX(-50%); width: min(720px, 100vw); height: min(82vh, 760px);
  display: flex; flex-direction: column; background: #8a5a3c; box-shadow: 0 0 0 3px var(--ink), 0 -6px 0 rgba(0,0,0,.2);
  padding: 8px 8px calc(8px + var(--sab)); animation: up .25s ease-out; }
.sheet.small { height: auto; max-height: 86vh; width: min(460px, 100vw); }
@keyframes up { from { transform: translate(-50%, 30px); opacity: .4; } }
@media (max-width: 560px), (max-height: 520px) { .sheet { height: 100%; width: 100vw; padding-top: calc(8px + var(--sat)); } .sheet.small { height: auto; } }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 0 2px 8px; color: #f7ecd3; }
.sheet-head h2 { margin: 0 0 0 6px; font-family: var(--serif); font-size: 22px; }
.sheet-head .close { margin-left: auto; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tabs button { min-height: 44px; padding: 0 12px; border: 0; background: #6a4430; color: #f0dcb4; font-weight: 700; font-size: 15px; cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--paper); color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.paper { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; padding: 16px 16px 24px 30px;
  background: var(--paper) repeating-linear-gradient(to bottom, transparent 0 27px, var(--line) 27px 28px);
  box-shadow: 0 0 0 2px var(--ink), inset 22px 0 0 -20px #e3a090; -webkit-user-select: text; user-select: text; }
.paper h3 { font-family: var(--serif); font-size: 21px; margin: 0 0 4px; }
.paper p { margin: 0 0 10px; line-height: 1.45; font-size: 15px; }
.entry { padding: 12px 0 14px; border-bottom: 2px dashed var(--line); }
.entry:last-child { border-bottom: 0; }
.entry .intro { font-style: italic; color: var(--ink2); }
.entry.locked h3 { color: #a8957a; letter-spacing: .3em; }
.entry.solved h3::after { content: " ✓"; color: var(--green); }
.clues { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 8px; }
.clue { display: flex; gap: 10px; align-items: center; }
.sketch { width: 56px; height: 56px; flex: none; background: #fbf4e2; box-shadow: 0 0 0 2px #b9a682; display: grid; place-items: center; padding: 6px; transform: rotate(-2deg); }
.clue:nth-child(2n) .sketch { transform: rotate(2deg); }
.sketch canvas { image-rendering: pixelated; filter: sepia(.65) saturate(.9) contrast(1.05); }
.note { font-family: var(--hand); font-size: 16px; line-height: 1.3; color: #3a3060; }
.clue.missing .sketch { background: transparent; box-shadow: 0 0 0 2px #cbb88c; box-shadow: none; outline: 2px dashed #cbb88c; }
.clue.missing .note { color: #a8957a; font-family: var(--sans); font-style: italic; font-size: 14px; }
.status { font-family: var(--hand); font-size: 18px; color: var(--red); margin: 6px 0; }
.hintbox { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.hinttext { flex-basis: 100%; font-family: var(--hand); font-size: 16px; color: #2f6f5a; }
.empty { color: #8a7a62; font-style: italic; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.cur { background: #fbf4e2; box-shadow: 0 0 0 2px #b9a682; padding: 8px 4px 6px; text-align: center; font-size: 12px; line-height: 1.2; min-height: 104px; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--ink); }
.cur .pic { height: 52px; display: grid; place-items: center; }
.cur canvas { image-rendering: pixelated; }
.cur.missing { background: transparent; box-shadow: 0 0 0 2px #d6c49c; color: #a8957a; cursor: default; }
.cur.missing canvas { filter: brightness(0) opacity(.28); }
.cur[aria-expanded="true"] { grid-column: 1 / -1; flex-direction: row; text-align: left; padding: 10px; }
.cur[aria-expanded="true"] .pic { flex: none; width: 80px; }
.cur .txt { display: none; font-size: 14px; line-height: 1.35; }
.cur[aria-expanded="true"] .txt { display: block; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; font-size: 16px; }
.row input[type=range] { width: 52%; accent-color: var(--red); height: 32px; }
.toggle { width: 28px; height: 28px; accent-color: var(--green); }
.fine { font-size: 13px !important; color: var(--ink2); margin-top: 14px !important; }

/* ---------- cards ---------- */
.card { position: fixed; z-index: 30; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100vw - 32px)); background: var(--paper);
  padding: 22px 22px 18px; box-shadow: 0 0 0 3px var(--ink), 6px 6px 0 3px rgba(0,0,0,.3); text-align: center; animation: pop .35s cubic-bezier(.2, 1.4, .5, 1); }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.8); opacity: 0; } }
.card h2 { font-family: var(--serif); margin: 6px 0 8px; font-size: 24px; }
.card p { line-height: 1.5; font-size: 16px; margin: 0 0 16px; }
.card .buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.stamp { display: inline-block; font-family: var(--hand); color: var(--red); font-size: 22px; border: 3px solid var(--red); padding: 0 10px; transform: rotate(-6deg); }

/* ---------- vignette letterbox ---------- */
#letterbox { position: fixed; inset: 0; z-index: 8; pointer-events: none; }
#letterbox .bar { position: absolute; left: 0; right: 0; height: 9vh; background: #120c14; animation: bar .5s ease-out; }
#letterbox .top { top: 0; } #letterbox .bottom { bottom: 0; }
@keyframes bar { from { height: 0; } }
#skip { position: absolute; right: calc(12px + var(--sar)); bottom: calc(9vh + 12px); pointer-events: auto; }

/* ---------- title ---------- */
#title { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(42,31,45,.25), rgba(42,31,45,.7)); }
.title-card { text-align: center; padding: 26px 26px 22px; background: rgba(247,236,211,.95); box-shadow: 0 0 0 3px var(--ink), 6px 6px 0 3px rgba(0,0,0,.35); width: min(460px, calc(100vw - 32px)); }
#bigLogo canvas { width: 100%; height: auto; image-rendering: pixelated; }
.subtitle { font-family: var(--serif); font-style: italic; font-size: 19px; margin: 10px 0 16px; }
#loading { font-size: 15px; color: var(--ink2); }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; color: #fff; font-size: 18px; }
@media (prefers-reduced-motion: reduce) { .sheet, .card, #letterbox .bar { animation: none; } }
