:root { --bg:#16130f; --panel:#25201a; --text:#f2eadf; --muted:#c7b9a6; --accent:#d9a55b; --focus:#ffd98a; --line:#4a3f33; color-scheme: dark; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin:0; background:var(--bg); color:var(--text); font: 1.0625rem/1.55 -apple-system, system-ui, sans-serif; }

/* Fixed top bar: Back top left, Cancel top centre, Save top right. Three fixed slots,
   so a control never moves even when another slot is empty. */
.topbar, .bottombar { position: fixed; left: 0; right: 0; z-index: 5; display: grid; background: var(--bg); }
.topbar { top: 0; grid-template-columns: 1fr 1fr 1fr; padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left)); border-bottom: 1px solid var(--line); }
.bottombar { bottom: 0; grid-template-columns: 1fr 1fr; padding: 6px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); border-top: 1px solid var(--line); }
.slot { display: flex; min-height: 56px; align-items: center; }
.slot.left { justify-content: flex-start; } .slot.centre { justify-content: center; } .slot.right { justify-content: flex-end; }
.topbar button, .bottombar button { min-width: 88px; min-height: 56px; padding: .5rem .8rem; font-size: 1rem; }
main { max-width: 44rem; margin: 0 auto; padding: calc(var(--topbar-h, 76px) + 12px) 16px calc(var(--bottombar-h, 0px) + 32px); }

h1 { font-size: 1.55rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.2rem; margin: 1.6rem 0 .4rem; color: var(--accent); }
p, li { margin: .5rem 0; }
.prose ul, .prose ol { padding-left: 1.4rem; }
.label { color: var(--accent); font-style: italic; margin-top: 1.2rem; }
.block + .block { margin-top: 1rem; }
.note { color: var(--muted); }
.banner { background: #3a2d19; color: var(--text); padding: .4rem .8rem; border-radius: .5rem; font-size: .95rem; margin: 0 0 .5rem; }

button { font: inherit; background: var(--panel); color: var(--text); border: 1px solid var(--accent); border-radius: .6rem; padding: .7rem 1rem; min-height: 48px; text-align: left; }
button[aria-disabled="true"], button:disabled { opacity: .5; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
#title:focus, #title:focus-visible { outline: none; }
.stack { display: flex; flex-direction: column; align-items: stretch; gap: .55rem; margin: .8rem 0 1.2rem; }
.stack button { width: 100%; }
.buttons { display: flex; flex-wrap: wrap; gap: .6rem; margin: .8rem 0; }
label { display: block; margin: .8rem 0 .3rem; }
input[type=text], input[type=search], input[type=number], textarea { font: inherit; width: 100%; padding: .6rem; border-radius: .5rem; border: 1px solid var(--accent); background: var(--panel); color: var(--text); }
textarea { min-height: 14rem; }
.error { color: #ffb4a0; font-weight: 600; }
.error:empty, .status:empty { display: none; }
.status { color: var(--muted); }
fieldset { border: 1px solid var(--line); border-radius: .6rem; padding: .4rem 1rem .8rem; margin: 1rem 0; }
legend { padding: 0 .3rem; color: var(--accent); }
.choice { display: flex; align-items: center; gap: .7rem; margin: .5rem 0; min-height: 44px; }
.choice input { width: 1.4rem; height: 1.4rem; }
.choice label { margin: 0; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--accent); border-radius: .8rem; padding: 1rem 1.2rem; max-width: 28rem; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0,0,0,.65); }

/* One stop per item (Everflame actions-stop technique). */
.row { position: relative; padding: .7rem .9rem; border: 1px solid var(--line); border-radius: .6rem; background: var(--panel); min-height: 56px; }
.row .t { display: block; }
.row .a { display: block; color: var(--accent); font-size: .9rem; }
.row .a:empty { display: none; }
.row input[type=range] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; pointer-events: none; }
.row:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.list { display: flex; flex-direction: column; gap: .55rem; margin: .8rem 0; }

/* Hexagram Explorer: full screen, line 1 physically at the bottom. */
body.explorer main { max-width: none; padding: calc(var(--topbar-h, 76px) + 4px) 0 0; height: 100dvh; display: flex; flex-direction: column; }
body.explorer #title, body.explorer #test-banner { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
body.explorer #screen { flex: 1; display: flex; }
.explorer-lines { flex: 1; display: flex; flex-direction: column-reverse; padding: 4px max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)); gap: 6px; }
.explorer-lines button { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; text-align: center; border-radius: .5rem; font-size: 1.1rem; }
.explorer-lines .shape { display: flex; gap: 14%; width: 70%; height: 22%; min-height: 10px; }
.explorer-lines .seg { flex: 1; background: var(--text); border-radius: 3px; }
textarea.short { min-height: 6rem; }
