:root {
  color-scheme: dark;
  --ink: #1c201e;
  --deep: #171b19;
  --surface: #242825;
  --raised: #303530;
  --line: #414640;
  --text: #eeeae0;
  --second: #c5c7bc;
  --muted: #a2a69b;
  --brass: #d6b879;
  --paper: #e9e2d0;
  --overlay: rgb(24 29 26 / 94%);
  --edge: clamp(16px, 2.3vw, 32px);
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  font: 14px/1.4 var(--ui);
  font-variant-numeric: tabular-nums;
}
* { box-sizing: border-box }
html, body { height: 100%; margin: 0; overflow: hidden }
body { display: flex; flex-direction: column; background: var(--deep); color: var(--text) }
button, input, select { font: inherit; color: inherit }
button { cursor: pointer; background: none; border: 0; padding: 0; touch-action: manipulation }
button:disabled { cursor: default; opacity: .5 }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px }
svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round }
.sprites, [hidden], #loading[hidden], #modal-back[hidden] { display: none }
header, footer { flex: none; background: var(--deep); z-index: 5; display: flex; align-items: center; padding-inline: var(--edge) }
header { height: 56px; gap: 24px; border-bottom: 1px solid var(--line) }
.brand, nav, .nav, .head-right, .friends, .on-status, .icon-btn, .mini-key, .day, .land-line, .quest-cap,
.hints, .hints > span, .foot-right, footer button, .purse, .weapon-caption, .row-inline, .panel-actions, .room-actions { display: flex; align-items: center }
.brand { gap: 8px; color: var(--paper) }
.brand img { width: 32px; height: 36px }
.brand span { font: 500 28px/1 var(--serif); letter-spacing: .12em; text-transform: uppercase }
.divider, .foot-right > i { width: 1px; height: 20px; background: var(--line) }
nav { align-self: stretch; gap: 4px }
.nav { position: relative; padding-inline: 12px; gap: 8px; font-size: 13px; color: var(--muted) }
.nav.active { color: var(--text) }
.nav.active::after { content: ""; position: absolute; inset: auto 12px 0; height: 2px; background: var(--brass) }
.nav:hover, .icon-btn:hover, footer button:hover { color: var(--text); background: var(--surface) }
.head-right { margin-left: auto; gap: 16px }
.on-status { color: var(--muted); gap: 8px; font-size: 12px }
.on-status i { display: none }
.on-status.online i { display: block; width: 6px; height: 6px; border-radius: 50%; background: #a4b696 }
.friends, .btn { justify-content: center; gap: 8px; border-radius: 5px; min-height: 36px; padding: 8px 12px; font-size: 13px; font-weight: 500 }
.friends { background: var(--paper); color: #252925 }
.friends:hover, .btn.primary:hover { background: #f6f0e1 }
.icon-btn { justify-content: center; width: 36px; height: 36px; border-radius: 4px; color: var(--second) }
main { position: relative; isolation: isolate; flex: 1; min-height: 0; overflow: hidden; background: #636d5e }
#scene, .vignette, #eye, #loading, #modal-back { position: absolute; inset: 0; width: 100%; height: 100% }
#scene { display: block; outline: 0; touch-action: none }
.vignette { pointer-events: none; background: linear-gradient(to top, rgb(13 19 16 / 28%), transparent 20%) }
#eye { pointer-events: none; display: none; background: linear-gradient(90deg, #101210 44%, transparent 54%) }

/* The region and its current order share one edge, leaving the trail clear. */
.field-notes { position: absolute; top: 20px; left: var(--edge); width: min(264px, 36vw); }
.location { width: fit-content; max-width: 100%; padding: 8px 16px 12px; color: #252b24; background: rgb(235 229 211 / 95%); border-radius: 2px; }
.land-line { gap: 8px; color: #4b5147; font: 500 12px/16px var(--ui) }
.land-number { padding-right: 8px; border-right: 1px solid #a9aa98; font: 14px/14px var(--serif); }
.location h1 { font: 400 clamp(25px, 2.3vw, 36px)/1.12 var(--serif); letter-spacing: -.035em; margin: 4px 0 }
.day { gap: 6px; color: #505548; font-size: 12px; line-height: 16px }
.day svg { width: 16px; height: 16px }
.quest { width: fit-content; max-width: 100%; margin-top: 8px; display: grid; text-align: left; grid-template-columns: 12px 1fr auto; align-items: baseline; gap: 2px 8px; padding: 8px 12px; color: var(--text); background: var(--overlay); border-radius: 2px }
.quest > svg { align-self: center; width: 12px; height: 12px; color: var(--brass); fill: var(--brass) }
.quest strong { font: 500 16px/20px var(--serif) }
#quest-distance { font: 12px/16px var(--ui); color: var(--brass); white-space: nowrap }
#quest-text { grid-column: 2 / -1; font-size: 12px; line-height: 16px; color: var(--second) }
.quest:hover, .hero-card:hover { background: #262d28 }
.compass { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); width: clamp(144px,22vw,304px); height: 32px; pointer-events: none }
.compass canvas { display: block; width: 100%; height: 100% }
.needle { position: absolute; left: calc(50% - 3px); top: -1px; border: 3px solid transparent; border-top: 5px solid var(--brass) }
.minimap-btn { position: absolute; top: 12px; right: var(--edge); width: clamp(108px,10.5vw,148px); display: grid; justify-items: center; }
#mini { width: 100%; height: auto; aspect-ratio: 1; display: block }
.mini-key { gap: 4px; padding: 1px 6px; margin-top: -4px; color: var(--text); font-size: 11px; background: var(--overlay); border-radius: 2px }
kbd { display: inline-block; background: var(--raised); border: 1px solid #52584f; border-radius: 3px; padding: 0 4px; font: 500 11px/16px var(--ui); color: var(--second); white-space: nowrap }
.mini-key kbd { border: 0; padding: 0; background: none }
#aim { pointer-events: none; position: absolute; top: 50%; left: 50%; width: 3px; height: 3px; border-radius: 50%; background: #f7efddbd }
#waypoint, .actor-label, #target-prompt, #notice { pointer-events: none; position: absolute; }
#waypoint, .actor-label { transform: translate(-50%, -100%) }
#waypoint { display: grid; justify-items: center; gap: 2px; color: var(--brass) }
#waypoint svg { width: 20px; height: 20px; fill: var(--brass); stroke: #524832; stroke-width: 1.5 }
#waypoint small, .actor-label { font-size: 11px; color: var(--text); padding: 0 4px; background: var(--overlay); border-radius: 2px; white-space: nowrap }
.actor-label.other { color: #e2bfaa }
#target-prompt, #notice { left: 50%; transform: translateX(-50%); bottom: 104px; text-align: center; color: var(--text); background: var(--ink); border: 1px solid var(--line); border-radius: 4px; padding: 8px 12px; font-size: 13px }
#notice { z-index: 6; bottom: 148px; max-width: calc(100% - 24px); width: max-content }
#target-prompt:empty, #notice:empty { display: none }

.hud { position: absolute; left: var(--edge); right: var(--edge); bottom: 16px; display: flex; align-items: end; justify-content: space-between; pointer-events: none }
.hud button { pointer-events: auto }
.hero-card { display: inline-flex; align-items: center; gap: 12px; padding: 8px 12px 8px 8px; min-width: 224px; color: var(--text); background: var(--overlay); border-radius: 4px; text-align: left }
.portrait { display: block; width: 52px; height: 60px; background: var(--raised); border-radius: 2px; overflow: hidden }
.portrait img { width: 100%; height: 100%; object-fit: cover }
.hero-info { flex: 1; display: grid; gap: 2px }
.hero-name { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 2px }
.hero-name strong { font: 400 18px/20px var(--serif) }
.hero-name small { font-size: 11px; color: var(--muted) }
.stat { display: grid; grid-template-columns: 12px minmax(24px,1fr) 28px; align-items: center; gap: 6px; }
.stat svg { width: 12px; height: 12px }
.healthico { color: #d79c89 } .stamico { color: #b9c8a3 }
.track { height: 4px; background: #40443c }
.track i { display: block; height: 100%; transform-origin: left; transition: transform .14s ease-out }
#hp { background: #cc8d7d } #stam { background: #a8b68c }
.stat em { color: var(--text); text-align: right; font: 500 14px/16px var(--ui) }
.quickbar { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); }
.bar-slots { display: flex; background: var(--overlay); padding: 4px; gap: 2px; border-radius: 4px }
.slot { position: relative; width: clamp(40px,3.7vw,52px); height: clamp(40px,3.7vw,52px); padding: 4px; background: rgb(238 234 224 / 4%); border-bottom: 2px solid transparent; border-radius: 2px }
.slot.selected { border-bottom-color: var(--brass); background: rgb(214 184 121 / 12%) }
.slot:hover { background: #41463b }
.slot img { width: 100%; height: 100%; object-fit: contain }
.slot kbd, .slot small { position: absolute; background: var(--ink); color: var(--second); font: 500 11px/14px var(--ui); border: 0; padding: 0 2px; border-radius: 2px }
.slot kbd { left: 1px; top: 0 } .slot small { bottom: 0; right: 1px; color: var(--text) }
.weapon-caption { justify-content: center; margin-top: 4px; }
#weapon-title { color: var(--text); background: var(--overlay); padding: 0 6px; border-radius: 2px; font: 12px/16px var(--serif) }
.purse { gap: 4px; padding: 4px 8px; font-size: 13px; background: var(--overlay); border-radius: 3px }
.purse svg { color: var(--brass) }
footer { height: 36px; justify-content: space-between; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px }
.hints { gap: 16px } .hints > span, footer button { gap: 6px }
.foot-right { gap: 8px } .foot-right > i { height: 16px }
.foot-right button { min-height: 28px; padding: 4px }
.touchcontrols { display: none }
#loading { z-index: 7; display: grid; place-content: center; justify-items: center; gap: 16px; background: var(--ink); font: 20px var(--serif) }
#loading img { width: 48px }

#modal-back { z-index: 8; display: grid; place-items: center; padding: 16px; background: rgb(13 17 14 / 62%) }
#panel { display: flex; flex-direction: column; width: min(480px,100%); max-height: 100%; min-height: 0; border-radius: 8px; overflow: hidden; outline: 0; background: var(--ink); color: var(--text); box-shadow: 0 12px 48px #0b0e0b66; border: 1px solid #52564d }
#panel.wide { width: min(620px,100%) }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); flex: none }
.panel-head h2 { margin: 0; font: 400 28px/32px var(--serif); letter-spacing: -.025em }
.panel-head .icon-btn { margin-right: -8px }
#panel-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px 20px 20px; scrollbar-color: #555b51 var(--ink) }
.panel-text, .item p, .faction p { font-size: 14px; line-height: 1.5; color: var(--second); margin: 0 0 12px }
.field-label, .identity-fields label { display: block; font-size: 12px; color: var(--second); line-height: 16px }
.field-label { margin-bottom: 4px }
input, select { background: var(--deep); color: var(--text); border: 1px solid #51574f; border-radius: 4px; width: 100%; min-width: 0; height: 40px; padding: 8px 12px }
input::placeholder { color: var(--muted) }
.row-inline, .panel-actions, .room-actions { gap: 8px }
.btn { display: inline-flex; align-items: center; flex-shrink: 0; background: var(--raised); border: 1px solid #52584f; color: var(--text) }
.btn:hover { background: #3e433e }
.btn.primary { background: var(--paper); color: #272b25; border-color: transparent }
.panel-actions { flex-wrap: wrap; margin-top: 16px }
.rule { border: 0; border-top: 1px solid var(--line); margin: 16px 0 }
.identity-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px }
.identity-fields input, .identity-fields select { margin-top: 4px }
.invite-block { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px 12px; }
.roomcode { display: block; color: var(--brass); font: 500 32px/36px ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .06em }
#invite-link { grid-column: 1/-1; height: 32px; background: var(--surface); font-size: 12px; color: var(--second); border-color: var(--line); user-select: all }
.roster-head, .line-action, .item, .faction, .setting { display: flex; align-items: center; gap: 12px }
.roster-head { margin-top: 16px; padding-bottom: 4px; justify-content: space-between; color: var(--muted); font-size: 12px }
.roster-head h3 { margin: 0; color: var(--text); font: 500 14px var(--ui) }
.room-guests { padding: 0; margin: 0; list-style: none }
.room-guests li { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 8px; min-height: 40px; border-top: 1px solid var(--line) }
.room-guests li > img { width: 28px; height: 28px; object-fit: cover; background: var(--raised); border-radius: 3px }
.room-guests li > span { overflow-wrap: anywhere }
.room-guests em { margin-left: 4px; color: var(--muted); font: 12px var(--ui) }
.room-guests small, .dim { color: var(--muted); font-size: 12px }
.room-actions { justify-content: space-between; border-top: 1px solid var(--line); padding-top: 12px; }
.room-actions [data-act="leave"] { border-color: transparent; background: none; color: var(--second) }
.room-actions [data-act="leave"]:hover { background: var(--raised) }
.item, .faction, .line-action, .journal-entry { padding: 12px 0; border-bottom: 1px solid var(--line) }
.item strong, .faction strong, .journal-entry strong { font: 500 20px/24px var(--serif) }
.item p, .faction p { font-size: 13px; margin: 4px 0 0 }
.faction img { width: 48px; height: 52px; object-fit: contain; border-radius: 3px; background: var(--raised) }
.item .btn, .faction .btn, .faction .dim { flex: none; margin-left: auto }
.line-action { min-height: 40px; width: 100%; justify-content: space-between; text-align: left }
.line-action:hover { background: var(--surface) }
.quest-cap { gap: 8px; color: var(--second); font-size: 13px }
.quest-cap svg { color: var(--brass); fill: var(--brass) }
.journal-entry p { margin: 4px 0; color: var(--second) }
.journal-entry small { color: var(--muted) }
.status-tags, .map-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; color: var(--second); font-size: 12px; margin-block: 8px }
.map-legend b { color: var(--brass) }
.map-frame { width: min(100%,55vh); aspect-ratio: 1; height: auto; margin: auto; display: block }
.controls-grid { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; align-items: center; margin-bottom: 16px }
.controls-grid kbd { justify-self: start }
.setting { justify-content: space-between; margin: 0 0 12px }
.setting input, .setting select { width: 46% }
input[type="range"] { accent-color: var(--brass) }
.error { color: #edb99c; margin: 8px 0 0 }
.error:empty { display: none }
#room-code { text-transform: uppercase } #room-code::placeholder { text-transform: none }

@media (max-width: 960px) {
  header { gap: 16px } .head-right { gap: 8px } .on-status { display: none }
  .hero-card { min-width: 192px; gap: 8px } .portrait { width: 44px; height: 56px }
  .hints { gap: 8px } .hints > span:nth-child(2) { display: none }
}
@media (max-width: 700px) {
  :root { --edge: 12px }
  header { height: 48px; gap: 8px }
  .brand { gap: 4px } .brand img { width: 24px } .brand span { font-size: 20px }
  .divider { display: none } nav { gap: 0 } .nav { padding: 0 8px }
  .nav > span { display: none } .nav.active::after { inset-inline: 6px }
  .friends { font-size: 12px; min-height: 32px; padding: 4px 8px }
  .head-right { gap: 4px } .settings-top { width: 32px }
  .field-notes { top: 12px; width: min(210px,55vw) }
  .location { padding: 8px 12px } .location h1 { font-size: 23px; margin: 2px 0 }
  .land-line, .day { font-size: 11px } .quest { gap: 2px 4px; margin-top: 4px; padding: 6px 8px }
  .quest strong { font-size: 15px } #quest-text { font-size: 12px }
  .compass { display: none } .minimap-btn { width: 92px }
  .hud { bottom: 12px } .hero-card { min-width: 0; gap: 6px; padding: 4px 8px 4px 4px }
  .hero-name { gap: 4px } .hero-name strong { font-size: 15px } .portrait { width: 32px; height: 48px }
  .stat { grid-template-columns: 12px minmax(20px,1fr) 24px; gap: 4px }
  .stat em { font-size: 12px } .quickbar { position: static; transform: none } .purse { display: none }
  .slot { width: 36px; height: 36px } .bar-slots { padding: 2px; gap: 1px } .weapon-caption { margin-top: 2px }
  footer { height: 32px; justify-content: flex-end } .hints { display: none }
  #panel { border-radius: 6px } .panel-head { padding: 12px 16px } .panel-head h2 { font-size: 24px }
  #panel-body { padding: 12px 16px 16px } .identity-fields { gap: 8px }
  .faction img { width: 36px; height: 44px }
}
@media (max-width: 370px) {
  :root { --edge: 8px } header { gap: 4px } .nav { padding-inline: 6px }
  .hero-card .portrait { width: 24px } .invite-block { column-gap: 4px }
  .invite-block .btn { font-size: 12px; padding: 8px } .roomcode { font-size: 24px }
}
@media (max-height: 540px) {
  header { height: 44px } footer { height: 28px }
  .field-notes, .minimap-btn { top: 8px } .minimap-btn { width: 84px }
  .location { padding: 6px 12px } .location h1 { font-size: 24px; margin: 0 }
  .hud { bottom: 8px } .quest { margin-top: 4px }
  #modal-back { padding: 8px } .panel-head { padding: 8px 16px } .panel-head h2 { font-size: 24px; line-height: 28px }
  #panel-body { padding: 12px 16px } .roster-head { margin-top: 8px } .room-guests li { min-height: 36px }
}
@media (pointer: coarse) {
  .touchcontrols { position: absolute; inset: auto var(--edge) 84px; display: flex; align-items: end; justify-content: space-between; pointer-events: none }
  #stick { width: 72px; height: 72px; border-radius: 50%; border: 1px solid #d5d5c7a3; background: rgb(25 30 25 / 60%); display: grid; place-items: center; touch-action: none; pointer-events: auto }
  #stick i { width: 28px; height: 28px; border-radius: 50%; background: #bfc4ace8 }
  .touch-actions { display: flex; gap: 4px }
  .touch-actions button { width: 44px; height: 44px; border-radius: 50%; background: var(--overlay); border: 1px solid #777c6d; pointer-events: auto; touch-action: manipulation; }
  .touch-actions svg { vertical-align: middle }
  #target-prompt { bottom: 164px }
}
@media (prefers-reduced-motion: reduce) { .track i { transition: none } }
