/* hman-wangzhan.cn — chart-paper + ink-line system.
   Light aged-paper base, ink-blue text, vermilion accents, and a deep-water
   panel for the game stages. System font stacks only, no remote assets. */

:root {
  --paper: #f3ebdc;
  --paper-2: #e9dec8;
  --paper-3: #fbf6ec;
  --rule: #c9b38c;
  --rule-soft: #ded0b4;
  --ink: #16324f;
  --ink-2: #4a6480;
  --ink-3: #6f8499;
  --vermilion: #b24a2e;
  --vermilion-2: #8e3721;
  --verdigris: #2f6f62;
  --deep: #0e2233;
  --deep-2: #163449;
  --deep-line: #28577a;
  --shoal: #d9c9ad;
  --f-serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  --f-sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --f-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --maxw: 1140px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  background-image:
    repeating-linear-gradient(0deg, rgba(201, 179, 140, .16) 0 1px, transparent 1px 64px),
    repeating-linear-gradient(90deg, rgba(201, 179, 140, .16) 0 1px, transparent 1px 64px);
  color: var(--ink);
  font: 400 16px/1.8 var(--f-sans);
}

a { color: var(--vermilion-2); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--vermilion); outline-offset: 2px; }

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--ink); color: #fff; padding: 10px 14px; z-index: 9;
}
.skip:focus { left: 8px; top: 8px; }

