:root {
  --bg: #e4eed2;            /* pale grass */
  --bg-2: #d3e4b8;          /* grass, for the background fade */
  --panel: #ffffff;
  --field: #f7faf1;         /* inputs */
  --text: #1d2418;
  --muted: #5f6b58;
  --border: #d5dccb;
  --leaf: #4b9a3c;
  --leaf-2: #3c8531;
  --leaf-dark: #2c6a24;
  --accent: #3c8531;        /* links and focus */
  --sun: #f2a01c;           /* warm orange-yellow */
  --accent-text: #ffffff;
  --map-bg: #0f0f0f;
  --error: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(44, 106, 36, 0.12), 0 2px 10px rgba(44, 106, 36, 0.08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141c10;
    --bg-2: #0d130a;
    --panel: #1d2619;
    --field: #161e12;
    --text: #e6ece0;
    --muted: #a3ae98;
    --border: #34442c;
    --leaf: #4b9a3c;
    --leaf-2: #3c8531;
    --leaf-dark: #a6dc8f;
    --accent: #8fd37a;
    --accent-text: #ffffff;
    --error: #f2b8b5;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 10px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* Elements marked hidden stay hidden even when a class gives them a display (like .field). */
[hidden] { display: none !important; }

html { background: var(--bg); }
body {
  margin: 0;
  background: linear-gradient(180deg, var(--bg) 0, var(--bg) 340px, var(--bg-2) 100%) fixed;
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}

main, .site-header, .site-footer {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
}

.site-header { padding-top: 14px; }
.site-header h1 { margin: 0; font-size: 1.6rem; }
.site-header p { margin: 6px 0 14px; color: var(--muted); }
.logo a {
  display: flex; align-items: center; gap: 6px; color: var(--leaf-dark); text-decoration: none;
  font-weight: 800; letter-spacing: -0.5px; text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.8);
}
@media (prefers-color-scheme: dark) { .logo a { text-shadow: none; } }
.logo svg { flex: none; }

.site-footer { color: var(--muted); font-size: 0.85rem; padding-bottom: 24px; }
a { color: var(--accent); }
a:hover { color: var(--leaf-dark); }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 4px solid var(--sun);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span:first-child { font-size: 0.8rem; color: var(--muted); }
.field.grow { flex: 1 1 220px; }
.check-row { display: flex; flex-wrap: wrap; gap: 4px 12px; min-height: 36px; align-items: center; }

select, input, button {
  font: inherit;
  color: inherit;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  min-height: 36px;
}

select { max-width: 100%; }
#seed { width: 8.5em; font-family: ui-monospace, Consolas, monospace; text-transform: uppercase; }
#seed:invalid { border-color: var(--error); }
#seed.seed64 { width: 13.5em; }

.seed-row { display: flex; gap: 4px; }
.icon-btn { padding: 0 10px; font-size: 1.2rem; line-height: 1; }

button { cursor: pointer; }
button:hover { border-color: var(--leaf); }
select:focus-visible, input:focus-visible, button:focus-visible { outline: 2px solid var(--sun); outline-offset: 1px; }
button.primary {
  background: linear-gradient(135deg, var(--leaf), var(--leaf-2)); color: var(--accent-text);
  border-color: var(--leaf-2); font-weight: 700; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}
button.primary:hover { background: var(--leaf-2); border-color: var(--leaf-2); }
.buttons { display: flex; gap: 8px; }

.status { margin: 10px 2px; min-height: 1.4em; color: var(--muted); }
.status.error { color: var(--error); }
.status:empty { min-height: 0; margin: 6px 0; }

.result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
  margin-bottom: 20px;
}

.map-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 4px solid var(--sun);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 0;
}

.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.map-title { font-weight: 600; }
.spacer { flex: 1; }
.check, .zoom { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; }
.map-toolbar button, .map-toolbar select { min-height: 30px; padding: 3px 8px; font-size: 0.9rem; }

