:root {
  color-scheme: light;
  --paper: #f4f0e5;
  --card: #faf5e8;
  --ink: #272920;
  --muted: #5a594e;
  --line: #c9bda6;
  --red: #963c31;
  --blue: #245664;
  --serif: "Hiragino Mincho ProN","Yu Mincho","Noto Serif CJK JP",serif;
  font-family: system-ui,-apple-system,sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}
* { box-sizing: border-box }
html,body { margin: 0; width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none }
[hidden] { display: none !important }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%) }
#field { position: relative; width: 100%; height: 100%; height: 100dvh; isolation: isolate; overflow: hidden; background: radial-gradient(ellipse at 45% 36%,#fffaf0,var(--paper) 69%,#e9e0cf) }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; outline: none }
#board.dragging { cursor: grabbing }
#board text { pointer-events: none }
button,input { font: inherit; color: inherit }
button { border: 1px solid var(--line); border-radius: 2px; background: var(--card); cursor: pointer; min-width: 44px; min-height: 44px; padding: 0 12px; font-weight: 600; touch-action: manipulation }
button:disabled { opacity: .42; cursor: default }
button:focus-visible,input:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px }
@media (hover:hover) { button:not(:disabled):hover { color: var(--red) } }

.top,.bottom { position: absolute; z-index: 1; pointer-events: none; left: max(10px,env(safe-area-inset-left)); right: max(10px,env(safe-area-inset-right)) }
.top { top: calc(env(safe-area-inset-top) + 7px); display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr); align-items: start; column-gap: 12px }
.top button,.tray button,#market,#inspector { pointer-events: auto }
.identity,.tools { display: flex; align-items: center; gap: 5px; min-width: 0; min-height: 44px }
.identity { position: relative; padding-left: 7px }
.mark { display: block; width: 32px; height: 32px; flex: none; color: var(--red); filter: drop-shadow(0 0 3px var(--paper)) }
.mark svg { width: 100%; height: 100% }
.mark text { font: 700 19px var(--serif) }
.game-title { font: 700 clamp(15px,1.8vw,20px)/1.17 var(--serif); margin: 0; white-space: nowrap }
.game-title,.cash-line,.objective { text-shadow: 0 0 3px var(--paper),0 0 7px var(--paper),0 0 9px var(--paper) }
.top button { display: grid; place-items: center; padding: 0; border: 0; background: transparent; filter: drop-shadow(0 0 3px var(--paper)) }
.top #undo { position: absolute; top: 100%; left: 0 }
.tools { justify-content: flex-end; gap: 0 }
.cash-line { display: flex; align-items: baseline; gap: 3px; white-space: nowrap; font-variant-numeric: tabular-nums }
.cash-line strong { font: 700 22px/1 var(--serif) }
.cash-label,.unit { font-size: 12px; color: var(--muted) }
.cash-label { margin-right: 2px }
.top .objective { display: grid; align-content: center; justify-items: stretch; gap: 7px; padding-inline: 8px; white-space: nowrap }
.month-status { display: flex; align-items: baseline; gap: 8px; justify-content: space-between }
.date { display: inline-flex; align-items: center; gap: 4px; font: 700 17px/1 var(--serif) }
.date svg { color: var(--red) }
#counter { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--blue); line-height: 1.05 }
.chapter-ticks { display: grid; grid-template-columns: repeat(12,minmax(0,1fr)); gap: 3px }
.chapter-ticks i { height: 2px; background: #cfc3ab }
.chapter-ticks .earned { background: var(--red) }
.chapter-ticks .current { background: var(--blue) }
.stage-date { display: grid; align-content: center; gap: 6px; min-width: 105px; font-size: 17px }

.bottom { bottom: calc(env(safe-area-inset-bottom) + 9px); display: flex; flex-direction: column; align-items: flex-start; gap: 9px }
.tray { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 7px }
.tray button { white-space: nowrap }
#add { background: var(--ink); color: var(--card); border-color: var(--ink); padding-inline: 10px }
#add:is([aria-pressed=true],[aria-expanded=true]) { background: var(--red); border-color: var(--red) }
.zoom { display: flex; background: var(--card); box-shadow: 0 2px 4px #4d302011 }
.zoom button { display: grid; place-items: center; padding: 0; border-radius: 0; font-size: 20px }
.zoom button+button { border-left: 0 }
.zoom-icon { display: block; width: 20px; height: 20px }
#layers { font-size: 13px; padding-inline: 3px }

#market,#inspector { width: min(100%,398px); background: var(--card); border: 1px solid var(--line); box-shadow: 1px 3px 0 #54452f13 }
#market:not([hidden]) { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); padding: 8px 3px }
#market button { display: grid; grid-template-rows: 37px auto auto; justify-items: center; align-content: center; min-width: 0; padding: 3px 2px; background: transparent; border: 0; border-radius: 0; font: 700 14px/1.35 var(--serif) }
#market button+button { border-left: 1px solid var(--line) }
#market button small { font: 500 12px/1.3 system-ui,sans-serif; color: var(--muted); font-variant-numeric: tabular-nums }
.part-portrait { display: block; width: 47px; height: 37px }
.part-portrait g { stroke-linejoin: round; stroke-width: 1.15 }
.portrait-front { fill: #eddfc4; stroke: #774b35 }
.portrait-back { fill: #d9e3dd; stroke: var(--blue) }
.portrait-back > path:first-child { stroke-dasharray: 2.4 1.45 }
.part-portrait circle { fill: var(--card) }
.part-portrait .bore { fill: none; stroke-width: .5 }

#inspector { padding: 5px 9px 4px }
.part-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 7px }
.part-actions { display: flex; flex: none; align-items: center; gap: 7px }
.part-actions:not(:has(:not([hidden]))) { display: none }
.part-line { display: flex; align-items: baseline; flex-wrap: wrap; gap: 1px 8px; min-width: 0 }
#part-name { font: 700 16px/1.25 var(--serif) }
#reading { font-size: 13px; color: var(--blue); line-height: 1.25 }
#reading.warning { color: var(--red) }
#inspector:has(#resize:not([hidden])) .part-line { display: block }
#inspector:has(#resize:not([hidden])) #part-name { display: block }
#inspector:has(#resize:not([hidden])) #reading { display: block; height: 2.5em; overflow: auto }
#inspector:has(#torque-reading:not([hidden])) #reading { height: auto; overflow: visible }
#torque-reading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 1px 9px; margin-top: 3px; color: var(--muted); font-size: 13px; line-height: 1.25; font-variant-numeric: tabular-nums }
#torque-reading span { white-space: nowrap }
#torque-reading span + span { padding-inline-start: 8px; border-inline-start: 1px solid var(--line) }
#torque-reading strong { color: var(--ink) }
#torque-reading.warning #torque-limit { color: var(--red) }
#resize:not([hidden]) { display: flex; gap: 5px; align-items: center; font-size: 13px; white-space: nowrap }
#radius { min-width: 36px; flex: 1; min-height: 44px; margin: 0; accent-color: var(--red); touch-action: pan-y }
#radius-value { min-width: 3.4em; text-align: right; font-variant-numeric: tabular-nums }
#face-control { display: flex; flex: none; align-items: stretch; min-height: 44px }
#face-control label { position: relative; display: grid; place-items: center; cursor: pointer; touch-action: manipulation; min-width: 41px }
#face-control span { display: grid; place-items: center; width: 100%; height: 30px; line-height: 1; border: 1px solid var(--line); font-size: 13px; font-weight: 600; background: #f1e8d5 }
#face-control label:first-child span { border-radius: 3px 0 0 3px }
#face-control label:last-child span { border-left: 0; border-radius: 0 3px 3px 0 }
#face-control input:checked+span { background: var(--blue); border-color: var(--blue); color: var(--card) }
#face-control input:focus-visible+span { outline: 2px solid var(--blue); outline-offset: 2px; z-index: 1 }
#remove { font-size: 13px }
#remove { color: var(--red); --button-rule: #b69581; --button-paper: #f7ebdb; --button-down: #ead7c3 }
#resize-cost { display: grid; justify-items: end; align-content: center; min-height: 44px; font-size: 12px; line-height: 1.25; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap }
#resize-amount { color: var(--ink) }
#resize-warning { color: var(--red) }

.sheet { color: var(--ink); width: min(454px,calc(100vw - 34px)); max-height: calc(100dvh - 40px); padding: 19px clamp(20px,6vw,33px) 26px; border: none; border-radius: 0; background: #fcf7e9; box-shadow: 0 0 0 1px #65574362,3px 4px 0 -1px #d8ccb4,3px 4px 0 0 #65574362; font-size: 16px; line-height: 1.65 }
.sheet::backdrop { background: #29261f70 }
.paperhead { min-height: 45px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #a99b81; color: var(--red); font: 700 14px var(--serif); letter-spacing: .08em }
.paperhead { padding-bottom: 6px }
.paperhead form { margin: 0 }
.paper-close { font: 600 13px system-ui,sans-serif; color: var(--ink); --button-rule: #bcae92; --button-paper: #f3ead8; --button-down: #e9dcc3 }
.paper-close,#remove { border: 0; background: transparent; padding: 0; min-height: 44px }
.paper-close>span,#remove>span { display: inline-grid; min-height: 28px; min-width: 44px; place-items: center; border: 1px solid var(--button-rule); background: var(--button-paper); padding-inline: 6px }
.paper-close:active>span,#remove:active>span { background: var(--button-down) }
.paper-close:focus-visible,#remove:focus-visible { outline: none }
.paper-close:focus-visible>span,#remove:focus-visible>span { outline: 2px solid var(--blue); outline-offset: 2px }
.sheet h2 { margin: 17px 0 11px; font: 700 clamp(24px,6vw,32px)/1.18 var(--serif); letter-spacing: .055em }
.sheet .chapter-note { margin: 14px 0 27px; font: 500 17px/1.95 var(--serif); letter-spacing: .03em; text-wrap: pretty }
.stage-facts { margin: 0; padding-top: 13px; border-top: 1px solid #a99b81 }
.stage-facts > div { display: grid; grid-template-columns: 6em 1fr; align-items: baseline; gap: 2px; margin: 0 0 5px }
.stage-facts dt { color: var(--muted); font-size: 13px }
.stage-facts dd { margin: 0; font-size: 14px }
#stage-waiting { margin-top: 17px; padding-top: 12px; border-top: 1px solid #a99b81 }
#waiting-heading { margin: 0 0 5px; font: 700 16px/1.45 var(--serif) }
#waiting-list { margin: 0; padding: 0; list-style: none }
#waiting-list li+li { border-top: 1px solid var(--line) }
#waiting-list button { display: grid; width: 100%; grid-template-columns: minmax(0,1fr) auto; align-items: baseline; gap: 6px; border: 0; background: transparent; padding: 8px 2px; text-align: left; font-size: 14px }
#waiting-list strong { text-decoration: underline; text-decoration-color: #b8a98b; text-underline-offset: 3px }
#waiting-list span { color: var(--red); font-size: 13px; text-align: right }
#reward { font: 700 19px var(--serif); color: var(--red); margin-right: 7px; white-space: nowrap }
#reward-state { display: inline-block; font-size: 12px; color: var(--muted) }
#stage-first-move { margin-top: 9px; color: var(--blue); background: transparent; font-size: .875rem }
#manual { width: min(490px,calc(100vw - 28px)); overscroll-behavior: contain; padding-inline: clamp(15px,5vw,28px) }
#manual .paperhead h2 { margin: 0; font: inherit; letter-spacing: inherit }
#manual .paperhead + .guide-section { border-top: 0; margin-top: 0 }
#manual .gear { cursor: inherit }
#manual .gear text { pointer-events: none }
.guide-section { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 13px }
.guide-section h3 { margin: 0 0 8px; font: 700 1.125rem/1.4 var(--serif) }
.guide-section p { color: var(--muted); font-size: .9375rem; line-height: 1.6; margin: 0 0 8px }
.guide-section p:last-child { margin-bottom: 0 }
.guide-board { margin: 0 0 10px; border: 1px solid var(--line); background: radial-gradient(ellipse at 45% 36%,#fffaf0,var(--paper) 69%,#e9e0cf) }
.guide-board svg { display: block; width: 100%; height: clamp(151px,49vw,190px) }
.guide-profile { display: grid; grid-template-columns: clamp(66px,23vw,90px) minmax(0,1fr); gap: 12px; align-items: start; padding: 9px 0; border-bottom: 1px solid #c9bda67d }
.guide-profile:last-child { border-bottom: 0; padding-bottom: 0 }
.guide-gear { display: block; width: 100%; aspect-ratio: 1; background: #f5efdf; border: 1px solid #c9bda67d }
.guide-profile h4,.guide-profile h5,.guide-relay-heading { margin: 0 0 2px; font: 700 1rem/1.4 var(--serif) }
.guide-relay-heading { margin: 11px 0 3px }
.guide-3d { display: flex; align-items: start; gap: 11px }
.guide-cube { display: inline-grid; flex: 0 0 36px; place-items: center; height: 36px; border: 1px solid var(--line); background: var(--card) }
.guide-cube svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.55 }
.guide-lookup details { border-bottom: 1px solid var(--line) }
.guide-lookup details:first-of-type { border-top: 1px solid var(--line) }
.guide-lookup summary { display: flex; align-items: center; gap: 9px; min-height: 46px; padding: 7px 0; cursor: pointer; list-style: none; font: 700 .9375rem/1.35 var(--serif); touch-action: manipulation }
.guide-lookup summary::-webkit-details-marker { display: none }
.guide-lookup summary::before { content: "+"; flex: 0 0 14px; color: var(--red); font: 500 1.25rem/1 system-ui,sans-serif }
.guide-lookup details[open] summary::before { content: "−" }
.guide-lookup summary:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px }
.guide-body { margin: 0 0 13px 23px }
.guide-status-example { display: inline-flex; margin-bottom: 8px; padding: 3px 8px; align-items: baseline; gap: 9px; border-top: 2px dashed #963c31; background: #f6efdf }
.guide-status-example strong { font-family: var(--serif); color: var(--ink) }
.guide-status-example span { font-size: .8125rem; color: var(--blue); font-weight: 700 }
.manual-actions { display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 18px }
#manual .manual-actions { align-items: center; gap: 12px }
#manual .manual-actions button { padding-inline: 9px }
#reset-run { font-size: 13px; background: transparent; color: var(--muted) }
.manual-close { min-height: 46px; color: var(--card); background: var(--ink); border-color: var(--ink) }
.manual-close:not(:disabled):hover { color: var(--card); background: #444436 }
.reset-confirm { background: var(--red); color: var(--card); border-color: var(--red) }
.reset-confirm:not(:disabled):hover { color: var(--card); background: #82382d }

.gear { cursor: grab }
.gear.fixed { cursor: pointer }
.gear .body,.gear .rear-outline { stroke-width: 1.35; stroke-linejoin: round }
.gear .label { paint-order: stroke; stroke: var(--card); stroke-width: 2.5px; stroke-linejoin: round; font: bold 11px system-ui; fill: var(--ink) }
.gear .number { font: bold 9.5px system-ui; fill: var(--muted) }
.gear .number.warning { fill: #8b3229 }
.covered-lettering { opacity: .76 }
.covered-lettering .number { paint-order: stroke; stroke: var(--card); stroke-width: 2px; stroke-linejoin: round }
.gear .target-dir { font: 700 13px system-ui; fill: #245664; paint-order: stroke; stroke: #fff6e6; stroke-width: 2px; stroke-linejoin: round }
.gear .target-speed { font-size: 10px; font-variant-numeric: tabular-nums }
.gear .attempt-dir { display: none; font: bold 13px system-ui; fill: var(--red); paint-order: stroke; stroke: var(--card); stroke-width: 2px }
@media (prefers-reduced-motion:reduce) { .gear .attempt-dir { display: block } }

@media (max-width:710px) {
  .top { grid-template-columns: minmax(0,1fr) auto; column-gap: 4px; row-gap: 3px; align-items: start }
  .mark { width: 30px; height: 30px }
  .game-title { font-size: clamp(13px,3.6vw,18px); white-space: normal }
  .game-title span { white-space: nowrap }
  .tools { grid-column: 2; grid-row: 1 }
  .top .objective { grid-column: 1/-1; grid-row: 2; justify-self: center }
}
@media (max-width:344px) {
  .cash-line { gap: 2px }
  .cash-line strong { font-size: 20px }
  .cash-label { margin-right: 0 }
  #face-control label { min-width: 35px }
  #inspector { padding-inline: 7px }
  .part-head,.part-actions { gap: 4px }
}

/* The display case is deliberately separate from the game HUD. */
#gallery {
 position: fixed; inset: 0; margin: 0; padding: 0; border: 0;
 width: 100%; height: 100%; max-width: none; max-height: none;
 overflow: hidden; color: #eee4c9;
 background: radial-gradient(ellipse at 50% 40%, #33352f 0%, #252a28 54%, #151a19 100%);
}
#gallery::backdrop { background: #191d1b }
.gallery-surface { position: absolute; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; outline: none }
.gallery-surface.orbiting { cursor: grabbing }
.gallery-surface canvas { display: block; width: 100%; height: 100%; pointer-events: none }
#gallery button {
 position: absolute; top: calc(env(safe-area-inset-top) + 14px); display: grid; place-items: center;
 min-width: 46px; min-height: 46px; padding: 0; border-color: #77786a;
 background: #262b28; color: #eee4c9;
}
#gallery button:focus-visible { outline-color: #eee4c9 }
#gallery button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.55; stroke-linecap: round; stroke-linejoin: round }
.gallery-close { left: calc(env(safe-area-inset-left) + 14px) }
.gallery-reset { right: calc(env(safe-area-inset-right) + 14px) }
@media (hover:hover) { #gallery button:hover { background: #41473d; color: #fff5dd } }
@media (max-width:350px) {
 .zoom button { min-width: 40px }
 #add { padding-inline: 6px }
 .tray { gap: 5px }
}

.mesh-conflict{transform:scale(var(--mark-scale,1))}
.mesh-conflict circle{fill:#a44236;stroke:#f7efdf;stroke-width:1.4}
.mesh-conflict path{fill:none;stroke:#fff6e4;stroke-width:1.65;stroke-linecap:round}
[data-conflict][data-layer="1"] circle{stroke-dasharray:2 1}
