.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 16px;
  min-height: 68px;
  padding: 9px max(14px, calc((100vw - 1180px) / 2));
  color: var(--paper-pale);
  background: rgba(29, 25, 49, .97);
  border-bottom: 3px solid #0f0d1d;
  box-shadow: 0 4px 0 rgba(33, 29, 56, .14);
}

.brand { display: flex; align-items: center; gap: 9px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; width: 38px; height: 38px; place-items: center; border: 2px solid currentColor; font-size: 1.25rem; font-weight: 900; box-shadow: 3px 3px 0 #776a8b; }
.brand strong, .brand small { display: block; white-space: nowrap; }
.brand strong { font-size: .95rem; letter-spacing: .04em; }
.brand small { margin-top: 2px; color: #c6bdd2; font-size: .58rem; }

.wallet { display: grid; grid-template-columns: auto auto; column-gap: 5px; align-items: center; min-width: 74px; color: #f3d486; }
.wallet strong { font-size: 1rem; }
.wallet small { grid-column: 1 / -1; color: #b8afc4; font-size: .54rem; text-transform: uppercase; letter-spacing: .1em; }

.top-actions { display: flex; justify-content: flex-end; gap: 6px; }
.compact-button { position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 7px 10px; color: var(--paper-pale); border-color: #766e89; background: #29243f; box-shadow: none; }
.compact-button:hover:not(:disabled) { background: #37304f; }
.badge { position: absolute; top: -6px; right: -5px; min-width: 18px; padding: 2px 4px; color: var(--ink); background: #f3d486; border-radius: 10px; font-size: .58rem; text-align: center; }
.browsertoys-link { color: #cfc7da; font-size: .67rem; white-space: nowrap; }

.game-shell { width: min(1180px, calc(100% - 28px)); margin: 24px auto 40px; }
.map-card, .panel { min-width: 0; border: 1px solid var(--line-dark); background: rgba(251, 245, 232, .9); box-shadow: var(--pixel-shadow); }
.map-card { padding: clamp(14px, 2.5vw, 26px); }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.world-clock { color: var(--ink-soft); font-size: .72rem; text-align: right; }

.journey-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 45px;
  margin-top: 16px;
  padding: 9px 12px;
  color: var(--paper-pale);
  background: var(--ink);
  border-left: 5px solid #f3d486;
  font-size: .72rem;
}
.journey-banner strong { color: #f3d486; }
.journey-banner .progress-track { flex: 0 1 210px; height: 8px; border: 1px solid #817a94; background: #121021; }
.journey-banner .progress-fill { display: block; height: 100%; background: #f3d486; }

.map-wrap { position: relative; max-width: 920px; margin: 5px auto 0; }
.rail-map { display: block; width: 100%; height: auto; min-height: 360px; overflow: visible; }
.route-line-under { fill: none; stroke: var(--paper-pale); stroke-width: 15; stroke-linejoin: round; stroke-linecap: round; }
.route-line { fill: none; stroke-width: 8; stroke-linejoin: round; stroke-linecap: round; opacity: .92; }
.route-line.is-highlighted { stroke-width: 12; filter: drop-shadow(0 0 3px rgba(33,29,56,.2)); }
.station-node { cursor: pointer; }
.station-node .station-dot { fill: var(--paper-pale); stroke: var(--ink); stroke-width: 3; }
.station-node .station-hit { fill: transparent; }
.station-node .station-label { fill: var(--ink); font-size: 12px; font-weight: 700; paint-order: stroke; stroke: var(--paper-pale); stroke-width: 4px; stroke-linejoin: round; }
.station-node .station-label-note { font-size: 10px; }
.station-node:hover .station-dot, .station-node.is-selected .station-dot { fill: #f3d486; }
.station-node.is-current .station-dot { fill: var(--ink); stroke: #fff7e4; stroke-width: 4; }
.station-node.is-goal .station-dot { stroke: #c35161; stroke-width: 6; }
.station-node.is-destination .station-dot { fill: #f3d486; stroke: #c35161; stroke-width: 5; }
.train-dot { stroke: var(--paper-pale); stroke-width: 2; filter: drop-shadow(1px 2px 0 rgba(33,29,56,.32)); }
.train-window { fill: var(--paper-pale); pointer-events: none; }
.player-marker { fill: #f3d486; stroke: var(--ink); stroke-width: 3; filter: drop-shadow(2px 2px 0 rgba(33,29,56,.24)); }
.player-marker-core { fill: var(--ink); }
.player-pulse { fill: none; stroke: var(--ink); stroke-width: 2; transform-box: fill-box; transform-origin: center; animation: marker-pulse 1.8s steps(4, end) infinite; }

.map-legend { position: absolute; right: 4px; bottom: 9px; display: grid; gap: 4px; padding: 8px; background: rgba(251,245,232,.9); border: 1px solid var(--line); font-size: .6rem; }
.legend-line { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 20px; height: 5px; background: var(--swatch); }

.station-inspection { min-height: 55px; margin-top: 2px; padding: 10px 12px; border: 1px dashed var(--line); color: var(--ink-soft); font-size: .72rem; line-height: 1.45; }
.station-inspection strong { color: var(--ink); }
.station-index { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.station-index button { min-height: 32px; padding: 5px 8px; border-color: var(--line); box-shadow: none; font-size: .62rem; }
.station-index button[aria-pressed="true"] { color: var(--paper-pale); background: var(--ink); }
.home-index-tag, .ticket-home-tag, .home-inline { display: inline-block; padding: 2px 4px; color: var(--ink); background: #f3d486; border: 1px solid #8b6e34; font-size: .52rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; vertical-align: middle; }
.station-index button[aria-pressed="true"] .home-index-tag { border-color: #f3d486; }

.panel-grid { display: grid; grid-template-columns: minmax(300px, .8fr) minmax(400px, 1.2fr); gap: 18px; margin-top: 18px; align-items: start; }
.panel { padding: clamp(14px, 2vw, 22px); }
.panel-intro { margin: 8px 0 16px; color: var(--ink-soft); font-size: .72rem; line-height: 1.5; }
.subheading { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 20px 0 8px; padding-top: 12px; border-top: 1px dashed var(--line); }
.subheading:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.subheading span { color: var(--ink-soft); font-size: .62rem; }

.line-group { margin-top: 12px; padding: 11px; border: 1px solid var(--line); background: #f6efdf; }
.line-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .78rem; }
.line-dot { width: 10px; height: 10px; background: var(--line-color); border-radius: 50%; }
.ticket-list { display: grid; gap: 7px; margin-top: 9px; }
.ticket-option { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; width: 100%; min-height: 51px; padding: 8px 10px; text-align: left; border-color: #918979; background: var(--paper-pale); box-shadow: none; }
.ticket-option strong { font-size: .7rem; }
.ticket-option small { color: var(--ink-soft); font-size: .68rem; line-height: 1.4; }
.ticket-option .fare { grid-row: 1 / 3; grid-column: 2; font-weight: 700; color: #71522c; }
.ticket-home-tag { margin-left: 4px; }
.community-pass { margin-top: 14px; padding: 11px; border: 1px solid #758e72; background: #edf0df; font-size: .68rem; line-height: 1.45; }
.community-pass button { width: 100%; margin-top: 8px; background: #f7f4de; }
.journey-card { padding: 15px; border: 1px solid var(--ink); background: #f7f0df; }
.journey-card .big-status { margin: 8px 0; font-size: 1.05rem; font-weight: 700; }
.journey-card dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; margin: 14px 0 0; font-size: .68rem; }
.journey-card dt { color: var(--ink-soft); }
.journey-card dd { margin: 0; text-align: right; font-weight: 700; }

.station-hero { position: relative; display: grid; grid-template-columns: 104px 1fr; gap: 14px; min-height: 110px; padding: 12px; overflow: hidden; color: var(--paper-pale); background: var(--ink); border-left: 8px solid var(--station-accent); }
.station-hero::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(255,255,255,.02) 3px 4px); }
.station-flair { z-index: 1; width: 104px; height: 78px; object-fit: contain; image-rendering: pixelated; }
.station-hero h2 { position: relative; z-index: 1; margin-top: 8px; font-size: 1.35rem; }
.station-hero p { position: relative; z-index: 1; margin: 8px 0 0; color: #d1c9d8; font-size: .7rem; line-height: 1.45; }
.arrival-in { animation: arrival-in 340ms steps(5, end); }
.locked-panel { padding: 18px; border: 1px dashed var(--line-dark); color: var(--ink-soft); background: #eee5d3; font-size: .74rem; line-height: 1.6; }

.card-list { display: grid; gap: 9px; }
.resident-card, .shop-card, .stray-card, .job-card, .pet-card, .inventory-card, .visitor-card { border: 1px solid var(--line); background: var(--paper-pale); }
.resident-card, .visitor-card { display: grid; grid-template-columns: 52px 1fr; gap: 10px; padding: 10px; }
.portrait { width: 48px; height: 48px; border: 1px solid var(--line-dark); background: #dad0bb; image-rendering: pixelated; }
.resident-card p, .visitor-card p { margin: 5px 0 0; color: var(--ink-soft); font-size: .68rem; line-height: 1.45; }
.resident-card .role, .visitor-card .role { color: #766e7d; font-size: .57rem; text-transform: uppercase; letter-spacing: .07em; }
.offer-box { grid-column: 1 / -1; margin-top: 2px; padding: 9px; border-left: 3px solid var(--rose); background: #efe2d4; font-size: .69rem; line-height: 1.45; }
.offer-box button, .job-action { width: 100%; margin-top: 8px; }

.shop-card { display: grid; grid-template-columns: 42px 1fr auto; gap: 9px; align-items: center; padding: 9px; }
.item-icon { width: 38px; height: 38px; padding: 3px; color: var(--ink); background: #e5dac3; border: 1px solid var(--line); image-rendering: pixelated; }
.shop-card p, .inventory-card p { margin: 3px 0 0; color: var(--ink-soft); font-size: .68rem; line-height: 1.4; }
.shop-card button { min-width: 66px; min-height: 38px; padding: 6px 8px; font-size: .65rem; }
.shop-card .price { display: block; color: #71522c; font-weight: 700; }

.stray-card { display: grid; grid-template-columns: 72px 1fr; gap: 10px; padding: 11px; background: #efe9d1; border-color: #7f8c70; }
.stray-card p { margin: 4px 0; color: var(--ink-soft); font-size: .68rem; line-height: 1.45; }
.stray-card button { width: 100%; margin-top: 6px; }
.pet-sprite { width: 64px; height: 64px; flex: none; image-rendering: pixelated; animation: pet-bob 1.8s steps(2, end) infinite; }
.pet-sprite.sheet { background-image: url("../assets/pets/pet_concepts.png"); background-size: 256px 384px; background-position: -192px calc(var(--pet-row) * -64px); background-repeat: no-repeat; }
.pet-sprite.blob { object-fit: contain; }

.drawer { width: min(560px, calc(100vw - 24px)); max-height: min(760px, calc(100svh - 24px)); margin: auto; padding: 18px; overflow-y: auto; border: 2px solid var(--ink); border-radius: 0; background: var(--paper); box-shadow: 8px 8px 0 rgba(10,8,20,.35); }
.narrow-drawer { width: min(470px, calc(100vw - 24px)); }
.dialog-heading { position: sticky; z-index: 3; top: -18px; display: flex; align-items: start; justify-content: space-between; gap: 16px; margin: -18px -18px 16px; padding: 18px; background: var(--paper); border-bottom: 1px solid var(--line); }
.close-button { width: 40px; padding: 0; font-size: 1.35rem; box-shadow: none; }
.prose p, .settings-actions p { color: var(--ink-soft); font-family: system-ui, sans-serif; font-size: .86rem; line-height: 1.6; }
.empty-state { padding: 17px; color: var(--ink-soft); border: 1px dashed var(--line); text-align: center; font-size: .7rem; line-height: 1.5; }
.job-card { margin-bottom: 10px; padding: 11px; }
.job-card.active { border-left: 5px solid var(--rose); }
.job-card p { margin: 6px 0; color: var(--ink-soft); font-size: .68rem; line-height: 1.45; }
.job-meta { display: flex; justify-content: space-between; gap: 8px; font-size: .6rem; }
.job-meta strong { color: #71522c; }
.job-card .abandon { min-height: 30px; padding: 4px 7px; color: #7a3f4b; border-color: #b78c94; box-shadow: none; font-size: .58rem; }
.notice-feed { display: grid; gap: 7px; }
.notice-card { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--line); border-left: 4px solid #7f8c70; background: #f5eedb; }
.notice-card p { margin: 4px 0 0; color: var(--ink-soft); font-size: .68rem; line-height: 1.45; }
.notice-kind { color: #695f70; font-size: .56rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.notice-card button { min-height: 34px; padding: 5px 8px; box-shadow: none; font-size: .6rem; }

.inventory-section { margin-top: 20px; }
.inventory-section:first-child { margin-top: 0; }
.inventory-card { display: grid; grid-template-columns: 42px 1fr auto; gap: 9px; align-items: center; padding: 9px; }
.inventory-count { min-width: 34px; font-weight: 700; text-align: right; }
.pet-card { display: grid; grid-template-columns: 72px 1fr; gap: 10px; padding: 10px; }
.pet-card .pet-details { min-width: 0; }
.pet-card p { margin: 4px 0; color: var(--ink-soft); font-size: .68rem; line-height: 1.4; }
.pet-possessions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.possession { display: inline-flex; align-items: center; gap: 4px; min-height: 29px; padding: 4px 6px; border: 1px solid var(--line); background: #e8deca; font-size: .56rem; }
.possession button { min-height: 22px; padding: 0 4px; border: 0; background: transparent; box-shadow: none; }
.pet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.pet-actions select, .adopt-form input { width: 100%; min-height: 38px; padding: 7px; color: var(--ink); border: 1px solid var(--line-dark); background: #fffaf0; }
.pet-actions button { min-height: 38px; font-size: .61rem; }
.adopt-form { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-top: 8px; }
.heart-pop { position: fixed; z-index: 90; color: #c35161; pointer-events: none; font-size: 2rem; animation: heart-pop 850ms ease-out forwards; }

.settings-actions { display: grid; gap: 10px; }
.settings-actions button, .file-button { width: 100%; text-align: center; }
.setting-toggle { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; padding: 11px; border: 1px solid var(--line); background: #f7f0df; cursor: pointer; }
.setting-toggle input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--ink); }
.setting-toggle strong, .setting-toggle small { display: block; }
.setting-toggle strong { font-size: .75rem; }
.setting-toggle small { margin-top: 5px; color: var(--ink-soft); font-family: system-ui, sans-serif; font-size: .78rem; line-height: 1.45; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.danger-button { color: #76323f; border-color: #a35d68; background: #f4e1df; }
.text-button { min-height: auto; padding: 0; border: 0; background: transparent; box-shadow: none; text-decoration: underline; }

.dev-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 18px; padding: 9px; color: #d8d0e3; background: var(--ink); border: 2px dashed #706783; font-size: .64rem; }
.dev-panel button { min-height: 32px; padding: 5px 8px; box-shadow: none; }

footer { display: flex; justify-content: space-between; gap: 14px; padding: 18px max(14px, calc((100vw - 1180px) / 2)); color: #c4bbd0; background: var(--ink); font-size: .66rem; }
footer .text-button { color: inherit; }

.toast-region { position: fixed; z-index: 100; right: 16px; bottom: 16px; display: grid; gap: 7px; width: min(330px, calc(100vw - 32px)); pointer-events: none; }
.toast { padding: 11px 13px; color: var(--paper-pale); background: var(--ink); border-left: 4px solid #f3d486; box-shadow: 4px 4px 0 rgba(0,0,0,.22); font-size: .68rem; animation: toast-in 220ms steps(4,end), toast-out 220ms 2.9s steps(4,end) forwards; }

@keyframes marker-pulse { 50% { transform: scale(1.65); opacity: .08; } }
@keyframes pet-bob { 50% { transform: translateY(-2px); } }
@keyframes arrival-in { from { transform: translateX(20px); opacity: 0; } }
@keyframes toast-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes toast-out { to { transform: translateX(18px); opacity: 0; } }
@keyframes heart-pop { from { transform: translateY(0) scale(.6); opacity: 1; } to { transform: translateY(-55px) scale(1.4); opacity: 0; } }

@media (max-width: 820px) {
  .topbar { grid-template-columns: auto 1fr auto; gap: 10px; }
  .top-actions { grid-column: 1 / -1; justify-content: stretch; }
  .top-actions button { flex: 1; justify-content: center; }
  .browsertoys-link { grid-column: 3; grid-row: 1; font-size: .58rem; }
  .panel-grid { grid-template-columns: 1fr; }
  .rail-map { min-height: 300px; }
}

@media (max-width: 560px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto; width: 100%; padding: 8px 10px; overflow: hidden; }
  .brand { min-width: 0; overflow: hidden; }
  .brand > span:last-child { min-width: 0; }
  .brand strong { overflow: hidden; text-overflow: ellipsis; }
  .brand small { display: none; }
  .brand-mark { width: 32px; height: 32px; }
  .wallet { grid-column: 2; grid-row: 1; justify-self: end; }
  .browsertoys-link { display: none; }
  .top-actions { grid-column: 1 / -1; grid-row: 2; min-width: 0; width: 100%; gap: 4px; overflow: hidden; }
  .compact-button { flex: 1 1 0; width: 0; min-width: 0; padding: 6px 3px; font-size: .56rem; line-height: 1.1; white-space: normal; }
  .compact-button > span:first-child { display: none; }
  .game-shell { width: min(calc(100% - 16px), 1180px); margin-top: 12px; }
  .map-card, .panel { box-shadow: 2px 3px 0 var(--shadow); }
  .map-card { padding: 11px; }
  .section-heading { align-items: start; }
  .world-clock { flex: none; font-size: .59rem; }
  .clock-copy { display: none; }
  .journey-banner { align-items: start; flex-direction: column; gap: 6px; }
  .journey-banner .progress-track { width: 100%; flex-basis: 8px; }
  .rail-map { min-height: 265px; }
  .station-node .station-label { font-size: 14px; stroke-width: 4px; }
  .map-legend { position: static; grid-template-columns: 1fr 1fr; margin-top: -4px; }
  .station-index { max-width: 100%; max-height: none; overflow: visible; }
  .station-hero { grid-template-columns: 82px 1fr; }
  .station-flair { width: 82px; }
  .shop-card { grid-template-columns: 36px 1fr auto; }
  footer { flex-direction: column; }
}
