:root {
  color-scheme: dark;
  --bg: #0f1518;
  --surface: #172024;
  --surface-raised: #1e292e;
  --glass: #10171bed;
  --border: #ffffff20;
  --text: #edf3f0;
  --muted: #a4b6af;
  --accent: #28765d;
  --accent-hover: #31886c;
  --focus: #81d9b8;
  --radius: 12px;
  --shadow: 0 8px 30px #0005;
  --edge: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font: 14px/1.5 system-ui, "Microsoft YaHei", sans-serif;
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
input[type=checkbox], progress { accent-color: var(--accent-hover); }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 20px; }
h2 { font-size: 18px; }
code { background: #ffffff0f; padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.center { text-align: center; }

.top {
  min-height: 54px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 20px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; white-space: nowrap; }
.top nav { display: flex; align-items: center; gap: 6px; }
.top nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
.top nav a:hover, .top nav a[aria-current=page] { background: #ffffff12; color: var(--text); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff0c;
  color: var(--text);
  padding: 6px 12px;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover { background: #ffffff1e; }
.btn.primary { background: var(--accent); border-color: #75d5b15c; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: #c753402b; border-color: #d45d4e70; color: #ffc0b4; }
.btn.danger:hover { background: #d45d4e4d; }
.btn:disabled { opacity: .55; cursor: default; }

main { position: relative; min-height: 0; flex: 1; }
.scroll-page { height: 100%; overflow: auto; padding: 24px 20px 36px; }
.container { max-width: 1220px; margin: 0 auto; display: grid; gap: 18px; }
.hero {
  display: grid;
  gap: 14px;
  padding: 18px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: radial-gradient(600px 180px at 0% 0%, #28765d47, transparent 70%), var(--surface);
}
.hero.drag { border-color: var(--focus); background: radial-gradient(700px 220px at center, #31886c60, transparent 80%), #162a25; }
.launcher-main, .launcher-actions, .modhub-drawer { display: flex; align-items: center; flex-wrap: wrap; }
.launcher-main { justify-content: space-between; gap: 16px 24px; }
.launcher-actions { gap: 8px; }
.hero p, .board-head p { color: var(--muted); font-size: 13px; margin-top: 4px; }
.btn.drop-pill-btn { border: 1px dashed #81d9b88c; padding: 8px 16px; }
#toggle-modhub[aria-expanded=true] { background: #28765d40; border-color: var(--focus); color: #bdf2de; }
.modhub-drawer { gap: 10px; padding-top: 12px; border-top: 1px solid var(--border); }
.drawer-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 240px;
  min-width: 0;
  padding: 3px 3px 3px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.drawer-input-wrap:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px #81d9b829; }
#modhub-link { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 13px; }
.drawer-input-wrap .btn { padding: 5px 12px; font-size: 13px; border-radius: 6px; }
.drawer-hint { font-size: 12px; color: var(--muted); }
.drawer-hint button { border: 0; background: none; padding: 0; color: var(--focus); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
@media (prefers-reduced-motion: no-preference) {
  .modhub-drawer { animation: drawer-open .16s ease-out; }
  @keyframes drawer-open { from { opacity: 0; transform: translateY(-4px); } }
}
#ov-choices { max-width: 100%; margin-top: 8px; }
.hero code { color: #c8e9dc; }
.board-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.tabs { display: inline-flex; gap: 3px; padding: 3px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); }
.tabs button { border: 0; border-radius: 6px; background: transparent; color: var(--muted); padding: 5px 13px; cursor: pointer; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-pressed=true] { background: var(--accent); color: #fff; }
.empty { border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 16px; text-align: center; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(248px, 100%), 1fr)); gap: 14px; }
.grid:empty, .container > .center:has(> #more[hidden]) { display: none; }
.card { display: flex; flex-direction: column; overflow: hidden; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.card:hover { border-color: #81d9b863; }
.card .thumb { display: block; position: relative; overflow: hidden; isolation: isolate; aspect-ratio: 16 / 10; background: #243239; }
.card .thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
.card .thumb span { position: absolute; top: 10px; color: #fff; background: var(--glass); padding: 3px 8px; border-radius: 6px; font-size: 12px; }
.card .thumb .rank { left: 10px; font-weight: 650; }
.card .thumb .size { right: 10px; }
.card .body { flex: 1; display: flex; flex-direction: column; gap: 5px; padding: 11px 13px; }
.card h3 { font-size: 16px; overflow-wrap: anywhere; }
.card h3 a:hover { text-decoration: underline; text-underline-offset: 3px; }
.card .stats { font-size: 12.5px; }
.card .row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin-top: auto; padding-top: 5px; }
.card .row .btn { font-size: 12px; }
.votes { display: inline-flex; gap: 4px; white-space: nowrap; }
.vote { font-size: 13px; border: 1px solid var(--border); border-radius: 7px; padding: 3px 9px; background: #ffffff09; color: var(--muted); cursor: pointer; }
.vote:hover:not(:disabled) { background: #ffffff1e; color: var(--text); }
.vote.on.up { color: #a9efd5; background: #317a5b50; border-color: #81d9b863; }
.vote.on.down { color: #ffc0b4; background: #a6493e50; border-color: #d45d4e70; }
.vote:disabled { opacity: .55; cursor: default; }

#viewer { position: absolute; inset: 0; overflow: hidden; background: #182226; }
#map { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#map:active { cursor: grabbing; }
#viewer-controls { position: absolute; inset: 0; pointer-events: none; }
.glass { background: var(--glass); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.float-top, .float-bottom { position: absolute; left: var(--edge); right: var(--edge); display: flex; justify-content: space-between; gap: 10px; }
.float-top { top: var(--edge); align-items: flex-start; z-index: 2; }
.float-bottom { bottom: var(--edge); align-items: flex-end; z-index: 1; }
.vtitle, .vactions, .map-popover, .info, .dock, .zoom-tools { pointer-events: auto; }
.vtitle { min-width: 0; max-width: 540px; padding: 9px 13px; }
.vtitle h1 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#v-meta { font-size: 12px; font-variant-numeric: tabular-nums; }
.warn { color: #f4c479; }
.action-stack { position: relative; min-width: max-content; display: flex; flex-direction: column; align-items: flex-end; gap: 7px; }
.vactions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 5px; max-width: min(450px, 100vw - 2 * var(--edge)); padding: 5px; }
.vactions:empty { display: none; }
.vactions .btn { padding-inline: 9px; }
.map-popover > summary { list-style: none; }
.map-popover > summary::-webkit-details-marker { display: none; }
.map-popover > summary::after { content: ""; width: 5px; height: 5px; border: solid currentColor; border-width: 0 1px 1px 0; transform: rotate(45deg); margin: -3px 1px 0; }
.map-popover[open] > summary::after { transform: rotate(225deg); margin-top: 3px; }
.panel {
  position: absolute;
  width: min(350px, 100vw - 2 * var(--edge));
  max-height: min(430px, 60dvh);
  overflow-y: auto;
  display: grid;
  gap: 9px;
  padding: 12px;
  background: var(--surface);
}
.action-stack .panel { top: calc(100% + 7px); right: 0; }
.panel label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.panel .check { display: flex; align-items: center; }
.panel input:not([type=checkbox]), select {
  min-width: 0;
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-raised);
  color: var(--text);
}
#publish-note { font-size: 12px; }
.share-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.map-tools { position: relative; min-width: 0; display: grid; justify-items: start; gap: 7px; }
.info { max-width: 100%; padding: 7px 10px; font-size: 12px; overflow-wrap: anywhere; }
.info:empty { display: none; }
.dock { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; padding: 5px; }
.dock .btn { font-size: 12px; padding-inline: 8px; }
#places { max-width: min(210px, 100%); font-size: 13px; }
.dock .panel { left: 0; bottom: calc(100% + 7px); }
.layer-options { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 4px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.layer-options label { display: flex; align-items: center; }
.layer-options label:has(input:checked) { color: var(--text); }
.layer-options label:has(input:disabled) { opacity: .55; }
.layer-panel > label { grid-template-columns: 70px minmax(0, 1fr); align-items: center; }
.infra-panel { width: min(670px, 100vw - 2 * var(--edge)); }
.toolbar { display: grid; grid-template-columns: repeat(auto-fit, minmax(94px, 1fr)); gap: 6px; }
.infra-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(190px, 100%), 1fr)); gap: 7px; font-size: 13px; }
.infra-list > div { display: grid; grid-template-columns: 42px 1fr; gap: 4px 7px; align-items: center; padding: 7px; border: 1px solid var(--border); border-radius: 7px; }
.infra-list img { width: 42px; height: 32px; object-fit: contain; background: #a8b9af; border-radius: 4px; }
.infra-list small { display: block; color: var(--muted); }
.infra-list .initial-module { grid-column: span 2; }

.zoom-tools { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 5px; flex-shrink: 0; }
.zoom-tools .btn { width: 36px; height: 33px; padding: 0; font-size: 12px; }
#plus, #minus { font-size: 17px; }
.compass { color: var(--muted); font-size: 11px; }
.map-scale { position: absolute; right: calc(var(--edge) + 72px); bottom: var(--edge); padding: 4px 7px; font-size: 11px; text-align: center; white-space: nowrap; }
.map-scale:empty { display: none; }
.map-scale span { display: block; height: 5px; border: solid #d8e3dc; border-width: 0 1px 1px; }

.overlay { position: absolute; z-index: 3; inset: 0; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; background: #0c1217ba; padding: 16px; }
.ovbox { width: min(100%, 420px); padding: 16px 20px; text-align: center; overflow-wrap: anywhere; }
#ov-source { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
#ov-text { margin-top: 4px; }
.ovbox progress { display: block; width: 100%; height: 8px; margin-top: 10px; }
.ovbox.err { color: #ffc0b4; }
.toast { position: fixed; z-index: 5; bottom: 24px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 20px); padding: 8px 14px; border: 1px solid #81d9b863; border-radius: 9px; background: var(--surface); box-shadow: var(--shadow); }

@media (max-width: 760px) {
  :root { --edge: 8px; }
  .top { padding-inline: 10px; }
  .float-top { flex-direction: column; align-items: stretch; gap: 5px; }
  .vtitle { max-width: none; }
  .action-stack { min-width: 0; }
  #places { max-width: min(126px, 100%); }
  .map-scale { bottom: calc(var(--edge) + 178px); right: var(--edge); }
  .scroll-page { padding: 16px 12px 24px; }
  .container { gap: 12px; }
  .hero { padding: 13px 14px; }
}
@media (max-width: 400px) {
  .top { padding-inline: 8px; gap: 6px; }
  .brand { gap: 5px; font-size: 14px; }
  .top nav { gap: 2px; }
  .top nav a, .top nav button { padding-inline: 5px; font-size: 12px; }
}

.color-key { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; }
.color-key span { display: inline-flex; align-items: center; gap: 4px; }
.color-key i { width: 14px; height: 8px; border-radius: 2px; }

.save-help { font-size: 12px; color: var(--muted); margin-top: 5px; overflow-wrap: anywhere; }
summary { cursor: pointer; }
#ov-actions { margin-top: 10px; }
#meta-toggle { display: none; }
.zoom-tools #fill, .zoom-tools #fit { width: auto; padding-inline: 5px; }
#edit-dialog { color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
#edit-dialog::backdrop { background: #0009; }
#edit-map, #edit-map label { display: grid; gap: 8px; }
#edit-map input { padding: 6px; }
@media (max-width: 760px) {
  .vtitle { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; }
  #v-meta { grid-column: span 2; }
  #meta-toggle { display: inline-flex; font-size: 12px; }
  #meta-toggle[aria-expanded=false] + #v-meta,
  .float-top:has(#meta-toggle[aria-expanded=false]) #v-actions:not(:has(.modhub-source)) { display: none; }
  .map-tools, .dock { width: 100%; }
  .float-bottom { flex-direction: column-reverse; align-items: flex-end; gap: 6px; }
  .zoom-tools { flex-direction: row; }
  .compass { display: none; }
  .dock { flex-wrap: nowrap; }
  #places { flex: 1; max-width: none; }
  .map-scale { right: auto; left: var(--edge); bottom: calc(var(--edge) + 52px); }
  .dock .panel { bottom: calc(100% + 52px); max-height: min(430px, 50dvh); }
  .map-tools { display: flex; flex-direction: column; align-items: stretch; }
  .info { position: absolute; bottom: calc(100% + 52px); left: 0; }
  .map-tools:has(details[open]) .info { display: none; }
  .info { font-size: 14px; border-inline-start: 3px solid var(--focus); }
}
