/* Layout: full-screen 3D canvas; field-notebook HUD floats over it.
   Single committed dusk palette (the game world sets the mood, so no light theme). */
:root {
  --ink: rgba(12, 26, 31, 0.80);
  --ink-solid: #0c1a1f;
  --line: rgba(190, 226, 212, 0.18);
  --paper: #e6f0ea;
  --muted: #93aea5;
  --hi: #ffd27a;
  --water: #5ab8ff;
  --earth: #d79f58;
  --fire: #ff6b3f;
  --wind: #9ff0c6;
  --font-ui: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --font-title: "Zen Old Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --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);
  color-scheme: dark;
}
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--ink-solid); color: var(--paper);
  font-family: var(--font-ui); touch-action: none; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
[hidden] { display: none !important; }
button { font-family: inherit; color: inherit; touch-action: manipulation; }
button:focus-visible { outline: 2px solid var(--hi); outline-offset: 2px; }

/* HUD */
#hud { position: fixed; top: calc(var(--sat) + 10px); left: calc(var(--sal) + 12px); right: calc(var(--sar) + 200px);
  display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
#manaWrap { width: min(220px, 50vw); height: 8px; border-radius: 4px; background: rgba(0,0,0,.45); overflow: hidden; border: 1px solid var(--line); }
#mana { height: 100%; width: 100%; background: linear-gradient(90deg, #7fd8ff, #c8a6ff); transition: width .1s linear; }
#stats { font-size: 12px; color: var(--paper); opacity: .9; letter-spacing: .04em; font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px #000, 0 0 6px rgba(0,0,0,.6); }
#task { font-size: 13px; text-shadow: 0 1px 3px #000; max-width: 62ch; }
#task b { color: var(--hi); font-weight: 700; }
#topBtns { position: fixed; top: calc(var(--sat) + 8px); right: calc(var(--sar) + 10px); display: flex; gap: 8px; }
.iconBtn { min-width: 44px; padding: 0 10px; white-space: nowrap; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--ink);
  font-size: 13px; font-weight: 700; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }

#crosshair { position: fixed; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; pointer-events: none; }
#crosshair::before, #crosshair::after { content: ""; position: absolute; background: rgba(255,255,255,.85); box-shadow: 0 0 2px #000; }
#crosshair::before { left: 8px; top: 0; width: 2px; height: 18px; }
#crosshair::after { top: 8px; left: 0; height: 2px; width: 18px; }

/* Spell composer */
#composer { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--sab) + 8px);
  width: min(560px, calc(100vw - 16px - var(--sal) - var(--sar))); box-sizing: border-box;
  display: grid; gap: 6px; padding: 8px; border-radius: 16px; background: var(--ink); border: 1px solid var(--line);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.row { display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 6px; }
.row > span { font-size: 11px; color: var(--muted); letter-spacing: .12em; writing-mode: horizontal-tb; text-align: center; }
.opts { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.opt { height: 38px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.04);
  display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 16px; font-weight: 700; padding: 0 4px; }
.opt small { font-size: 10px; color: var(--muted); font-weight: 500; }
.opt[aria-pressed="true"] { background: rgba(255, 210, 122, .16); border-color: var(--hi); color: var(--hi); }
.opt[aria-pressed="true"] small { color: var(--hi); }
.opt.el-0[aria-pressed="true"] { color: var(--water); border-color: var(--water); background: rgba(90,184,255,.15); }
.opt.el-1[aria-pressed="true"] { color: var(--earth); border-color: var(--earth); background: rgba(215,159,88,.15); }
.opt.el-2[aria-pressed="true"] { color: var(--fire); border-color: var(--fire); background: rgba(255,107,63,.15); }
.opt.el-3[aria-pressed="true"] { color: var(--wind); border-color: var(--wind); background: rgba(159,240,198,.13); }
.opt .new { width: 6px; height: 6px; border-radius: 50%; background: var(--hi); display: none; }

