:root {
  --ink: #f4f0e5;
  --mist: rgba(244, 240, 229, .82);
  --faint: rgba(244, 240, 229, .52);
  --hairline: rgba(244, 240, 229, .18);
  --panel: rgba(8, 11, 18, .72);
  --accent: #f3a55d;
  --accent-rgb: 243, 165, 93;
  --ground: #080b12;
}

* { box-sizing: border-box; }
html, body { min-width: 320px; height: 100%; overflow: hidden; background: var(--ground); }
body { margin: 0; color: var(--ink); font-family: "Manrope", sans-serif; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; }
button:focus-visible, input:focus-visible { outline: 1px solid var(--accent); outline-offset: 4px; }
h1, h2, h3, p { margin: 0; }

.world { position: fixed; z-index: -1; inset: 0; overflow: hidden; background: #0a101c; transition: background 1.2s ease; }
.world::before, .world::after { position: absolute; content: ""; inset: 0; pointer-events: none; }
.world::before { background-image: radial-gradient(rgba(255,255,255,.48) .65px, transparent .8px), radial-gradient(rgba(255,255,255,.26) .5px, transparent .75px); background-position: 0 0, 31px 19px; background-size: 82px 82px, 137px 137px; opacity: .28; }
.world::after { background: linear-gradient(90deg, rgba(2, 4, 8, .7), transparent 52%, rgba(2, 4, 8, .48)), linear-gradient(0deg, rgba(2, 4, 8, .78), transparent 44%); }
.world-glow { position: absolute; width: 78vmax; height: 78vmax; top: -40vmax; right: -18vmax; border-radius: 50%; background: radial-gradient(circle, rgba(var(--accent-rgb), .4), rgba(var(--accent-rgb), .08) 31%, transparent 67%); filter: blur(12px); animation: breathe 10s ease-in-out infinite; }
.world-orbit { position: absolute; border: 1px solid rgba(255,255,255,.16); border-radius: 50%; transform: rotate(-21deg); }
.orbit-a { width: 118vmax; height: 31vmax; top: 27vh; left: 11vw; }
.orbit-b { width: 73vmax; height: 18vmax; top: 53vh; left: 34vw; border-color: rgba(var(--accent-rgb), .34); }
.world-signal { position: absolute; width: 22vmax; height: 22vmax; top: 36vh; right: 17vw; border: 1px solid rgba(var(--accent-rgb), .65); border-radius: 50%; box-shadow: 0 0 100px rgba(var(--accent-rgb), .18), inset 0 0 54px rgba(var(--accent-rgb), .11); animation: signal 6s ease-out infinite; }
.world-grain { position: absolute; inset: 0; opacity: .1; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.9'/%3E%3C/svg%3E"); mix-blend-mode: overlay; }

body[data-adventure="tidemark-bell"] .world::after { background: linear-gradient(90deg, rgba(2, 9, 13, .30), transparent 54%, rgba(2, 9, 13, .20)), linear-gradient(0deg, rgba(2, 9, 13, .42), transparent 58%); }
body[data-adventure="tidemark-bell"] .world::before { opacity: .14; }

body[data-scene="hearth"] { --accent: #ec7254; --accent-rgb: 236, 114, 84; --ground: #150c0b; }
body[data-scene="hearth"] .world { background: #190d0b; }
body[data-scene="shatterbelt"] { --accent: #b7c9ff; --accent-rgb: 183, 201, 255; --ground: #070a12; }
body[data-scene="shatterbelt"] .world { background: #070a12; }
body[data-scene="shatterbelt"] .world-glow { top: 18vmax; right: 48vw; }
body[data-scene="relay"] { --accent: #ffd06d; --accent-rgb: 255, 208, 109; --ground: #100e0b; }
body[data-scene="relay"] .world { background: #100e0b; }
body[data-scene="relay"] .world-signal { width: 32vmax; height: 32vmax; top: 23vh; right: 11vw; }

.game { width: min(1320px, calc(100% - 44px)); height: 100dvh; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 0 max(18px, env(safe-area-inset-bottom)); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 13px; overflow: hidden; }
.gamebar { display: flex; align-items: center; min-height: 32px; justify-content: space-between; gap: 20px; }
.wordmark { color: var(--ink); display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font: 600 12px/1 "DM Mono", monospace; letter-spacing: .03em; }
.wordmark-mark { width: 13px; height: 13px; border: 1px solid var(--accent); border-radius: 50%; box-shadow: 0 0 14px rgba(var(--accent-rgb), .75); }
.statusline { color: var(--faint); font: 9px/1.4 "DM Mono", monospace; text-transform: uppercase; letter-spacing: .08em; }
.gamebar-tools { display: flex; align-items: center; gap: 16px; }
.quiet-button, .close-journal { padding: 0; border: 0; background: transparent; color: var(--mist); font: 9px/1 "DM Mono", monospace; letter-spacing: .07em; text-transform: uppercase; transition: color .2s; }
.quiet-button:hover:not(:disabled), .close-journal:hover { color: var(--accent); }
.quiet-button:disabled { opacity: .35; }

.stage { min-height: 0; display: grid; grid-template-columns: minmax(112px, 150px) minmax(0, 690px) minmax(118px, 170px); justify-content: center; align-items: stretch; gap: clamp(18px, 3vw, 48px); overflow: hidden; }
.micro-label, .moment-label { color: var(--accent); font: 9px/1.45 "DM Mono", monospace; text-transform: uppercase; letter-spacing: .12em; }
.inventory, .world-state { align-self: start; margin-top: 16px; padding-top: 10px; border-top: 1px solid var(--hairline); }
.inventory-items { display: grid; gap: 12px; margin-top: 18px; }
.inventory-item { display: grid; grid-template-columns: 24px 1fr; align-items: center; gap: 9px; color: var(--mist); font-size: 11px; line-height: 1.4; }
.item-icon { position: relative; display: block; width: 19px; height: 19px; border: 1px solid var(--accent); border-radius: 50%; }
.item-icon::after { position: absolute; inset: 5px; border: 1px solid var(--accent); border-radius: 50%; content: ""; }
.empty-inventory, .muted { margin-top: 14px; color: var(--faint); font-size: 10px; line-height: 1.55; }

.story { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: clamp(22px, 4vh, 42px) clamp(22px, 4vw, 52px); border: 1px solid var(--hairline); background: linear-gradient(140deg, rgba(10, 14, 23, .84), rgba(9, 12, 20, .52)); box-shadow: 0 16px 60px rgba(0, 0, 0, .15); scrollbar-color: rgba(var(--accent-rgb), .65) transparent; scrollbar-width: thin; }
.story::-webkit-scrollbar, .journal-entries::-webkit-scrollbar { width: 5px; }
.story::-webkit-scrollbar-thumb, .journal-entries::-webkit-scrollbar-thumb { background: rgba(var(--accent-rgb), .65); }
.story-location h1 { margin-top: 10px; max-width: 600px; font: 600 clamp(43px, 5.3vw, 68px)/.88 "Cormorant Garamond", serif; letter-spacing: -.045em; }
.story-rule { width: 38px; height: 1px; margin: 25px 0 21px; background: var(--accent); box-shadow: 0 0 14px rgba(var(--accent-rgb), .75); }
.story-copy { max-width: 62ch; color: var(--mist); font: 400 clamp(17px, 1.35vw, 20px)/1.56 "Source Serif 4", Georgia, serif; }
.story-copy p + p { margin-top: 16px; }
.story-copy em { color: var(--ink); }
.moment { max-width: 62ch; margin-top: 28px; padding: 18px 0 0 19px; border-top: 1px solid var(--hairline); border-left: 1px solid rgba(var(--accent-rgb), .75); color: var(--ink); font: 400 18px/1.54 "Source Serif 4", Georgia, serif; }
.moment-label { margin-bottom: 7px; }
.entered-command { margin: 0 0 14px; color: var(--faint); font: 9px/1 "DM Mono", monospace; }
.world-turn { margin-top: 24px; padding-top: 19px; border-top: 1px solid var(--hairline); }
.world-turn h2 { margin-bottom: 8px; font: 600 27px/1 "Cormorant Garamond", serif; }
.world-state { text-align: right; }
.threat { margin-top: 10px; color: var(--ink); font: 600 27px/.9 "Cormorant Garamond", serif; }
.threat-rising, .threat-unstable { color: #ffd06d; }
.threat-critical { color: #ff8068; }
.facts { display: grid; gap: 12px; margin-top: 29px; }
.facts p { padding-right: 9px; border-right: 1px solid var(--accent); color: var(--faint); font-size: 10px; line-height: 1.55; }

.command-deck { width: min(780px, 100%); margin: 0 auto; padding: 16px 21px 14px; border: 1px solid var(--hairline); background: rgba(6, 8, 14, .83); backdrop-filter: blur(13px); box-shadow: 0 12px 55px rgba(0,0,0,.24); }
.feedback { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 15px; align-items: start; margin: -1px -1px 15px; padding: 13px 14px; border: 1px solid rgba(var(--accent-rgb), .4); background: rgba(var(--accent-rgb), .08); color: var(--mist); font: 400 16px/1.4 "Source Serif 4", Georgia, serif; }
.feedback[hidden] { display: none; }
.feedback-observation { max-height: min(150px, 19dvh); overflow-y: auto; scrollbar-color: rgba(var(--accent-rgb), .65) transparent; scrollbar-width: thin; }
.feedback-label { margin-bottom: 5px; color: var(--accent); font: 9px/1.45 "DM Mono", monospace; text-transform: uppercase; letter-spacing: .12em; }
.feedback-close { border: 0; background: transparent; color: var(--faint); font: 8px/1 "DM Mono", monospace; letter-spacing: .08em; text-transform: uppercase; }
.feedback-close:hover { color: var(--accent); }
.command-label { display: block; color: var(--accent); font: 9px/1 "DM Mono", monospace; text-transform: uppercase; letter-spacing: .13em; }
.command-row { display: grid; grid-template-columns: 15px 1fr auto; align-items: center; gap: 9px; margin-top: 10px; }
.prompt { color: var(--accent); font: 24px/.7 "Cormorant Garamond", serif; }
.command-row input { width: 100%; min-width: 0; border: 0; background: transparent; color: var(--ink); font: 400 20px/1.2 "Source Serif 4", Georgia, serif; }
.command-row input::placeholder { color: rgba(244,240,229,.37); }
.command-row input:disabled { cursor: wait; }
.send-command, .restart, .gate-primary, .gate-secondary { border: 1px solid rgba(var(--accent-rgb), .75); background: transparent; color: var(--ink); padding: 9px 13px; font: 9px/1 "DM Mono", monospace; letter-spacing: .08em; text-transform: uppercase; transition: background .2s, color .2s; }
.send-command:hover:not(:disabled), .restart:hover, .gate-primary:hover, .gate-secondary:hover { background: var(--accent); color: #080b12; }
.send-command:disabled { opacity: .45; }
.command-note { display: flex; align-items: center; gap: 10px; margin-top: 10px; color: var(--faint); font-size: 10px; line-height: 1.4; }
.command-progress { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font: 8px/1 "DM Mono", monospace; letter-spacing: .08em; text-transform: uppercase; }
.command-progress[hidden] { display: none; }
.command-progress::before { width: 8px; height: 8px; border: 1px solid rgba(var(--accent-rgb), .35); border-top-color: var(--accent); border-radius: 50%; content: ""; animation: spin 1s linear infinite; }

.ending { position: fixed; z-index: 15; inset: 0; display: grid; place-content: center; padding: 22px; background: rgba(3, 4, 8, .82); text-align: center; }
.ending[hidden] { display: none; }
.ending > * { max-width: 560px; }
.ending h2 { margin-top: 10px; font: 600 48px/.9 "Cormorant Garamond", serif; }
.ending p:not(.micro-label) { margin: 17px auto 0; color: var(--mist); font: 400 19px/1.5 "Source Serif 4", Georgia, serif; }
.restart { margin-top: 25px; }

.journal-dialog { width: min(750px, calc(100% - 32px)); height: min(720px, calc(100dvh - 42px)); padding: 25px; border: 1px solid var(--hairline); background: #10131c; color: var(--ink); box-shadow: 0 28px 100px rgba(0,0,0,.6); overflow: hidden; }
.journal-dialog::backdrop { background: rgba(0,0,0,.7); backdrop-filter: blur(4px); }
.journal-head { display: flex; align-items: start; justify-content: space-between; padding-bottom: 20px; border-bottom: 1px solid var(--hairline); }
.journal-head h2 { margin-top: 7px; font: 600 38px/.8 "Cormorant Garamond", serif; }
.journal-entries { height: calc(100% - 72px); padding-top: 5px; overflow-y: auto; overscroll-behavior: contain; scrollbar-color: rgba(var(--accent-rgb), .65) transparent; scrollbar-width: thin; }
.journal-entry { display: grid; grid-template-columns: 56px 1fr; gap: 15px; padding: 17px 0; border-bottom: 1px solid var(--hairline); }
.journal-entry > span, .journal-command { color: var(--accent); font: 9px/1.6 "DM Mono", monospace; text-transform: uppercase; }
.journal-command { margin-bottom: 7px; color: var(--faint); text-transform: none; }
.journal-entry h3 { font: 600 23px/.95 "Cormorant Garamond", serif; }
.journal-entry p:not(.journal-command) { margin-top: 7px; color: var(--mist); font: 400 16px/1.45 "Source Serif 4", Georgia, serif; }
.journal-entry .journal-event { color: var(--faint); font-size: 14px; }

.campaign-gate { position: fixed; z-index: 30; inset: 0; display: grid; place-items: center; padding: 22px; background: rgba(3, 5, 9, .78); backdrop-filter: blur(8px); }
.campaign-gate[hidden] { display: none; }
.gate-panel { width: min(520px, 100%); padding: clamp(28px, 7vw, 54px); border: 1px solid rgba(var(--accent-rgb), .45); background: linear-gradient(140deg, rgba(21, 26, 38, .96), rgba(7, 9, 15, .96)); box-shadow: 0 28px 100px rgba(0,0,0,.45); text-align: center; }
.gate-panel h2 { margin-top: 11px; font: 600 clamp(37px, 6vw, 55px)/.9 "Cormorant Garamond", serif; }
.gate-panel > p:not(.micro-label) { margin-top: 17px; color: var(--mist); font: 400 18px/1.48 "Source Serif 4", Georgia, serif; }
.gate-actions { display: flex; justify-content: center; gap: 10px; margin-top: 29px; }
.gate-primary { background: var(--accent); color: #080b12; }

body[data-effect="flare"] .world-signal { animation: flare .75s ease-out; }
body[data-effect="flicker"] .world { animation: flicker .6s steps(2, end) 2; }
body[data-effect="intrusion"] .world::before { animation: interference .65s linear 2; }
body[data-effect="travel"] .world-orbit { animation: travel .7s ease-out; }
body[data-effect="restore"] .world-glow, body[data-effect="ending"] .world-glow { animation: restore .95s ease-out; }

@keyframes breathe { 50% { transform: scale(1.12); opacity: .74; } }
@keyframes signal { 0% { transform: scale(.45); opacity: 0; } 25% { opacity: .9; } 100% { transform: scale(1.45); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes flare { 0% { opacity: 1; } 30% { transform: scale(2.3); opacity: 1; box-shadow: 0 0 180px 85px rgba(var(--accent-rgb), .72); } 100% { transform: scale(1); } }
@keyframes flicker { 50% { opacity: .35; filter: contrast(1.8); } }
@keyframes interference { 50% { transform: translateX(8px); opacity: .7; } }
@keyframes travel { 50% { transform: rotate(-21deg) scale(1.18) translateX(80px); opacity: .1; } }
@keyframes restore { 50% { transform: scale(1.35); opacity: 1; } }

@media (max-width: 1040px) {
  .game { width: min(100% - 34px, 860px); }
  .stage { grid-template-columns: 110px minmax(0, 1fr) 125px; gap: 18px; }
  .statusline { display: none; }
  .story { padding: 27px 31px; }
}

@media (max-width: 700px) {
  .game { width: min(100% - 24px, 620px); padding-top: max(12px, env(safe-area-inset-top)); gap: 9px; }
  .gamebar-tools { gap: 11px; }
  .gamebar-tools .quiet-button:first-child { display: none; }
  .stage { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); gap: 8px; }
  .inventory { display: flex; align-items: center; gap: 14px; margin: 0; padding: 7px 0; }
  .inventory-items { display: flex; gap: 14px; margin: 0; }
  .inventory-item { grid-template-columns: 20px auto; font-size: 10px; }
  .empty-inventory { margin: 0; }
  .world-state { display: none; }
  .story { padding: 22px 20px; }
  .story-location h1 { font-size: clamp(42px, 13vw, 61px); }
  .story-rule { margin: 19px 0 16px; }
  .story-copy { font-size: 18px; }
  .moment { margin-top: 22px; font-size: 17px; }
  .command-deck { padding: 14px 15px 12px; }
  .feedback { margin-bottom: 12px; font-size: 15px; }
  .command-row input { font-size: 19px; }
  .journal-dialog { height: min(700px, calc(100dvh - 24px)); padding: 20px; }
}

@media (max-width: 430px) {
  .wordmark { font-size: 10px; }
  .quiet-button { font-size: 8px; }
  .gamebar-tools { gap: 9px; }
  .story-copy { font-size: 17px; }
  .send-command { padding: 8px 9px; }
  .gate-actions { flex-direction: column; }
}

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