:root {
  --ink: #101e22;
  --surface: #17292d;
  --surface-raised: #20373a;
  --panel: #132529f5;
  --line: #93aaa131;
  --gold: #e3bc81;
  --paper: #f5eddd;
  --muted: #a9bdb5;
  --heading-font: "Noto Serif SC", "Songti SC", STSong, SimSun, Georgia, serif;
  color: var(--paper);
  color-scheme: dark;
}
.navigation-entry { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding: 16px; margin-top: 14px; border: 1px solid #d9b67466; border-radius: 8px; background: #244446; text-decoration: none; }
.navigation-entry strong { color: var(--gold); }
.navigation-entry span { color: var(--muted); font-size: 12px; }
.menu-workbenches{margin-top:16px;padding:12px;border:1px solid var(--line);border-radius:8px}
.menu-workbenches summary{cursor:pointer;min-height:35px;align-content:center;color:var(--gold)}
.workbench-links{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;padding-top:10px}
.workbench-links a{display:flex;flex-direction:column;gap:5px;padding:12px;background:var(--surface);border-radius:5px}
.workbench-links b{font-size:13px;color:var(--gold)}.workbench-links span{font-size:11px;color:var(--muted)}

body { background: var(--ink); }
a:focus-visible, summary:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
button:disabled { opacity: .45; }
.topbar, .statusbar { background: var(--ink); border-color: var(--line); }
.brand span { font-family: var(--heading-font); font-weight: 700; }
.project input { color: var(--paper); font-size: 13px; }
.project span, .statusbar, .statusbar em { color: var(--muted); }
.mode-tabs button, .project-actions button span { color: var(--muted); }
.mode-tabs button.active { color: var(--gold); }
.topbar #game-menu-open { border-radius: 6px; background: #263b3a; }

.left-panel, .inspector, .editor-tools, .view-tools, .sea-hud, .lesson-hud {
  border-color: var(--line);
  background: var(--panel);
  backdrop-filter: none;
  box-shadow: 0 7px 24px #07121430;
  border-radius: 8px;
}
body:not(.mobile-layout) .topbar { gap: clamp(10px, 1.5vw, 26px); }
body:not(.mobile-layout) .brand { min-width: 0; white-space: nowrap; }
body:not(.mobile-layout) .project { padding-left: clamp(10px, 1.2vw, 22px); }
body:not(.mobile-layout) .mode-tabs button { padding-inline: clamp(10px, 1.1vw, 20px); white-space: nowrap; }
body:not(.mobile-layout) .left-panel { padding: 0 0 38px; overflow: hidden; }
body:not(.mobile-layout) #build-palette {
  flex: 1;
  min-height: 0;
  padding: 0 13px 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
body:not(.mobile-layout) #sail-controls { margin: 0; padding: 14px; overflow-y: auto; }
.workbench-tabs, .library-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--line);
}
.workbench-tabs { position: sticky; top: 0; z-index: 2; background: #14262a; margin-bottom: 12px; }
.workbench-tabs button, .library-tabs button {
  flex: 1;
  padding: 8px 5px;
  min-height: 42px;
  text-align: center;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.workbench-tabs [aria-pressed=true], .library-tabs [aria-pressed=true] {
  color: var(--gold);
  border-bottom-color: var(--gold);
}
.workbench-tabs b { margin-left: 4px; color: currentColor; font-size: .8em; }
.categories button { color: var(--muted); font-size: 11px; }
.part-palette { min-height: 0; gap: 7px; }
.part-card { background: #ffffff05; border-color: var(--line); min-width: 0; border-radius: 6px; }
.part-card span { color: var(--paper); font-size: 11px; }
.part-card small { display: none; }
.parts-heading { margin: 0; padding: 0; border: 0; }
.parts-heading button { color: var(--gold); }
.part-tree { max-height: none; }
.part-tree button { color: var(--paper); min-height: 34px; font-size: 11px; }
.inspector-heading { color: var(--paper); font-weight: 650; }
.entity-title { font-family: var(--heading-font); color: var(--paper); }
.entity-description, .inspector-note, .field { color: var(--muted); }
.entity-eyebrow { display: none; }
.field input, .field select { background: #0e2024; border-color: var(--line); color: var(--paper); }
.side-bottom { color: var(--muted); }
.editor-tools button, .view-tools button { color: #d5e2d8; }
.editor-tools button.active, .view-tools button.active { color: var(--gold); background: #d8b87525; }
#preflight-check { color: var(--gold); border: 1px solid #e3bc8155; }
.launch-button { background: var(--gold); border-color: #f5d6a7; color: var(--ink); backdrop-filter: none; }
.launch-button:hover { background: #f4d4a3; color: var(--ink); }
.launch-button span { color: var(--ink); font-weight: 750; }
#loading { background: #14272b; }

body:not(.mobile-layout) .editor-tools { top: auto; bottom: 48px; }
body:not(.mobile-layout) .view-tools { top: 80px; bottom: auto; }
body:not(.mobile-layout) .bottom-center { bottom: 103px; }
body:not(.mobile-layout).sea-mode .bottom-center { bottom: 50px; }
body:not(.mobile-layout) .placement-hint { top: 125px; }
body:not(.mobile-layout) .sea-hud { top: 125px; }
body:not(.mobile-layout) .location-card { display: none; }
body:not(.mobile-layout) .interaction-hint { margin-bottom: 8px; font-size: 10px; }
#location-subtitle:empty { display: none; }
.mobile-layout .workbench-tabs { top: -12px; }
.mobile-layout #workbench-parts .categories { position: static; background: transparent; }
.mobile-layout .workbench-tabs button { min-height: 44px; }
.mobile-layout .part-card span { font-size: 12px; }

/* Main menu and settings */
dialog.game-menu {
  width: min(1080px, calc(100% - 32px));
  max-height: calc(100dvh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  padding: clamp(16px, 2.7vw, 30px);
  border: 1px solid #aabbb44d;
  border-radius: 12px;
  background: var(--ink);
}
dialog.game-menu::backdrop, #dialog::backdrop { background: #061315c7; backdrop-filter: none; }
.game-menu-tabs { margin-bottom: 14px; }
.game-menu-tabs button, .game-menu-actions :is(button,a) { border-radius: 6px; }
.game-menu-intro {
  display: flex;
  align-items: end;
  min-height: clamp(250px, 35vw, 390px);
  overflow: hidden;
  isolation: isolate;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(90deg,#07171be8 1%,#0b1b1c95 42%,#0a191a1a 75%),
              linear-gradient(0deg,#09181dc4,transparent 60%),
              url("./art/harbor.webp") 59% 55% / cover no-repeat #1c3030;
}
.menu-hero-copy { padding: clamp(20px, 4vw, 45px); }
.game-menu-intro .menu-port { color: var(--gold); font-size: 12px; letter-spacing: .17em; margin-bottom: 8px; }
.game-menu-intro h2 { font: 700 clamp(36px, 6vw, 68px)/1.12 var(--heading-font); color: var(--paper); margin: 0 0 12px; }
.game-menu-intro p { color: #e6e7dc; margin-bottom: 19px; }
.game-menu-actions .menu-primary { padding-inline: 17px; }
.game-menu-actions button:not(.menu-primary), .game-menu-actions a { background: #11252be8; }
.menu-lessons { grid-template-columns: repeat(4,minmax(0,1fr)); gap: 11px; margin-top: 22px; }
.menu-lessons h3 { color: var(--paper); }
.menu-lessons h3 span { color: var(--muted); }
.menu-lessons a.menu-lesson-card { padding: 0; overflow: hidden; background: var(--surface); border-radius: 7px; }
.menu-lesson-card img { display: block; width: 100%; height: auto; aspect-ratio: 2 / 1; object-fit: cover; }
.menu-lesson-copy { padding: 11px 12px 13px; }
.menu-lessons a strong { font-size: 15px; display: block; line-height: 1.4; }
.menu-lessons a span { margin-bottom: 4px; font-size: 11px; }
.menu-credits { color: var(--muted); font-size: 11px; margin-top: 14px; }
.menu-credits summary { cursor: pointer; width: fit-content; padding: 4px 0; }
.game-menu[data-page=settings] { width: min(920px, calc(100% - 32px)); }
.game-menu[data-page=settings] h2 { font-family: var(--heading-font); font-size: 29px; }
.game-settings section { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.setting-row select { background: #0e2024; color: var(--paper); font-size: 13px; }
.game-settings p { color: var(--muted); padding-bottom: 7px; }

/* Blueprint library */
#dialog:has(.library-heading) { width: min(920px, calc(100% - 28px)); background: var(--ink); border-color: var(--line); }
.library-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-right: 28px; }
.library-heading h2 { font: 700 clamp(24px,4vw,36px)/1.1 var(--heading-font); margin: 0; }
.library-actions { display: flex; gap: 5px; }
.library-actions button { min-height: 38px; padding: 5px 9px; color: var(--gold); background: var(--surface); border: 1px solid var(--line); border-radius: 5px; white-space: nowrap; }
.library-tabs { margin: 14px 0; }
.library-tabs small { margin-left: 4px; color: var(--muted); }
.library-note { color: var(--muted); line-height: 1.7; }
#dialog .blueprint-grid { gap: 10px; }
#dialog .historical-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
#dialog .blueprint-card { border-color: var(--line); background: var(--surface); border-radius: 6px; }
#dialog .blueprint-card:hover { border-color: #e3bc8180; background: var(--surface-raised); }
#dialog .blueprint-card b { color: var(--paper); font-family: var(--heading-font); line-height: 1.35; }
#dialog .blueprint-card span, #dialog .historical-blueprint p { color: var(--muted); }
#dialog .historical-blueprint { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
#dialog .historical-blueprint .blueprint-card { background: #253b3c; min-height: 44px; }
#dialog .historical-blueprint summary { min-height: 34px; align-content: center; cursor: pointer; }
#dialog .historical-load-status { color: var(--gold); }
#dialog .saved-blueprint { background: var(--surface); border-color: var(--line); }
#dialog .saved-blueprint button { min-height: 42px; color: var(--gold); }

@media (max-width: 700px) {
  .menu-lessons { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .game-menu-intro { background-position: 65% 50%; }
  .game-settings { grid-template-columns: 1fr; }
  .setting-row select { font-size: 16px; }
}
@media (max-width: 485px) {
  dialog.game-menu { width: calc(100% - 16px); padding: 12px; }
  .game-menu-intro { min-height: 268px; background-image: linear-gradient(0deg,#07171bf2 3%,#0b1b1c55 64%),url("./art/harbor.webp"); }
  .menu-hero-copy { padding: 16px; }
  .menu-lessons a p { line-height: 1.5; }
  .menu-lesson-copy { padding: 10px; }
  #dialog:has(.library-heading) { padding-inline: 13px; }
  .library-heading { flex-wrap: wrap; }
  #dialog .historical-grid { grid-template-columns: 1fr; }
}

.view-advanced, .trial-panel-label, .sea-mode .build-panel-label { display: none; }
.sea-mode .trial-panel-label { display: inline; }
.view-advanced-toggle { white-space: nowrap; border-left: 1px solid var(--line); }
.view-advanced-toggle[aria-expanded=true] { color: var(--gold); }
body:not(.mobile-layout) .view-advanced-toggle[aria-expanded=true] + .view-advanced {
  position: absolute;
  inset: calc(100% + 7px) 0 auto;
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 4px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 8px 24px #07121455;
}
.view-advanced button, .view-advanced .harbor-portal { white-space: nowrap; min-height: 34px; }
.view-advanced .harbor-portal { display: inline-flex; align-items: center; padding: 0 8px; text-decoration: none; }
.mobile-layout .view-advanced { display: contents; }
.mobile-layout .view-advanced-toggle { display: none; }
#dialog .historical-blueprint { padding: 12px; }
#dialog .historical-blueprint .blueprint-card { display: block; width: 100%; padding: 7px 10px; min-height: 48px; }
#dialog .historical-blueprint .blueprint-card b { margin: 0; }
#dialog .historical-blueprint p { margin: 9px 0; }
body:not(.mobile-layout) #sail-controls > h2 {
  font: 700 19px var(--heading-font);
  margin: 2px 0 12px;
  color: var(--paper);
}
@media (max-width: 700px) {
  .mobile-layout:not(.sea-mode) .left-panel:has(#workbench-structure[hidden]) {
    height: auto;
    max-height: min(58dvh,480px);
  }
}

.setting-details { margin-top: 10px; }
.setting-details summary {
  min-height: 44px;
  align-content: center;
  padding: 7px 8px;
  border-radius: 5px;
  background: var(--surface-raised);
  color: var(--paper);
  cursor: pointer;
}
.setting-details[open] summary { color: var(--gold); }

.bond-controls summary {
  display: list-item;
  min-height: 40px;
  align-content: center;
  padding: 6px 9px;
  border-radius: 5px;
  background: var(--surface-raised);
  color: var(--paper);
  cursor: pointer;
}
.bond-controls[open] summary { margin-bottom: 10px; color: var(--gold); }

.structure-search { display: grid; gap: 5px; margin: 7px 0; }
.structure-search input {
  width: 100%;
  min-height: 36px;
  padding: 6px 9px;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--paper);
}
.structure-search span { color: var(--muted); font-size: 11px; }
.part-tree-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mobile-layout .structure-search input { min-height: 44px; font-size: 16px; }

.build-placement, .selection-actions, .selection-nudge {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 7px 24px #07121455;
}
.build-placement {
  position: fixed;
  z-index: 23;
  top: 125px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 34px);
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 8px 6px 12px;
}
.build-placement-copy, .build-placement-actions, .selection-actions { min-width: 0; }
.build-placement-copy { display: grid; gap: 4px; }
.build-placement-copy b { color: var(--gold); font-size: 13px; }
.build-placement-copy span { color: var(--muted); font-size: 11px; }
.build-placement-actions, .selection-actions, .nudge-options { display: flex; align-items: center; gap: 4px; }
.build-placement button, .workbench-selection button {
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  white-space: nowrap;
  font-size: 12px;
}
.build-placement button[aria-pressed=true], .workbench-selection button[aria-expanded=true] {
  color: var(--gold);
  background: #d8b87525;
  border-color: #e3bc8166;
}
#confirm-placement { background: var(--gold); color: var(--ink); font-weight: 700; }
.workbench-selection {
  position: fixed;
  z-index: 22;
  left: 50%;
  bottom: 178px;
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
}
.selection-actions { padding: 4px; }
.selection-name {
  color: var(--gold);
  max-width: 146px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 5px;
  font-size: 11px;
}
.selection-nudge { position: absolute; width: 100%; min-width: 245px; bottom: calc(100% + 6px); padding: 8px; }
.nudge-options { justify-content: space-between; gap: 6px; margin-bottom: 6px; }
.nudge-options label { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 11px; }
.nudge-options select { min-height: 36px; padding: 3px; background: var(--ink); }
.nudge-axes { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 4px; }
.nudge-axes div { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 3px; text-align: center; }
.nudge-axes span { grid-column: 1 / -1; color: var(--muted); font-size: 11px; }
.nudge-axes button { font-size: 18px; padding: 0; }
.mobile-layout .build-placement {
  top: calc(var(--mobile-top) + var(--mobile-size) + 6px);
  width: max-content;
  max-width: calc(100vw - var(--mobile-left) - var(--mobile-right));
  flex-wrap: wrap;
  justify-content: center;
  padding: 7px;
  gap: 7px;
}
.mobile-layout .build-placement-copy { flex: 1 1 100%; text-align: center; }
.mobile-layout:is([data-mobile-density=compact],.immersive-mode):not([data-mobile-panel=panels]) .build-placement { top: var(--mobile-top); }
.mobile-layout .workbench-selection { bottom: var(--mobile-bottom); }
.mobile-layout .workbench-selection button, .mobile-layout .build-placement button, .mobile-layout .nudge-options select { min-height: 44px; }
.mobile-layout .nudge-options select { font-size: 16px; }
.mobile-layout .selection-name { max-width: 118px; }
.mobile-layout:not([data-mobile-panel=""]) .workbench-selection { visibility: hidden; }
.mobile-layout[data-mobile-panel=""]:has(.workbench-selection:not([hidden])) #notice {
  top: calc(var(--mobile-top) + var(--mobile-size) + 6px);
  bottom: auto;
}
.mobile-layout:is([data-mobile-density=compact],.immersive-mode)[data-mobile-panel=""]:has(.workbench-selection:not([hidden])) #notice { top: var(--mobile-top); }

body.night-interface {
  --ink: #101520;
  --surface: #19202e;
  --surface-raised: #242d3e;
  --panel: #131b2af7;
  --line: #95a4c044;
  --paper: #e1e9f3;
  --muted: #a8b8cc;
}
body.night-interface dialog.game-menu {
  background: #141e30;
  border-color: var(--line);
}
body.night-interface .navigation-entry { background: #223149; }

.world-recovery-status {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  margin: 0;
  padding: .8rem 1.1rem;
  border-radius: .4rem;
  background: #183239;
  color: #f5eedb;
  pointer-events: none;
}
