:root {
  color-scheme: light;
  color: #172d29;
  background: #f5f5ef;
  font: 1rem/1.55 system-ui, sans-serif;
  --muted: #50665f;
  --border: #dce4db;
  --accent: #16634f;
  --paper: #fffdfa;
  --pine: #143b34;
  --shadow: 0 4px 18px #143b3410;
}

* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--accent); text-underline-offset: .2em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid #ae6e21; outline-offset: 3px; }

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 2rem;
  padding: .8rem max(1rem, calc((100vw - 76rem) / 2));
  background: #102f29;
  border-bottom: 1px solid #436156;
}

.brand, nav a { color: #fff9e9; text-decoration: none; }
.brand, .login-brand { display: inline-flex; align-items: center; gap: .7rem; font-weight: 800; }
.brand { font-size: 1.05rem; }
.brand-mark { width: 2.2rem; height: 2.2rem; object-fit: cover; border-radius: .55rem; }
nav { display: flex; gap: .25rem; flex-wrap: wrap; }
nav a { padding: .4rem .65rem; border-radius: .45rem; }
nav a:hover, nav a[aria-current] { color: #fff4d7; background: #305348; }

main { max-width: 78rem; margin: auto; padding: clamp(1.35rem, 4vw, 2.5rem) 1rem 3rem; }
h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); line-height: 1.15; margin: 0 0 1rem; letter-spacing: -.035em; }
h2 { font-size: 1.25rem; margin: 0 0 .75rem; }
section { margin-top: 1.6rem; }
.lead { color: var(--muted); overflow-wrap: anywhere; }
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
  gap: .75rem;
}

.metric, .empty, .scroll, .panel, .building, .inline-building {
  border: 1px solid var(--border);
  background: var(--paper);
  border-radius: .95rem;
}

