:root {
  color-scheme: dark;
  --blueprint: #0b2b46;
  --blueprint-dark: #061927;
  --line: #8fd4df;
  --paper: #eef7e8;
  --yellow: #ffd75a;
  --orange: #ef7b45;
  --red: #ef5d68;
  --green: #70d6a5;
  --ink: #112739;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--blueprint-dark); }
body { margin: 0; color: var(--paper); background: var(--blueprint-dark); font-family: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", system-ui, sans-serif; }
button { font: inherit; }
button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.blueprint-shell { min-height: 100vh; overflow-x: hidden; background-color: var(--blueprint); background-image: linear-gradient(rgba(143,212,223,.08) 1px,transparent 1px),linear-gradient(90deg,rgba(143,212,223,.08) 1px,transparent 1px); background-size: 28px 28px; }
.masthead { min-height: 84px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 2px solid var(--line); padding: 14px clamp(16px,4vw,54px); background: rgba(6,25,39,.92); }
.masthead h1 { margin: 2px 0 0; font-size: clamp(1.35rem,3vw,2.2rem); letter-spacing: .06em; }
.eyebrow,.serial { margin: 0; color: var(--yellow); font-family: ui-monospace, "Cascadia Mono", monospace; font-size: .78rem; letter-spacing: .13em; text-transform: uppercase; }
.tool-button,.clear-button,.repair-button,.ranking-button { color: var(--paper); border: 1px solid var(--line); background: #102f48; padding: 10px 14px; min-height: 44px; cursor: pointer; }

.start-screen { min-height: calc(100vh - 84px); display: grid; grid-template-columns: minmax(280px,1.1fr) minmax(300px,.9fr); align-items: stretch; }
.start-diagram { position: relative; min-height: 520px; display: grid; place-items: center; overflow: hidden; border-right: 2px solid var(--line); background: #0d3554; }
.start-diagram svg { width: min(80%,560px); fill: none; stroke: var(--line); stroke-width: 7; stroke-linecap: square; filter: drop-shadow(0 0 8px rgba(143,212,223,.25)); }
.start-diagram svg circle { stroke: var(--yellow); stroke-width: 10; }
.battery-mark { position: absolute; left: 8%; bottom: 10%; display: flex; align-items: center; gap: 10px; color: var(--yellow); font: 800 1.6rem ui-monospace,monospace; }
.battery-mark i { width: 100px; height: 46px; border: 5px solid var(--yellow); position: relative; }
.battery-mark i::after { content: ""; position: absolute; right: -11px; top: 12px; width: 7px; height: 16px; background: var(--yellow); }
.mini-tower { position: absolute; z-index: 2; width: 34%; height: 58%; bottom: 20%; display: flex; flex-direction: column-reverse; gap: 8px; }
.mini-tower b { flex: 1; border: 5px solid var(--paper); background: repeating-linear-gradient(135deg,transparent 0 12px,rgba(255,255,255,.08) 12px 20px); }
.mini-tower em { position: absolute; left: 50%; top: -55px; translate: -50%; color: var(--yellow); font-style: normal; font-size: 4rem; text-shadow: 0 0 18px var(--yellow); }
.start-copy { align-self: center; padding: clamp(34px,7vw,90px); max-width: 760px; }
.start-copy h2 { margin: 14px 0 22px; font-size: clamp(2rem,5vw,4.6rem); line-height: 1.12; color: #fff; }
.start-copy > p:not(.serial):not(.best-line) { font-size: 1.05rem; line-height: 1.9; }
.start-rules { margin: 26px 0; display: grid; gap: 9px; border-left: 2px solid var(--yellow); padding-left: 15px; }
.start-rules span { display: flex; align-items: center; gap: 10px; }
.start-rules b { display: grid; place-items: center; width: 26px; height: 26px; color: var(--ink); background: var(--yellow); }
.power-button { min-height: 58px; border: 0; border-bottom: 5px solid #9b521f; background: var(--yellow); color: var(--ink); padding: 12px 24px; font-weight: 900; cursor: pointer; box-shadow: 8px 8px 0 rgba(0,0,0,.2); }
.power-button span { display: block; font-size: 1.08rem; }
.power-button small { font-weight: 700; }
.best-line { margin-top: 18px; color: var(--line); }

.instrument-strip { position: sticky; top: 0; z-index: 8; display: grid; grid-template-columns: .7fr 1fr 1.5fr .8fr; border-bottom: 2px solid var(--line); background: #061927; }
.instrument-strip > div { min-height: 66px; padding: 9px 16px; border-right: 1px solid rgba(143,212,223,.45); }
.instrument-strip small { display: block; color: var(--line); font-size: .72rem; }
.instrument-strip strong { display: block; margin-top: 2px; font: 800 1.18rem ui-monospace,"Cascadia Mono",monospace; }
.meter { display: block; width: 100%; max-width: 220px; height: 6px; margin-top: 6px; background: #243f52; }
.meter i { display: block; height: 100%; width: 72%; background: var(--green); transition: width .25s ease,background .25s ease; }

.game-world { min-height: 670px; display: grid; grid-template-columns: minmax(210px,.72fr) minmax(390px,1.6fr) minmax(220px,.78fr); touch-action: pan-y; }
.material-cabinet,.test-console { padding: 18px; background: rgba(6,25,39,.88); }
.material-cabinet { border-right: 2px solid var(--line); }
.test-console { border-left: 2px solid var(--line); }
.material-cabinet h2,.test-console h2,.discovery-ledger h2 { margin: 0 0 10px; color: var(--yellow); font: 800 .88rem ui-monospace,monospace; letter-spacing: .12em; }
.selection-text { min-height: 58px; margin: 0 0 12px; padding: 9px; color: var(--line); border: 1px dashed rgba(143,212,223,.55); font-size: .86rem; line-height: 1.55; }
.material-tray { display: grid; gap: 9px; }
.material { position: relative; width: 100%; min-height: 64px; border: 2px solid #57798d; border-left: 10px solid var(--material-color,#aaa); background: #13354d; color: #fff; padding: 8px 9px; text-align: left; cursor: grab; touch-action: pan-y; }
.material[aria-pressed="true"] { border-color: var(--yellow); border-left-color: var(--yellow); translate: 5px 0; box-shadow: -5px 0 0 var(--yellow); }
.material strong,.material small { display: block; }
.material small { margin-top: 3px; color: #cde4e8; }
.material .result-tag { position: absolute; right: 6px; top: 6px; font-size: .68rem; padding: 2px 5px; border: 1px solid currentColor; }
.clear-button { width: 100%; margin-top: 10px; }
.legend { margin-top: 18px; display: grid; gap: 7px; color: #cde4e8; font-size: .72rem; }
.legend span { display: flex; align-items: center; gap: 7px; }
.legend i { width: 14px; height: 14px; border: 2px solid #fff; }
.known-conductor { background: var(--yellow); border-radius: 50%; }
.known-insulator { background: #37576b; }
.unknown { border-style: dashed !important; }

.tower-bay { position: relative; padding: 12px 20px 20px; overflow: hidden; background-color: #0c3150; background-image: linear-gradient(rgba(143,212,223,.12) 1px,transparent 1px),linear-gradient(90deg,rgba(143,212,223,.12) 1px,transparent 1px); background-size: 22px 22px; }
.wind-ruler { min-height: 48px; display: flex; align-items: center; justify-content: center; gap: 13px; color: #fff; }
.wind-ruler span { color: var(--line); font-size: .74rem; }
.wind-ruler strong { min-width: 110px; }
.wind-ruler i { color: var(--orange); font-size: 2rem; font-style: normal; }
.tower-stage { position: relative; min-height: 580px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.lab-wall { position: absolute; inset: 5% 0 8%; pointer-events: none; color: rgba(143,212,223,.14); font: 800 clamp(2rem,5vw,5rem) ui-monospace,monospace; writing-mode: vertical-rl; }
.lab-wall b { position: absolute; width: 64px; height: 64px; border: 2px dashed currentColor; }
.lab-wall b:nth-child(2) { left: 5%; top: 12%; }.lab-wall b:nth-child(3){right:8%;top:34%}.lab-wall b:nth-child(4){left:12%;bottom:3%}
.tower-stack { width: min(78%,510px); display: flex; flex-direction: column-reverse; align-items: stretch; gap: 3px; z-index: 2; }
.built-floor { height: 52px; display: grid; grid-template-columns: 1fr .72fr 1fr; border: 3px solid var(--paper); background: #173d59; box-shadow: 0 0 18px rgba(255,215,90,.12); }
.built-floor span { display: grid; place-items: center; border-right: 2px solid rgba(238,247,232,.5); font-size: .78rem; }
.built-floor span:last-child { border: 0; }
.built-floor.lit { border-color: var(--yellow); }
.built-floor.lit span:first-child,.built-floor.lit span:last-child { color: var(--yellow); background: linear-gradient(90deg,transparent 43%,var(--yellow) 44% 56%,transparent 57%); text-shadow: 1px 1px #000; }
.built-floor.near { animation: settle .7s ease; }
.working-floor { position: relative; z-index: 3; width: min(96%,650px); min-height: 250px; padding: 20px 16px 14px; border: 3px dashed var(--line); background: #0b2b46; transform-origin: 50% 100%; }
.working-floor h2 { margin: 0; text-align: center; font-size: 1.25rem; color: #fff; }
.working-floor > p { margin: 5px auto 14px; max-width: 520px; text-align: center; color: #cde4e8; font-size: .85rem; }
.working-floor.testing { animation: windTest 1s ease-in-out; }
.working-floor.success { border-style: solid; border-color: var(--yellow); box-shadow: 0 0 35px rgba(255,215,90,.35); }
.working-floor.fail { border-color: var(--red); }
.slot-row { display: grid; grid-template-columns: 1fr .84fr 1fr; gap: 8px; }
.slot { position: relative; min-height: 118px; border: 2px dashed #6f9daf; background: #102f48; color: #fff; padding: 9px 7px; cursor: pointer; }
.slot small,.slot strong,.slot span { display: block; }
.slot small { color: var(--line); font-size: .67rem; }
.slot strong { margin: 9px 0; font-size: .85rem; }
.slot span { color: #aac7d0; font-size: .7rem; }
.slot.filled { border-style: solid; border-color: var(--material-color,var(--yellow)); background: #173d59; }
.slot.filled::after { content: "交換OK"; position: absolute; right: 4px; bottom: 3px; font-size: .58rem; color: var(--line); }
.slot.can-place { border-color: var(--yellow); box-shadow: inset 0 0 0 2px rgba(255,215,90,.16); }
.circuit-line { height: 22px; display: grid; grid-template-columns: 1fr .84fr 1fr; gap: 8px; }
.circuit-line i { width: 5px; height: 24px; justify-self: center; background: var(--yellow); }
.circuit-line b { border-top: 3px solid #7795a5; margin-top: 10px; }
.lamp-crown { display: none; position: absolute; left: 50%; top: -50px; translate: -50%; gap: 42px; }
.working-floor.finale .lamp-crown { display: flex; }
.lamp-crown i { width: 30px; height: 38px; border: 3px solid var(--yellow); border-radius: 50% 50% 35% 35%; background: rgba(255,215,90,.18); }
.battery-base { z-index: 3; width: min(72%,470px); height: 54px; display: grid; grid-template-columns: 50px 1fr 50px; place-items: center; border: 4px solid var(--yellow); color: var(--yellow); background: #17293a; font-weight: 900; }
.battery-base span { letter-spacing: .2em; }
.preview-list { margin: 0; }
.preview-list div { display: grid; grid-template-columns: 1fr 1.2fr; gap: 6px; padding: 10px 0; border-bottom: 1px solid #43647a; }
.preview-list dt { color: var(--line); font-size: .78rem; }.preview-list dd { margin: 0; font-weight: 800; text-align: right; }
.status-message { min-height: 108px; margin: 16px 0; border-left: 5px solid var(--line); padding: 10px 11px; background: #102f48; line-height: 1.55; font-size: .88rem; }
.status-message.success { border-color: var(--green); }.status-message.warning { border-color: var(--orange); }.status-message.danger { border-color: var(--red); }
.test-button { width: 100%; min-height: 62px; border: 0; border-bottom: 5px solid #967b1f; background: var(--yellow); color: var(--ink); font-weight: 900; cursor: pointer; }
.test-button:disabled { opacity: .45; cursor: not-allowed; }
.bulb-icon { display: inline-block; width: 18px; height: 18px; margin-right: 8px; border: 3px solid currentColor; border-radius: 50%; vertical-align: -4px; }
.repair-button { width: 100%; margin-top: 10px; }
.risk-note { color: #bfd6dd; font-size: .75rem; line-height: 1.55; }.risk-note b{color:var(--orange)}
.discovery-ledger { border-top: 2px solid var(--line); padding: 15px clamp(16px,4vw,54px) 24px; background: #061927; }
.discovery-list { display: grid; grid-template-columns: repeat(7,minmax(90px,1fr)); gap: 7px; }
.discovery-chip { min-height: 50px; display: grid; place-items: center; text-align: center; border: 1px dashed #56798c; color: #96b4c0; padding: 6px; font-size: .74rem; }
.discovery-chip.known { border-style: solid; color: #fff; }.discovery-chip.conductor { border-color: var(--yellow); }.discovery-chip.insulator { border-color: var(--line); }

.quiz-screen,.result-screen { width: min(900px,calc(100% - 28px)); margin: clamp(24px,6vh,70px) auto; border: 3px solid var(--line); background: #0b2b46; padding: clamp(22px,5vw,54px); box-shadow: 12px 12px 0 #061927; }
.quiz-wire { height: 12px; margin-bottom: 22px; border-top: 4px solid var(--yellow); border-bottom: 2px dashed var(--line); }
.quiz-progress,.result-screen .serial { color: var(--yellow); font-family: ui-monospace,monospace; letter-spacing: .12em; }
.quiz-screen h2,.result-screen h2 { font-size: clamp(1.5rem,4vw,2.7rem); }
.quiz-question { font-size: 1.16rem; line-height: 1.7; }
.quiz-choices { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.quiz-choices button { min-height: 62px; border: 2px solid var(--line); background: #13354d; color: #fff; padding: 11px; text-align: left; cursor: pointer; }
.quiz-choices button[data-correct="true"] { border-color: var(--yellow); box-shadow: inset 8px 0 0 var(--yellow); }.quiz-choices button[data-chosen="true"]{font-weight:900}
.quiz-feedback { margin-top: 18px; border-left: 6px solid var(--yellow); padding: 13px 16px; background: #102f48; }
.quiz-feedback strong { color: var(--yellow); font-size: 1.15rem; }.quiz-feedback p{line-height:1.7}
.quiz-feedback button { min-height: 48px; border: 0; background: var(--yellow); color: var(--ink); padding: 10px 18px; font-weight: 900; cursor: pointer; }
.result-screen { text-align: center; }
.result-tower { width: 170px; height: 190px; margin: 0 auto 22px; display: flex; flex-direction: column-reverse; position: relative; }
.result-tower b { flex: 1; border: 3px solid var(--yellow); margin-top: -3px; background: linear-gradient(90deg,transparent 20%,var(--yellow) 21% 26%,transparent 27% 73%,var(--yellow) 74% 79%,transparent 80%); }
.result-tower i { height: 26px; border: 4px solid var(--yellow); background: #17293a; }
.result-tower em { position: absolute; top: -29px; width: 100%; color: var(--yellow); font-style: normal; font-size: 1.8rem; text-shadow: 0 0 14px var(--yellow); }
.final-score small { display: block; color: var(--line); }.final-score strong { color: var(--yellow); font: 900 clamp(2.8rem,8vw,5.5rem) ui-monospace,monospace; }
.result-ledger { display: grid; grid-template-columns: repeat(3,1fr); border-block: 1px solid var(--line); margin: 24px 0; }.result-ledger p{padding:12px;border-right:1px solid var(--line)}.result-ledger p:last-child{border:0}.result-ledger b{display:block;color:var(--yellow);margin-top:5px}
.result-message { max-width: 700px; margin: 18px auto; line-height: 1.7; }
.result-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 14px; }
.ranking-panel { margin: 22px auto 0; max-width: 640px; min-height: 160px; padding: 12px; border: 2px solid var(--line); background: #f4f8ef; color: #142735; text-align: left; }
.ranking-panel button,.ranking-panel [role="tab"] { color: #142735 !important; background: #dce9e4 !important; }.ranking-panel [aria-selected="true"],.ranking-panel .active{background:#173d59!important;color:#fff!important}

@keyframes windTest { 0%,100%{transform:rotate(0)} 28%{transform:rotate(1.8deg)} 58%{transform:rotate(-1.4deg)} 80%{transform:rotate(.7deg)} }
@keyframes settle { 0%{transform:rotate(2deg)} 45%{transform:rotate(-1.5deg)} 100%{transform:rotate(0)} }

@media (max-width: 980px) {
  .game-world { grid-template-columns: 210px minmax(360px,1fr); }
  .test-console { grid-column: 1 / -1; border-left: 0; border-top: 2px solid var(--line); display: grid; grid-template-columns: 1fr 1.3fr; gap: 12px 20px; }
  .test-console h2,.test-console .preview-list{grid-column:1}.status-message{grid-column:2;grid-row:1 / span 2;margin:0}.test-button,.repair-button,.risk-note{grid-column:1 / -1}.repair-button{margin-top:0}
  .discovery-list { grid-template-columns: repeat(4,1fr); }
}

@media (max-width: 680px) {
  .masthead { min-height: 70px; padding: 10px 12px; }.masthead h1{font-size:1.12rem}.eyebrow{font-size:.62rem}.tool-button{padding:8px 9px;font-size:.78rem}
  .start-screen { display: block; min-height: auto; }.start-diagram{min-height:300px;border-right:0;border-bottom:2px solid var(--line)}.start-copy{padding:26px 18px 42px}.start-copy h2{font-size:2.2rem}
  .instrument-strip { grid-template-columns: repeat(4,1fr); }.instrument-strip > div{padding:7px 6px;min-height:60px}.instrument-strip small{font-size:.6rem}.instrument-strip strong{font-size:.86rem}.stability-block .meter{margin-top:5px}
  .game-world { display: flex; flex-direction: column; min-height: auto; }
  .tower-bay { order: 1; padding: 8px 8px 14px; }.material-cabinet{order:2;border-right:0;border-top:2px solid var(--line)}.test-console{order:3;display:block;border-top:2px solid var(--line)}
  .tower-stage { min-height: 500px; }.working-floor{width:100%;padding-inline:7px}.slot-row{gap:5px}.slot{min-height:112px;padding:7px 3px}.slot strong{font-size:.74rem}.slot small,.slot span{font-size:.6rem}.tower-stack{width:88%}
  .material-tray { grid-template-columns: repeat(2,minmax(0,1fr)); }.material{min-height:70px}.selection-text{min-height:auto}
  .discovery-list { grid-template-columns: repeat(2,1fr); }.discovery-chip:last-child{grid-column:1 / -1}
  .quiz-screen,.result-screen{width:calc(100% - 20px);margin:18px auto;padding:20px 14px}.quiz-choices{grid-template-columns:1fr}.quiz-choices button{width:100%;min-width:0;white-space:normal;overflow-wrap:anywhere}
  .result-ledger{grid-template-columns:1fr}.result-ledger p{border-right:0;border-bottom:1px solid var(--line);margin:0}.result-actions{display:grid}.ranking-panel{max-height:70vh;overflow:auto}
}

@media (prefers-reduced-motion: reduce) {
  *,*::before,*::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
