/* Commonweal: somewhere between a strategy game and a good atlas. */
:root {
  --paper: #f4f0e6;
  --paper-2: #ebe5d6;
  --paper-3: #ddd4bf;
  --ink: #26251f;
  --ink-2: #57544a;
  --ink-3: #8a8575;
  --accent: #2f6f73;
  --accent-2: #3f8a8f;
  --warn: #b0741c;
  --urgent: #a23b2a;
  --good: #4f7a3a;
  --sea: #23384d;
  --line: rgba(38, 37, 31, .14);
  --shadow: 0 6px 24px rgba(20, 24, 30, .22);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --top: 48px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--sans); color: var(--ink); background: var(--sea); overflow: hidden; -webkit-font-smoothing: antialiased; }
#app { position: fixed; inset: 0; }
.boot { color: #d9d2c0; font-family: var(--serif); text-align: center; margin-top: 40vh; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0 0 .5em; letter-spacing: .01em; }
h1 { font-size: 1.9rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.02rem; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  cursor: pointer; border: 1px solid var(--line); background: #fffdf8; border-radius: 6px; padding: .45em .8em;
  transition: background .12s, border-color .12s;
}
button:hover { background: #fff; border-color: rgba(38, 37, 31, .3); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: var(--accent-2); }
button.danger { color: var(--urgent); border-color: rgba(162, 59, 42, .35); }
button:disabled { opacity: .5; cursor: default; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: .45em .6em; border: 1px solid var(--line); border-radius: 6px; background: #fffdf8;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
label { display: block; margin: .6em 0 .2em; font-size: .86rem; color: var(--ink-2); }
label.check { display: flex; gap: .5em; align-items: center; color: var(--ink); font-size: .92rem; }
.muted { color: var(--ink-3); } .small { font-size: .82rem; }
.err { color: var(--urgent); min-height: 1.3em; }
.row { display: flex; gap: .6em; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.num { font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: .05em .55em; border-radius: 99px; font-size: .78rem; background: var(--paper-2); color: var(--ink-2); }
.pill.warn { background: #f4e2c4; color: #7d500f; } .pill.urgent { background: #f2d3cc; color: #7d2517; } .pill.good { background: #dcebcf; color: #34561f; }
hr { border: 0; border-top: 1px solid var(--line); margin: .8em 0; }

/* ----- auth / setup screens ----- */
.backdrop {
  position: fixed; inset: 0; overflow: auto; padding: 5vh 16px calc(5vh + var(--safe-b));
  background: radial-gradient(ellipse at 30% 20%, #35536d 0, var(--sea) 60%), var(--sea);
}
.card { max-width: 440px; margin: 0 auto; background: var(--paper); border-radius: 12px; box-shadow: var(--shadow); padding: 28px; }
.card.wide { max-width: 780px; }
.card .lede { color: var(--ink-2); font-family: var(--serif); font-style: italic; margin-top: -.3em; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 0 0 1em; overflow-x: auto; }
.tabs button { border: 0; border-radius: 6px 6px 0 0; background: none; padding: .5em .9em; color: var(--ink-2); white-space: nowrap; }
.tabs button.on { background: var(--paper-2); color: var(--ink); font-weight: 600; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 1em 0; padding: .4em 1em 1em; }
legend { font-family: var(--serif); font-weight: 600; padding: 0 .4em; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 1em; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .5em; margin: .4em 0; }
.choice { border: 1px solid var(--line); border-radius: 8px; padding: .6em .7em; cursor: pointer; background: #fffdf8; }
.choice.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: #eef5f2; }
.choice b { display: block; font-family: var(--serif); }
.choice span { font-size: .8rem; color: var(--ink-2); }

/* ----- game ----- */
#map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; display: block; }
#map.tool { cursor: crosshair; }
.topbar {
  position: absolute; top: 0; left: 0; right: 0; height: calc(var(--top) + var(--safe-t)); padding: var(--safe-t) 10px 0;
  display: flex; align-items: center; gap: 14px; background: rgba(244, 240, 230, .95); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px); z-index: 20; white-space: nowrap; overflow-x: auto; scrollbar-width: none;
}
.topbar .name { font-family: var(--serif); font-size: 1.15rem; font-weight: 600; cursor: pointer; }
.topbar .tier { font-size: .8rem; color: var(--ink-3); font-style: italic; font-family: var(--serif); }
.stat { display: flex; flex-direction: column; line-height: 1.1; }
.stat small { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.stat b { font-variant-numeric: tabular-nums; font-weight: 600; }
.stat.neg b { color: var(--urgent); }
.topbar .spacer { flex: 1; }
.iconbtn { border: 0; background: none; padding: .35em .5em; border-radius: 6px; }
.iconbtn:hover, .iconbtn.on { background: var(--paper-2); }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); display: inline-block; }
.live.on { background: var(--good); }

.toolbar {
  position: absolute; left: 10px; top: calc(var(--top) + var(--safe-t) + 10px); z-index: 15; display: flex; flex-direction: column; gap: 4px;
  background: rgba(244, 240, 230, .96); border-radius: 10px; padding: 6px; box-shadow: var(--shadow); max-height: calc(100% - var(--top) - 30px); overflow-y: auto;
}
.toolbar button { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; border: 0; background: none; border-radius: 8px; font-size: 1.15rem; position: relative; }
.toolbar button:hover { background: var(--paper-2); }
.toolbar button.on { background: var(--accent); color: #fff; }
.toolbar button svg { width: 24px; height: 24px; }
.toolbar .sep { height: 1px; background: var(--line); margin: 2px 4px; }
.palette {
  position: absolute; left: 70px; top: calc(var(--top) + var(--safe-t) + 10px); z-index: 16; width: 250px; max-height: calc(100% - var(--top) - 30px);
  overflow-y: auto; background: rgba(244, 240, 230, .98); border-radius: 10px; box-shadow: var(--shadow); padding: 10px;
}
.palette h3 { margin-bottom: .3em; }
.palette .opt { display: flex; gap: .6em; align-items: flex-start; width: 100%; text-align: left; border: 0; background: none; padding: .45em .5em; border-radius: 6px; }
.palette .opt:hover { background: var(--paper-2); }
.palette .opt.on { background: #e1ece9; box-shadow: inset 0 0 0 1px var(--accent); }
.palette .swatch { width: 16px; height: 16px; border-radius: 4px; flex: none; margin-top: 2px; border: 1px solid rgba(0,0,0,.15); }
.palette .opt small { display: block; color: var(--ink-3); font-size: .76rem; }

.side {
  position: absolute; right: 0; top: calc(var(--top) + var(--safe-t)); bottom: 0; width: min(400px, 100%); z-index: 18;
  background: rgba(244, 240, 230, .97); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column; transition: transform .2s ease;
}
.side.closed { transform: translateX(100%); box-shadow: none; }
.side .tabs { padding: 6px 8px 0; margin: 0; flex: none; }
.side .body { overflow-y: auto; padding: 12px 14px calc(24px + var(--safe-b)); flex: 1; }
.side .close { position: absolute; left: -38px; top: 8px; width: 32px; height: 32px; border-radius: 8px 0 0 8px; background: rgba(244,240,230,.97); border: 1px solid var(--line); border-right: 0; padding: 0; }
.side.closed .close { left: -40px; }

.plan {
  position: absolute; left: 70px; bottom: calc(12px + var(--safe-b)); z-index: 17; width: min(380px, calc(100% - 80px)); max-height: 55%;
  display: flex; flex-direction: column; background: var(--paper); border-radius: 10px; box-shadow: var(--shadow); border-top: 4px solid var(--accent);
}
.plan header { padding: 10px 12px 4px; }
.plan .items { overflow-y: auto; padding: 0 12px; flex: 1; }
.plan footer { padding: 8px 12px 10px; border-top: 1px solid var(--line); }
.plan .item { display: flex; gap: .5em; padding: .35em 0; border-bottom: 1px dashed var(--line); font-size: .88rem; }
.plan .item .x { border: 0; background: none; color: var(--ink-3); padding: 0 .3em; }
.plan ul { margin: .2em 0 .2em 1.1em; padding: 0; font-size: .82rem; }
.plan .total { display: flex; justify-content: space-between; font-weight: 600; }

.toasts { position: absolute; top: calc(var(--top) + var(--safe-t) + 8px); left: 50%; transform: translateX(-50%); z-index: 40; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: min(560px, 92%); }
.toast { background: var(--ink); color: var(--paper); border-radius: 8px; padding: .55em .9em; box-shadow: var(--shadow); font-size: .9rem; pointer-events: auto; animation: rise .25s ease; }
.toast.sig3 { background: #3c3524; border-left: 4px solid #d8b35f; font-family: var(--serif); }
@keyframes rise { from { opacity: 0; transform: translateY(-6px); } }
.hint { position: absolute; bottom: calc(12px + var(--safe-b)); left: 50%; transform: translateX(-50%); z-index: 12; background: rgba(38, 37, 31, .8); color: var(--paper); padding: .35em .8em; border-radius: 99px; font-size: .82rem; pointer-events: none; white-space: nowrap; }
.hint:empty { display: none; }
.minimap-legend { position: absolute; right: 12px; bottom: calc(12px + var(--safe-b)); z-index: 12; background: rgba(244, 240, 230, .92); border-radius: 8px; padding: 6px 10px; font-size: .78rem; box-shadow: var(--shadow); }
.legend-bar { width: 140px; height: 8px; border-radius: 4px; margin: 3px 0; }

/* panels */
.kv { display: grid; grid-template-columns: 1fr auto; gap: .15em 1em; font-size: .9rem; }
.kv > :nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--paper-3); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.demand { display: grid; grid-template-columns: 90px 1fr 42px; gap: 4px 8px; align-items: center; font-size: .86rem; }
.dbar { position: relative; height: 12px; background: var(--paper-3); border-radius: 3px; }
.dbar::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--ink-3); }
.dbar > i { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
details { margin: .2em 0; }
summary { cursor: pointer; }
.factors { margin: .2em 0 .5em; padding: 0; list-style: none; font-size: .82rem; }
.factors li { display: flex; justify-content: space-between; gap: 1em; padding: .1em 0; border-bottom: 1px dotted var(--line); }
.factors .pos { color: var(--good); } .factors .neg { color: var(--urgent); }
.factors small { display: block; color: var(--ink-3); }
.advice { border-left: 3px solid var(--ink-3); padding: .4em .7em; margin: .6em 0; background: #fffdf8; border-radius: 0 6px 6px 0; }
.advice.warn { border-color: var(--warn); } .advice.urgent { border-color: var(--urgent); }
.advice .dept { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.advice h3 { margin: .1em 0 .2em; }
.advice ul { margin: .3em 0 0 1.1em; padding: 0; font-size: .86rem; }
.advice .aside { font-family: var(--serif); font-style: italic; color: var(--ink-2); font-size: .86rem; margin-top: .3em; }
.group { margin: .7em 0; }
.group .head { display: flex; justify-content: space-between; align-items: baseline; }
.event { padding: .4em 0; border-bottom: 1px solid var(--line); font-size: .88rem; }
.event .d { font-size: .74rem; color: var(--ink-3); }
.event.s2 { font-weight: 500; } .event.s3 { font-family: var(--serif); font-size: .98rem; }
.gazette { background: #fbf8f0; border: 1px solid var(--line); padding: 12px; font-family: var(--serif); }
.gazette .mast { text-align: center; font-size: 1.35rem; font-weight: 700; letter-spacing: .06em; border-bottom: 3px double var(--ink); padding-bottom: .2em; margin-bottom: .5em; text-transform: uppercase; }
.gazette .date { text-align: center; font-size: .75rem; color: var(--ink-2); margin: -.3em 0 .6em; }
.gazette .hl { font-weight: 600; margin: .45em 0; line-height: 1.25; }
.gazette .hl.lead { font-size: 1.15rem; }
.slider { display: grid; grid-template-columns: 1fr 120px 48px; align-items: center; gap: 8px; font-size: .86rem; margin: .25em 0; }
.slider input { width: 100%; }
table.data { width: 100%; border-collapse: collapse; font-size: .84rem; }
table.data th, table.data td { text-align: left; padding: .3em .4em; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data td.n, table.data th.n { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }
svg.spark { width: 100%; height: 44px; display: block; }
.adv { display: none; }
body.advanced .adv { display: revert; }
body.advanced .normal-only { display: none; }

/* admin */
.admin { position: fixed; inset: 0; overflow: auto; background: var(--paper-2); padding: calc(16px + var(--safe-t)) 16px calc(40px + var(--safe-b)); }
.admin .wrap { max-width: 1100px; margin: 0 auto; }
.admin .panel { background: var(--paper); border-radius: 10px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.08); margin-bottom: 14px; }
.banner { background: #f7e3c0; border: 1px solid #d9b26a; border-radius: 8px; padding: 12px; margin-bottom: 14px; }
.banner.danger { background: #f5d6cf; border-color: #cc8a7c; }
pre.json { white-space: pre-wrap; word-break: break-word; font: .74rem/1.3 var(--mono); max-height: 8em; overflow: auto; margin: 0; }

@media (max-width: 720px) {
  :root { --top: 52px; }
  .topbar { gap: 10px; }
  .topbar .hide-s { display: none; }
  .toolbar { top: auto; bottom: calc(10px + var(--safe-b)); left: 50%; transform: translateX(-50%); flex-direction: row; max-width: calc(100% - 20px); overflow-x: auto; }
  .toolbar .sep { width: 1px; height: auto; margin: 4px 2px; }
  .palette { left: 10px; right: 10px; width: auto; top: auto; bottom: calc(72px + var(--safe-b)); max-height: 45%; }
  .plan { left: 10px; right: 10px; width: auto; bottom: calc(72px + var(--safe-b)); max-height: 45%; }
  .side { top: 38%; width: 100%; border-left: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; }
  .side.closed { transform: translateY(100%); }
  .side .close { left: auto; right: 12px; top: -40px; border-radius: 8px; border: 1px solid var(--line); }
  .side.closed .close { left: auto; top: -44px; }
  .minimap-legend, .hint { display: none; }
}
