:root {
  --bg: #F7F4EE; --panel: #FFFDF8; --border: #E6D9BE; --ink: #23252D; --muted: #6B6D75;
  --navy: #1E2847; --gold: #B58C42; --brown: #5A4A2E; --ghost: #6F8FD8; --s: 16px;
}
* { box-sizing: border-box; min-width: 0; }
html, body { margin: 0; background: var(--bg); color: var(--ink); overflow-x: clip; }
body { font-family: Heebo, system-ui, sans-serif; font-size: 15px; line-height: 1.5; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
bdi { unicode-bidi: isolate; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.top { background: linear-gradient(160deg, #1E2847, #121A31); color: #fff; padding: calc(14px + env(safe-area-inset-top)) var(--s) 12px; }
.top h1 { margin: 0; font-family: "Frank Ruhl Libre", serif; font-size: 21px; line-height: 1.2; }
.steps { display: flex; gap: 6px; margin-top: 10px; }
.step { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 6px; border-radius: 10px; background: rgba(255,255,255,.08); color: #C9CEDD; font-size: 13px; min-height: 44px; white-space: nowrap; }
.step i { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-weight: 700; background: rgba(255,255,255,.15); color: #fff; font-size: 12px; }
.step[aria-current="step"] { background: #fff; color: var(--navy); font-weight: 700; }
.step[aria-current="step"] i { background: var(--gold); }

main { max-width: 560px; margin: 0 auto; padding: var(--s) var(--s) calc(24px + env(safe-area-inset-bottom)); }
.screen { display: flex; flex-direction: column; gap: 12px; }
.screen[hidden] { display: none; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 12px; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.warn { margin: 0; font-size: 13px; color: #8a3a26; background: #F7E9E3; border-radius: 10px; padding: 8px 10px; }
.warn[hidden] { display: none; }

.layers { display: flex; gap: 6px; }
.layers button { flex: 1; min-height: 44px; border-radius: 99px; border: 1px solid var(--border); background: #fff; font-weight: 500; font-size: 14px; color: var(--brown); white-space: nowrap; }
.layers button[aria-pressed="true"] { background: var(--navy); color: #fff; border-color: var(--navy); }
.mag { margin: 0; background: #fff; border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
.mag svg { display: block; width: 100%; height: auto; direction: ltr; }
.mag-t { display: flex; justify-content: space-between; padding: 6px 10px 0; font-size: 12px; color: var(--muted); }
.mag-cap { padding: 0 10px 8px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.drag { position: absolute; bottom: 10px; right: 10px; z-index: 2; background: rgba(255,255,255,.9); border-radius: 99px; padding: 2px 10px; font-size: 12px; color: var(--navy); pointer-events: none; }
.seg { display: flex; background: #EFE7D6; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; font-weight: 500; font-size: 14px; color: var(--brown); min-height: 44px; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--navy); color: #fff; }

.stage { position: relative; height: min(42vh, 340px); min-height: 240px; border-radius: 16px; overflow: hidden; background: radial-gradient(circle at 50% 40%, #3a3a40, #1d1d22); touch-action: none; }
.stage canvas { display: block; width: 100%; height: 100%; }
.tb { position: absolute; left: 8px; bottom: 8px; display: flex; gap: 6px; z-index: 2; }
.tb button { width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.92); color: var(--navy); font-size: 20px; box-shadow: 0 2px 6px rgba(0,0,0,.3); display: grid; place-items: center; }
.tb button[aria-pressed="true"] { background: #d3ad5d; }

.nums { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); border-radius: 14px; overflow: hidden; border: 1px solid var(--border); }
.nums div { background: var(--panel); padding: 10px 12px; display: flex; flex-direction: column; }
.nums span { font-size: 12px; color: var(--muted); }
.nums b { font-size: 20px; }

.actions { display: flex; gap: 8px; }
.btn { flex: 2; display: grid; place-items: center; min-height: 52px; border-radius: 14px; background: var(--navy); color: #fff; font-weight: 700; font-size: 16px; white-space: nowrap; border: 0; }
.btn.sec { flex: 1; background: var(--panel); color: var(--brown); border: 1px solid var(--border); font-weight: 600; }

.btn.wide { flex: none; width: 100%; }
#wi { display: flex; flex-direction: column; gap: 12px; }
#wi[hidden] { display: none; }
.wi { border: 2px solid var(--navy); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 6px; background: var(--panel); }
.wi-hd { display: flex; justify-content: space-between; align-items: center; }
.wi-hd b { font-size: 16px; }
.x { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: #fff; display: grid; place-items: center; }
.ctl { display: flex; flex-direction: column; padding: 4px 0; border-top: 1px solid var(--border); }
.wi-hd + .ctl { border-top: 0; }
.ctl .lab { display: flex; justify-content: space-between; align-items: center; font-size: 14px; }
.track { position: relative; display: block; }
.track input { position: relative; z-index: 1; }
.track u { position: absolute; top: 9px; width: 3px; height: 18px; margin-right: -1.5px; border-radius: 2px; background: var(--ghost); pointer-events: none; }
.range { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: -6px; }
input[type=range] { width: 100%; accent-color: var(--gold); height: 36px; margin: 0; }
.h3 { margin: 0 0 4px; font-size: 15px; }
table.cmp { width: 100%; border-collapse: collapse; font-size: 14px; }
.cmp th { font-size: 12px; color: var(--muted); font-weight: 500; text-align: start; padding: 4px 6px; }
.cmp td { padding: 8px 6px; border-top: 1px solid var(--border); }
.cmp td.df { color: var(--navy); font-weight: 700; }
.parch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.parch > div { background: #F4E9CF; border-radius: 12px; padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 13px; }
.parch svg { width: 100%; max-width: 120px; }
.parch b { font-size: 18px; }
.pdiff { margin-top: 8px; display: flex; justify-content: space-around; background: #F3EEE3; border-radius: 10px; padding: 8px; font-size: 13px; color: var(--navy); }
.toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 8px 16px; border-radius: 99px; font-size: 14px; z-index: 10; }
