:root {
  --ink: #06101d;
  --ink-2: #0b1b2c;
  --ink-3: #102a3a;
  --parchment: #f2e6c9;
  --parchment-dim: #c9ba96;
  --gold: #e2b85c;
  --gold-hot: #ffd989;
  --copper: #9f6235;
  --blue: #71b7d8;
  --green: #6fb477;
  --red: #db6a5f;
  --shadow: rgba(0, 0, 0, 0.48);
  --panel: rgba(7, 18, 31, 0.94);
  --line: rgba(226, 184, 92, 0.34);
  --radius: 8px;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #030912; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--parchment);
  background:
    radial-gradient(circle at 50% -20%, rgba(44, 100, 126, 0.28), transparent 48%),
    linear-gradient(150deg, #030912 0%, #0a1625 48%, #050c16 100%);
  font-family: Inter, system-ui, sans-serif;
  overflow-x: hidden;
}

button { font: inherit; }
button:focus-visible, canvas:focus-visible { outline: 2px solid var(--gold-hot); outline-offset: 3px; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--gold);
  font: 600 10px/1.2 Inter, sans-serif;
  letter-spacing: .16em;
  text-transform: uppercase;
}

kbd {
  display: inline-flex;
  min-width: 20px;
  min-height: 19px;
  padding: 1px 5px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(242, 230, 201, .28);
  border-bottom-color: rgba(242, 230, 201, .12);
  border-radius: 3px;
  color: var(--parchment-dim);
  background: rgba(255, 255, 255, .045);
  font: 600 10px/1 Inter, sans-serif;
  box-shadow: 0 1px 0 rgba(255,255,255,.05) inset;
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  isolation: isolate;
  background:
    linear-gradient(rgba(3, 9, 18, .34), rgba(3, 9, 18, .82)),
    url('assets/asterra-atlas.png') center 2% / min(1180px, 130vw) auto no-repeat,
    #030912;
}

.splash::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(circle at 50% 28%, transparent 0 10%, #030912 70%);
}

.splash__mist {
  position: absolute;
  inset: auto 0 0;
  height: 45%;
  background: linear-gradient(transparent, rgba(4, 11, 20, .96));
  pointer-events: none;
}

.splash__card {
  position: relative;
  width: min(680px, 100%);
  padding: 42px clamp(24px, 7vw, 72px) 34px;
  text-align: center;
  border: 1px solid rgba(226, 184, 92, .46);
  border-radius: 4px;
  background:
    linear-gradient(145deg, rgba(16, 42, 58, .94), rgba(5, 14, 26, .97)),
    var(--ink);
  box-shadow: 0 26px 100px rgba(0, 0, 0, .72), 0 0 0 5px rgba(3,9,18,.78), 0 0 90px rgba(65, 133, 158, .13) inset;
}

.splash__card::before,
.splash__card::after {
  content: '✦';
  position: absolute;
  top: 10px;
  color: var(--gold);
  opacity: .72;
}
.splash__card::before { left: 12px; }
.splash__card::after { right: 12px; }