.map-scroll {
  overflow: auto;
  background: var(--map-bg);
  max-height: 80vh;
  display: flex;
}

#map { display: block; margin: auto; image-rendering: pixelated; }

.summary {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  font-size: 0.9rem;
  align-self: start;
}

.summary h2 { font-size: 0.95rem; margin: 0 0 6px; padding-bottom: 2px; border-bottom: 2px solid var(--sun); display: inline-block; }
.summary h2:not(:first-child) { margin-top: 14px; }
.summary ul { list-style: none; margin: 0; padding: 0; }
.summary li { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.summary li img { width: 24px; height: 24px; object-fit: contain; flex: none; }
.summary .scroll-list { max-height: 260px; overflow-y: auto; padding-right: 4px; scrollbar-width: thin; }
.summary .gen-time { font-size: 0.8rem; }
.summary .value { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.summary .muted { color: var(--muted); }

@media (max-width: 860px) {
  .result { grid-template-columns: minmax(0, 1fr); }
  .map-scroll { max-height: 70vh; }
}

/* ?embed=1: just the controls and the map, for iframes. */
body.embed .site-header, body.embed .site-footer, body.embed .summary { display: none; }
body.embed .result { grid-template-columns: minmax(0, 1fr); margin-bottom: 0; }
body.embed main { padding: 8px; }
body.embed .controls { padding: 8px; gap: 8px; }

.title-row { display: flex; align-items: center; gap: 12px; }
.lang-toggle { margin-left: auto; min-height: 30px; padding: 3px 12px; font-size: 0.88rem; border-radius: 999px; }

.summary li span:first-of-type { min-width: 0; overflow-wrap: anywhere; }
.icon-gap { width: 24px; flex: none; }

.map-scroll { position: relative; }
.tooltip {
  position: absolute;
  z-index: 2;
  max-width: 280px;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(20, 22, 19, 0.92);
  color: #f2f3ef;
  font-size: 0.85rem;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

:lang(ja) body, html:lang(ja) {
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
}

/* Advanced options */
.advanced, .caveinfo {
  margin-top: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0 14px;
}
.advanced > summary, .caveinfo > summary {
  cursor: pointer;
  padding: 10px 0;
  font-weight: 700;
  color: var(--leaf-dark);
}
.advanced[open] > summary, .caveinfo[open] > summary { border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.advanced[open], .caveinfo[open] { padding-bottom: 12px; }
.caveinfo { margin-bottom: 20px; }

.advanced-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}
.advanced-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.advanced fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 0;
  padding: 8px 10px 10px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.advanced legend { font-size: 0.85rem; font-weight: 700; color: var(--leaf-dark); padding: 0 4px; }
.advanced [title] { cursor: help; }
.advanced input, .advanced select, .advanced a { cursor: pointer; }
.advanced input[type="number"], #query { cursor: text; }
.map-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 3px 10px; }
.map-options .check { font-size: 0.88rem; }
.help { margin: 0; font-size: 0.82rem; color: var(--muted); }
#judge { width: 100%; }
.search-row { display: flex; flex-wrap: wrap; gap: 8px; }
.search-row input[type="number"] { width: 8em; }
#query { width: 100%; font-family: ui-monospace, Consolas, monospace; }
#search-go { align-self: flex-start; }
.search .status { margin: 0; }
.count-results { display: flex; flex-direction: column; gap: 2px; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.count-results:empty { display: none; }
.count-title { color: var(--muted); margin-bottom: 2px; }
.count-row { display: grid; grid-template-columns: 2.5em minmax(0, 1fr) auto 4.5em; gap: 8px; align-items: center; }
.count-n { text-align: right; min-width: 4em; }
.count-k { text-align: right; font-weight: 700; }
.count-bar { height: 10px; background: var(--field); border-radius: 3px; overflow: hidden; }
.count-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--leaf), var(--leaf-2)); }
.count-pct { text-align: right; color: var(--muted); }
#count-what { font-family: ui-monospace, Consolas, monospace; }
.search-results {
  margin: 0;
  padding-left: 2.2em;
  max-height: 320px;
  overflow: auto;
  font-variant-numeric: tabular-nums;
}
.search-results li { padding: 1px 0; }
.search-results li.muted { list-style: none; margin-left: -2.2em; color: var(--muted); }
.search-results .value { margin-left: 10px; }
.search-results .rank { margin-left: 8px; font-size: 0.85rem; }
.seed-link {
  min-height: 0;
  padding: 1px 6px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.9rem;
}
.judge-line { font-weight: 600; }