.metric { display: grid; align-content: space-between; gap: .4rem; padding: .95rem 1rem; box-shadow: var(--shadow); }
.metric .icon { width: 2rem; height: 2rem; object-fit: contain; }
.metric span { color: var(--muted); font-size: .9rem; font-weight: 600; }
.metric strong { font-size: 1.85rem; line-height: 1.15; font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.player-assets { display: flex; align-items: center; gap: .35rem; }
.player-code { color: var(--muted); font: .82em ui-monospace, monospace; }
.player-asset { display: inline-flex; align-items: center; gap: .2rem; padding: .14rem .38rem; border: 1px solid var(--border); border-radius: .45rem; background: var(--paper); font-variant-numeric: tabular-nums; }
.player-asset .icon { width: 1.55rem; height: 1.55rem; object-fit: contain; }
.city-metrics { grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); }
.city-metrics .metric { position: relative; padding-right: 3.6rem; }
.city-metrics .metric .icon { position: absolute; right: .85rem; top: .85rem; }
.empty { color: var(--muted); padding: 1rem; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .65rem .85rem; text-align: left; white-space: nowrap; }
th { background: #eaf1e9; color: #28473d; font-size: .8rem; }
td { border-top: 1px solid var(--border); }
tr:nth-child(even) td { background: #f8f7ef; }

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(8rem, 24rem);
  align-items: center;
  gap: .9rem;
  margin: 0 0 1.4rem;
  padding: clamp(1.1rem, 3vw, 2.3rem);
  border: 1px solid #376458;
  border-radius: 1.25rem;
  background: radial-gradient(ellipse at 85% 75%, #498973, #22564b 40%, #173f36 72%);
  color: #fffcee;
  box-shadow: 0 11px 26px #123b3427;
}
.hero h2 { font-size: clamp(1.35rem, 3vw, 2.15rem); line-height: 1.16; max-width: 20ch; }
.hero p { max-width: 46ch; color: #e7efe8; }
.hero-art { width: 100%; height: clamp(8rem, 19vw, 14rem); object-fit: contain; filter: drop-shadow(0 .5rem .6rem #0b2d28a1); }
.button { display: inline-block; color: #163329; background: #f0d6a4; border-radius: .65rem; padding: .6rem .9rem; font-weight: 750; text-decoration: none; }
.button:hover { background: #ffe4b3; }
.hero-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.button.secondary { background: #2e6154; color: #fff4d7; border: 1px solid #749f8a; }
.button.secondary:hover { background: #416f60; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .7rem; }
.toolbar label { margin: 0; }
.toolbar select { min-width: 0; max-width: 100%; }
.building-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .7rem; }
.building { display: grid; grid-template-rows: auto 1fr auto; gap: .25rem; min-width: 0; padding: .65rem; text-decoration: none; box-shadow: var(--shadow); }
.building:hover, .building[aria-current] { border-color: #4a8a75; background: #eaf3e9; }
.building strong { line-height: 1.28; align-self: end; }
.building small, .inline-building small { color: var(--muted); }
.building-art { width: 100%; height: 5.4rem; object-fit: contain; }
.inline-building { display: flex; align-items: center; gap: .9rem; padding: .8rem; }
.inline-building .building-art { width: 6rem; }
.inline-building h2 { margin: .14rem 0; }
.panel { padding: clamp(.75rem, 2vw, 1.3rem); box-shadow: var(--shadow); scroll-margin-top: 1rem; min-width: 0; }
.panel .lead { margin: .65rem 0; }
.stage-table td:first-child { min-width: 11rem; white-space: normal; }
.stage-table td small { display: block; color: var(--muted); }
.stage-table tbody tr.selected-stage td { background: #dceee2; }
.chart-bar { display: flex; align-items: center; gap: .65rem; }
.chart-bar progress { width: clamp(5rem, 18vw, 14rem); height: .6rem; accent-color: #2a775e; }
.chart-bar b { min-width: 2ch; }
.funnel-steps { list-style: none; padding: 0; margin: .8rem 0 0; }
.funnel-steps li { display: grid; grid-template-columns: minmax(12rem, 1fr) minmax(10rem, 1fr); gap: .65rem; padding: .7rem 0; border-top: 1px solid var(--border); }
.funnel-steps small { display: block; color: var(--muted); }
.funnel-steps progress { flex: 1; width: auto; min-width: 2rem; height: .75rem; }
.funnel-steps .chart-bar small { min-width: 4ch; text-align: right; }
.flag, .insight { color: #68451e; background: #f9eccf; border: 1px solid #eddab4; }
.flag { border-radius: 999px; padding: .2rem .55rem; font-weight: 650; font-size: .8rem; }
.insight { padding: .7rem .95rem; border-radius: .8rem; }

form { margin-bottom: 1rem; }
label { display: block; font-weight: 650; margin-bottom: .35rem; }
.search { display: flex; gap: .5rem; max-width: 28rem; }
input, select, button { border-radius: .5rem; font: inherit; padding: .55rem .75rem; }
input { flex: 1; min-width: 0; border: 1px solid #9eab9f; background: #fffdf6; color: inherit; }
select { border: 1px solid #9eab9f; background: #fffdf6; color: inherit; }
.filter-label { margin-top: .65rem; }
input[type="search"] { width: min(28rem, 100%); }
button { border: 1px solid var(--accent); color: white; background: var(--accent); font-weight: 700; cursor: pointer; }
button:hover { background: #164f41; }
.paging { display: flex; gap: 1rem; margin-top: .75rem; }
.login { max-width: 30rem; min-height: 100dvh; align-content: center; }
.login form { padding: clamp(1rem, 5vw, 2rem); border: 1px solid var(--border); border-radius: .9rem; background: #fffdf6; }
.login .lead { margin: 0 0 .35rem; font-weight: 750; }
.login-brand { color: var(--pine); margin-bottom: .9rem; }
.login input, .login button { width: 100%; margin-bottom: .85rem; }
.login button { margin: .25rem 0 0; }
.login-error { color: #812d26; background: #fbe8df; border-radius: .45rem; padding: .65rem .75rem; }
.logout { margin: 0 0 0 auto; }
.logout button { color: #fff9e9; border-color: #b8cabd; background: transparent; }
.logout button:hover { background: #245a4b; }

@media (max-width: 54rem) {
  .building-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 32rem) {
  nav { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  nav a { overflow-wrap: anywhere; }
  .logout { order: -1; margin: 0; }
  .brand { margin-right: auto; order: -1; }
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero-art { display: none; }
  .funnel-steps li { grid-template-columns: minmax(0, 1fr); }
  .building-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .player-assets { flex-wrap: wrap; min-width: 10.75rem; }
  .player-asset .icon { width: 1.2rem; height: 1.2rem; }
}