/* ---------- masthead ---------- */
.masthead {
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, var(--paper-3), var(--paper));
}
.brand-row, .nav-row, .wrap, .footer > * {
  max-width: var(--maxw); margin: 0 auto; padding: 0 16px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 14px 0 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark { display: block; width: 44px; height: 44px; color: var(--vermilion); flex: none; }
.rose { display: block; width: 100%; height: 100%; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font: 700 clamp(19px, 5vw, 25px)/1.25 var(--f-serif); letter-spacing: .02em; }
.brand-sub { font-size: 12.5px; color: var(--ink-3); letter-spacing: .06em; }
.nb { white-space: nowrap; }

.nav { border-top: 1px dashed var(--rule-soft); }
.nav-row { display: flex; flex-wrap: wrap; gap: 4px 2px; padding: 6px 12px 8px; }
.nav-link {
  padding: 7px 12px; font-size: 14.5px; color: var(--ink-2);
  border-bottom: 2px solid transparent; min-height: 40px; display: flex; align-items: center;
}
.nav-link:hover { color: var(--vermilion-2); text-decoration: none; }
.nav-link.is-on { color: var(--vermilion-2); border-bottom-color: var(--vermilion); font-weight: 600; }

/* ---------- page frame ---------- */
.wrap { padding-top: 18px; padding-bottom: 40px; }
.crumb { font-size: 13px; color: var(--ink-3); margin: 0 0 14px; }
.crumb a { color: var(--ink-2); }
.crumb-sep { margin: 0 6px; }

.h1 {
  font: 700 clamp(23px, 6.2vw, 36px)/1.35 var(--f-serif);
  margin: 0 0 12px; letter-spacing: .01em;
  padding-bottom: 12px; border-bottom: 3px double var(--rule);
}
.lede { font-size: 16.5px; color: var(--ink-2); margin: 0 0 22px; max-width: 70ch; }
.h2 {
  font: 700 clamp(19px, 4.6vw, 24px)/1.4 var(--f-serif);
  margin: 34px 0 12px; padding-left: 12px; border-left: 4px solid var(--vermilion);
}
.h3 { font: 700 17px/1.5 var(--f-sans); margin: 22px 0 8px; }
p { margin: 0 0 14px; }
.prose, .article { max-width: 68ch; }
.article p, .article li { color: #1b3550; }
ul, ol { padding-left: 1.3em; }
li { margin: 0 0 8px; }
code { font: 13.5px/1.6 var(--f-mono); background: var(--paper-2); padding: 1px 5px; border-radius: 2px; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 28px 0; }

.contour { color: var(--rule); margin: 30px 0; }
.contour svg { display: block; width: 100%; height: 22px; }

/* ---------- cards ---------- */
/* Single column by default: `repeat(auto-fit, minmax(0, 1fr))` would hand each
   card its own track at any width, squeezing six cards into six slivers on a
   phone. Columns are added only at the widths that can hold them. */
.grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.grid > * { min-width: 0; }
@media (min-width: 620px) { .grid-2, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 960px) { .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.card {
  position: relative; background: var(--paper-3);
  border: 1px solid var(--rule); border-left: 3px solid var(--verdigris);
  padding: 16px 16px 12px; min-width: 0;
}
.card-no {
  font: 600 11.5px/1 var(--f-mono); color: var(--vermilion);
  letter-spacing: .1em; display: block; margin-bottom: 7px;
}
.card-h { font: 700 17.5px/1.45 var(--f-serif); margin: 0 0 7px; }
.card-h a { color: var(--ink); }
.card-h a:hover { color: var(--vermilion-2); }
.card-p { font-size: 14.5px; color: var(--ink-2); margin: 0 0 8px; }
.card-meta { font: 12.5px/1.6 var(--f-mono); color: var(--ink-3); margin: 0; }
.card.is-hidden { display: none; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 18px; padding: 0; list-style: none; }
.tag-btn {
  font: 13.5px/1 var(--f-sans); padding: 10px 14px; min-height: 40px;
  background: var(--paper-3); color: var(--ink-2);
  border: 1px solid var(--rule); border-radius: 999px; cursor: pointer;
}
.tag-btn[aria-pressed="true"] { background: var(--verdigris); border-color: var(--verdigris); color: #fff; }
.tag { font: 12px/1 var(--f-mono); color: var(--verdigris); border: 1px solid var(--rule-soft); padding: 3px 7px; }

/* ---------- game stage ---------- */
.game { margin: 0 0 26px; }
@media (min-width: 900px) {
  .game { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 18px; align-items: start; }
}
.stage {
  background: var(--deep);
  background-image:
    repeating-linear-gradient(0deg, rgba(40, 87, 122, .55) 0 1px, transparent 1px 28px),
    repeating-linear-gradient(90deg, rgba(40, 87, 122, .55) 0 1px, transparent 1px 28px);
  border: 1px solid var(--deep-line); padding: 12px; min-width: 0;
}
/* Never upscale past the canvas's own pixel size: stretched to a 820px stage
   the compass and the water chart became mostly empty navy. */
.stage canvas { display: block; width: 100%; max-width: 640px; height: auto; margin: 0 auto; background: transparent; }
.state {
  margin: 10px 0 0; font: 600 14.5px/1.6 var(--f-sans); color: #e8f1f7;
  min-height: 2.6em; background: rgba(13, 32, 48, .75); padding: 7px 10px;
  border-left: 3px solid var(--vermilion);
}
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }
.btn {
  font: 600 15px/1 var(--f-sans); padding: 13px 18px; min-height: 46px; min-width: 46px;
  background: var(--vermilion); color: #fff; border: 1px solid var(--vermilion-2);
  cursor: pointer;
}
.btn:hover { background: var(--vermilion-2); }
.btn.sec { background: var(--paper-3); color: var(--ink); border-color: var(--rule); }
.btn.sec:hover { background: var(--paper-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.readout {
  background: var(--paper-3); border: 1px solid var(--rule); padding: 12px 14px; min-width: 0;
}
.readout dl { display: grid; grid-template-columns: auto auto; gap: 6px 10px; margin: 0; }
.readout dt { font-size: 13.5px; color: var(--ink-3); }
.readout dd { margin: 0; font: 700 15px/1.4 var(--f-mono); color: var(--ink); text-align: right; }
.warn {
  margin: 10px 0 0; padding: 9px 11px; font-size: 13.5px;
  background: #f7e3dc; border: 1px solid var(--vermilion); color: var(--vermilion-2);
}

/* chart grid for the route game */
.chart { display: grid; gap: 2px; grid-template-columns: repeat(10, minmax(0, 1fr)); }
.cell {
  aspect-ratio: 1; min-width: 0; padding: 0; border: 1px solid var(--deep-line);
  background: #123048; cursor: pointer; font: 700 11px/1 var(--f-mono); color: #cfe3ef;
}
.cell[data-k="rock"] { background: #3d3326; border-color: #6b5a3f; cursor: not-allowed; }
.cell[data-k="start"] { background: var(--verdigris); }
.cell[data-k="end"] { background: var(--vermilion); }
.cell.on { background: #2f86b5; }
.cell.head { outline: 2px solid #ffd9a0; outline-offset: -2px; }

/* cargo rows */
.boxes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.box-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  background: var(--paper-3); border: 1px solid var(--rule); padding: 8px 10px;
}
.box-w { font: 700 15px/1 var(--f-mono); min-width: 5.5em; }
.box-row .btn { padding: 9px 12px; min-height: 42px; font-size: 13.5px; }
.box-row[data-side="L"] .side-L, .box-row[data-side="R"] .side-R { background: var(--verdigris); border-color: var(--verdigris); color: #fff; }

/* knot buttons */
/* Four across at every width: two large squares on a phone pushed the start
   button and the status line below the fold. */
.knots { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; max-width: 420px; }
.knot {
  min-width: 0; aspect-ratio: 1; background: #14374f; border: 2px solid var(--deep-line);
  cursor: pointer; padding: 8px; color: #8fc4e4;
}
.knot svg { display: block; width: 100%; height: 100%; }
.knot.lit { background: var(--vermilion); border-color: #ffd9a0; color: #fff; }

/* flag cards: four across even on a phone, so all twelve cards and the status
   line stay on one screen instead of three rows of oversized cards */
.deck { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.flagcard {
  min-width: 0; aspect-ratio: 3 / 4; padding: 6px; cursor: pointer;
  background: #14374f; border: 2px solid var(--deep-line); color: #9ac7e2;
}
.flagcard svg { display: block; width: 100%; height: auto; }
.flagcard.up { background: var(--paper-3); border-color: var(--rule); }
.flagcard.done { background: #e4ece3; border-color: var(--verdigris); cursor: default; }
.flagcard .back { font: 700 20px/1 var(--f-mono); display: block; padding-top: 30%; text-align: center; }

/* ---------- forms ---------- */
.form { background: var(--paper-3); border: 1px solid var(--rule); padding: 14px; }
.field { display: block; margin: 0 0 12px; }
.field > span { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; font: 16px/1.4 var(--f-mono); padding: 11px 12px; min-height: 46px;
  background: #fff; border: 1px solid var(--rule); color: var(--ink);
}
.hint { font-size: 13px; color: var(--ink-3); margin: 4px 0 0; }
.result { margin: 12px 0 0; padding: 11px 13px; background: var(--paper-2); border-left: 3px solid var(--verdigris); font-size: 15px; }

/* ---------- tables → cards on narrow screens ---------- */
.tw { margin: 0 0 20px; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
caption { text-align: left; font-size: 13px; color: var(--ink-3); padding-bottom: 6px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--rule-soft); }
th { font: 600 13.5px/1.5 var(--f-sans); color: var(--ink-2); background: var(--paper-2); }
td.num { font-family: var(--f-mono); }
@media (max-width: 560px) {
  /* a table-caption inside a display:block table shrinks to min-content and
     renders one character per line, so it has to become a block too */
  .tw caption { display: block; width: 100%; }
  .tw table, .tw tbody, .tw tr, .tw td { display: block; width: 100%; }
  .tw thead { position: absolute; left: -9999px; }
  .tw tr { border: 1px solid var(--rule); background: var(--paper-3); margin-bottom: 10px; padding: 8px 10px; }
  .tw td { border: 0; padding: 4px 0; display: flex; gap: 10px; justify-content: space-between; }
  .tw td::before { content: attr(data-l); color: var(--ink-3); font-size: 13px; flex: none; }
}

/* ---------- figures, notes, toc ---------- */
.fig { margin: 22px 0; max-width: 100%; }
.fig img { display: block; width: 100%; height: auto; background: var(--paper-3); border: 1px solid var(--rule); }
.fig figcaption { font-size: 13.5px; color: var(--ink-3); margin-top: 7px; }
/* Full-bleed diagrams on phones: a 480-unit viewBox squeezed into a 358px
   column renders its 14px labels at about 10.5px. Edge to edge it is ~11.4px. */
@media (max-width: 560px) {
  .fig { margin-left: -16px; margin-right: -16px; }
  .fig img { border-left: 0; border-right: 0; }
  .fig figcaption { padding: 0 16px; }
}
.note {
  margin: 20px 0; padding: 12px 14px; background: var(--paper-2);
  border: 1px dashed var(--rule); font-size: 14.5px;
}
.note p { margin: 0; }
.toc { margin: 0 0 24px; padding: 12px 14px; background: var(--paper-3); border: 1px solid var(--rule); }
.toc h2 { font: 600 13px/1.4 var(--f-sans); color: var(--ink-3); margin: 0 0 7px; letter-spacing: .08em; padding: 0; border: 0; }
.toc ol { margin: 0; padding-left: 1.2em; font-size: 14.5px; }
.toc li { margin: 0 0 4px; }
@media (min-width: 1040px) {
  .withtoc { display: grid; grid-template-columns: minmax(0, 1fr) 232px; gap: 30px; align-items: start; }
  .withtoc .toc { position: sticky; top: 16px; order: 2; border-left: 3px solid var(--rule); }
  .withtoc .article { order: 1; }
}

.meta-row { font: 13px/1.7 var(--f-mono); color: var(--ink-3); margin: -4px 0 20px; }
.pager { display: flex; flex-wrap: wrap; gap: 10px; margin: 30px 0 0; font-size: 14.5px; }
.pager a { background: var(--paper-3); border: 1px solid var(--rule); padding: 10px 13px; }

/* ---------- footer ---------- */
.footer { border-top: 1px solid var(--rule); background: var(--paper-2); padding: 20px 0 30px; }
.disclaim { font-size: 13.5px; color: var(--ink-2); max-width: 78ch; }
.foot-links { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
