/* Layout idea: the board is drawn as a sea chart sheet with a neatline; controls sit beside it (below it on a phone). */

/* Self-hosted fonts (SIL Open Font License, see fonts/OFL-*.txt), latin subset. Archivo is a variable font. */
@font-face {
  font-family: "Archivo"; font-style: normal; font-weight: 400 700; font-stretch: 100%; font-display: swap;
  src: url("fonts/archivo-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Libre Caslon Text"; font-style: italic; font-weight: 400; font-display: swap;
  src: url("fonts/libre-caslon-text-italic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --page: #f3f6f3;
  --panel: #ffffff;
  --ink: #14303a;
  --muted: #56707a;
  --line: #c3d2d3;
  --accent: #b3246b;            /* chart magenta, used for lights and notes on sea charts */
  --sea: #e9f1ef;
  --shoal-outer: #d2e5e8;
  --shoal-inner: #b7d5dc;
  --pier: #14303a;
  --coast: #f6f1e0;
  --token: #fbf8ee;
  --map-ink: #14303a;
  --hot: #b3246b;
  --fog: #c3cdd0;
  --t-forest: #5f9d68;
  --t-pasture: #abd07c;
  --t-fields: #e7c659;
  --t-hills: #cc7950;
  --t-mountains: #919ca8;
  --t-desert: #e5d8b1;
  --t-gold: #e59a2e;
  --display: "Libre Caslon Text", "Iowan Old Style", Georgia, serif;
  --body: "Archivo", "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0c1a20; --panel: #12252d; --ink: #dce8e6; --muted: #8ea6ab; --line: #28434d;
    --accent: #f07fb2; --sea: #0f232b; --shoal-outer: #14323d; --shoal-inner: #1a4250;
    --pier: #dce8e6; --coast: #0c1a20; --token: #f1ecdc; --fog: #2d3f47;
    --t-forest: #4f8c59; --t-pasture: #97bf6b; --t-fields: #d3b24a; --t-hills: #b96a44;
    --t-mountains: #808c99; --t-desert: #cdbf97; --t-gold: #cf8926;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0c1a20; --panel: #12252d; --ink: #dce8e6; --muted: #8ea6ab; --line: #28434d;
  --accent: #f07fb2; --sea: #0f232b; --shoal-outer: #14323d; --shoal-inner: #1a4250;
  --pier: #dce8e6; --coast: #0c1a20; --token: #f1ecdc; --fog: #2d3f47;
  --t-forest: #4f8c59; --t-pasture: #97bf6b; --t-fields: #d3b24a; --t-hills: #b96a44;
  --t-mountains: #808c99; --t-desert: #cdbf97; --t-gold: #cf8926;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--page); color: var(--ink);
  font: 400 15px/1.45 var(--body);
  -webkit-text-size-adjust: 100%;
}
.wrap { max-width: 1080px; margin: 0 auto; padding: 20px 16px 40px; display: flex; flex-direction: column; gap: 18px; }
header { display: flex; flex-direction: column; gap: 4px; }
h1 { font: italic 400 clamp(28px, 7vw, 42px)/1.1 var(--display); margin: 0; text-wrap: balance; letter-spacing: -0.01em; }
header p { margin: 0; color: var(--muted); max-width: 60ch; }
h2 { font: 600 12px/1.2 var(--body); letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin: 0; }

main { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 880px) { main { grid-template-columns: minmax(0, 1fr) 330px; gap: 28px; } }

.sheet {
  background: var(--sea);
  border: 1px solid var(--ink);
  box-shadow: inset 0 0 0 4px var(--sea), inset 0 0 0 5px var(--ink);
  padding: 8px;
  position: relative;
}
#map svg { display: block; width: 100%; height: auto; }
/* until the script draws the board, hold the space of the default 3-4 board so the page doesn't jump */
#map:empty { aspect-ratio: 633 / 560; }
#prod:empty { min-height: 172px; }   /* likewise the six production rows of a base board */

/* edit mode: a corner button on the map, which opens a strip of move controls along the map's top */
.editbtn {
  position: absolute; top: 14px; right: 14px; z-index: 1;
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; font-size: 14px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--ink);
}
.editbtn:hover { color: var(--accent); border-color: var(--accent); }
.editbtn svg { width: 16px; height: 16px; display: block; }
.sheet.roomy { padding-top: 54px; }   /* a band for the Edit button when it would cover the map */
.editbar { margin-bottom: 8px; padding: 10px; background: var(--panel); border: 1px solid var(--line); }
.editrow { display: flex; flex-wrap: wrap; gap: 8px; }
.editrow .seg { flex: 1 1 250px; }
.edact { display: flex; gap: 8px; flex: 1 1 auto; }
.edact button { flex: 1 1 auto; padding: 10px 12px; font-size: 14px; }
button:disabled { opacity: .4; cursor: default; transform: none; }
button.alt:disabled:hover { color: var(--ink); border-color: var(--ink); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.note { margin: 0; color: var(--accent); font-weight: 600; overflow-wrap: anywhere; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.note:empty { display: none; }

aside { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.group { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.bar { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; }
.bar:has(> [hidden]) { grid-template-columns: 1.4fr 1fr; }   /* harbors off: no Harbors reshuffle */
button { font: 700 15px/1 var(--body); letter-spacing: .02em; border-radius: 2px; padding: 14px 10px; cursor: pointer; }
button.go { background: var(--ink); color: var(--page); border: 1px solid var(--ink); }
button.go:hover { background: var(--accent); border-color: var(--accent); }
button.alt { background: var(--panel); color: var(--ink); border: 1px solid var(--ink); }
button.alt:hover { color: var(--accent); border-color: var(--accent); }
button:active { transform: translateY(1px); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }

.strip { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; }
.strip button { flex: none; width: 68px; padding: 4px; background: var(--sea); border: 1px solid var(--line); }
.strip button[aria-current="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.strip svg { display: block; width: 100%; height: auto; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
legend { padding: 0; margin-bottom: 8px; font: 600 12px/1.2 var(--body); letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--ink); border-radius: 2px; overflow: hidden; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: 10px 6px; font-weight: 600; background: var(--panel); }
.seg label + label span { border-left: 1px solid var(--ink); }
.seg input:checked + span { background: var(--ink); color: var(--page); }
.seg input:disabled + span { color: var(--line); cursor: default; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -4px; }

.rules { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.rules label { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.rules input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); flex: none; }

/* production, which is also the map key: swatch, terrain and resource, bar, pips */
.prod { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; gap: 8px 12px; align-items: center; }
.prod .sw { display: grid; place-items: center; width: 22px; height: 22px; background: var(--sw); border: 1px solid var(--ink); color: var(--map-ink); }
.prod .sw svg { width: 15px; height: 15px; display: block; }
.prod .none { grid-column: span 2; color: var(--muted); font-size: 13px; }
.prod .bar2 { height: 10px; background: var(--line); }
.prod .bar2 i { display: block; height: 100%; }
.prod .n { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }

ol.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
ol.list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
ol.list b { font-weight: 600; white-space: nowrap; }
ol.list b i { display: inline-block; width: 10px; height: 10px; margin-right: 8px; border: 1px solid var(--ink); }
ol.list span { color: var(--muted); text-align: right; }
ol.rows li { display: block; }
ol.rows li em { font-style: normal; color: var(--muted); margin-right: 8px; font-variant-numeric: tabular-nums; }
ol.rows li u { text-decoration: none; color: var(--muted); }

.under { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
@media (min-width: 620px) { .under { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 24px; align-items: start; } }
details.fold { border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); min-width: 0; }
details.fold[open] { border-bottom: 0; }
details.fold summary {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 13px 0; cursor: pointer; list-style: none;
  font: 600 12px/1.2 var(--body); letter-spacing: .09em; text-transform: uppercase; color: var(--ink);
}
details.fold summary::-webkit-details-marker { display: none; }
details.fold summary::after { content: "+"; font: 400 20px/0.6 var(--body); }
details.fold[open] summary::after { content: "\2212"; }
details.fold p { margin: 0 0 10px; }

/* board */
.num { font: 700 21px var(--body); text-anchor: middle; fill: var(--map-ink); }
.num.hot { fill: var(--hot); }
.ratio { font: 700 14px var(--body); text-anchor: middle; fill: var(--map-ink); }
.ratio.any { font-size: 16px; }
.fogq { font: 700 24px var(--body); text-anchor: middle; fill: var(--map-ink); opacity: .45; }
.hex { outline: none; animation: rise .32s ease-out both; transform-box: fill-box; transform-origin: center; }
.hex.sel > polygon, .hex:focus-visible > polygon { stroke: var(--accent); stroke-width: 6; }
.hex.seln > circle:first-of-type { stroke: var(--accent); stroke-width: 5; }
.port.selp .pm, .port:focus-visible .pm { stroke: var(--accent); stroke-width: 5; }
.hex.live, .port[role], .spot { cursor: pointer; outline: none; }
.spot circle { fill: var(--token); fill-opacity: .9; stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 4 3; }
.spot:focus-visible circle { stroke-width: 5; stroke-dasharray: none; }
.port { animation: rise .32s ease-out both; transform-box: fill-box; transform-origin: center; }
.still .hex, .still .port { animation: none; }
@keyframes rise { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .hex, .port { animation: none; } }
/* the explainer under the tool: what the generator does, in words people search for */
.about summary h2 { font: inherit; letter-spacing: inherit; color: inherit; }   /* looks like the other dropdowns */
.about .cols { display: grid; gap: 0 40px; padding-bottom: 8px; }
@media (min-width: 880px) { .about .cols { grid-template-columns: 1fr 1fr; } }
.about h3 { font: 700 16px/1.3 var(--body); margin: 14px 0 6px; }
.about p { margin: 0 0 10px; max-width: 68ch; }
footer { color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); padding-top: 14px; }
footer p { margin: 0; text-wrap: pretty; }

/* printing: the board and its legend on white paper, whatever theme is on screen */
@media print {
  :root, :root:not([data-theme="light"]), :root[data-theme="dark"] {
    color-scheme: light;
    --page: #fff; --panel: #fff; --ink: #14303a; --muted: #56707a; --line: #c3d2d3;
    --sea: #e9f1ef; --shoal-outer: #d2e5e8; --shoal-inner: #b7d5dc; --pier: #14303a; --coast: #f6f1e0; --token: #fbf8ee; --fog: #c3cdd0;
    --t-forest: #5f9d68; --t-pasture: #abd07c; --t-fields: #e7c659; --t-hills: #cc7950; --t-mountains: #919ca8; --t-desert: #e5d8b1; --t-gold: #e59a2e;
  }
  aside, .bar, .hint, .strip, #histbox, .editbtn, .editbar, .note, .about, header p, footer { display: none !important; }
  .hex, .port { animation: none; }
  .spot { display: none; }
  .sheet { break-inside: avoid; }
}

/* rounded corners on the page's boxes, buttons and swatches (the board itself keeps its hex shapes) */
.sheet { border-radius: 14px; }
.editbtn, button, .strip button { border-radius: 8px; }
.editbar { border-radius: 10px; }
.seg { border-radius: 8px; }
.strip svg { border-radius: 4px; }
.prod .sw { border-radius: 6px; }
.prod .bar2, .prod .bar2 i { border-radius: 999px; }
ol.list b i { border-radius: 3px; }
