:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #5f6c77;
  --paper: #f4f1e9;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --line: #d9d4c8;
  --navy: #172c3f;
  --navy-soft: #e5ebef;
  --saffron: #bb6b22;
  --saffron-soft: #f6e9da;
  --green: #326b51;
  --green-soft: #e1eee7;
  --red: #9b3c35;
  --red-soft: #f4e2df;
  --shadow: 0 14px 40px rgba(23, 44, 63, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--paper); }

body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(187, 107, 34, 0.09), transparent 28rem),
    var(--paper);
}

button, input, select { font: inherit; }
button { touch-action: manipulation; }

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 0 max(24px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 2px 24px;
}

.topbar h1 { margin: 1px 0 0; font-family: Georgia, serif; font-size: clamp(2rem, 5vw, 3rem); letter-spacing: -0.04em; }
.eyebrow { margin: 0; color: var(--saffron); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.14em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.status-badge { padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.72); color: var(--muted); font-size: .78rem; }
.status-badge.online { color: var(--green); border-color: #aac8b8; background: var(--green-soft); }
.status-badge.offline { color: var(--red); border-color: #d7aaa6; background: var(--red-soft); }

.loading-panel, .empty-panel {
  min-height: 420px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  text-align: center;
  color: var(--muted);
}

.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--saffron); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.hero-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: clamp(24px, 5vw, 54px);
}
.hero-card::after {
  content: "";
  position: absolute;
  right: -90px;
  top: -110px;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  border: 48px solid rgba(187, 107, 34, .08);
  pointer-events: none;
}
.hero-card h2 { position: relative; margin: 7px 0 12px; max-width: 780px; font: 700 clamp(2rem, 6vw, 4.6rem)/.98 Georgia, serif; letter-spacing: -.05em; }
.hero-card .lead { position: relative; max-width: 720px; color: var(--muted); font-size: clamp(1rem, 2vw, 1.18rem); line-height: 1.65; }

.profile-grid, .scenario-grid { position: relative; display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; margin-top: 32px; }
.profile-card { display: flex; flex-direction: column; min-height: 260px; padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface-strong); }
.scenario-card { display: flex; flex-direction: column; min-height: 280px; padding: 20px; border: 1px solid color-mix(in srgb, var(--scenario-color) 28%, var(--line)); border-top: 5px solid var(--scenario-accent); border-radius: 18px; background: var(--surface-strong); }
.scenario-card h3 { margin: 12px 0 3px; color: var(--scenario-color); font: 700 1.35rem Georgia, serif; }
.scenario-card p { color: var(--muted); line-height: 1.5; }
.scenario-card .resource-preview { display: flex; flex-wrap: wrap; gap: 6px; margin: auto 0 16px; }
.scenario-card .button { background: var(--scenario-color); }
.profile-card h3 { margin: 12px 0 3px; font-size: 1.12rem; }
.profile-card .occupation { color: var(--saffron); font-weight: 700; font-size: .88rem; }
.profile-card p { color: var(--muted); line-height: 1.5; }
.profile-card .resource-preview { display: flex; flex-wrap: wrap; gap: 6px; margin: auto 0 16px; }
.chip { padding: 5px 8px; border-radius: 8px; background: var(--navy-soft); color: var(--navy); font-size: .75rem; font-weight: 700; }
.environment-strip { position: relative; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.environment-strip span { padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-strong); color: var(--muted); font-size: .78rem; }
.back-button { position: relative; margin-top: 18px; }

.button { min-height: 42px; border: 0; border-radius: 11px; padding: 10px 15px; font-weight: 800; cursor: pointer; transition: transform .12s ease, opacity .12s ease, background .12s ease; }
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:disabled { cursor: not-allowed; opacity: .5; transform: none; }
.button-primary { color: white; background: var(--navy); }
.button-secondary { color: var(--navy); border: 1px solid var(--line); background: var(--surface); }
.button-danger { color: var(--red); border: 1px solid #d7aaa6; background: var(--red-soft); }

.game-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .75fr); gap: 18px; align-items: start; }
.main-column, .side-column { display: grid; gap: 18px; }
.panel { border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: 0 8px 26px rgba(23, 44, 63, .05); }
.panel-inner { padding: 22px; }

