:root {
  color-scheme: dark;
  --bg: #081019; --panel: #111b27; --panel-2: #172433; --panel-3: #1d2d3e;
  --line: #2a3d50; --line-soft: #1e2c3b; --text: #f5f1e9; --muted: #9dafc0;
  --accent: #e5a744; --accent-strong: #ffc861; --accent-ink: #251707; --blue: #68c7da;
  --danger: #ef766f; --success: #72c69e; --shadow: 0 22px 70px rgba(0,0,0,.42);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); color: var(--text); }
body[data-view="roll"] { overflow: hidden; }
button, input, select, textarea { font: inherit; }
button, select { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 72%, transparent); outline-offset: 2px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.75rem, 4vw, 2.6rem); font-weight: 500; letter-spacing: -.025em; }
h2 { margin: 0; font-size: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 150; padding: 10px 14px; transform: translateY(-150%); background: var(--text); color: var(--bg); border-radius: 8px; }
.skip-link:focus { transform: none; }

.app-shell { min-height: 100vh; }
.topbar { position: relative; z-index: 50; display: grid; grid-template-columns: minmax(190px, .75fr) minmax(520px, 2.4fr) auto; align-items: center; gap: 16px; height: 64px; padding: 0 18px; background: rgba(9,15,23,.96); border-bottom: 1px solid var(--line-soft); box-shadow: 0 8px 30px rgba(0,0,0,.2); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 0; border: 0; background: transparent; text-align: left; cursor: pointer; }
.brand-mark { display: grid; flex: 0 0 auto; place-items: center; width: 38px; height: 38px; background: var(--accent); color: var(--accent-ink); clip-path: polygon(50% 0,95% 23%,88% 77%,50% 100%,12% 77%,5% 23%); font-family: Georgia, serif; font-size: .75rem; font-weight: 800; }
.brand-copy { min-width: 0; }
.brand strong, .brand small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand strong { font-family: Georgia, serif; font-size: 1rem; }
.brand small { margin-top: 1px; color: var(--muted); font-size: .75rem; }
.modifier-tools { display: flex; align-items: center; justify-content: center; gap: 5px; min-width: 0; }
.rail-button { flex: 0 0 auto; min-height: 36px; padding: 0 12px; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--muted); font-size: .84rem; cursor: pointer; }
.rail-button:hover, .rail-button.is-open { border-color: var(--line); background: var(--panel-2); color: var(--text); }
.modifier-search { display: flex; align-items: center; width: min(220px, 30vw); min-width: 150px; height: 38px; margin-left: 5px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: #0c151f; }
.modifier-search:focus-within { border-color: var(--blue); }
.modifier-search svg { flex: 0 0 auto; width: 17px; height: 17px; fill: none; stroke: var(--muted); stroke-width: 1.8; }
.modifier-search input { width: 100%; min-width: 0; padding: 0 0 0 8px; border: 0; outline: 0; background: transparent; color: var(--text); font-size: .84rem; }
.modifier-search input::placeholder { color: #728598; }
.topbar-actions, .header-actions, .row-actions { display: flex; align-items: center; gap: 6px; }
.rules-switch select { height: 38px; padding: 0 26px 0 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--text); font-size: .8rem; }
.icon-btn, .sound-button { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); cursor: pointer; }
.icon-btn:hover, .icon-btn.is-active, .sound-button:hover { border-color: var(--blue); background: var(--panel-2); }
.icon-btn svg, .sound-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.main-content { min-width: 0; }
.view { display: none; }
.view.is-active { display: block; animation: view-in .18s ease both; }
@keyframes view-in { from { opacity: 0; transform: translateY(4px); } }
.roll-workspace { position: relative; height: calc(100dvh - 64px); background: radial-gradient(circle at 50% 44%, #1b3346 0, #0c1722 38%, #081019 76%); }
.applied-rail { display: flex; align-items: center; gap: 9px; height: 44px; padding: 0 18px; border-bottom: 1px solid var(--line-soft); background: rgba(12,20,30,.78); overflow: hidden; }
.rail-label { flex: 0 0 auto; color: #7f92a5; font-size: .75rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.applied-list { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; overflow-x: auto; scrollbar-width: none; }
.applied-list::-webkit-scrollbar, .subcontext-rail::-webkit-scrollbar, .context-rail::-webkit-scrollbar { display: none; }
.applied-empty { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.applied-chip, .mode-pill { flex: 0 0 auto; min-height: 28px; padding: 0 10px; border: 1px solid #385069; border-radius: 999px; background: #142130; color: #dce6ed; font-size: .75rem; cursor: pointer; }
.applied-chip { display: inline-flex; align-items: center; gap: 7px; }
.applied-chip span { color: var(--accent-strong); font-weight: 800; }
.mode-pill { margin-left: auto; border-color: #66512f; color: var(--accent-strong); }

.roll-platform { position: relative; height: calc(100% - 168px); min-height: 260px; }
.platform-heading { position: absolute; z-index: 5; top: clamp(18px, 4vh, 42px); left: 50%; width: min(640px, calc(100% - 130px)); transform: translateX(-50%); text-align: center; pointer-events: none; }
.platform-heading > span { color: var(--accent); font-size: .75rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.platform-heading h1 { margin-top: 5px; font-size: clamp(1.7rem, 4vh, 2.7rem); }
.platform-heading p { margin: 7px 0 0; overflow: hidden; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.sound-button { position: absolute; z-index: 7; top: 16px; right: 18px; background: rgba(13,23,34,.7); }
.dice-stage { position: absolute; inset: 0; overflow: hidden; }
.dice-stage::after { content: ""; position: absolute; right: 18%; bottom: 8%; left: 18%; height: 15%; border-radius: 50%; background: rgba(0,0,0,.27); filter: blur(30px); pointer-events: none; }
#diceCanvas { position: absolute; z-index: 2; inset: 0; width: 100%; height: 100%; }
.dice-preview { position: absolute; z-index: 3; inset: clamp(92px, 18vh, 145px) 92px 70px; display: flex; flex-wrap: wrap; align-content: center; align-items: center; justify-content: center; gap: clamp(12px, 2vw, 24px); transition: opacity .18s ease; }
.dice-preview[hidden] { display: none; }
.die-token { position: relative; display: grid; flex: 0 0 auto; place-items: center; width: clamp(74px, 8vw, 104px); height: clamp(74px, 8vw, 104px); background: linear-gradient(145deg, #f0b858, #bd7625); color: #241506; clip-path: polygon(50% 0,94% 25%,84% 78%,50% 100%,15% 78%,6% 25%); filter: drop-shadow(0 12px 12px rgba(0,0,0,.3)); }
.die-token.is-d6 { clip-path: inset(7% round 20%); background: linear-gradient(145deg, #70cad8, #33798a); color: #07171d; }
.die-token.is-d4, .die-token.is-d8 { clip-path: polygon(50% 2%,96% 88%,4% 88%); background: linear-gradient(145deg, #be91dc, #6e4593); color: #160c1d; }
.die-token.is-d10 { clip-path: polygon(50% 0,91% 25%,77% 91%,23% 91%,9% 25%); background: linear-gradient(145deg, #e17b73, #963d40); color: #230b0c; }
.die-token.is-d12 { background: linear-gradient(145deg, #79bb92, #397252); color: #07170e; }
.die-token strong { font-family: Georgia, serif; font-size: clamp(1.2rem, 2.2vw, 1.7rem); }
.die-source { position: absolute; top: calc(100% + 7px); left: 50%; width: 130px; transform: translateX(-50%); color: var(--muted); font-size: .75rem; font-weight: 650; text-align: center; white-space: nowrap; }
.flat-token { display: grid; flex: 0 0 auto; place-items: center; min-width: 78px; height: 62px; padding: 0 13px; border: 1px solid #50677d; border-radius: 15px; background: rgba(19,32,45,.88); box-shadow: 0 10px 25px rgba(0,0,0,.25); }
.flat-token strong { color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.25rem; }
.flat-token small { max-width: 105px; margin-top: -8px; overflow: hidden; color: var(--muted); font-size: .7rem; text-overflow: ellipsis; white-space: nowrap; }
.roll-result { position: absolute; right: 18px; bottom: 88px; z-index: 6; max-width: calc(100% - 36px); padding: 12px 16px; border: 1px solid rgba(255,255,255,.15); border-radius: 11px; background: rgba(7,11,17,.84); backdrop-filter: blur(10px); }
.roll-result strong { font-size: 1.45rem; }
.roll-result span { display: block; margin-top: 3px; color: var(--muted); font-size: .75rem; }
.roll-button { position: absolute; z-index: 8; right: 22px; bottom: 18px; display: flex; align-items: center; justify-content: center; gap: 11px; min-width: 172px; min-height: 58px; padding: 0 16px; border: 0; border-radius: 13px; background: linear-gradient(135deg, var(--accent-strong), #db9135); color: var(--accent-ink); box-shadow: 0 10px 28px rgba(230,168,69,.22); cursor: pointer; }
.roll-button:hover { filter: brightness(1.06); transform: translateY(-1px); }
.roll-button:active { transform: translateY(1px); }
.roll-button:disabled { opacity: .55; cursor: wait; transform: none; }
.roll-button strong, .roll-button small { display: block; text-align: left; }
.roll-button small { margin-top: 1px; font-size: .72rem; opacity: .75; }
.roll-button kbd { margin-left: 5px; }
.roll-button-icon { font-size: 1.1rem; }
kbd { padding: 2px 6px; border: 1px solid rgba(36,21,6,.3); border-radius: 4px; font-size: .68rem; }

.subcontext-rail { display: flex; align-items: center; gap: 6px; height: 54px; padding: 7px 18px; overflow-x: auto; border-top: 1px solid var(--line-soft); background: rgba(12,20,30,.92); scrollbar-width: none; }
.subcontext-label { flex: 0 0 auto; margin-right: 3px; color: var(--muted); font-size: .75rem; font-weight: 750; }
.subcontext-divider { flex: 0 0 auto; width: 1px; height: 25px; margin: 0 4px; background: var(--line); }
.option-chip { flex: 0 0 auto; min-height: 36px; padding: 0 13px; border: 1px solid var(--line); border-radius: 9px; background: #111c28; color: var(--muted); font-size: .8rem; cursor: pointer; }
.option-chip:hover { color: var(--text); border-color: #4a647c; }
.option-chip.is-active { border-color: #8a6935; background: rgba(229,167,68,.12); color: var(--accent-strong); }
.subcontext-field { display: flex; flex: 0 0 auto; align-items: center; gap: 7px; min-height: 36px; padding: 0 9px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); font-size: .75rem; }
.subcontext-field input { width: 72px; padding: 0; border: 0; outline: 0; background: transparent; color: var(--text); }
.subcontext-field select { max-width: 220px; min-height: 30px; padding: 0 26px 0 7px; border: 0; border-radius: 6px; outline: 0; background: var(--panel-2); color: var(--text); font-size: .78rem; }
.spell-picker select { width: min(300px, 42vw); max-width: 300px; }
.spell-damage-summary { flex: 0 0 auto; color: var(--accent-strong); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .74rem; white-space: nowrap; }
.subcontext-field.wide input { width: 130px; }
.critical-chip { display: flex; align-items: center; gap: 7px; }
.critical-chip input { width: 17px; height: 17px; accent-color: var(--accent); }
.context-rail { display: grid; grid-template-columns: repeat(5, minmax(88px, 1fr)); height: 70px; padding: 5px max(10px, 8vw) calc(5px + var(--safe-bottom)); overflow-x: auto; border-top: 1px solid #32465a; background: #0b141e; box-shadow: 0 -10px 32px rgba(0,0,0,.22); scrollbar-width: none; }
.context-rail button { display: grid; place-items: center; gap: 1px; min-width: 88px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: .75rem; cursor: pointer; }
.context-rail button span { font-size: 1.05rem; }
.context-rail button:hover { color: var(--text); }
.context-rail button.is-active { background: var(--panel-2); color: var(--text); }
.context-rail button.is-active span { color: var(--accent); }

.modifier-popover { position: fixed; z-index: 80; top: 70px; left: 50%; display: grid; grid-template-rows: auto minmax(0,1fr) auto; width: min(560px, calc(100vw - 24px)); max-height: min(650px, calc(100dvh - 84px)); transform: translateX(-50%); overflow: hidden; border: 1px solid #415970; border-radius: 14px; background: #101a25; box-shadow: var(--shadow); }
.modifier-popover[hidden] { display: none; }
.modifier-popover > header { display: flex; align-items: center; justify-content: space-between; padding: 15px 16px; border-bottom: 1px solid var(--line); }
.modifier-popover header small { display: block; margin-bottom: 3px; color: var(--accent); font-size: .7rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.modifier-popover header h2 { font-family: Georgia, serif; font-size: 1.25rem; font-weight: 500; }
.popover-body { overflow-y: auto; padding: 10px; }
.modifier-group-title { margin: 10px 7px 6px; color: var(--muted); font-size: .7rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.modifier-option { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; min-height: 54px; padding: 8px 10px; border-radius: 9px; cursor: pointer; }
.modifier-option:hover { background: var(--panel-2); }
.modifier-option.is-disabled { opacity: .48; cursor: not-allowed; }
.modifier-option input { width: 18px; height: 18px; accent-color: var(--accent); }
.modifier-option strong, .modifier-option small { display: block; }
.modifier-option strong { font-size: .86rem; }
.modifier-option small { margin-top: 3px; color: var(--muted); font-size: .75rem; line-height: 1.35; }
.modifier-value { color: var(--accent-strong); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .78rem; }
.modifier-popover > footer { display: flex; justify-content: space-between; padding: 10px 15px; border-top: 1px solid var(--line); }
.mode-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; padding: 5px; }
.mode-options button { min-height: 42px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--muted); cursor: pointer; }
.mode-options button.is-active { border-color: var(--accent); background: rgba(229,167,68,.12); color: var(--accent-strong); }

.secondary-view { width: min(1080px, calc(100% - 40px)); margin: 0 auto; padding: 36px 0 70px; }
.workspace-head { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 25px; }
.eyebrow { margin-bottom: 6px; color: var(--accent); font-size: .75rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.quiet-btn, .text-btn { padding: 8px 5px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.quiet-btn:hover, .text-btn:hover { color: var(--text); }
.text-btn { color: var(--blue); font-size: .84rem; }
.primary-small { min-height: 40px; padding: 0 15px; border: 0; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-weight: 800; cursor: pointer; }
.panel-stack { display: grid; gap: 14px; }
.panel { padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.panel-head, .section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.imported-character-note { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -2px 0 16px; padding: 10px 12px; border: 1px solid #315268; border-radius: 9px; background: rgba(64,139,168,.09); }
.imported-character-note span { color: var(--muted); font-size: .76rem; }
.imported-character-note strong { color: var(--blue); font-size: .84rem; }
.known-mark { color: var(--accent); }
.section-title-row.spaced-title { margin-top: 20px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.field { display: grid; gap: 7px; }
.field.span-2 { grid-column: 1 / -1; }
.field-label { color: var(--muted); font-size: .78rem; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; }
.field-note { margin: 6px 0 0; color: var(--muted); font-size: .8rem; line-height: 1.45; }
.field input, .field select, .field textarea { width: 100%; min-height: 44px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #0d151f; color: var(--text); }
.field textarea { min-height: 90px; resize: vertical; }
.ability-grid { display: grid; grid-template-columns: repeat(6,1fr); gap: 8px; }
.ability { display: grid; gap: 5px; justify-items: center; padding: 11px 7px; border: 1px solid var(--line); border-radius: 9px; background: #0d151f; }
.ability label { color: var(--muted); font-size: .72rem; font-weight: 800; }
.ability input { width: 55px; height: 38px; border: 0; border-radius: 7px; background: var(--panel-3); color: var(--text); text-align: center; }
.ability output { color: var(--accent); font-size: .78rem; }
.data-list { display: grid; gap: 7px; }
.data-row { display: grid; grid-template-columns: minmax(120px,1fr) auto auto; align-items: center; gap: 10px; min-height: 50px; padding: 8px 11px; border: 1px solid var(--line-soft); border-radius: 9px; background: #0d151f; }
.data-row strong, .data-row small { display: block; }
.data-row small { margin-top: 3px; color: var(--muted); font-size: .75rem; }
.mini-btn { min-width: 34px; min-height: 34px; padding: 0 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); color: var(--muted); cursor: pointer; }
.mini-btn:hover { color: var(--text); border-color: var(--blue); }
.mini-btn.danger:hover { color: var(--danger); border-color: var(--danger); }
.notice { margin-bottom: 15px; padding: 12px 15px; border: 1px solid #315268; border-radius: 10px; background: rgba(64,139,168,.09); color: #c1d8e4; font-size: .84rem; line-height: 1.5; }
.effect-section + .effect-section { margin-top: 18px; }
.effect-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; }
.effect-card { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); }
.effect-card.is-active { border-color: color-mix(in srgb,var(--accent) 65%,var(--line)); background: linear-gradient(135deg,rgba(230,168,69,.11),var(--panel)); }
.effect-card p { margin: 5px 0 0; color: var(--muted); font-size: .78rem; line-height: 1.45; }
.switch { position: relative; width: 44px; height: 26px; }
.switch input { position: absolute; opacity: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #344354; cursor: pointer; }
.switch span::after { content: ""; position: absolute; top: 4px; left: 4px; width: 18px; height: 18px; border-radius: 50%; background: #c2ccd5; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); background: var(--accent-ink); }
.history-list { display: grid; gap: 9px; }
.history-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); }
.history-total { display: grid; place-items: center; width: 48px; height: 48px; color: var(--accent-strong); clip-path: polygon(50% 0,94% 25%,84% 78%,50% 100%,15% 78%,6% 25%); background: var(--panel-3); font-family: Georgia,serif; font-weight: 800; }
.history-row strong, .history-row small { display: block; }
.history-row small { margin-top: 4px; color: var(--muted); font-size: .76rem; }
.history-time { color: var(--muted); font-size: .72rem; }
.empty-state, .empty-inline { padding: 30px 18px; border: 1px dashed var(--line); border-radius: 11px; color: var(--muted); text-align: center; }
.empty-inline { padding: 13px; font-size: .84rem; }
.empty-state strong { display: block; margin-bottom: 6px; color: var(--text); }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; background: rgba(3,7,12,.72); backdrop-filter: blur(5px); }
.modal-backdrop[hidden] { display: none; }
.modal { display: grid; grid-template-rows: auto minmax(0,1fr) auto; width: min(650px,100%); max-height: min(820px,calc(100vh - 36px)); overflow: hidden; border: 1px solid #3a4f64; border-radius: 15px; background: #111a25; box-shadow: var(--shadow); }
.modal > header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal > header h2 { font-family: Georgia,serif; font-size: 1.3rem; font-weight: 500; }
.modal-body { overflow-y: auto; padding: 20px; }
.modal > footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); }
.modal-button { min-height: 42px; padding: 0 15px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); color: var(--text); cursor: pointer; }
.modal-button.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.modal-button.danger { color: var(--danger); }
.form-stack { display: grid; gap: 15px; }
.check-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 8px; }
.check-chip { display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: #0d141e; }
.check-chip input { width: 17px; height: 17px; accent-color: var(--accent); }
.import-drop { display: grid; place-items: center; min-height: 145px; padding: 24px; border: 1px dashed #4b667f; border-radius: 11px; background: #0d141e; text-align: center; cursor: pointer; }
.import-drop input { position: absolute; opacity: 0; pointer-events: none; }
.import-drop strong, .import-drop small { display: block; }
.import-drop small { margin-top: 7px; color: var(--muted); }
.import-summary { padding: 12px; border-radius: 9px; background: rgba(114,198,158,.1); color: #b8e3ce; }
.help-section + .help-section { margin-top: 22px; }
.help-section h3 { margin: 0 0 8px; }
.help-section p, .help-section li { color: var(--muted); line-height: 1.55; }
.license-copy { font-size: .75rem; }
.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 130; display: grid; gap: 8px; }
.toast { max-width: 340px; padding: 12px 15px; border: 1px solid #46617a; border-radius: 9px; background: #172331; box-shadow: var(--shadow); }

@media (max-width: 1000px) {
  .topbar { grid-template-columns: 1fr auto; grid-template-rows: 56px 52px; height: 108px; padding: 0 12px; gap: 0 10px; }
  .modifier-tools { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; margin: 0 -12px; padding: 7px 12px; overflow-x: auto; border-top: 1px solid var(--line-soft); scrollbar-width: none; }
  .modifier-tools::-webkit-scrollbar { display: none; }
  .modifier-search { flex: 0 0 190px; width: 190px; }
  .roll-workspace { height: calc(100dvh - 108px); }
  .modifier-popover { top: 114px; max-height: calc(100dvh - 126px); }
  .ability-grid { grid-template-columns: repeat(3,1fr); }
}

@media (max-width: 620px) {
  .brand-copy small { display: none; }
  .brand-mark { width: 36px; height: 36px; }
  .topbar-actions { gap: 4px; }
  .rules-switch select { width: 66px; }
  .icon-btn { width: 36px; height: 36px; }
  .applied-rail { padding: 0 10px; }
  .rail-label { display: none; }
  .roll-platform { height: calc(100% - 168px); }
  .platform-heading { top: 16px; width: calc(100% - 90px); }
  .platform-heading h1 { margin-top: 3px; font-size: 1.65rem; }
  .platform-heading p { margin-top: 4px; font-size: .7rem; }
  .sound-button { top: 10px; right: 10px; }
  .dice-preview { inset: 84px 18px 78px; gap: 14px; }
  .die-token { width: 72px; height: 72px; }
  .die-source { width: 95px; font-size: .68rem; }
  .flat-token { min-width: 68px; height: 54px; }
  .roll-button { right: 12px; bottom: 12px; min-width: 145px; min-height: 54px; padding: 0 13px; }
  .roll-button kbd { display: none; }
  .roll-result { right: 12px; bottom: 75px; }
  .subcontext-rail { padding: 7px 10px; }
  .context-rail { padding-right: 5px; padding-left: 5px; }
  .secondary-view { width: calc(100% - 28px); padding-top: 24px; }
  .workspace-head { align-items: center; }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; }
  .field-grid, .effect-grid, .check-grid { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: auto; }
  .data-row { grid-template-columns: minmax(0,1fr) auto; }
  .data-row > .row-meta { grid-column: 1 / -1; }
  .modal-backdrop { align-items: end; padding: 0; }
  .modal { width: 100%; max-height: calc(92vh - var(--safe-bottom)); border-radius: 16px 16px 0 0; }
  .modal > footer { padding-bottom: calc(14px + var(--safe-bottom)); }
  .toast-region { right: 12px; bottom: calc(12px + var(--safe-bottom)); left: 12px; }
  .toast { max-width: none; }
}

@media (max-height: 620px) and (min-width: 621px) {
  .platform-heading { top: 12px; }
  .dice-preview { top: 75px; }
  .die-token { width: 68px; height: 68px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
