:root {
  color-scheme: light;
  --background: #f4f1e8;
  --panel: #fdfbf6;
  --inset: #f7f5ee;
  --line: #dbd7c9;
  --text: #252a23;
  --muted: #5d6358;
  --accent: #24573f;
  --accent-strong: #153f2d;
  --gold: #aa8050;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--background); color: var(--text); }
button, input, select { font: inherit; }
button, summary { cursor: pointer; }
h1, h2, p { margin: 0; }
h2 { font-size: 1rem; font-weight: 680; }
a { color: var(--accent); }
.shell { width: min(100% - 3.5rem, 86rem); margin-inline: auto; }
.topbar { border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar-inner { min-height: 4.3rem; display: flex; align-items: center; gap: 1rem; }
.workshop-brand { display: flex; align-items: center; gap: .65rem; text-decoration: none; color: var(--text); }
.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  flex: none;
  border-radius: .56rem;
  color: #f5e9cd;
  background: var(--accent);
  box-shadow: inset 0 0 0 1px #ffffff50;
  font: 1.2rem/1 var(--mono);
}
.workshop-brand .brand-mark::before {
  content: "";
  width: 1.05rem;
  height: 1.05rem;
  border: 1px solid currentColor;
  transform: rotate(45deg);
}
.workshop-brand .brand-mark::after {
  content: "";
  position: absolute;
  width: .52rem;
  height: .9rem;
  background: currentColor;
  clip-path: polygon(50% 0, 100% 65%, 50% 49%, 0 65%);
}
.brand { font-size: .94rem; font-weight: 740; white-space: nowrap; letter-spacing: .04em; }
.brand span { display: block; font-size: .68rem; margin-top: .11rem; color: var(--muted); font-weight: 500; }
.topbar-actions { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: .65rem 1.35rem; }
.topbar-play { color: var(--muted); font-size: .875rem; text-decoration: none; white-space: nowrap; }
.topbar-play:hover { color: var(--accent); }
.topbar-play span { margin-left: .15rem; color: var(--accent); }

.intro { padding-block: clamp(2rem, 5vw, 3.2rem) 1.55rem; }
.intro h1 { font-size: clamp(2rem, 4vw, 3.15rem); line-height: 1.15; letter-spacing: -.045em; }
.intro p { color: var(--muted); margin-top: .55rem; line-height: 1.6; font-size: .95rem; }
.workshop {
  background-image: radial-gradient(ellipse at 2% 22%, #e7e7d8, transparent 50%);
  background-repeat: no-repeat;
}
.workshop-intro { padding-block: clamp(1.5rem, 3vw, 2.7rem) clamp(1rem, 2vw, 1.65rem); }
.workshop-intro h1 { font-family: "Songti SC", "Noto Serif CJK SC", "SimSun", serif; font-weight: 800; letter-spacing: .045em; }
.workspace { display: grid; grid-template-columns: clamp(14rem, 20.5vw, 17.5rem) minmax(0, 1fr); gap: 1rem; align-items: start; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: .85rem;
  box-shadow: 0 2px 4px #37302308, 0 10px 30px -24px #332e24a0;
}
.controls { padding: 1.2rem 1rem 1.05rem; }
.panel-heading { padding-inline: .1rem; }
.panel-heading h2 { font-size: 1.12rem; }
.controls form { display: grid; gap: 1rem; margin-top: 1rem; }
.terrain-field { border: 0; margin: 0; padding: 0; min-inline-size: 0; }
.terrain-field legend { padding: 0; margin-bottom: .45rem; color: var(--muted); font-size: .8rem; font-weight: 620; }
.terrain-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .44rem; }
.terrain-option { position: relative; min-width: 0; cursor: pointer; }
.terrain-option input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.terrain-tile {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 3.1rem;
  border: 1px solid var(--line);
  padding: .35rem .45rem;
  border-radius: .48rem;
  font-weight: 610;
  font-size: .82rem;
  background: var(--inset);
}
.terrain-tile:hover { border-color: #a2a68d; }
.terrain-option input:checked + .terrain-tile { background: #e8ede0; color: var(--accent-strong); border-color: #608371; }
.terrain-option input:focus-visible + .terrain-tile { outline: 2px solid var(--accent); outline-offset: 2px; }
.terrain-symbol { display: grid; place-items: center; width: 1.4rem; height: 1.4rem; flex: none; border-radius: .3rem; }
.terrain-symbol::before { content: ""; display: block; width: .85rem; height: .85rem; background: currentColor; }
.terrain-forest { color: #305c45; background: #d4e1cd; }
.terrain-forest::before { clip-path: polygon(50% 0, 85% 48%, 70% 48%, 98% 79%, 60% 79%, 60% 100%, 40% 100%, 40% 79%, 2% 79%, 30% 48%, 15% 48%); }
.terrain-marsh { color: #35686b; background: #d7e5e0; }
.terrain-marsh::before { height: .67rem; background: repeating-linear-gradient(0deg, currentColor 0 2px, transparent 2px 4px); transform: skewX(-24deg); }
.terrain-ridge { color: #665d4c; background: #e4dfcc; }
.terrain-ridge::before { clip-path: polygon(0 91%, 33% 29%, 49% 58%, 70% 5%, 100% 91%); }
.terrain-town { color: #885a41; background: #ece0cd; }
.terrain-town::before { clip-path: polygon(0 45%, 50% 5%, 100% 45%, 86% 45%, 86% 95%, 59% 95%, 59% 65%, 40% 65%, 40% 95%, 14% 95%, 14% 45%); }
.terrain-palace { color: #8d6340; background: #eddebd; }
.terrain-forbidden { color: #99514b; background: #eedcd2; }
.terrain-palace::before, .terrain-forbidden::before { clip-path: polygon(50% 1%, 70% 21%, 97% 35%, 100% 46%, 88% 46%, 88% 94%, 62% 94%, 62% 62%, 38% 62%, 38% 94%, 12% 94%, 12% 46%, 0 46%, 3% 35%, 30% 21%); }
.field { display: grid; gap: .35rem; margin-bottom: .15rem; min-width: 0; }
.field label, .scan-route label { font-size: .8125rem; color: var(--muted); font-weight: 620; }
.field input, .field select, .scan-route select {
  width: 100%;
  min-height: 2.65rem;
  border: 1px solid var(--line);
  border-radius: .45rem;
  padding: .5rem .65rem;
  background: var(--inset);
  color: var(--text);
  font-size: 1rem;
}
.field input { font-family: var(--mono); }
.field input::placeholder { color: var(--muted); font-family: system-ui, sans-serif; font-size: .875rem; }
.field-hint { color: var(--muted); font-size: .76rem; line-height: 1.55; }
.select-wrap { position: relative; }
.select-wrap select { appearance: none; padding-right: 2rem; }
.select-wrap::after { content: ""; position: absolute; right: .75rem; top: 42%; width: .42rem; height: .42rem; border: solid var(--muted); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); pointer-events: none; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-height: 2.45rem;
  padding: .48rem .72rem;
  border: 1px solid var(--line);
  border-radius: .45rem;
  background: var(--panel);
  color: var(--text);
  font-size: .82rem;
  font-weight: 630;
  text-align: center;
}
.button:hover { border-color: #a0a38d; background: #eeede3; }
.button:disabled { opacity: .5; cursor: default; }
.primary { color: #fff9eb; background: var(--accent); border-color: var(--accent); }
.primary:hover { color: #fff9eb; background: var(--accent-strong); border-color: var(--accent-strong); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.generate-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .4rem; }
.generate-actions .button { min-height: 2.65rem; white-space: nowrap; }
.generate-actions .primary:only-child, .generate-actions:has(#random[hidden]) .primary { grid-column: 1 / -1; }

.map-panel { padding: .9rem; min-width: 0; scroll-margin-top: .7rem; }
.map-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .6rem .85rem; margin-bottom: .8rem; }
.map-heading { min-width: 0; }
.map-heading h2 { font-size: clamp(1.15rem, 2vw, 1.42rem); }
.map-meta { color: var(--muted); font: .75rem/1.5 var(--mono); margin-top: .25rem; overflow-wrap: anywhere; }
.map-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .42rem; }
.view-toggle { display: inline-flex; align-items: center; gap: .12rem; border: 1px solid var(--line); background: var(--inset); border-radius: .5rem; padding: .15rem; }
.view-toggle button { border: 0; border-radius: .32rem; min-height: 2rem; background: none; color: var(--muted); padding: .25rem .62rem; font-size: .8rem; font-weight: 620; }
.view-toggle button:hover { color: var(--accent-strong); }
.view-toggle button[aria-pressed="true"] { background: #e0e9de; color: var(--accent-strong); }
.export-menu { position: relative; }
.export-menu summary { list-style: none; }
.export-menu summary::-webkit-details-marker { display: none; }
.export-menu[open] summary { background: #edeade; }
.export-options {
  position: absolute;
  z-index: 4;
  width: 8.4rem;
  top: calc(100% + .35rem);
  right: 0;
  padding: .24rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: .52rem;
  box-shadow: 0 .35rem 1.1rem #35352930;
}
.export-options button { display: block; text-align: left; width: 100%; border: 0; border-radius: .33rem; padding: .58rem .55rem; color: var(--text); background: transparent; font-size: .84rem; }
.export-options button:hover { background: #e8ede0; color: var(--accent-strong); }

.map-frame {
  position: relative;
  border: 1px solid #3f493b;
  border-radius: .58rem;
  background: #333e32;
  padding: .29rem;
}
.map-surface { min-width: 0; border-radius: .32rem; overflow: hidden; background: #2e3c31; }
.map-stage { position: relative; width: 100%; aspect-ratio: var(--map-columns, 39) / var(--map-rows, 19); container-type: inline-size; }
.map-stage > canvas, .map { display: block; position: absolute; inset: 0; width: 100%; height: 100%; }
.map-surface--pan:not(.map-surface--overview) { height: clamp(17rem, 53vh, 34rem); overflow: auto; scrollbar-color: #748674 #313d33; }
.map-surface--pan:not(.map-surface--overview) .map-stage { width: calc(var(--map-columns) * 14px); }
.map-surface--pan.map-surface--overview { display: grid; place-items: center; }
.map-surface--pan.map-surface--overview .map-stage { max-width: 47rem; }
.compass {
  position: absolute; z-index: 2; top: .7rem; right: .72rem;
  display: grid; justify-items: center; align-content: center; gap: .11rem;
  width: 2.35rem; height: 2.6rem; border: 1px solid #bfb38e86; border-radius: .36rem;
  background: #202b22d4; color: #e8d9b5; pointer-events: none;
}
.compass b { font: .65rem/1 var(--mono); }
.compass i { width: .8rem; height: 1rem; background: linear-gradient(90deg, #f2dfae 50%, #a59975 50%); clip-path: polygon(50% 0, 96% 100%, 50% 72%, 4% 100%); }
.player-marker, .scan-marker {
  position: absolute; z-index: 1; left: var(--x); top: var(--y); transform: translate(-50%, -50%);
  width: clamp(.55rem, 1.55cqi, 1rem); aspect-ratio: 1; pointer-events: none;
}
.player-marker { border-radius: 50%; background: #e3f4dd; border: 2px solid #265943; box-shadow: 0 0 0 1px #f9f1cb, 0 1px 4px 2px #162719ac; }
.scan-marker { border: 2px solid #fff2bd; border-radius: .16rem; box-shadow: 0 0 0 1px #5e462b, 0 0 6px #f0c077; }
.map {
  margin: 0; display: grid; grid-template-rows: repeat(var(--map-rows), minmax(0, 1fr)); color: #f1e9cd;
  font: 650 min(1.14rem, calc(77cqi / var(--map-columns)))/1 var(--mono);
  background: #213027;
  white-space: normal;
}
.map-row { display: grid; grid-template-columns: repeat(var(--map-columns), minmax(0, 1fr)); align-items: center; justify-items: center; }
.map .tile-plain { color: #afbaa6; }
.map .tile-forest { color: #aad092; }
.map .tile-water { color: #8bc9c5; }
.map .tile-ridge, .map .tile-building { color: #d2ae91; }
.map .tile-wall, .map .tile-hall { color: #e0aa80; }
.map .tile-path, .map .tile-gate, .map .tile-site, .map .tile-camp { color: #f3d598; }
.map .tile-square { color: #c4d0b0; }
.map .tile-residence { color: #f5b7c3; }
.scan-controls:not([hidden]) { display: flex; align-items: center; flex-wrap: wrap; gap: .45rem .65rem; margin-bottom: .65rem; }
.scan-route:not([hidden]) { display: flex; align-items: center; flex-wrap: wrap; gap: .45rem; }
.scan-route select { min-height: 2.2rem; font-size: .8rem; }
.scan-buttons { display: flex; gap: .31rem; flex-wrap: wrap; }
.scan-buttons .button { min-height: 2.2rem; padding: .34rem .56rem; }
.scan-buttons .button[aria-pressed="true"] { color: var(--accent-strong); background: #e3eddf; border-color: #829c83; }
.scan-position { color: var(--muted); font-size: .81rem; }
.map-info { display: flex; align-items: center; justify-content: space-between; gap: .55rem .8rem; flex-wrap: wrap; margin-top: .7rem; }
.legend { display: flex; flex-wrap: wrap; gap: .36rem .69rem; padding: 0; margin: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: .24rem; color: var(--muted); font-size: .73rem; white-space: nowrap; }
.legend-glyph { display: grid; place-items: center; width: 1rem; height: 1rem; border-radius: .25rem; background: #dedac5; color: #4d5142; font: 700 .64rem/1 var(--mono); }
.legend-glyph.tile-forest { background: #d8e5cf; color: #315b45; }
.legend-glyph.tile-water { background: #d3e5e1; color: #265d63; }
.legend-glyph.tile-ridge { background: #e1dfd2; color: #575b4e; }
.legend-glyph.tile-building, .legend-glyph.tile-wall, .legend-glyph.tile-hall { background: #efded0; color: #774d36; }
.legend-glyph.tile-path, .legend-glyph.tile-square { background: #ece2c6; color: #665238; }
.legend-glyph.tile-camp, .legend-glyph.tile-site, .legend-glyph.tile-gate { background: #f2e3bf; color: #775627; }
.legend-glyph.tile-residence { background: #efdbdc; color: #80454b; }
.play-help { display: flex; align-items: center; flex-wrap: wrap; gap: .25rem .65rem; color: var(--muted); font-size: .73rem; }
.play-help kbd { color: var(--text); font: 650 .72rem var(--mono); }
.player-key { display: inline-block; width: .62rem; height: .62rem; margin-right: .3rem; border-radius: 50%; background: #dcead6; border: 1.5px solid #38624b; }
.map-status, .map-credit { color: var(--muted); font-size: .76rem; line-height: 1.45; margin-top: .55rem; }
.map-status:empty { margin-top: 0; }
.map-credit a { text-underline-offset: .16em; }
.map-directions, .touch-help { display: none; }
.map-directions button { min-width: 2.75rem; min-height: 2.75rem; touch-action: manipulation; }

.samples { padding-block: 1.45rem 2.3rem; }
.section-heading { display: flex; align-items: center; margin-bottom: .65rem; }
.section-heading h2 { font-size: 1.14rem; }
.sample-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9.8rem), 1fr)); gap: .55rem; }
.sample { display: grid; align-content: start; gap: .48rem; min-width: 0; padding: .35rem; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: .55rem; color: var(--text); }
.sample:hover { border-color: #8f9a84; }
.sample[aria-pressed="true"] { border-color: #537d64; box-shadow: inset 0 0 0 1px #6a8c65; background: #edf0e5; }
.sample-map { display: block; width: 100%; aspect-ratio: 2 / 1; object-fit: cover; border-radius: .3rem; background: #3f5542; }
.sample-label { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: .2rem .45rem; padding: 0 .2rem .16rem; }
.sample-name { font-size: .82rem; font-weight: 700; }
.sample-seed { color: var(--muted); font: .65rem/1.3 var(--mono); }

@media (max-width: 840px) {
  .shell { width: min(100% - 2rem, 86rem); }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: .75rem; }
  .map-panel { grid-row: 1; }
  .terrain-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .controls { max-width: none; }
  .generate-actions { justify-content: start; grid-template-columns: auto auto; }
  .generate-actions .button { min-width: 6.4rem; }
}
@media (max-width: 500px) {
  .shell { width: calc(100% - 1.2rem); }
  .topbar-inner { min-height: 3.65rem; gap: .45rem; }
  .topbar-actions { gap: .38rem .62rem; justify-content: end; }
  .topbar-play { font-size: .74rem; }
  .intro p { font-size: .84rem; }
  .map-panel { padding: .55rem; }
  .map-header { gap: .45rem; margin-bottom: .55rem; }
  .map-heading h2 { font-size: 1.12rem; }
  .map-meta { font-size: .685rem; }
  .map-actions { gap: .3rem; }
  .map-actions .button { padding: .36rem .46rem; min-height: 2.25rem; }
  .view-toggle button { padding-inline: .48rem; }
  .terrain-tile { gap: .35rem; font-size: .76rem; }
  .map-stage .player-marker { border-width: 1px; }
  .compass { width: 1.6rem; height: 1.9rem; top: .48rem; right: .5rem; }
  .compass b { font-size: .53rem; }
  .compass i { width: .52rem; height: .7rem; }
  .sample-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (pointer: coarse) {
  .keyboard-help { display: none; }
  .touch-help { display: inline; }
  .map-directions { display: flex; gap: .35rem; margin-top: .55rem; }
}