.crest {
  position: relative;
  width: 88px;
  height: 88px;
  margin: -82px auto 28px;
  border: 1px solid var(--gold);
  border-radius: 50%;
  background: radial-gradient(circle, #183951 0 43%, #07111f 45% 100%);
  box-shadow: 0 0 0 7px #06101d, 0 0 0 8px rgba(226,184,92,.45), 0 8px 34px rgba(0,0,0,.6);
}
.crest__ring { position: absolute; inset: 13px; border: 1px dashed rgba(226,184,92,.58); border-radius: 50%; }
.crest__needle { position: absolute; width: 4px; height: 54px; left: 41px; top: 16px; background: linear-gradient(var(--parchment) 0 48%, var(--red) 49%); clip-path: polygon(50% 0,100% 48%,70% 100%,30% 100%,0 48%); transform: rotate(27deg); }
.crest__gem { position: absolute; inset: 35px; border: 2px solid var(--gold-hot); background: #1c8394; transform: rotate(45deg); box-shadow: 0 0 14px #53c6d5; }

.splash h1 {
  margin: 6px 0 12px;
  color: #fff5d8;
  font: 700 clamp(34px, 7vw, 64px)/.95 Cinzel, Georgia, serif;
  letter-spacing: -.035em;
  text-shadow: 0 3px 0 #5b3420, 0 9px 30px rgba(0,0,0,.75);
}
.splash__dek { max-width: 510px; margin: 0 auto 26px; color: var(--parchment-dim); font: 400 15px/1.65 Inter, sans-serif; }
.splash__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.button {
  padding: 12px 18px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--parchment);
  background: rgba(255,255,255,.035);
  cursor: pointer;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.button:hover { transform: translateY(-2px); border-color: var(--gold); background: rgba(226,184,92,.08); }
.button--primary { color: #171006; border-color: var(--gold); background: linear-gradient(#f0cc79, #b97834); font-weight: 700; box-shadow: 0 5px 18px rgba(0,0,0,.38); }
.button--primary:hover { background: linear-gradient(#ffe19b, #c98a42); }
.splash__controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 9px 16px; margin-top: 28px; color: #8fa4ae; font-size: 11px; }
.splash__note { margin: 18px 0 0; color: #71858e; font-size: 10px; }

.game-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 14px clamp(10px, 2vw, 24px) 30px;
}

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.brand-lockup { display: flex; align-items: center; gap: 10px; }
.brand-lockup__mark { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--gold); transform: rotate(45deg); color: var(--gold-hot); background: var(--ink-2); }
.brand-lockup__mark::first-letter { transform: rotate(-45deg); }
.brand-lockup__overline { display: block; color: #76929c; font: 600 9px/1.2 Inter, sans-serif; letter-spacing: .13em; text-transform: uppercase; }
.brand-lockup strong { color: #fff1ce; font: 600 18px/1.2 Cinzel, serif; }
.realm-state { display: flex; align-items: center; gap: 7px; }
.state-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 5px 9px; border: 1px solid rgba(255,255,255,.08); border-radius: 4px; color: #91a7b1; background: rgba(255,255,255,.025); font-size: 11px; }
.state-chip b { color: var(--parchment); font-weight: 600; }
.moon-disc { width: 15px; height: 15px; border-radius: 50%; background: var(--parchment); box-shadow: inset 5px 0 0 #53677a, 0 0 6px rgba(242,230,201,.35); }
.icon-button { width: 32px; height: 32px; border: 1px solid rgba(255,255,255,.1); border-radius: 4px; color: var(--gold); background: rgba(255,255,255,.03); cursor: pointer; }
.icon-button:hover { border-color: var(--gold); background: rgba(226,184,92,.08); }

.game-grid { display: grid; grid-template-columns: minmax(540px, 1fr) 320px; gap: 14px; align-items: start; }
.play-column { min-width: 0; }
.viewport-frame { position: relative; padding: 8px; border: 1px solid rgba(226,184,92,.54); border-radius: 7px; background: linear-gradient(145deg, #4f2d1d, #21130f 48%, #674225); box-shadow: 0 18px 48px var(--shadow), 0 0 0 1px #0a1118 inset; }
.viewport-frame::before, .viewport-frame::after { content: '◆'; position: absolute; top: 50%; z-index: 2; color: var(--gold); font-size: 9px; transform: translateY(-50%); }
.viewport-frame::before { left: 1px; }
.viewport-frame::after { right: 1px; }
.viewport-bezel { position: relative; overflow: hidden; aspect-ratio: 1; border: 2px solid #07101a; border-radius: 3px; background: #02070c; }
#world { display: block; width: 100%; height: 100%; image-rendering: pixelated; background: #071624; cursor: crosshair; }
.canvas-vignette { position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 34px rgba(0,0,0,.55), inset 0 0 0 1px rgba(242,230,201,.12); }
.context-toast { position: absolute; left: 50%; bottom: 14px; z-index: 4; max-width: calc(100% - 24px); padding: 7px 12px; transform: translateX(-50%) translateY(12px); border: 1px solid rgba(226,184,92,.34); border-radius: 4px; opacity: 0; color: var(--parchment); background: rgba(4,10,17,.9); font-size: 11px; pointer-events: none; transition: opacity .18s, transform .18s; }
.context-toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.mode-banner { position: absolute; top: 12px; left: 50%; z-index: 4; padding: 6px 12px; transform: translateX(-50%); border: 1px solid var(--gold); border-radius: 3px; color: #171006; background: var(--gold-hot); font: 700 10px/1 Inter, sans-serif; letter-spacing: .09em; text-transform: uppercase; box-shadow: 0 3px 18px rgba(0,0,0,.48); }

.dialogue-panel, .map-panel, .help-panel {
  position: absolute;
  inset: auto 14px 14px;
  z-index: 10;
  max-height: calc(100% - 28px);
  overflow: auto;
  border: 1px solid var(--gold);
  border-radius: 6px;
  background: linear-gradient(145deg, rgba(15,37,52,.985), rgba(4,12,22,.99));
  box-shadow: 0 18px 70px rgba(0,0,0,.82), 0 0 0 4px rgba(3,9,18,.65);
}
.dialogue-panel { display: grid; grid-template-columns: 112px 1fr; gap: 16px; padding: 18px; }
.dialogue-portrait { width: 112px; aspect-ratio: .82; align-self: start; border: 1px solid var(--line); border-radius: 4px; background-color: #07111f; background-image: url('assets/asterra-atlas.png'); background-repeat: no-repeat; box-shadow: inset 0 0 18px rgba(0,0,0,.44); }
.dialogue-copy h2, .panel-heading h2 { margin: 0 0 8px; color: #fff0cd; font: 600 19px/1.15 Cinzel, serif; }
.dialogue-copy > p:not(.eyebrow) { margin: 0; color: #d9cfb5; font: 400 13px/1.62 Inter, sans-serif; }
.dialogue-close { position: absolute; top: 7px; right: 8px; width: 29px; height: 29px; border: 0; color: #8da0a9; background: transparent; font-size: 24px; cursor: pointer; }
.dialogue-close:hover { color: var(--gold-hot); }
.dialogue-choices { display: grid; gap: 7px; margin-top: 14px; }
.dialogue-choices button { display: flex; gap: 9px; width: 100%; padding: 9px 10px; border: 1px solid rgba(226,184,92,.25); border-radius: 3px; color: var(--parchment); text-align: left; background: rgba(255,255,255,.03); cursor: pointer; }
.dialogue-choices button:hover { border-color: var(--gold); background: rgba(226,184,92,.08); }
.choice-index { color: var(--gold); }
.map-panel, .help-panel { inset: 14px; padding: 18px; }
.panel-heading { display: flex; align-items: start; justify-content: space-between; padding-right: 30px; }
#map-canvas { display: block; width: min(100%, 520px); height: auto; margin: 8px auto; border: 1px solid rgba(226,184,92,.28); background: #02070c; image-rendering: pixelated; }
.map-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 10px 0 0; color: #8399a3; font-size: 10px; }
.map-legend span { width: 8px; height: 8px; margin-right: -5px; border-radius: 50%; }
.legend-you { background: #fff3ae; box-shadow: 0 0 6px #fff3ae; }
.legend-place { background: var(--gold); }
.legend-dark { background: #142331; }
.help-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; margin-top: 12px; }
.help-grid div { display: flex; align-items: center; gap: 10px; padding: 9px; border: 1px solid rgba(255,255,255,.07); background: rgba(255,255,255,.025); font-size: 11px; }
.help-grid kbd { min-width: 64px; }
.help-tip { margin: 14px 0 0; color: var(--parchment-dim); font: 400 11px/1.55 Inter, sans-serif; }

.command-deck { display: grid; grid-template-columns: repeat(8, minmax(0,1fr)); gap: 5px; margin-top: 9px; }
.command-deck button { position: relative; display: grid; place-items: center; min-height: 58px; padding: 7px 3px 5px; border: 1px solid rgba(226,184,92,.22); border-radius: 4px; color: var(--parchment-dim); background: linear-gradient(rgba(19,45,60,.76), rgba(7,18,31,.9)); cursor: pointer; box-shadow: 0 2px 0 #02070d; transition: transform .12s, border-color .12s, color .12s; }
.command-deck button:hover { transform: translateY(-1px); border-color: var(--gold); color: #fff1ce; }
.command-deck button:active { transform: translateY(1px); }
.command-deck button b { font: 600 10px/1 Inter, sans-serif; }
.command-deck button kbd { position: absolute; top: 4px; right: 4px; min-width: 16px; min-height: 15px; padding: 1px 3px; font-size: 8px; opacity: .72; }
.command-icon { color: var(--gold); font-size: 18px; line-height: 1; }

.status-column { display: grid; gap: 10px; }
.status-card { position: relative; padding: 14px; overflow: hidden; border: 1px solid rgba(226,184,92,.24); border-radius: var(--radius); background: linear-gradient(145deg, rgba(13,34,48,.92), rgba(5,15,27,.96)); box-shadow: 0 10px 28px rgba(0,0,0,.22), inset 0 0 24px rgba(79,137,153,.035); }
.status-card::after { content: ''; position: absolute; inset: 5px; border: 1px solid rgba(255,255,255,.025); pointer-events: none; }
.card-heading { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-heading h2 { margin: 0; color: #f9e8bd; font: 600 15px/1.2 Cinzel, serif; }
.party-count, .compass-score, .gold-readout { color: var(--gold); font-size: 10px; }
.party-list { position: relative; z-index: 1; display: grid; gap: 6px; }
.party-member { display: grid; grid-template-columns: 42px 1fr auto; gap: 9px; align-items: center; padding: 6px; border: 1px solid rgba(255,255,255,.055); border-radius: 4px; background: rgba(255,255,255,.022); }
.party-member.is-wounded { border-color: rgba(219,106,95,.36); }
.party-avatar { width: 42px; height: 46px; border: 1px solid rgba(226,184,92,.22); border-radius: 3px; background-color: #07111f; background-image: url('assets/asterra-atlas.png'); background-repeat: no-repeat; }
.party-meta strong { display: block; color: #eaddbc; font: 600 11px/1.2 Inter, sans-serif; }
.party-meta span { color: #6f8994; font-size: 9px; }
.hp-track { height: 4px; margin-top: 5px; overflow: hidden; border-radius: 10px; background: #02080e; }
.hp-track i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #4f9f68, #8fca7b); }
.party-stats { color: #9aadb4; font: 600 9px/1.4 Inter, sans-serif; text-align: right; }
.party-stats b { display: block; color: var(--parchment); font-size: 11px; }

.virtue-list { position: relative; z-index: 1; display: grid; gap: 8px; }
.virtue { display: grid; grid-template-columns: 73px 1fr 25px; gap: 7px; align-items: center; }
.virtue-name { color: #bcc7c6; font-size: 10px; }
.virtue-track, .quest-progress { height: 5px; overflow: hidden; border-radius: 20px; background: #02080e; box-shadow: inset 0 1px 2px #000; }
.virtue-track i, .quest-progress span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #3f8190, var(--gold)); transition: width .4s ease; }
.virtue-value { color: var(--gold); font: 600 9px/1 Inter, sans-serif; text-align: right; }
.quest-card > p { position: relative; z-index: 1; margin: 0 0 10px; color: #aebcb9; font: 400 11px/1.55 Inter, sans-serif; }
.quest-progress { position: relative; z-index: 1; }
.mini-button { position: relative; z-index: 2; padding: 5px 7px; border: 1px solid rgba(226,184,92,.25); border-radius: 3px; color: var(--gold); background: rgba(255,255,255,.025); font-size: 9px; cursor: pointer; }
.mini-button:hover { border-color: var(--gold); }
.inventory-grid { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.item-slot { position: relative; min-height: 48px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.07); border-radius: 3px; background: rgba(2,8,14,.58); cursor: pointer; }
.item-slot:hover { border-color: rgba(226,184,92,.48); }
.item-slot.is-empty { cursor: default; opacity: .45; }
.item-glyph { color: var(--gold-hot); font-size: 21px; filter: drop-shadow(0 2px 3px #000); }
.item-count { position: absolute; right: 4px; bottom: 3px; color: #fff0c7; font: 600 9px/1 Inter, sans-serif; }
.item-label { position: absolute; left: 3px; top: 3px; color: #6d838c; font-size: 7px; text-transform: uppercase; }

.message-console { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: start; min-height: 92px; margin-top: 11px; padding: 12px 14px; border: 1px solid rgba(226,184,92,.28); border-radius: 6px; background: linear-gradient(100deg, rgba(5,15,27,.97), rgba(11,29,42,.93)); box-shadow: 0 10px 32px rgba(0,0,0,.22); }
.console-ornament { display: grid; place-items: center; width: 26px; height: 26px; border: 1px solid var(--gold); border-radius: 50%; color: var(--gold); font-size: 10px; }
#message-log { max-height: 57px; overflow: auto; color: #aab8b6; font: 400 11px/1.55 Inter, sans-serif; scrollbar-width: thin; }
#message-log p { margin: 0 0 2px; }
#message-log p:first-child { color: #f1dfb9; }
#message-log .good { color: #8cc995; }
#message-log .danger { color: #e68778; }
#message-log .gold { color: var(--gold-hot); }

.mobile-controls { display: none; }

@media (min-width: 981px) and (max-height: 820px) {
  .play-column {
    width: calc(100vh - 148px);
    max-width: 100%;
    min-width: 540px;
    justify-self: center;
  }

  .game-grid {
    grid-template-columns: minmax(540px, 1fr) 320px;
  }

  .message-console {
    width: min(1160px, 100%);
    margin-inline: auto;
  }
}

@media (max-width: 980px) {
  .game-grid { grid-template-columns: minmax(0, 1fr); }
  .status-column { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .party-card, .compass-card { min-height: 180px; }
  .inventory-card, .quest-card { min-height: 132px; }
}

@media (max-width: 680px) {
  .game-shell { padding: 6px 6px calc(110px + env(safe-area-inset-bottom)); }
  .topbar { min-height: 48px; margin-bottom: 6px; padding: 4px 3px 7px; }
  .brand-lockup__overline { display: none; }
  .brand-lockup strong { font-size: 14px; }
  .brand-lockup__mark { width: 27px; height: 27px; }
  .state-chip { min-height: 28px; padding: 4px 6px; }
  .moon-chip b { display: none; }
  .viewport-frame { padding: 4px; border-radius: 4px; }
  .command-deck { grid-template-columns: repeat(4, 1fr); }
  .command-deck button { min-height: 49px; }
  .status-column { grid-template-columns: 1fr; }
  .quest-card, .inventory-card { min-height: 0; }
  .dialogue-panel { grid-template-columns: 74px 1fr; gap: 11px; inset: auto 7px 7px; padding: 12px; }
  .dialogue-portrait { width: 74px; }
  .help-grid { grid-template-columns: 1fr; }
  .message-console { margin-bottom: 6px; }
  .mobile-controls { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; display: flex; align-items: end; justify-content: space-between; gap: 12px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(226,184,92,.34); background: rgba(3,9,17,.94); backdrop-filter: blur(12px); }
  .dpad { display: grid; grid-template: repeat(3, 31px) / repeat(3, 40px); gap: 3px; }
  .dpad button, .mobile-actions button { border: 1px solid rgba(226,184,92,.28); border-radius: 4px; color: var(--parchment); background: #102537; }
  .dpad [data-move="up"] { grid-area: 1/2; }
  .dpad [data-move="left"] { grid-area: 2/1; }
  .dpad [data-action="wait"] { grid-area: 2/2; color: var(--gold); }
  .dpad [data-move="right"] { grid-area: 2/3; }
  .dpad [data-move="down"] { grid-area: 3/2; }
  .mobile-actions { display: grid; grid-template-columns: repeat(3,1fr); gap: 5px; flex: 1; max-width: 250px; }
  .mobile-actions button { min-height: 48px; color: var(--gold-hot); font-size: 11px; }
}

@media (max-width: 430px) {
  .splash__card { padding: 35px 17px 23px; }
  .splash h1 { font-size: 38px; }
  .splash__controls { display: none; }
  .state-chip:first-child { display: none; }
  .command-deck button kbd { display: none; }
  .dialogue-panel { grid-template-columns: 1fr; }
  .dialogue-portrait { display: none; }
}

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