:root {
  color-scheme: dark;
  --ink: #e4f3f6;
  --muted: #92a9b3;
  --line: #294550;
  --panel: #101f2a;
  --deep: #0b141e;
  --amber: #ffbd70;
  --cyan: #7be2d9;
  --green: #c3f88a;
  font: 15px/1.35 "Aptos", "Helvetica Neue", system-ui, sans-serif;
  color: var(--ink);
  background: var(--deep);
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 300px; overscroll-behavior: none; }
button, select, input { font: inherit; }
button, select, .palette, dialog, summary { touch-action: manipulation; }
button { cursor: pointer; color: inherit; }
button:disabled { opacity: .42; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible, canvas:focus-visible { outline: 2px solid var(--cyan); outline-offset: -2px; }
button:not(.xgh-button), select {
  min-height: 38px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #152a35;
}
button:not(.xgh-button):not(:disabled):hover { background: #1b3845; }
button[aria-pressed="true"]:not(.xgh-button) { background: #254245; border-color: var(--cyan); }
button.primary:not(.xgh-button) {
  background: var(--amber);
  border-color: #ffd39e;
  font-weight: 750;
  color: #24170b;
}
button.primary:not(.xgh-button):not(:disabled):hover { background: #ffcd94; }
.shell {
  display: flex;
  flex-flow: column;
  min-height: 100vh;
  min-height: 100dvh;
  width: min(100%, 1480px);
  margin: auto;
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
}
.masthead { flex: none; min-height: 54px; padding-top: env(safe-area-inset-top); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.masthead[data-xgh-host] { position: relative; z-index: 2; }
.masthead h1 { font-size: 18px; }
.masthead nav { display: flex; gap: 5px; }
.workshop {
  min-height: 510px;
  height: calc(100vh - 56px);
  height: calc(100dvh - 56px - env(safe-area-inset-top));
  display: grid;
  grid-template-rows: auto minmax(230px, 1fr) auto;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.contract {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(148px, .82fr) 1.55fr auto;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-bottom-color: #3d5e6b;
  border-radius: 10px 10px 0 0;
  background: linear-gradient(115deg,#1b3240,#101d2a 50%);
}
.contract h2 { margin: 3px 0 0; font-size: clamp(15px, 2vw, 22px); font-weight: 720; line-height: 1.2; }
#district, .meters span { display: block; color: var(--muted); font-size: 11px; letter-spacing: .035em; }
#district { color: var(--cyan); }
#shipments { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; }
.shipment {
  position: relative; display: grid; grid-template-columns: auto 1fr; align-items: center;
  gap: 1px 6px; min-width: 0; flex: 0 0 auto; color: var(--muted);
  padding: 6px 7px; background: #101e29; border-radius: 5px; border-top: 1px solid #2b4552;
  font: 11px/1.3 ui-monospace, monospace;
}
.shipment i { grid-row: span 2; color: var(--item); font: normal 17px system-ui; }
.shipment b { color: var(--ink); white-space: nowrap; font-size: 11px; }
.shipment[data-done="true"] b { color: var(--green); }
.meters { display: flex; gap: 15px; white-space: nowrap; }
.meters strong { display: block; font: 600 14px/1.6 ui-monospace, monospace; }
.meters [data-weak="true"] { color: #ff9a79; }
progress { width: 62px; height: 4px; border: none; display: block; background: #1c3843; color: var(--cyan); }
progress::-webkit-progress-bar { background: #1c3843; border-radius: 4px; }
progress::-webkit-progress-value { background: var(--cyan); border-radius: 4px; }
progress::-moz-progress-bar { background: var(--cyan); border-radius: 4px; }
.workfloor { position: relative; min-height: 0; overflow: hidden; background: #080e18; border-inline: 1px solid var(--line); isolation: isolate; }
#yard { display: block; width: 100%; height: 100%; touch-action: none; outline-offset: -3px; }
#yard[data-tool="pan"] { cursor: grab; }
#yard[data-tool="belt"] { cursor: crosshair; }
.deck-indicator, .view-tools, .notice { position: absolute; z-index: 1; }
.deck-indicator { top: 13px; left: 13px; display: flex; align-items: center; gap: 7px; background: #0b1724e8; color: #b8d8e3; border: 1px solid #314551; border-radius: 5px; padding: 5px 9px; pointer-events: none; font: 11px/1.35 ui-monospace, monospace; }
.deck-indicator i { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); }
.workshop[data-state="running"] .deck-indicator i { background: var(--green); box-shadow: 0 0 10px #a9ff9b; }
.view-tools { display: flex; gap: 4px; right: 12px; bottom: 12px; }
.view-tools button { width: 34px; min-height: 32px; padding: 0; background: #111f2ade; font-size: 19px; }
.notice { top: 13px; right: 13px; max-width: min(56%, 300px); padding: 7px 11px; border-radius: 6px; border: 1px solid #886742; color: #fff1dc; background: #2f2319ed; font-size: 12px; pointer-events: none; }
.workbench {
  min-width: 0;
  padding: 10px 10px 8px;
  border: 1px solid #325260;
  border-radius: 0 0 10px 10px;
  background: linear-gradient(168deg,#1a303c 0%,#111d28 60%);
  box-shadow: inset 0 2px 0 #42657540;
}
.toolrow, .bench-detail { display: flex; justify-content: space-between; align-items: center; gap: 5px; }
.actions, .run-actions { display: flex; gap: 4px; min-width: 0; }
.actions button { display: flex; align-items: center; gap: 6px; }
.actions i { color: var(--cyan); font: normal 18px/1 system-ui; }
#run { min-width: 95px; white-space: nowrap; }
#speed { font-family: ui-monospace, monospace; }
.bench-detail { min-height: 36px; }
#hint { color: #b4cbd3; font-size: 12px; margin: 5px 1px; }
#tool-config { min-height: 27px; font-size: 11px; margin-block: 3px; color: var(--cyan); flex: 0 1 auto; }
.palette { display: flex; gap: 6px; overflow-x: auto; padding: 0 1px 4px; scrollbar-width: thin; scrollbar-color: #406573 transparent; }
.palette button { flex: 0 0 83px; display: grid; grid-template-columns: 27px 1fr; align-items: center; text-align: left; gap: 4px; height: 44px; padding: 3px 4px; border-color: #314d5b; }
.palette button [data-icon] { background: #0d1c27; width: 26px; height: 26px; border-radius: 5px; }
.palette button span { font-size: 10px; line-height: 1.08; overflow-wrap: anywhere; }
:root[lang="en"] .palette button { flex-basis: 97px; }
.palette button small { display: block; margin-top: 3px; font-size: 9px; color: var(--muted); }
dialog {
  background: #13232f; color: var(--ink); border: 1px solid #416471; border-radius: 12px;
  width: min(95vw, 625px); max-height: 88vh; max-height: 88dvh; margin: auto; padding: 0;
  box-shadow: 0 20px 80px #040912d9;
  overscroll-behavior: contain;
}
dialog::backdrop { background: #080c18cc; }
.panel-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 15px; border-bottom: 1px solid var(--line); background: #192e3c; }
.panel-head h2 { margin: 0; font-size: 18px; }
#close-panel { font-size: 22px; padding: 0; width: 38px; }
#panel-body { padding: 12px 15px 18px; }
#panel-body h3 { font-size: 14px; margin: 15px 0 6px; color: var(--cyan); }
#panel-body p, #panel-body li { color: #b9cdd6; font-size: 13px; }
#panel-body p { margin: 7px 0 12px; }
#panel-body ul { padding-left: 20px; }
#panel-body li + li { margin-top: 7px; }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(134px, 1fr)); gap: 6px; }
.menu-grid button { display: grid; gap: 3px; text-align: left; padding: 8px; }
.menu-grid small { color: var(--muted); }
.blueprint { display: grid; grid-template-columns: 1fr auto; gap: 4px; }
.menu-tabs, .dialog-actions { display: flex; flex-wrap: wrap; gap: 7px; margin: 4px 0 10px; }
.setting { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid #2d4653; }
.setting input { width: 100px; padding: 8px; background: #0c1924; color: var(--ink); border-radius: 5px; border: 1px solid var(--line); }
.result-list { margin-block: 12px; }
.result-line { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.result-line small { display: block; color: var(--muted); }
.result-line strong { font: 600 13px ui-monospace, monospace; }
.earned { color: var(--green); }
@media (max-width: 760px) {
  .shell { padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
  .contract { gap: 8px; padding: 7px 8px; grid-template-columns: minmax(100px, 1fr) minmax(90px,1fr) auto; }
  .meters { gap: 7px; }
  .meters strong { font-size: 12px; }
  .actions button { padding-inline: 7px; }
  .actions button span { display: none; }
  .actions button { min-width: 32px; min-height: 37px; justify-content: center; }
  #run { min-width: 76px; padding-inline: 7px; font-size: 13px; }
  #speed { padding-inline: 6px; }
  .view-tools { right: 6px; bottom: 7px; }
  .deck-indicator { left: 6px; top: 7px; }
}
@media (max-width: 430px) {
  .contract { grid-template-columns: minmax(0,1fr) auto; }
  #shipments { grid-column: 1 / -1; grid-row: 2; }
  .shipment { padding: 3px 6px; grid-template-columns: repeat(3, auto); }
  .shipment i { grid-row: auto; font-size: 14px; }
  .workbench { padding-inline: 5px; }
  .palette button { flex-basis: 73px; }
  :root[lang="en"] .palette button { flex-basis: 84px; }
}
@media (orientation: landscape) and (max-height: 570px) {
  .masthead { min-height: 46px; }
  .workshop { min-height: 340px; height: calc(100dvh - 48px - env(safe-area-inset-top)); grid-template-rows: auto minmax(148px,1fr) auto; }
  .bench-detail { min-height: 28px; }
  .workbench { padding-block: 4px; }
}
