:root {
  --ink: #1F2440;
  --ink-deep: #0F1226;
  --paper: #FFF8EC;
  --gold: #FFD23F;
  --red: #E63946;
  --blue: #3A86FF;
  --purple: #8E5BD9;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink-deep);
  font-family: 'Fredoka', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button { font-family: inherit; color: inherit; cursor: pointer; }

/* The stage is always 844 x 390 and is scaled to fit by game.js. */
#frame { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
#stage { position: relative; width: 844px; height: 390px; flex: none; overflow: hidden; background: var(--ink); transform-origin: center center; }
#scene, #overlay { position: absolute; left: 0; top: 0; }
#overlay { pointer-events: none; }
#hot { position: absolute; inset: 0; }
#hot button:not(.btn) { position: absolute; padding: 0; border: 0; background: transparent; border-radius: 12px; }
#hot button:not(.btn):focus-visible { outline: 3px solid var(--gold); }

/* HUD */
#hud { position: absolute; left: 0; right: 0; top: 0; padding: 8px 14px; display: flex; align-items: center; justify-content: space-between; pointer-events: none; }
#hud > * { pointer-events: auto; }
.pill { display: flex; align-items: center; gap: 6px; padding: 5px 10px; background: var(--ink); border-radius: 20px; }
.pill svg { display: block; }
.hud-right { display: flex; gap: 8px; align-items: center; }
.tag { padding: 5px 14px; background: var(--paper); border: 3px solid var(--ink-deep); border-radius: 20px; font-size: 14px; font-weight: 700; }
.btn { height: 44px; padding: 0 18px; display: inline-flex; align-items: center; gap: 8px; background: var(--gold); border: 4px solid var(--ink-deep); border-radius: 22px; font-size: 17px; font-weight: 700; color: var(--ink-deep); }
.btn.white { background: #fff; }
.btn.dark { background: #2A3058; border-color: #5A6194; color: #C5CAEC; }
.btn.big { height: 52px; padding: 0 30px; font-size: 20px; border-radius: 26px; }
.btn:active { transform: translateY(2px); }
.btn[disabled] { opacity: 0.55; }

/* Dialogue */
#dialogue { position: absolute; left: 14px; right: 14px; bottom: 10px; padding: 10px 12px 10px 16px; display: flex; align-items: center; gap: 14px; background: var(--paper); border: 4px solid var(--ink-deep); border-radius: 22px; }
#dialogue[hidden], #modal[hidden], #toast[hidden], #rotate[hidden] { display: none; }
#dialogue .who { flex: none; padding: 2px 12px; background: var(--blue); border: 3px solid var(--ink-deep); border-radius: 14px; color: var(--ink-deep); font-size: 13px; font-weight: 700; letter-spacing: 0.04em; }
#dialogue .who.note { background: var(--gold); }
#dialogue .who:empty { display: none; }
#dialogue p { flex: 1; margin: 0; font-size: 19px; font-weight: 600; line-height: 1.25; }

/* Modals */
#modal { position: absolute; inset: 0; padding: 16px 22px; display: flex; align-items: stretch; gap: 16px; background: rgba(15, 18, 38, 0.86); }
.card { background: var(--paper); border: 4px solid var(--ink-deep); border-radius: 22px; }
.side { width: 180px; flex: none; padding: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: #2A3058; border: 4px solid var(--ink-deep); border-radius: 22px; color: var(--paper); text-align: center; }
.side .n { font-size: 14px; font-weight: 700; letter-spacing: 0.04em; color: var(--gold); }
.side .l { font-size: 16px; font-weight: 500; line-height: 1.3; }
.side .digit { width: 72px; height: 88px; display: flex; align-items: center; justify-content: center; background: #FFF3A6; border: 4px solid var(--ink-deep); border-radius: 14px; color: var(--ink); font-size: 52px; font-weight: 700; }
.side .digit.empty { background: #3B4270; border-style: dashed; color: #8C93C4; }
.q { flex: 1; min-width: 0; padding: 14px 18px; display: flex; flex-direction: column; gap: 10px; }
.q h1 { margin: 0; font-size: 22px; font-weight: 700; line-height: 1.2; }
.answers { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.answers button { min-height: 52px; padding: 6px 14px; background: #fff; border: 4px solid var(--ink-deep); border-radius: 18px; font-size: 17px; font-weight: 600; text-align: left; line-height: 1.2; }
.answers button.wrong { background: #E9E4DA; color: #77736B; border-color: #77736B; animation: shake 0.3s; }
.answers button.right { background: var(--gold); }
.q .foot { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.q .line { margin: 0; flex: 1; font-size: 16px; font-weight: 600; color: #1D3A8A; line-height: 1.25; }

.simple { margin: auto; max-width: 560px; padding: 20px 24px; display: flex; flex-direction: column; gap: 12px; }
.simple h1 { margin: 0; font-size: 26px; font-weight: 700; line-height: 1.15; }
.simple p { margin: 0; font-size: 18px; font-weight: 500; line-height: 1.35; }
.simple .row { display: flex; gap: 10px; flex-wrap: wrap; }

/* Keypad */
.keys-wrap { flex: 1; display: flex; align-items: center; gap: 28px; padding: 0 10px; color: var(--paper); }
.keys-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.keys-info h1 { margin: 0; font-size: 28px; font-weight: 700; line-height: 1.1; }
.keys-info p { margin: 0; font-size: 17px; font-weight: 500; line-height: 1.3; color: #C5CAEC; }
.dots { display: flex; gap: 10px; }
.dots i { width: 34px; height: 44px; display: flex; align-items: center; justify-content: center; background: #2A3058; border: 3px solid #5A6194; border-radius: 10px; font-style: normal; font-size: 24px; font-weight: 700; color: var(--paper); }
.dots.bad { animation: shake 0.3s; }
.keys { width: 290px; flex: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keys button { height: 76px; background: var(--paper); border: 4px solid var(--ink-deep); border-radius: 16px; font-size: 26px; font-weight: 700; color: var(--ink-deep); }
.keys button.fn { background: #2A3058; color: var(--paper); font-size: 18px; }
.keys button.go { background: var(--gold); font-size: 20px; }

/* Toast */
#toast { position: absolute; left: 50%; top: 56px; transform: translateX(-50%); padding: 8px 18px; background: var(--ink); border: 3px solid var(--gold); border-radius: 20px; color: var(--paper); font-size: 16px; font-weight: 600; white-space: nowrap; }

/* Start screen */
.start { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: var(--ink); color: var(--paper); text-align: center; }
.start .stamp { padding: 4px 16px; border: 3px solid var(--red); border-radius: 8px; color: var(--red); font-size: 15px; font-weight: 700; letter-spacing: 0.2em; transform: rotate(-4deg); }
.start h1 { margin: 0; font-size: 46px; font-weight: 700; line-height: 1.05; }
.start p { margin: 0; font-size: 18px; font-weight: 500; color: #C5CAEC; }

/* Rotate prompt */
#rotate { position: fixed; inset: 0; z-index: 10; padding: 32px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; background: var(--ink); color: var(--paper); text-align: center; }
#rotate h1 { margin: 0; font-size: 30px; font-weight: 700; }
#rotate p { margin: 0; font-size: 18px; font-weight: 500; color: #C5CAEC; }

/* Little animations */
.dance { animation: dance 0.9s ease-in-out 3; transform-box: fill-box; transform-origin: 50% 100%; }
.bob { animation: bob 2.4s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 100%; }
.pop { animation: pop 0.45s ease-out; transform-box: fill-box; transform-origin: 50% 50%; }
.pulse { animation: pulse 1.2s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 50%; }
@keyframes dance { 0%, 100% { transform: rotate(0) translateY(0); } 25% { transform: rotate(-9deg) translateY(-8px); } 50% { transform: rotate(0) translateY(0); } 75% { transform: rotate(9deg) translateY(-8px); } }
@keyframes bob { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes pop { 0% { transform: scale(0.2); opacity: 0; } 70% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.14); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

@media (prefers-reduced-motion: reduce) {
  .dance, .bob, .pop, .pulse, .answers button.wrong, .dots.bad { animation: none; }
}

.btn[hidden] { display: none; }

/* Getting a piece */
.award { flex: 1; display: flex; align-items: center; justify-content: center; gap: 30px; color: var(--paper); }
.award .rays { flex: none; width: 270px; height: 300px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: radial-gradient(circle, rgba(255, 210, 63, 0.45) 0%, rgba(255, 210, 63, 0) 68%); }
.award-text { max-width: 330px; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.award-text .n { padding: 3px 14px; background: var(--gold); border: 3px solid var(--ink-deep); border-radius: 16px; color: var(--ink-deep); font-size: 14px; font-weight: 700; letter-spacing: 0.06em; }
.award-text h1 { margin: 0; font-size: 28px; font-weight: 700; line-height: 1.12; }
.award-text p { margin: 0; font-size: 17px; font-weight: 500; color: #C5CAEC; }

/* Things she carries, and her notes */
.tag.item { background: var(--gold); }
#notes { position: absolute; left: 14px; bottom: 12px; display: flex; align-items: center; gap: 6px; padding: 5px 8px; background: var(--ink); border-radius: 16px; pointer-events: none; }
#notes .nl { padding: 0 4px; color: var(--gold); font-size: 12px; font-weight: 700; letter-spacing: 0.06em; }
#notes .chip { padding: 2px 10px; background: #FFF3A6; border: 2px solid var(--ink-deep); border-radius: 12px; font-size: 14px; font-weight: 700; color: var(--ink); }
.simple .row .btn { height: 42px; padding: 0 16px; font-size: 16px; }

/* Lounge shop */
.shop-me { width: 190px; }
.shop-grid { grid-template-columns: 1fr 1fr 1fr 1fr; }
.shop-grid button { min-height: 48px; text-align: center; padding: 4px 8px; font-size: 16px; }

/* ---------- Sunday ---------- */
.mini { position: absolute; inset: 0; z-index: 0; }
.btn.pad { position: absolute; width: 68px; height: 54px; justify-content: center; font-size: 22px; border-radius: 18px; touch-action: none; user-select: none; -webkit-user-select: none; opacity: 0.92; }
.mini.drawer { background: #B9794C; }
.mini.drawer::before { content: ""; position: absolute; left: 36px; top: 46px; right: 22px; bottom: 20px; background: #EAD2AC; border: 5px solid var(--ink); border-radius: 16px; box-shadow: inset 0 7px 0 rgba(31, 36, 64, 0.12); }
.tray { position: absolute; left: 58px; top: 56px; width: 448px; height: 250px; background: #343A63; border: 4px solid var(--ink); border-radius: 14px; }
.mini.drawer.done .tray { border-color: var(--gold); }
.slot { position: absolute; line-height: 0; filter: brightness(0); opacity: 0.22; }
.thing { position: absolute; z-index: 5; line-height: 0; touch-action: none; cursor: grab; filter: drop-shadow(0 3px 0 rgba(31, 36, 64, 0.28)); }
.thing.home { filter: none; cursor: default; }
.thing.binned { transform: scale(0.45) !important; opacity: 0.55; }
.bin { position: absolute; box-sizing: border-box; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 4px; background: #9AA3B5; border: 4px solid var(--ink); border-radius: 6px 6px 14px 14px; font-size: 12px; font-weight: 700; letter-spacing: 0.1em; color: var(--ink); }
.mini.jig { background: var(--ink); }
.board { position: absolute; background: #2A3058 center / cover no-repeat; border-radius: 6px; outline: 4px dashed #5A6194; }
.board.whole { outline: 5px solid var(--paper); }
.tile { position: absolute; z-index: 5; border-radius: 6px; background-repeat: no-repeat; box-shadow: 0 0 0 3px #0F1226, 0 5px 0 3px rgba(0, 0, 0, 0.35); touch-action: none; cursor: grab; }
.tile.home { border-radius: 0; box-shadow: 0 0 0 1px rgba(15, 18, 38, 0.5); cursor: default; }
.jside { position: absolute; left: 532px; right: 22px; top: 56px; bottom: 16px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 8px; color: var(--paper); }
.jside h1 { margin: 0; font-size: 30px; font-weight: 700; line-height: 1.05; }
.jside p { margin: 0; font-size: 16px; font-weight: 500; color: #C5CAEC; }
.jside .strong { font-size: 18px; font-weight: 700; color: var(--paper); }
.jside .sign { font-style: italic; color: var(--paper); }
.jside .stamp { padding: 3px 10px; border: 3px solid var(--gold); border-radius: 8px; color: var(--gold); font-size: 13px; font-weight: 700; letter-spacing: 0.12em; transform: rotate(-2deg); }
.jside .btn { margin-top: 6px; }
.mini.after { display: flex; align-items: center; gap: 8px; padding: 0 30px 0 20px; background: radial-gradient(circle at 24% 40%, #4B2F86 0%, #1F2440 60%, #0F1226 100%); color: var(--paper); }
.after .pair { flex: none; margin-top: 34px; }
.after .words { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.after h1 { margin: 0; font-size: 34px; font-weight: 700; line-height: 1.08; }
.after p { margin: 0; font-size: 19px; font-weight: 500; color: #D9CCF5; }
.after .tap { min-height: 24px; font-size: 15px; }
.pieces { display: flex; gap: 10px; margin-top: 8px; }
.mem { width: 70px; height: 76px; padding: 0; display: flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, 0.08); border: 3px solid rgba(255, 255, 255, 0.25); border-radius: 16px; }
.mem.gem { background: transparent; border-color: transparent; }
.after.all .mem.gem svg { animation: twinkle 1.8s ease-in-out infinite; }
.after.all .mem.gem:nth-child(2n) svg { animation-delay: 0.5s; }
@keyframes twinkle { 50% { transform: translateY(-5px) scale(1.08); } }
.memcard { margin: auto; width: 700px; height: 340px; box-sizing: border-box; padding: 12px; display: flex; flex-direction: row; align-items: stretch; gap: 14px; background: var(--paper); border: 4px solid var(--ink-deep); border-radius: 18px; font-family: inherit; color: var(--ink-deep); text-align: left; cursor: pointer; }
.memcard .n { font-size: 13px; font-weight: 700; letter-spacing: 0.06em; color: #5A6194; }
.memphoto { flex: 0 0 400px; height: 100%; box-sizing: border-box; background: #14182E center / contain no-repeat; border: 3px solid var(--ink-deep); border-radius: 12px; }
.memphoto.empty { display: flex; align-items: center; justify-content: center; padding: 20px; text-align: center; color: #C5CAEC; font-weight: 700; }
.memside { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 12px; }
.memcard .cap { font-size: 22px; line-height: 1.25; font-weight: 700; }
.memcard .again { font-size: 13px; font-weight: 700; color: #5A6194; }
.memcard .mrow { display: flex; gap: 8px; flex-wrap: wrap; }
.hidefile { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { .after.all .mem.gem svg { animation: none; } }

/* ---------- menu ---------- */
.btn.burger { width: 42px; height: 38px; padding: 0; justify-content: center; border-radius: 14px; }
.card.menu { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.mtabs { display: flex; gap: 6px; padding: 10px 12px 0; border-bottom: 4px solid var(--ink-deep); background: #EFE6D6; }
.mtabs button { padding: 8px 16px; background: #E0D5C2; border: 3px solid var(--ink-deep); border-bottom: 0; border-radius: 14px 14px 0 0; font-size: 16px; font-weight: 700; color: var(--ink); }
.mtabs button.on { background: var(--paper); padding-bottom: 12px; margin-bottom: -4px; }
.mtabs button.x { margin-left: auto; margin-bottom: 8px; border: 3px solid var(--ink-deep); border-radius: 12px; background: #fff; }
.mbody { flex: 1; overflow-y: auto; padding: 8px 18px 14px; -webkit-overflow-scrolling: touch; }
.mh { margin: 10px 0 6px; font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: #6B6F8C; }
.mrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.mrow > svg { display: block; }
.mrow .btn { height: 40px; padding: 0 16px; font-size: 16px; }
.mrow .chip { padding: 3px 12px; background: #FFF3A6; border: 3px solid var(--ink-deep); border-radius: 14px; font-size: 16px; font-weight: 700; }
.mrow input[type=range] { width: 200px; accent-color: #E63946; }
.dim { font-size: 15px; font-weight: 500; color: #6B6F8C; }
.mp { margin: 0 0 10px; font-size: 18px; font-weight: 600; }
.idcard { display: flex; align-items: center; gap: 14px; padding: 8px 14px; background: #fff; border: 3px solid var(--ink-deep); border-radius: 16px; }
.idcard .who { line-height: 0; }
.idcard .nm { font-size: 20px; font-weight: 700; }
.agents { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.ag { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; background: #fff; border: 3px solid var(--ink-deep); border-radius: 14px; font-size: 11px; font-weight: 700; text-align: center; }
.ag.unmet svg { filter: brightness(0); opacity: 0.25; }
.btn.pad.ghost { pointer-events: none; opacity: 0.8; font-size: 16px; }

/* ---------- jigsaw: plain pieces, then shards ---------- */
.hole { position: absolute; box-sizing: border-box; border: 3px dashed #5A6194; }
.board:not(.whole) { outline-style: solid; outline-color: #5A6194; }
.tile.plain { display: flex; align-items: center; justify-content: center; background: #FFD23F; }
.tile.plain svg { opacity: 0.35; }
.tile.plain.home { box-shadow: 0 0 0 2px #0F1226; }
.shard { position: absolute; z-index: 5; line-height: 0; pointer-events: none; }
.shard svg { overflow: visible; display: block; }
.shard polygon { pointer-events: none; fill: #FFD23F; stroke: #0F1226; stroke-width: 3; stroke-linejoin: round; cursor: grab; touch-action: none; }
.shard.home polygon { stroke-width: 1.5; stroke: rgba(15, 18, 38, 0.45); cursor: default; }
.shard.fly { transition: left 0.8s cubic-bezier(0.2, 0.9, 0.3, 1), top 0.8s cubic-bezier(0.2, 0.9, 0.3, 1); }
.jig.fused .shard { opacity: 0; transition: opacity 0.8s; }
.cracks { position: absolute; left: 0; top: 0; opacity: 0; transition: opacity 3s; pointer-events: none; }
.jig.hinted .cracks { opacity: 0.45; }
.jside.low { top: auto; bottom: 10px; left: 30px; right: auto; width: 464px; flex-direction: row; align-items: center; justify-content: flex-start; gap: 14px; pointer-events: none; }
.jside.low h1 { font-size: 18px; }
.jside.low p { font-size: 14px; }
.jside.low .btn { pointer-events: auto; margin: 0 0 0 auto; }
.btn.small { height: 34px; padding: 0 12px; font-size: 13px; }
.jig .tile { pointer-events: none; }
#radio { position: absolute; left: 50%; top: 52px; transform: translateX(-50%); max-width: 620px; display: flex; align-items: center; gap: 10px; padding: 7px 16px 7px 8px; background: var(--paper); border: 3px solid var(--ink-deep); border-radius: 18px; font-size: 15px; font-weight: 600; line-height: 1.25; pointer-events: none; }
#radio .who { flex: none; padding: 2px 10px; background: #3A86FF; border: 2px solid var(--ink-deep); border-radius: 10px; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; color: var(--ink-deep); }
#radio[hidden] { display: none; }
.mini.rest { background: #141A3C; }
.tw { animation: tw 3.6s ease-in-out infinite; }
@keyframes tw { 50% { opacity: 0.25; } }
.shoot { opacity: 0; animation: shoot 7s linear infinite; }
@keyframes shoot { 0%, 88% { opacity: 0; transform: translate(120px, -60px); } 90% { opacity: 1; } 100% { opacity: 0; transform: translate(-260px, 130px); } }
@media (prefers-reduced-motion: reduce) { .tw, .shoot { animation: none; } }
.drawer .thing { pointer-events: none; }
.after .words .btn { align-self: flex-start; }