/* Action buttons */
#actions { position: fixed; right: calc(var(--sar) + 14px); bottom: calc(var(--sab) + 160px); display: flex; flex-direction: column; align-items: center; gap: 12px; }
#castBtn { width: 92px; height: 92px; border-radius: 50%; border: 2px solid var(--hi); position: relative;
  background: radial-gradient(circle at 50% 40%, rgba(255,210,122,.28), rgba(12,26,31,.85) 70%);
  font-weight: 700; font-size: 13px; line-height: 1.25; text-shadow: 0 1px 3px #000, 0 0 6px rgba(0,0,0,.6); }
#castBtn .ring { position: absolute; inset: -6px; border-radius: 50%; pointer-events: none;
  background: conic-gradient(var(--hi) calc(var(--charge, 0) * 1turn), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent 58%, #000 60%); mask: radial-gradient(circle, transparent 58%, #000 60%); }
#castBtn .lbl { font-size: 11px; color: var(--muted); display: block; font-weight: 500; }
#jumpBtn { width: 58px; height: 58px; border-radius: 50%; border: 1px solid var(--line); background: var(--ink); font-size: 12px; font-weight: 700; }

#joy { position: fixed; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.18); pointer-events: none; }
#joy i { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%; background: rgba(255,255,255,.35); }

@media (orientation: landscape) and (max-height: 560px) {
  #composer { width: min(360px, 44vw); padding: 5px; gap: 4px; border-radius: 12px; }
  .row { grid-template-columns: 26px 1fr; gap: 4px; }
  .row > span { font-size: 10px; letter-spacing: 0; }
  .opt { height: 28px; font-size: 14px; border-radius: 8px; }
  .opt small { display: none; }
  body #toasts { left: calc(var(--sal) + 12px); transform: none; top: calc(var(--sat) + 76px); width: min(320px, 40vw); }
  body .toast { font-size: 12px; padding: 6px 10px; }
  #actions { bottom: calc(var(--sab) + 14px); }
  #castBtn { width: 80px; height: 80px; font-size: 12px; }
  #castBtn .lbl { display: none; }
}

/* Toasts */
#toasts { position: fixed; top: calc(var(--sat) + 70px); left: 50%; transform: translateX(-50%); width: min(420px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 6px; pointer-events: none; z-index: 5; }
.toast { background: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 13px; line-height: 1.5;
  animation: tin .25s ease-out; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.toast .k { font-size: 11px; letter-spacing: .14em; color: var(--hi); display: block; }
.toast.react .k { color: #c8a6ff; }
.toast.task .k { color: var(--wind); }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* Notebook & intro */
.modal { position: fixed; inset: 0; z-index: 10; background: rgba(4, 10, 12, .72); display: flex; align-items: center; justify-content: center;
  padding: calc(var(--sat) + 12px) max(12px, var(--sar)) calc(var(--sab) + 12px) max(12px, var(--sal)); }
.sheet { width: min(640px, 100%); max-height: 100%; overflow: auto; background: #12252b; border: 1px solid var(--line); border-radius: 18px;
  padding: 18px 18px 20px; box-sizing: border-box; -webkit-user-select: text; user-select: text; touch-action: pan-y; }
.sheet h2 { font-family: var(--font-title); font-size: 24px; margin: 0 0 4px; letter-spacing: .06em; text-wrap: balance; }
.sheet h3 { font-size: 13px; letter-spacing: .16em; color: var(--muted); margin: 18px 0 8px; font-weight: 700; }
.sheet p { line-height: 1.75; margin: 0 0 8px; font-size: 14px; max-width: 62ch; }
.sheetHead { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.tabs { display: flex; gap: 6px; margin: 12px 0 4px; }
.tab { flex: 1; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: transparent; font-weight: 700; font-size: 13px; }
.tab[aria-selected="true"] { background: rgba(255,210,122,.14); border-color: var(--hi); color: var(--hi); }
.tasks { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.tasks li { display: grid; grid-template-columns: 22px 1fr; gap: 8px; font-size: 14px; line-height: 1.5; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.03); }
.tasks li.done { color: var(--muted); }
.tasks li .ck { width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--muted); margin-top: 2px; box-sizing: border-box; }
.tasks li.done .ck { background: var(--wind); border-color: var(--wind); }
.tasks li small { display: block; color: var(--muted); font-size: 12px; }
.grimoire { display: grid; gap: 10px; }
.gEl { display: grid; grid-template-columns: 28px 1fr; gap: 8px; align-items: start; }
.gEl > b { font-size: 18px; text-align: center; padding-top: 18px; }
.gForms { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.gForm { display: grid; gap: 3px; }
.gForm > span { font-size: 10px; color: var(--muted); text-align: center; letter-spacing: .1em; }
.gCells { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; }
.gCell { aspect-ratio: 1; max-width: 100%; border-radius: 6px; border: 1px solid var(--line); background: transparent; font-size: 12px; padding: 0; color: var(--muted); }
.gCell.known { color: var(--ink-solid); font-weight: 700; }
#gDetail { min-height: 3.5em; font-size: 13px; line-height: 1.6; padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,.04); margin-top: 10px; }
.reacts { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; }
.reacts div { padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.03); font-size: 13px; line-height: 1.5; min-width: 0; }
.reacts div b { display: block; color: #c8a6ff; }
.reacts div.unk b { color: var(--muted); }
.reacts div small { color: var(--muted); }
.primary { height: 48px; border-radius: 12px; border: none; background: var(--hi); color: var(--ink-solid); font-weight: 700; font-size: 16px; padding: 0 24px; width: 100%; margin-top: 12px; }
.ghost { height: 36px; border-radius: 10px; border: 1px solid var(--line); background: transparent; padding: 0 12px; font-size: 13px; }
.controls { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; line-height: 1.6; }
.controls dt { color: var(--hi); font-weight: 700; }
.controls dd { margin: 0; }
.eyebrow { font-size: 11px; letter-spacing: .22em; color: var(--muted); }
.formula { font-family: var(--font-title); font-size: 18px; letter-spacing: .1em; margin: 10px 0; }
.formula .w { color: var(--water); } .formula .e { color: var(--earth); } .formula .f { color: var(--fire); } .formula .a { color: var(--wind); }
#lawList { display: grid; gap: 10px; margin-top: 10px; }
.law { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: grid; gap: 6px; min-width: 0; }
.law.ok { border-color: var(--c); background: rgba(255,255,255,.02); }
.law header { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.law header b { color: var(--c); font-size: 20px; font-family: var(--font-title); }
.law header span { font-weight: 700; }
.law header em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--muted); }
.law.ok header em { color: var(--c); }
.law p { font-size: 13px; margin: 0; line-height: 1.6; }
.law table { width: 100%; border-collapse: separate; border-spacing: 4px; table-layout: fixed; }
.law th { font-size: 12px; font-weight: 700; color: var(--muted); }
.law th small { display: block; font-size: 9px; font-weight: 500; }
.lc { width: 100%; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255,255,255,.04); font-size: 17px; font-weight: 700; color: var(--paper); padding: 0; }
.lc.unk { color: var(--muted); font-size: 13px; }
.lc.hit { border: 2px solid var(--hi); color: var(--hi); }
.lc.miss { border-color: rgba(255,140,120,.55); }
.lc.derived { border-style: dashed; border-color: var(--c); color: var(--c); }
.legend { font-size: 12px; color: var(--muted); line-height: 1.6; margin: 8px 0 0; }
#predict { z-index: 12; }
#predict .sheet { width: min(460px, 100%); }
#predict h2 { margin-top: 4px; }
#pdOpts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 10px; }
.pdOpt { height: 52px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.05); font-size: 15px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; }
.pdOpt span { font-size: 20px; color: var(--hi); }
.pdOpt:active { background: rgba(255,210,122,.18); }
.pdRow { display: flex; gap: 8px; }
.pdRow .ghost { flex: 1; height: 42px; }
.toast.hit .k { color: var(--hi); }
.toast.miss .k { color: #ff9a85; }
.toast.law { border-color: var(--wind); }
.toast.law .k { color: var(--wind); }
#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 58%, rgba(8, 16, 22, .38) 100%); }
#castBtn { border-color: var(--elc, var(--hi)); box-shadow: 0 0 18px -4px var(--elc, var(--hi)); }
#castBtn .ring { background: conic-gradient(var(--elc, var(--hi)) calc(var(--charge, 0) * 1turn), transparent 0); }
#qBtn { font-size: 12px; }
@media (max-width: 420px) { #qBtn { font-size: 11px; padding: 0 8px; } }
