/* Parish: 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: #6f6a5c;
  --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 .town { display: flex; align-items: baseline; gap: 8px; }
.topbar .strip { display: contents; } /* on phones it becomes its own scrolling row */
.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; }
.toolbar .panel { display: none; } /* phones only: the panel opens from the tool row */
.dock { display: contents; } /* phones only: stacks the palette, plan and tools */
.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;
}
.has-plan .palette { max-height: calc(45% - var(--top) - 20px); }
.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; visibility: hidden; transition: transform .2s ease, visibility 0s .2s; }
.side .tabs { padding: 6px 8px 0; margin: 0; flex: none; flex-wrap: wrap; row-gap: 0; }
/* The sheet's handle: drag to resize, tap to step through the heights. */
.side .grab { display: none; width: 100%; height: 28px; border: 0; background: none; padding: 0; touch-action: none; position: relative; flex: none; }
.side .grab::before { content: ''; position: absolute; left: 50%; top: 10px; width: 44px; height: 5px; margin-left: -22px; border-radius: 3px; background: var(--paper-3); }
.side .grab:active::before { background: var(--ink-3); }
.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; visibility: visible; }
.side.closed .close { left: -40px; }
.side .close .when-open { display: none; }

.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; left: 50%; transform: translateX(-50%); bottom: calc(52px + 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; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
#map:focus-visible { outline: 3px solid #ffe36a; outline-offset: -3px; }
.notice { background: var(--paper-2); border-radius: 8px; padding: 8px 10px; margin: .6em 0; }
.notice h3 { margin-bottom: .2em; }
.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) {
  /* Two rows: the town on top, its figures on a strip that scrolls. */
  :root { --top: 74px; }
  .topbar { gap: 8px 12px; flex-wrap: wrap; align-content: center; padding: var(--safe-t) 10px 0; overflow: hidden; }
  .topbar .hide-s { display: none; }
  .topbar > :first-child { flex: 1 1 100%; display: flex; align-items: baseline; gap: 8px; min-width: 0; height: 30px; }
  .topbar .name { font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55vw; }
  .topbar .switch { max-width: 42vw; font-size: .8rem; padding: 3px 4px; }
  /* With several towns the switcher is the name: no need to print it twice. */
  .topbar .town:has(.switch) .name { display: none; }
  .topbar .town:has(.switch) .switch { max-width: 80vw; flex: 0 1 auto; font: 600 1rem var(--serif); color: var(--ink); }
  /* Everything after the town: one scrolling strip of figures, fading at the edge it scrolls past. */
  .topbar .strip { flex: 1 1 100%; display: flex; align-items: center; gap: 14px; height: 34px;
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); }
  .topbar .strip > .stat.neg, .topbar .strip > .stat:nth-child(3) { order: -1; } /* treasury first */
  .topbar .strip > :last-child { padding-right: 28px; } /* so the last figure can scroll clear of the fade */
  .topbar .strip::-webkit-scrollbar { display: none; }
  .topbar .spacer { display: none; }
  /* The dock: palette, then plan, then tools, stacked up from the bottom edge. */
  .dock { display: flex; flex-direction: column; gap: 6px; position: absolute; left: 10px; right: 10px; bottom: calc(10px + var(--safe-b)); z-index: 16;
    max-height: calc(100% - var(--top) - var(--safe-t) - 20px); }
  .dock > * { position: static; width: auto; max-height: none; flex: 0 1 auto; min-height: 0; }
  .dock .palette, .dock .plan { max-height: 45vh; }
  .toolbar { flex: none; flex-direction: row; overflow-x: auto; gap: 2px; scroll-snap-type: x proximity; scrollbar-width: none; padding: 6px 0 6px 6px; }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar button { width: 44px; height: 44px; flex: none; scroll-snap-align: center; }
  .toolbar .sep { width: 1px; height: auto; margin: 4px 2px; }
  /* The panel button stays pinned at the right while the tools scroll under it. */
  .toolbar .panel { display: grid; position: sticky; right: 0; margin-left: auto; background: rgba(244, 240, 230, 1); border-left: 1px solid var(--line); border-radius: 0 10px 10px 0; width: 50px; }
  /* The panel is a bottom sheet the player sizes: see .grab. */
  .side { top: var(--sheet-top, 42%); 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: 6px; top: 0; width: 44px; height: 28px; border-radius: 8px; border: 0; background: none; z-index: 2; font-size: 1.1rem; line-height: 1; }
  .side.closed .close { display: none; }
  .side .close .when-closed { display: none; }
  .side .close .when-open { display: inline; }
  .side .grab { display: block; }
  /* One row of tabs that scrolls, so the sheet keeps its height for content. */
  .side .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 0 8px; scroll-snap-type: x proximity;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); }
  .side .tabs::-webkit-scrollbar { display: none; }
  .side .tabs button { scroll-snap-align: center; }
  .side .tabs button:last-child { margin-right: 28px; }
  .minimap-legend, .hint { display: none; }
  /* Administration on a phone: smaller heading, nothing clipped. */
  h1 { font-size: 1.5rem; }
  .admin { padding-left: 12px; padding-right: 12px; }
  .admin .panel { padding: 12px; }
  .admin .row { flex-wrap: wrap; row-gap: .3em; }
  .card { padding: 20px 16px; }
  /* With the sheet open the dock rides just above its edge, still reachable. */
  #app:has(.side:not(.closed)) .dock { bottom: calc(100% - var(--sheet-top, 42%) + 8px); }
  #app:has(.side:not(.closed)) .dock .palette, #app:has(.side:not(.closed)) .dock .plan { max-height: 30vh; }
  /* At half the view controls would sit under the dock; at full the dock would sit on the top bar. Both wait. */
  :root:not([data-sheet="0"]) #app:has(.side:not(.closed)) .mapctl { display: none; }
  :root[data-sheet="2"] #app:has(.side:not(.closed)) .dock { display: none; }
  .topbar .switch { min-height: 40px; }
}


