:root {
  color-scheme: dark;
  --cave: #150d22; --paper: #d9d0e4; --ink: #1f1530;
  --vuartz: #a66cff; --vdark: #5b2fa3; --magma: #ff6a2b; --brallas: #f6c6dc; --mute: #9a8db0;
  --line: rgba(31, 21, 48, .16);
  --hand: 'Caveat Brush', 'Segoe Print', cursive;
  --body: 'Patrick Hand', 'Segoe Print', 'Comic Sans MS', sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
*, *::before, *::after { box-sizing: inherit; }
html { height: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0; min-height: 100%; background: var(--cave); color: #ebe4f4;
  font-family: var(--body); font-size: 18px; line-height: 1.4; overflow: hidden;
  -webkit-tap-highlight-color: transparent; touch-action: none;
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(60% 40% at 50% 112%, rgba(255,106,43,.25), transparent 70%),
              radial-gradient(40% 30% at 12% 0%, rgba(166,108,255,.2), transparent 70%);
}
body[data-phase="night"]::before { animation: scream 2.4s ease-in-out infinite; background: radial-gradient(70% 50% at 50% 115%, rgba(255,106,43,.4), transparent 70%); }
@keyframes scream { 0%, 100% { opacity: .6; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { body[data-phase="night"]::before { animation: none; } }

#app { position: relative; height: 100vh; height: 100dvh; display: grid; place-items: center; padding: 10px; }
#frame {
  position: relative; container-type: inline-size; width: min(100%, calc((100dvh - 20px) * 16 / 9)); aspect-ratio: 16 / 9;
  background: #0b0614; border: 3px solid #120a1e; border-radius: 10px 4px 12px 5px;
  box-shadow: 8px 8px 0 rgba(0,0,0,.45), 0 0 0 6px rgba(217,208,228,.92); overflow: hidden;
}
#frame::after { content: ""; position: absolute; top: -2px; left: 30px; width: 90px; height: 16px; background: rgba(166,108,255,.6); transform: rotate(-2deg); z-index: 5; pointer-events: none; }
#game { display: block; width: 100%; height: 100%; cursor: crosshair; }
kbd { font-family: var(--body); font-size: .75em; border: 1.5px solid currentColor; border-radius: 4px; padding: 0 5px; margin-right: 4px; opacity: .7; }

/* HUD (scales with the frame) */
#hud, #hint, #toasts, #quickbar { position: absolute; font-size: clamp(11px, 1.9cqw, 19px); pointer-events: none; }
#hud { inset: 0; }
.note {
  position: absolute; top: 1.4cqw; background: var(--paper); color: var(--ink); padding: .5em .8em .6em;
  border-radius: 4px 10px 5px 9px; box-shadow: 3px 3px 0 rgba(0,0,0,.4);
  background-image: repeating-linear-gradient(transparent 0 1.25em, var(--line) 1.25em calc(1.25em + 1px));
}
.note.bars { left: 1.4cqw; display: grid; gap: .25em; min-width: 14em; }
.note.clock { right: 1.4cqw; text-align: right; min-width: 9em; }
.note.clock b { font-family: var(--hand); font-weight: 400; font-size: 1.6em; display: block; line-height: 1; }
.note.clock small { display: block; opacity: .7; font-size: .8em; }
.m { display: grid; grid-template-columns: 3.6em 1fr 1.6em; align-items: center; gap: .5em; }
.m b { font-weight: 400; text-align: right; }
.bar { height: .85em; border: 2px solid var(--ink); border-radius: 7px 3px 7px 3px; overflow: hidden; background: rgba(31,21,48,.15); }
.bar i { display: block; height: 100%; transition: width .25s; }
.m.hp i { background: var(--magma); } .m.belly i { background: #e88ab8; } .m.mind i { background: var(--vuartz); }
#hud.low-hp .m.hp { animation: pulse .6s infinite alternate; }
#hud.low-mind .m.mind { animation: pulse .6s infinite alternate; }
@keyframes pulse { to { transform: translateX(2px); } }

#hint {
  left: 50%; bottom: 7.5cqw; transform: translateX(-50%); background: rgba(21,13,34,.85); color: #fff; border: 2px solid var(--vuartz);
  border-radius: 10px 4px 10px 4px; padding: .15em .8em; opacity: 0; transition: opacity .15s; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis;
}
#hint.on { opacity: 1; }
#toasts { left: 50%; top: 1.6cqw; transform: translateX(-50%); width: min(58%, 34em); display: grid; gap: .4em; justify-items: center; }
.toast {
  background: var(--paper); color: var(--ink); padding: .25em .9em; border-radius: 4px 12px 5px 10px; box-shadow: 3px 3px 0 rgba(0,0,0,.4);
  text-align: center; animation: pop .25s ease-out; transition: opacity .5s, transform .5s;
}
.toast.night { background: #2a1b40; color: #f0e8fb; border: 2px solid var(--magma); }
.toast.item { display: inline-flex; align-items: center; gap: .4em; }
.toast.out { opacity: 0; transform: translateY(-6px); }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }

#quickbar { left: 50%; bottom: 1.2cqw; transform: translateX(-50%); display: flex; gap: .4em; flex-wrap: wrap; justify-content: center; width: 96%; pointer-events: none; }
.qb {
  pointer-events: auto; font: inherit; color: #ebe4f4; background: rgba(21,13,34,.88); border: 2px solid rgba(166,108,255,.5);
  border-radius: 9px 3px 10px 4px; padding: .1em .7em; cursor: pointer; display: inline-flex; align-items: center; gap: .25em;
}
.qb.on { background: var(--vuartz); color: #1b1029; border-color: var(--vuartz); }
.qb:disabled { opacity: .35; cursor: default; }
.qb.menu { border-color: rgba(255,255,255,.4); }

/* item icons come from the same art as the world */
.gem { display: inline-block; width: 1.5em; height: 1.5em; flex: none; vertical-align: -.35em; object-fit: contain; }
/* old shape classes, unused */
.gem { display: inline-block; width: 1.1em; height: 1.1em; flex: none; background: var(--c); vertical-align: -.15em; }
.gem.crystal { clip-path: polygon(50% 0, 100% 40%, 80% 100%, 20% 100%, 0 40%); }
.gem.flake { clip-path: polygon(10% 0, 100% 20%, 80% 100%, 0 70%); }
.gem.bar { height: .7em; border-radius: 2px; }
.gem.drop { clip-path: polygon(50% 0, 80% 45%, 92% 70%, 50% 100%, 8% 70%, 20% 45%); }
.gem.blob { border-radius: 42% 58% 55% 45%; }
.gem.rock { clip-path: polygon(15% 10%, 85% 0, 100% 55%, 70% 100%, 10% 85%); }
.gem.spring { background: repeating-linear-gradient(0deg, var(--c) 0 3px, transparent 3px 6px); border-radius: 6px; }
.gem.puff { border-radius: 50%; }
.gem.brick { height: .75em; background: linear-gradient(90deg, transparent 48%, rgba(0,0,0,.3) 48% 52%, transparent 52%), var(--c); border-radius: 2px; }

/* paper sheets: dialog, panels, overlays */
#dialog, #panel, #overlay { position: fixed; z-index: 20; display: none; }
#dialog.on { display: block; left: 50%; bottom: 14px; transform: translateX(-50%); width: min(720px, calc(100vw - 20px)); }
#panel.on { display: grid; inset: 0; place-items: center; background: rgba(8,3,18,.6); padding: 12px; }
#overlay.on { display: grid; inset: 0; place-items: center; background: rgba(8,3,18,.82); padding: 12px; z-index: 30; }
.sheet {
  position: relative; background-color: var(--paper); color: var(--ink); padding: 22px 26px 24px; border-radius: 6px 16px 8px 14px;
  background-image: repeating-linear-gradient(transparent 0 31px, var(--line) 31px 32px);
  box-shadow: 7px 7px 0 rgba(0,0,0,.45); max-width: 100%; touch-action: auto;
}
.sheet::before { content: ""; position: absolute; top: -11px; left: 30px; width: 90px; height: 22px; background: rgba(166,108,255,.6); transform: rotate(-3deg); }
.sheet.night, #dialog.night .sheet, #dialog.sim .sheet { background-color: #2a1b40; color: #f0e8fb; --line: rgba(255,255,255,.07); }
.sheet.night::before, #dialog.night .sheet::before { background: rgba(255,106,43,.55); }
.sheet h3 { font-family: var(--hand); font-weight: 400; font-size: 1.9rem; line-height: 1.1; margin: 0 0 6px; }
.sheet h4 { font-family: var(--hand); font-weight: 400; font-size: 1.35rem; margin: 10px 0 2px; }
.sheet p { margin: 0 0 8px; font-size: 1.1rem; line-height: 32px; }
.sheet p.small { font-size: .95rem; line-height: 1.35; }
.sheet.big { width: min(860px, 100%); max-height: calc(100dvh - 24px); display: flex; flex-direction: column; padding: 18px 22px; }
.pbody { overflow: auto; padding-right: 6px; min-height: 0; }
.ptabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.ttl { font-family: var(--hand); font-size: 1.6rem; font-weight: 400; margin-right: auto; }
.tab {
  font: inherit; color: var(--ink); background: transparent; border: 2px solid var(--ink); border-radius: 99px; padding: 1px 12px; cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.tab.close { margin-left: auto; border-style: dashed; }
.tab kbd { margin: 0 0 0 6px; }
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(10em, 1fr)); gap: 6px; }
.it { display: flex; align-items: center; gap: 8px; padding: 4px 9px; border: 2px solid rgba(31,21,48,.3); border-radius: 8px 3px 8px 3px; }
.it b { margin-left: auto; font-weight: 400; }
.empty { opacity: .6; }
.note2 { color: #8a3a9a; font-size: .95rem; margin: 2px 0 6px; }
.card { border: 2px solid rgba(31,21,48,.35); border-radius: 10px 4px 10px 4px; padding: 8px 12px; margin-bottom: 10px; }
.card.done { opacity: .5; }
.card h4 { margin: 0; }
.card p { font-size: 1rem; line-height: 1.3; margin: 2px 0 6px; }
.req { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.req span { font-size: .9rem; padding: 0 9px; border-radius: 99px; background: rgba(31,21,48,.12); }
.req span.lack { background: rgba(255,106,43,.35); }
.btn, .row {
  font: inherit; color: inherit; background: transparent; border: 2px solid currentColor; border-radius: 9px 3px 10px 4px; padding: 2px 14px; cursor: pointer;
  box-shadow: 2px 2px 0 currentColor;
}
.btn:hover:not(:disabled), .row:hover { transform: translate(-1px, -1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.row { display: flex; width: 100%; align-items: center; gap: 8px; margin-bottom: 6px; text-align: left; }
.row b { margin-left: auto; font-weight: 400; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 560px) { .two { grid-template-columns: 1fr; } }
.je { font-size: 1rem !important; line-height: 1.35 !important; border-bottom: 2px dotted rgba(31,21,48,.25); padding-bottom: 4px; }
.ent { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; font-size: 1rem; line-height: 1.3; }
.ent b { font-weight: 400; font-family: var(--hand); font-size: 1.2rem; display: block; }
.ent em { font-style: normal; font-size: .85rem; opacity: .65; display: block; }
.ent.lock { opacity: .4; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 1px 11px; border-radius: 99px; font-size: .98rem; background: #fff9; color: var(--ink); border: 2px solid rgba(31,21,48,.25); }
.chip.hp { background: #ffb58f; } .chip.belly { background: var(--brallas); } .chip.mind { background: #cdb3ff; } .chip.neg { border-style: dashed; }

.choices { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.choice {
  font: inherit; color: inherit; text-align: left; background: transparent; cursor: pointer; border: 2px solid currentColor;
  border-radius: 11px 4px 12px 5px; padding: 8px 14px 9px; box-shadow: 3px 3px 0 currentColor; transition: transform .08s, box-shadow .08s;
}
.choice:hover:not(:disabled), .choice:focus-visible { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 currentColor; }
.choice:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 currentColor; }
.choice:disabled { opacity: .42; cursor: not-allowed; box-shadow: none; }
.choice .cl { display: block; font-size: 1.18rem; }
.choice .cs { display: block; font-size: .9rem; opacity: .78; line-height: 1.25; }
:focus-visible { outline: 3px solid var(--vuartz); outline-offset: 2px; }

.sheet.title { text-align: center; width: min(520px, 100%); }
.sheet.title h1 { font-family: var(--hand); font-weight: 400; font-size: 4.2rem; line-height: 1; margin: 0; color: var(--vdark); }
.sheet.title .sub { font-family: var(--hand); font-size: 1.6rem; color: var(--magma); margin: 0 0 6px; line-height: 1.2; }
.sheet.title p { line-height: 1.35; }
.crystal { width: 54px; height: 64px; margin: -34px auto 4px; background: linear-gradient(135deg, #c9a4ff, #8a50e0); clip-path: polygon(50% 0, 100% 38%, 82% 100%, 18% 100%, 0 38%); filter: drop-shadow(3px 3px 0 rgba(0,0,0,.4)); }

/* touch controls */
#touch { display: none; position: absolute; inset: 0; pointer-events: none; }
#touch.on { display: block; }
#stick { position: absolute; left: 3cqw; bottom: 9cqw; width: 18cqw; height: 18cqw; border-radius: 50%; border: 3px solid rgba(255,255,255,.35); background: rgba(21,13,34,.4); pointer-events: auto; touch-action: none; }
#knob { position: absolute; left: 50%; top: 50%; width: 38%; height: 38%; margin: -19% 0 0 -19%; border-radius: 50%; background: rgba(166,108,255,.7); }
#tbtns { position: absolute; right: 2cqw; bottom: 9cqw; display: grid; grid-template-columns: 1fr 1fr; gap: 1.4cqw; pointer-events: auto; }
#tbtns button { font: inherit; font-size: 2.2cqw; width: 9cqw; height: 9cqw; border-radius: 50%; border: 3px solid rgba(255,255,255,.5); background: rgba(21,13,34,.6); color: #fff; touch-action: none; }
@media (pointer: coarse) { body { font-size: 16px; } #quickbar { bottom: 0.6cqw; } }

/* GLaD's simulations: a glowing console */
#dialog.sim .sheet { background-color: #14082a; color: #ffd8ff; background-image: repeating-linear-gradient(transparent 0 3px, rgba(255,122,217,.07) 3px 4px); border: 2px solid #ff7ad9; box-shadow: 7px 7px 0 rgba(0,0,0,.45), 0 0 28px rgba(255,122,217,.35); }
#dialog.sim .sheet::before { background: rgba(255,122,217,.6); }
#dialog.sim .sheet h3 { color: #ff9ae8; }
