/* Forge of Ages — painterly, somewhat serious. Each Age re-skins the page via body.age-* */
:root {
  --bg: #1d1712;
  --panel: rgba(34, 27, 20, 0.86);
  --panel-solid: #2a2119;
  --ink: #f1e6d0;
  --muted: #b9a888;
  --line: rgba(241, 230, 208, 0.16);
  --gold: #d9a441;
  --gold-ink: #2a1d07;
  --good: #8fbf6a;
  --bad: #d9694a;
  --indep: #8a8173;
  --title: "Cinzel", Georgia, serif;
  --body: "EB Garamond", Georgia, serif;
  --radius: 10px;
}
body.age-medieval { --gold: #c9a14a; --bg: #1c1a16; }
body.age-frontier { --gold: #d98a3a; --bg: #23180f; --panel: rgba(46, 31, 18, 0.88); }
body.age-industrial { --gold: #c8a46a; --bg: #191714; --panel: rgba(30, 28, 25, 0.88); }
body.age-greatwar { --gold: #b9a46a; --bg: #171813; --panel: rgba(30, 32, 24, 0.9); }
body.age-spacerace { --gold: #8fd18a; --bg: #0f1612; --panel: rgba(16, 30, 22, 0.9); --title: "Cinzel", "Courier New", monospace; }
body.age-modern { --gold: #6fb6e8; --bg: #10151b; --panel: rgba(22, 30, 40, 0.86); }
body.age-future { --gold: #7fe3ff; --bg: #070d16; --panel: rgba(12, 22, 38, 0.84); }

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.4 var(--body);
  -webkit-font-smoothing: antialiased;
}
.backdrop {
  position: fixed; inset: 0; z-index: -1;
  background-size: cover; background-position: center;
  opacity: 0.22; filter: saturate(0.8);
}
h1, h2, h3, .title { font-family: var(--title); letter-spacing: 0.02em; margin: 0; }
h2 { font-size: 1.15rem; margin: 14px 0 8px; color: var(--gold); }
button { font: inherit; cursor: pointer; }
a { color: var(--gold); }
.loading { padding: 40vh 16px; text-align: center; font-family: var(--title); color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.row { display: flex; gap: 8px; align-items: center; }
.spread { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

/* ---------- Join ---------- */
.hero { position: relative; min-height: 46vh; display: flex; align-items: flex-end; padding: 16px; background-size: cover; background-position: center; }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 30%, var(--bg)); }
.hero > div { position: relative; z-index: 1; }
.hero h1 { font-size: clamp(2.2rem, 9vw, 3.6rem); font-weight: 800; color: #fff6e2; text-shadow: 0 2px 12px #000; }
.hero p { margin: 4px 0 0; color: #f3e6c8; text-shadow: 0 1px 6px #000; }
.join { max-width: 760px; margin: 0 auto; padding: 0 16px 40px; }
.field { display: block; margin: 12px 0; }
.field input, .field select { width: 100%; margin-top: 4px; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel-solid); color: var(--ink); font: inherit; }
.peoples { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.people { position: relative; border: 2px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel-solid); text-align: left; color: var(--ink); padding: 0; }
.people img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: block; }
.people .cap { padding: 6px 8px 8px; }
.people .cap b { font-family: var(--title); font-size: 0.9rem; display: block; }
.people .cap span { font-size: 0.8rem; color: var(--muted); }
.people.sel { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: var(--radius); border: 1px solid var(--gold); background: var(--gold); color: var(--gold-ink); font-family: var(--title); font-weight: 600; }
.btn.ghost { background: transparent; color: var(--gold); }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.wide { width: 100%; margin-top: 12px; padding: 14px; font-size: 1.05rem; }
.error { color: var(--bad); margin: 8px 0; }

/* ---------- Shell ---------- */
.top { position: sticky; top: 0; z-index: 5; background: var(--panel); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); }
.top .age { font-family: var(--title); color: var(--gold); font-size: 1rem; }
.stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.95rem; margin-top: 2px; }
.stats b { font-weight: 600; }
main { max-width: 900px; margin: 0 auto; padding: 8px 16px 100px; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; background: var(--panel); backdrop-filter: blur(8px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; background: none; border: 0; color: var(--muted); padding: 10px 2px 12px; font-family: var(--title); font-size: 0.75rem; }
.tabs button .ico { display: block; font-size: 1.3rem; line-height: 1.2; }
.tabs button.on { color: var(--gold); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 10px 0; }

/* ---------- Map ---------- */
.worldgrid { display: grid; gap: 6px; }
.region { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 2px solid var(--line); background: #3a3026 center / cover; color: #fff; text-align: left; padding: 0; }
.region::after { content: ""; position: absolute; inset: 0; background: linear-gradient(rgba(0,0,0,0.05), rgba(0,0,0,0.7)); }
.region .lbl { position: absolute; z-index: 1; left: 5px; right: 5px; bottom: 4px; font-size: 0.68rem; line-height: 1.15; text-shadow: 0 1px 3px #000; }
.region .mine { position: absolute; z-index: 1; top: 4px; right: 5px; background: var(--gold); color: var(--gold-ink); border-radius: 99px; font-size: 0.7rem; padding: 0 6px; font-weight: 700; }
.region.has-mine { border-color: var(--gold); }
.region.uncharted { filter: grayscale(0.9) brightness(0.5); }
.valleygrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.valley { position: relative; border-radius: 8px; overflow: hidden; min-height: 92px; background: #3a3026 center / cover; border: 1px solid var(--line); padding: 4px; display: flex; flex-direction: column; justify-content: flex-end; gap: 3px; }
.valley::before { content: ""; position: absolute; inset: 0; background: linear-gradient(rgba(0,0,0,0.0), rgba(0,0,0,0.55)); }
.valley.coastal { box-shadow: inset 0 0 0 2px rgba(80, 150, 220, 0.6); }
.chip { position: relative; z-index: 1; display: flex; align-items: center; gap: 3px; border-radius: 6px; border: 1px solid rgba(0,0,0,0.4); padding: 2px 4px; font-size: 0.7rem; color: #fff; text-shadow: 0 1px 2px #000; background: var(--indep); text-align: left; min-height: 24px; }
.chip.mine { background: var(--gold); color: var(--gold-ink); text-shadow: none; font-weight: 700; }
.chip.can { outline: 2px solid #fff; }
.chip .nm { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); margin: 6px 0; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }

/* ---------- Sheet ---------- */
.sheet-bg { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,0.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; max-height: 88vh; overflow: auto; background: var(--panel-solid); border-top: 2px solid var(--gold); border-radius: 14px 14px 0 0; padding: 0 16px 24px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.sheet .pic { margin: 0 -16px 10px; height: 150px; background: center / cover; }
.sheet h3 { font-size: 1.2rem; }
.deps { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.dep { display: flex; align-items: center; gap: 4px; background: rgba(255,255,255,0.06); border-radius: 6px; padding: 2px 6px 2px 2px; font-size: 0.85rem; }
.dep img { width: 24px; height: 24px; border-radius: 4px; object-fit: cover; }
.dep.hot { outline: 1px solid var(--gold); }
.armyline { display: flex; gap: 8px; flex-wrap: wrap; font-size: 0.9rem; }
.verdict { font-family: var(--title); font-size: 1.1rem; margin: 8px 0; }

/* ---------- Army ---------- */
.units { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.unit { display: flex; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.unit img { width: 72px; height: 96px; object-fit: cover; border-radius: 6px; flex: none; background: #3a3026; }
.unit .nm { font-family: var(--title); font-size: 0.95rem; }
.unit .buy { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.unit.off { opacity: 0.45; }
.slider { width: 100%; accent-color: var(--gold); }
.bar { height: 8px; background: rgba(255,255,255,0.1); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--gold); }

/* ---------- Lists ---------- */
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
td, th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-weight: 400; font-size: 0.8rem; }
tr.me td { color: var(--gold); font-weight: 600; }
.log { list-style: none; padding: 0; margin: 0; }
.log li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.log .when { font-size: 0.78rem; color: var(--muted); display: block; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 30; background: var(--panel-solid); border: 1px solid var(--gold); border-radius: var(--radius); padding: 10px 16px; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,0.5); }
.agecard { position: relative; border-radius: var(--radius); overflow: hidden; min-height: 140px; background: center / cover; display: flex; align-items: flex-end; margin: 10px 0; }
.agecard::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 20%, rgba(0,0,0,0.75)); }
.agecard > div { position: relative; z-index: 1; padding: 10px 12px; }
.agecard h3 { color: #fff6e2; font-size: 1.3rem; text-shadow: 0 1px 6px #000; }

@media (min-width: 700px) {
  .valley { min-height: 120px; }
  .chip { font-size: 0.8rem; }
}

/* ---------- Board ---------- */
.board { width: 100%; height: auto; display: block; border-radius: 12px; border: 3px solid #5a4630; box-shadow: 0 6px 24px rgba(0,0,0,.45), inset 0 0 40px rgba(0,0,0,.4); background: #4f7390; touch-action: manipulation; }
.board .ocean { fill: #56809e; }
.board path[data-region] { cursor: pointer; }
.board .coast { fill: none; stroke: #3b2c1c; stroke-width: 5; stroke-linejoin: round; }
.board .rborder { fill: none; stroke: #3b2c1c; stroke-width: 6; stroke-linejoin: round; stroke-linecap: round; }
.board .strait { fill: none; stroke: #5b8fb8; stroke-width: 12; stroke-linecap: round; }
.board .rlabel { cursor: pointer; }
.board .rlabel text { font-family: var(--title); font-size: 26px; font-weight: 800; text-anchor: middle; fill: #2b1f12; paint-order: stroke; stroke: rgba(246, 236, 210, .85); stroke-width: 5px; }
.board .rlabel .badge { fill: var(--gold-ink); stroke: none; font-size: 22px; }
.board.region { background: #56809e; }
.board .vborder { fill: none; stroke: rgba(43, 31, 18, .75); stroke-width: 2.5; stroke-linejoin: round; }
.board .vborder.held { stroke: var(--gold); stroke-width: 5; }
.board .road { stroke: #6b4f2c; stroke-width: 3; stroke-dasharray: 7 6; opacity: .8; }
.board .searoute { stroke: #cfe6f7; stroke-width: 3; stroke-dasharray: 3 7; opacity: .9; }
.board .token { cursor: pointer; }
.board .token .piece { stroke: #2b1f12; stroke-width: 2.5; filter: drop-shadow(0 2px 2px rgba(0,0,0,.5)); }
.board .token text { font-size: 15px; text-anchor: middle; font-weight: 700; pointer-events: none; }
.board .token .ring { fill: none; stroke: #fff; stroke-width: 2.5; stroke-dasharray: 4 3; animation: pulse 1.6s ease-in-out infinite; }
.board .token .star { font-size: 13px; fill: #ffd34d; stroke: #2b1f12; stroke-width: .8px; paint-order: stroke; }
.board .token .eye { font-size: 11px; }
@keyframes pulse { 50% { opacity: .35; } }