.generator-callout { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin: 24px 0; padding: 18px; border: 1px solid color-mix(in srgb, var(--saffron) 45%, var(--line)); border-radius: 15px; background: var(--saffron-soft); }
.campaign-panel { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(210px, .65fr); gap: 14px 20px; margin: 24px 0; padding: 18px; border: 1px solid var(--line); border-radius: 15px; background: var(--navy-soft); }
.campaign-panel strong, .campaign-panel > div > span { display: block; }
.campaign-panel > div > span { margin-top: 4px; color: var(--muted); font-size: .84rem; line-height: 1.4; }
.campaign-panel label { display: grid; gap: 6px; color: var(--navy); font-size: .75rem; font-weight: 850; }
.campaign-panel select, .campaign-panel input { min-height: 42px; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: var(--surface-strong); color: var(--ink); font: inherit; }
.campaign-panel form { grid-column: 1 / -1; display: flex; gap: 8px; }
.campaign-panel form input { flex: 1; }
.campaign-link { margin: 14px 0 0; color: var(--saffron); font-size: .82rem; font-weight: 850; }
.generator-callout strong, .generator-callout span { display: block; }
.generator-callout span { margin-top: 4px; color: var(--muted); font-size: .86rem; }
.generated-badge { float: right; color: var(--saffron); font-size: .67rem; font-weight: 900; letter-spacing: .08em; }
.generator-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 24px; }
.generator-form > label { display: grid; gap: 7px; color: var(--navy); font-size: .78rem; font-weight: 850; }
.generator-form select, .generator-form input { width: 100%; min-height: 45px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: var(--surface-strong); color: var(--ink); font: inherit; }
.modifier-field { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; border: 1px solid var(--line); border-radius: 13px; padding: 14px; }
.modifier-field legend { padding: 0 6px; color: var(--navy); font-size: .78rem; font-weight: 850; }
.check-label { display: flex; align-items: flex-start; gap: 7px; color: var(--muted); font-size: .78rem; line-height: 1.35; }
.check-label input { width: auto; min-height: auto; margin-top: 2px; }
.generator-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 10px; }