@media (max-width: 640px) {
  .advanced-grid { grid-template-columns: minmax(0, 1fr); }
}

/* CaveInfo: laid out like Caveripper's caveinfo image */
.ci { display: flex; flex-direction: column; gap: 10px; }
.ci-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
.ci-head h3 { margin: 0; font-size: 1.35rem; }
.ci-meta { display: flex; align-items: center; gap: 10px; }
.ci-meta-icon { position: relative; display: inline-flex; flex-direction: column; align-items: center; line-height: 1; }
.ci-meta-icon img { width: 34px; height: 34px; object-fit: contain; }
.ci-meta-icon img.ci-over { position: absolute; left: 0; top: 0; }
.ci-gate small { font-size: 0.7rem; color: var(--muted); }
.ci-gate b { font-size: 0.85rem; }
.ci-stats, .ci-unit-stats { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 0.9rem; color: var(--muted); }
.ci-stats b, .ci-unit-stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.ci-boxes { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; }
.ci-box { border: 2px solid var(--c); border-radius: 10px; padding: 4px 8px 6px; min-width: 0; max-width: 100%; }
.ci-box-head { display: flex; align-items: center; gap: 6px; font-weight: 700; margin-bottom: 4px; }
.ci-box-icon { width: 20px; height: 20px; object-fit: contain; }
.ci-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); flex: none; }
.ci-score { font-weight: 400; font-size: 0.82rem; color: var(--muted); margin-left: 4px; }
.ci-tiles { display: flex; flex-wrap: wrap; gap: 6px 10px; }
.ci-tile { margin: 0; width: 76px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.ci-pic { position: relative; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; }
.ci-pic > img, .ci-pic > .icon-gap { width: 44px; height: 44px; object-fit: contain; }
.ci-carry { position: absolute; right: -8px; bottom: -4px; }
.ci-carry img, .ci-carry .icon-gap { width: 24px; height: 24px; object-fit: contain; }
.ci-pic > img.ci-fall { position: absolute; left: -6px; top: -4px; width: 18px; height: 18px; }
.ci-nums { font-weight: 800; color: var(--c); font-size: 0.9rem; font-variant-numeric: tabular-nums; line-height: 1.2; }
.ci-name { font-size: 0.72rem; color: var(--muted); line-height: 1.15; overflow-wrap: anywhere; }
.ci-extra { display: flex; gap: 6px; align-items: center; font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.ci-poko { display: inline-flex; align-items: center; gap: 2px; }
.ci-poko img { width: 14px; height: 14px; }
.ci-carry-n { color: var(--muted); }
.ci-units { background: var(--map-bg); color: #d8ddd2; border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }
.ci-units .ci-unit-stats { color: #a9b0a2; }
.ci-units .ci-unit-stats b { color: #f2f4ee; }
.ci-unit-grid { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; }
.ci-unit { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; max-width: 100%; }
.ci-unit-img { display: block; image-rendering: pixelated; max-width: 100%; height: auto; }
.ci-unit figcaption { font-size: 0.7rem; color: #a9b0a2; max-width: 140px; overflow-wrap: anywhere; text-align: center; }
.icon-gap { display: inline-block; }

body.embed .advanced, body.embed .caveinfo { display: none; }
input[type="checkbox"] { min-height: 0; padding: 0; margin: 0; }
.advanced fieldset { align-self: start; }

/* Navigation between the pages */
.title-row { flex-wrap: wrap; }
.site-nav {
  display: flex; flex-wrap: wrap; gap: 2px; font-size: 0.92rem; font-weight: 700;
  background: linear-gradient(135deg, var(--leaf), var(--leaf-2)); border-radius: 999px; padding: 3px;
  box-shadow: inset 4px 0 0 var(--sun);
}
.site-nav a { text-decoration: none; color: #fff; padding: 3px 12px; border-radius: 999px; }
.site-nav a:hover { color: #fff; background: rgba(0, 0, 0, 0.15); }
.site-nav a[aria-current="page"] { background: #fff; color: var(--leaf-2); }

/* Map zoom */
.zoom-buttons { display: inline-flex; }
.zoom-buttons button { border-radius: 0; margin-left: -1px; min-width: 32px; }
.zoom-buttons button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.zoom-buttons button:last-child { border-radius: 0 6px 6px 0; }
#zoom-fit { min-width: 56px; font-variant-numeric: tabular-nums; }
#zoom-fit.on { border-color: var(--accent); }
#map, .agg-map { cursor: grab; touch-action: none; }
#map.dragging, .agg-map.dragging { cursor: grabbing; }
.map-help { margin: 6px 10px; font-size: 0.8rem; color: var(--muted); }
.result.single-view { grid-template-columns: minmax(0, 1fr); }
.result.single-view .summary { display: none; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field.inline > span:first-child { font-size: 0.88rem; }
.advanced .field.inline { margin-top: 4px; }

/* Suggestion box */
main.narrow > * { max-width: 680px; }
.suggest { display: flex; flex-direction: column; gap: 12px; background: var(--panel); border: 1px solid var(--border); border-top: 4px solid var(--sun); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.suggest textarea { font: inherit; color: inherit; background: var(--field); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; resize: vertical; }
.suggest .buttons { align-items: center; gap: 12px; }
.suggest .status { margin: 0; }

/* Aggregator */
.agg-show {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}
.agg-show > span:first-child { color: var(--muted); }
.agg-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 14px; margin-bottom: 20px; }
.agg-card { background: var(--panel); border: 1px solid var(--border); border-top: 4px solid var(--sun); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px; min-width: 0; }
.agg-card h3 { margin: 0 0 4px; font-size: 1rem; }
.agg-examples { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 8px; line-height: 2; }
.agg-examples .seed-link { text-decoration: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
.agg-scroll { overflow: auto; max-height: 75vh; background: var(--map-bg); border-radius: 6px; display: flex; }
.agg-map { display: block; margin: auto; }
.tooltip.floating { white-space: pre-line; }

/* The map pane keeps its size; the map zooms and moves inside it. */
.map-scroll {
  height: min(78vh, 900px);
  min-height: 320px;
  max-height: none;
  overflow: hidden;
  display: block;
  touch-action: none;
  cursor: grab;
}
.map-scroll.dragging { cursor: grabbing; }
.map-scroll #map { margin: 0; image-rendering: auto; cursor: inherit; }
@media (max-width: 860px) {
  .map-scroll { height: 65vh; max-height: none; }
}
body.embed .map-scroll { height: 70vh; }

/* Aggregator maps: a fixed pane each, like the generator's. */
.agg-pane {
  position: relative;
  height: 440px;
  overflow: hidden;
  background: var(--map-bg);
  border-radius: 6px;
  touch-action: none;
  cursor: grab;
}
.agg-pane.dragging { cursor: grabbing; }
.agg-pane .agg-map { display: block; cursor: inherit; }

.agg-help { margin: 0 2px 10px; }
main.narrow h2 { padding-bottom: 2px; border-bottom: 2px solid var(--sun); display: inline-block; }
.map-toolbar { background: linear-gradient(180deg, var(--panel), var(--field)); }
.map-title { color: var(--leaf-dark); }
.advanced-col > fieldset { align-self: stretch; }
.advanced-col.map-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.map-col .map-options { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 420px) { .advanced-col.map-col { grid-template-columns: minmax(0, 1fr); } }