/* ----- Phase 1.1: everywhere ----- */
html, body { overscroll-behavior: none; }
#map, .toolbar, .palette, .topbar, .hint { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.backdrop { padding-top: calc(5vh + var(--safe-t)); }
.conn {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(var(--top) + var(--safe-t) + 8px); z-index: 45;
  background: #6b2f22; color: #fbeee6; padding: .5em 1em; border-radius: 8px; box-shadow: var(--shadow); font-size: .9rem;
  max-width: min(560px, 92%); text-align: center;
}
.plan header { cursor: pointer; }
.plan .chev { color: var(--ink-3); font-size: .9em; }
.plan.collapsed .items, .plan.collapsed header .details { display: none; }
.plan.collapsed { max-height: none; }
label.check input { width: auto; flex: none; }
label.check { align-items: flex-start; }
label.check input { margin-top: .25em; }
@media (pointer: coarse) {
  .iconbtn { min-width: 44px; min-height: 44px; }
  .mapctl button, .toolbar button { min-height: 44px; }
  button, .choice, a.button { min-height: 40px; }
  .side .body button.link { min-height: 36px; padding: .35em .2em; }
  .tabs button { padding: .7em 1em; }
  .plan .item .x { padding: .4em .7em; }
  .slider input[type=range] { height: 44px; }
  input, select, textarea { min-height: 40px; }
  .side .tabs button { min-height: 44px; }
  details summary { padding: .3em 0; }
}
/* Tablets: a narrower side panel so the map keeps most of the screen. */
@media (min-width: 721px) and (max-width: 1100px) {
  .side { width: min(340px, 45%); }
  .topbar { gap: 10px; }
}
/* Phones in landscape: the side panel becomes a right-hand drawer again. */
@media (max-width: 920px) and (max-height: 500px) and (orientation: landscape) {
  :root { --top: 44px; }
  .side { top: calc(var(--top) + var(--safe-t)); width: min(360px, 50%); border-radius: 0; border-left: 1px solid var(--line); }
  .side.closed { transform: translateX(100%); }
  .side .close { left: -46px; right: auto; top: 8px; width: 40px; height: 40px; border: 1px solid var(--line); background: rgba(244,240,230,.97); }
  .side.closed .close { left: -48px; }
  .side .grab { display: none; }
  .side.closed .close { display: block; }
  .side .close .when-closed { display: inline; }
  .side .close .when-open { display: none; }
  .topbar { flex-wrap: nowrap; }
  .topbar > :first-child, .topbar .strip { flex: none; height: auto; -webkit-mask-image: none; mask-image: none; }
  .topbar .strip { overflow: visible; }
  .topbar .town:has(.switch) .name { display: none; }
  .topbar .town:has(.switch) .switch { max-width: 40vw; font: 600 1rem var(--serif); color: var(--ink); }
  /* Lying down the dock dissolves: tools down the left, palette beside them, the drawer at the right. */
  .dock { display: contents; }
  .dock > * { position: absolute; }
  .toolbar { top: calc(var(--top) + var(--safe-t) + 6px); bottom: auto; left: calc(8px + env(safe-area-inset-left, 0px)); transform: none; flex-direction: column; max-height: calc(100% - var(--top) - 16px); overflow-x: hidden; overflow-y: auto; padding: 6px; gap: 4px; }
  .toolbar .panel { display: none; }
  .toolbar .sep { width: auto; height: 1px; margin: 2px 4px; }
  .palette, .plan { left: calc(66px + env(safe-area-inset-left, 0px)); right: auto; width: 300px; bottom: 8px; top: auto; max-height: 70%; }
}
.palette.chip { padding: 4px; max-height: none; }
@media (max-width: 720px) {
  /* The chip leaves the dock for the top of the map, clear of the view controls at the right. */
  .dock .palette.chip { position: fixed; left: 10px; right: 66px; width: auto; max-width: none; top: calc(var(--top) + var(--safe-t) + 6px); bottom: auto; max-height: none; }
}
.mapctl {
  position: absolute; z-index: 14; left: 10px; top: calc(var(--top) + var(--safe-t) + 470px); display: flex; flex-direction: column; gap: 4px;
  background: rgba(244, 240, 230, .96); border-radius: 10px; padding: 6px; box-shadow: var(--shadow); width: 56px;
}
.mapctl button { width: 44px; height: 40px; padding: 0; border: 0; background: none; border-radius: 8px; font-size: 1.2rem; }
.mapctl button:hover:not(:disabled) { background: var(--paper-2); }
.mapctl button.on { background: var(--accent); color: #fff; }
.mapctl .overlays {
  position: absolute; left: 62px; top: 0; width: 190px; max-height: 60vh; overflow-y: auto; display: flex; flex-direction: column;
  background: rgba(244, 240, 230, .98); border-radius: 10px; box-shadow: var(--shadow); padding: 6px;
}
.mapctl .overlays button { width: 100%; height: auto; text-align: left; font-size: .9rem; padding: .45em .6em; }
/* Short desktop windows: the controls sit in a row by the panel button. */
@media (min-width: 721px) and (max-height: 860px) {
  .mapctl { top: calc(var(--top) + var(--safe-t) + 8px); left: auto; right: calc(min(400px, 100%) + 52px); flex-direction: row; width: auto; }
  .mapctl .overlays { left: auto; right: 0; top: 52px; }
}
@media (min-width: 721px) { .hint { max-width: calc(100% - 520px); overflow: hidden; text-overflow: ellipsis; } }
@media (max-width: 720px) {
  /* The map's own controls run down the right edge, under the thumb and out of the dock's way. */
  .mapctl { top: calc(var(--top) + var(--safe-t) + 10px); bottom: auto; left: auto; right: 10px; flex-direction: column; width: 48px; padding: 4px; gap: 2px; }
  .mapctl button { width: 40px; height: 40px; min-height: 40px; flex: none; }
  .mapctl .overlays { left: auto; right: 52px; top: 0; bottom: auto; width: min(220px, calc(100vw - 80px)); max-height: 50vh; }
  .side { background: var(--paper); }
}
@media (max-width: 920px) and (max-height: 500px) and (orientation: landscape) {
  .mapctl { top: auto; bottom: calc(8px + var(--safe-b)); left: auto; right: calc(10px + env(safe-area-inset-right, 0px)); flex-direction: row; width: auto; justify-content: flex-start; }
  /* With the drawer open the controls move clear of it. */
  #app:has(.side:not(.closed)) .mapctl { right: calc(min(360px, 50%) + 10px + env(safe-area-inset-right, 0px)); }
  .mapctl .overlays { left: auto; right: 0; top: auto; bottom: 56px; max-height: 70vh; }
  /* Height is scarce lying down: one scrolling row of tabs. */
  .side .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; }
  .side .tabs::-webkit-scrollbar { display: none; }
  .side .tabs button { scroll-snap-align: center; }
  .hint { display: none; }
}
.stat.wx b { white-space: nowrap; }
.wxnow { display: flex; gap: .7em; align-items: center; margin: .3em 0 .6em; }
.wxnow .wxicon { font-size: 2rem; line-height: 1; }
canvas.interior { width: 100%; max-width: 360px; display: block; border-radius: 8px; margin: .4em 0 .6em; image-rendering: auto; }
canvas.radar { width: 100%; max-width: 240px; aspect-ratio: 1; border-radius: 8px; display: block; margin: .3em 0; }
.modes { display: flex; height: 10px; border-radius: 5px; overflow: hidden; margin: .4em 0 .2em; background: var(--line, #ddd); }
.modes i { display: block; height: 100%; }
.topbar .switch { font-size: .78rem; padding: 1px 4px; max-width: 14em; min-width: 7em; flex: none; border: 1px solid var(--line); border-radius: 4px; background: transparent; color: var(--ink-2); }
.civ summary { cursor: pointer; padding: .3em 0; } details.unread > summary { font-weight: 600; }

/* Motion is decoration; those who ask for less get none. */
@media (prefers-reduced-motion: reduce) {
  .side, .toast, .banner, .sheet { transition: none !important; animation: none !important; }
}
.choice { font: inherit; text-align: left; width: 100%; color: inherit; }

a.button { display: inline-block; border: 1px solid var(--line); border-radius: 8px; padding: .45em .8em; background: #fffdf8; color: var(--ink); text-decoration: none; font: inherit; }
a.button:hover { border-color: var(--accent); }

label.field { display: block; }
label.field > span { display: block; margin: .6em 0 .2em; font-size: .86rem; color: var(--ink-2); }
label.field > small { display: block; margin-top: .2em; }