.mission-panel { background: var(--navy); color: white; border-color: var(--navy); }
.mission-panel .eyebrow { color: #f1bd82; }
.mission-panel h2 { margin: 7px 0 8px; font: 700 clamp(1.7rem, 4vw, 2.7rem)/1.05 Georgia, serif; letter-spacing: -.03em; }
.mission-panel p { color: #dce5eb; line-height: 1.55; }
.citizen-strip { display: flex; justify-content: space-between; gap: 16px; align-items: end; margin-top: 22px; padding-top: 18px; border-top: 1px solid rgba(255,255,255,.18); }
.citizen-strip strong { display: block; }
.citizen-strip span { color: #c3d1da; font-size: .83rem; }
.turn-number { text-align: right; }
.turn-number strong { font-size: 1.55rem; }

.resource-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.metric-card { padding: 15px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface-strong); }
.metric-card .label { color: var(--muted); font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.metric-card .value { margin-top: 4px; font-size: 1.35rem; font-weight: 850; }

.progress-section { margin-top: 18px; }
.progress-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: .9rem; font-weight: 800; }
.progress-track { overflow: hidden; height: 12px; margin-top: 8px; border-radius: 999px; background: #e5e0d6; }
.progress-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--saffron), #dd9b52); transition: width .5s ease; }
.status-text { margin: 14px 0 0; padding: 13px 15px; border-left: 4px solid var(--saffron); background: var(--saffron-soft); line-height: 1.5; }

.city-panel { overflow: hidden; }
.city-map { position: relative; min-height: 330px; overflow: hidden; border: 1px solid color-mix(in srgb, var(--navy) 22%, var(--line)); border-radius: 17px; background:
  linear-gradient(32deg, transparent 48%, rgba(255,255,255,.64) 49%, rgba(255,255,255,.64) 52%, transparent 53%) 0 0 / 130px 110px,
  linear-gradient(-28deg, transparent 47%, rgba(255,255,255,.5) 48%, rgba(255,255,255,.5) 51%, transparent 52%) 0 0 / 170px 135px,
  color-mix(in srgb, var(--paper) 76%, var(--navy-soft)); }
.city-canvas-host, .city-dom-fallback { position: absolute; inset: 0; }
.city-canvas-host canvas { display: block; width: 100% !important; height: 100% !important; }
.city-dom-fallback[hidden] { display: none; }
.city-plan-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.city-plan-svg polyline { fill: none; vector-effect: non-scaling-stroke; stroke-linecap: round; stroke-linejoin: round; }
.map-water polyline { stroke: #54a8ca; stroke-width: 4; opacity: .72; }
.map-rail polyline { stroke: #57636b; stroke-width: 1.5; opacity: .34; }
.map-road polyline { stroke: #c2aa7d; stroke-width: 1.6; opacity: .74; }
.map-road .map-primary { stroke-width: 3.5; }
.map-road .map-trunk { stroke-width: 4.5; }
.map-road .map-motorway { stroke: #d89b42; stroke-width: 5.5; }
.map-attribution { display: flex; justify-content: space-between; gap: 12px; margin-top: 9px; color: var(--muted); font-size: .68rem; line-height: 1.45; }
.map-attribution a { color: var(--navy); }
.city-map::before, .city-map::after { content: ""; position: absolute; border-radius: 38%; background: color-mix(in srgb, var(--green) 18%, transparent); }
.city-map::before { width: 34%; height: 38%; left: -6%; bottom: -12%; transform: rotate(-12deg); }
.city-map::after { width: 26%; height: 30%; right: -4%; top: -8%; transform: rotate(18deg); }
.city-river { position: absolute; width: 120%; height: 34px; left: -10%; top: 57%; transform: rotate(-5deg); background: color-mix(in srgb, #4b9ac1 50%, transparent); opacity: .55; }
.city-location { position: absolute; z-index: 2; width: 96px; min-height: 54px; transform: translate(-50%, -50%); border: 2px solid var(--line); border-radius: 12px; padding: 7px; background: rgba(255,253,248,.94); color: var(--ink); box-shadow: 0 7px 20px rgba(23,44,63,.13); font-size: .7rem; font-weight: 850; line-height: 1.2; cursor: default; }
.city-location.available { border-color: var(--saffron); cursor: pointer; animation: locationPulse 2.4s ease-in-out infinite; }
.city-location.available:hover, .city-location.available:focus-visible { z-index: 4; transform: translate(-50%, -50%) scale(1.06); outline: 3px solid color-mix(in srgb, var(--saffron) 30%, transparent); }
.city-location.locked { opacity: .66; border-style: dashed; }
.city-location.context { opacity: .78; }
@keyframes locationPulse { 50% { box-shadow: 0 7px 24px color-mix(in srgb, var(--saffron) 35%, transparent); } }

.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.section-title h3 { margin: 0; font-size: 1.05rem; }
.section-title span { color: var(--muted); font-size: .78rem; }
.action-list { display: grid; gap: 10px; }
.action-button { width: 100%; min-height: 92px; display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; text-align: left; padding: 15px 16px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); background: var(--surface-strong); cursor: pointer; }
.action-button:hover:not(:disabled) { border-color: #af9c83; background: #fffaf2; }
.action-button:disabled { cursor: not-allowed; opacity: .56; }
.action-title { display: block; font-weight: 850; }
.action-description { display: block; margin-top: 4px; color: var(--muted); font-size: .84rem; line-height: 1.4; }
.action-cost { display: grid; gap: 4px; min-width: 104px; text-align: right; color: var(--muted); font-size: .75rem; }
.action-cost strong { color: var(--navy); }
.disabled-reason { grid-column: 1 / -1; color: var(--red); font-size: .76rem; }

.secondary-metrics { display: grid; gap: 13px; }
.stat-row { display: grid; gap: 6px; }
.stat-header { display: flex; justify-content: space-between; gap: 10px; font-size: .82rem; }
.mini-track { height: 8px; overflow: hidden; border-radius: 999px; background: #e6e1d7; }
.mini-fill { height: 100%; background: var(--navy); border-radius: inherit; }

.timeline { display: grid; gap: 14px; }
.timeline-item { position: relative; padding-left: 22px; }
.timeline-item::before { content: ""; position: absolute; left: 3px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--saffron); }
.timeline-item::after { content: ""; position: absolute; left: 6.5px; top: 19px; bottom: -16px; width: 1px; background: var(--line); }
.timeline-item:last-child::after { display: none; }
.timeline-item h4 { margin: 0 0 3px; font-size: .88rem; }
.timeline-item p { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.45; }
.event-meta { margin-top: 4px; color: var(--saffron); font-size: .73rem; font-weight: 750; }

.end-banner { padding: 20px; border-radius: 18px; text-align: center; }
.end-banner.won { border: 1px solid #aac8b8; background: var(--green-soft); }
.end-banner.lost { border: 1px solid #d7aaa6; background: var(--red-soft); }
.end-banner h3 { margin: 0 0 6px; font: 700 1.8rem Georgia, serif; }

.result-dialog { width: min(500px, calc(100% - 28px)); border: 0; border-radius: 20px; padding: 0; background: var(--surface); box-shadow: 0 24px 70px rgba(0,0,0,.22); }
.result-dialog::backdrop { background: rgba(17, 30, 41, .65); backdrop-filter: blur(3px); }
.dialog-content { padding: 28px; }
.dialog-content h2 { margin: 7px 0 10px; font: 700 2rem Georgia, serif; }
.dialog-content p { color: var(--muted); line-height: 1.55; }
.delta-line { margin: 16px 0 22px; padding: 12px; border-radius: 10px; background: var(--navy-soft); color: var(--navy); font-weight: 800; }

footer { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; padding: 24px 0 0; color: var(--muted); font-size: .75rem; }

@media (max-width: 900px) {
  .game-layout { grid-template-columns: 1fr; }
  .side-column { grid-template-columns: 1fr 1fr; }
  .profile-grid, .scenario-grid { grid-template-columns: 1fr; }
  .profile-card { min-height: auto; }
}

@media (max-width: 640px) {
  .app-shell { width: min(100% - 20px, 1180px); }
  .topbar { align-items: flex-start; }
  .topbar-actions { flex-direction: column; align-items: flex-end; }
  .status-badge { display: none; }
  .hero-card { border-radius: 18px; padding: 24px 18px; }
  .resource-grid { grid-template-columns: 1fr 1fr; }
  .side-column { grid-template-columns: 1fr; }
  .panel-inner { padding: 17px; }
  .action-button { grid-template-columns: 1fr; gap: 8px; }
  .action-cost { display: flex; flex-wrap: wrap; gap: 8px; text-align: left; }
  .citizen-strip { align-items: flex-start; }
  .city-map { min-height: 280px; }
  .map-attribution { display: grid; }
  .city-location { width: 78px; min-height: 48px; font-size: .62rem; }
  .generator-callout { align-items: stretch; flex-direction: column; }
  .campaign-panel { grid-template-columns: 1fr; }
  .campaign-panel form { grid-column: 1; align-items: stretch; flex-direction: column; }
  .generator-form { grid-template-columns: 1fr; }
  .modifier-field { grid-column: 1; grid-template-columns: 1fr; }
  .generator-actions { grid-column: 1; }
}

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