:root {
  font-family:Arial,'Noto Sans KR','Apple SD Gothic Neo',sans-serif;
  color:#18313d;
  background:#d8dfe0;
  font-synthesis:none;
  --navy:#173442;
  --cream:#fff9ec;
  --green:#1e7650;
  --accent:#ffc64b;
  --control-h:166px;
  --header-h:72px
}
* {
  box-sizing:border-box
}
body {
  margin:0;
  overflow:hidden;
  /* Korean text breaks between words, not inside them (M5.1). */
  word-break:keep-all;
  overflow-wrap:break-word
}
button,a {
  -webkit-tap-highlight-color:transparent
}
button {
  font:inherit;
  cursor:pointer;
  border:1px solid #aab8bc;
  border-radius:8px;
  padding:9px 13px;
  color:var(--navy);
  background:var(--cream);
  font-weight:700
}
button:focus-visible,a:focus-visible {
  outline:3px solid #168b5a;
  outline-offset:3px
}
button:disabled {
  cursor:default;
  opacity:.5
}
.hidden {
  display:none!important
}
#app {
  height:100dvh;
  min-height:300px;
  position:relative;
  overflow:hidden
}
.top-bar {
  height:var(--header-h);
  display:flex;
  align-items:center;
  gap:13px;
  padding:12px 24px;
  background:var(--navy);
  color:var(--cream);
  position:relative;
  z-index:10
}
.brand {
  display:flex
}
.heading {
  display:grid;
  gap:5px
}
.heading strong {
  font-size:16px
}
.eyebrow {
  font-size:11px;
  font-weight:700;
  letter-spacing:.1em
}
.top-bar .eyebrow {
  color:#b7cbd1
}
.hud {
  margin-left:auto;
  display:flex;
  align-items:center;
  gap:18px
}
.hud time {
  font-size:27px;
  font-weight:800;
  font-variant-numeric:tabular-nums
}
.hud span {
  font-size:13px
}
#langBtn {
  font-size:11px;
  background:transparent;
  color:#fff4d8;
  border-color:#637883;
  padding:8px
}
#stage {
  position:absolute;
  top:var(--header-h);
  bottom:var(--control-h);
  left:0;
  right:0;
  overflow:hidden;
  touch-action:none
}
#scene {
  width:100%;
  height:100%;
  display:block;
  touch-action:none
}
.stage-caption {
  position:absolute;
  top:14px;
  left:20px;
  right:20px;
  display:flex;
  justify-content:space-between;
  pointer-events:none;
  font-size:11px;
  font-weight:bold;
  color:#4c6270
}
.stage-caption span {
  background:#edf3edbc;
  border:1px solid #ffffff8c;
  padding:6px 9px;
  border-radius:4px
}
#spotLayer,#impactLayer {
  position:absolute;
  inset:0;
  pointer-events:none
}
.placement-cell,.invalid-cell {
  position:absolute;
  transform:translate(-50%,-50%);
  pointer-events:none;
  height:10px;
  border:1px dashed #d3ffd4;
  background:#18834f66;
  box-shadow:0 0 0 1px #18583780;
  border-radius:2px
}
.placement-cell.hovered {border:2px solid #e5ffcf;background:#35ac6aaa}
.invalid-cell {width:25px;height:25px;border:3px solid #c6362d;background:#ffe1de55}
.impact {
  position:absolute;
  transform:translate(-50%,-50%);
  font-size:25px;
  color:#ba3028;
  font-weight:900;
  text-shadow:0 1px #fff,-1px 0 #fff,1px 0 #fff,0 -1px #fff;
  animation:blink .65s infinite
}
.bang {
  position:absolute;
  transform:translate(-50%,-50%) rotate(-10deg);
  color:#a92a24;
  background:#ffdd79;
  padding:7px;
  clip-path:polygon(0 20%,25% 22%,20% 0,48% 15%,70% 0,75% 22%,100% 15%,88% 50%,100% 85%,65% 78%,50% 100%,35% 78%,0 90%,12% 50%);
  font-weight:900;
  font-size:17px
}
#panHint {
  display:none;
  position:absolute;
  bottom:24px;
  left:0;
  right:0;
  text-align:center;
  font-size:11px;
  color:#fff;
  background:#173442bd;
  padding:7px;
  pointer-events:none
}
#mapNav {
  display:none;
  position:absolute;
  bottom:10px;
  left:20%;
  width:60%;
  height:5px;
  border-radius:4px;
  background:#18313d44;
  pointer-events:none
}
#mapNav span {
  position:absolute;
  height:100%;
  background:#fff4c6;
  border-radius:4px
}
.controls {
  position:absolute;
  bottom:0;
  left:0;
  right:0;
  height:var(--control-h);
  background:var(--cream);
  padding:12px 24px 7px;
  border-top:3px solid #cbbb98;
  z-index:12;
  box-shadow:0 -6px 24px #24313b0b
}
.control-top {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:8px
}
.control-top p {
  margin:0;
  font-size:13px;
  font-weight:700
}
.time-controls {
  display:flex;
  gap:5px;
  flex-shrink:0
}
.time-controls button {
  font-size:12px;
  padding:7px 12px
}
.time-controls .active {
  background:var(--navy);
  color:white
}
.toolbar {
  display:grid;
  grid-template-columns:repeat(5,1fr);
  gap:8px;
  max-width:1100px;
  margin:auto
}
.toolbar[data-count="6"] {
  grid-template-columns:repeat(6,1fr);
  gap:6px
}
.tool {
  position:relative;
  display:flex;
  align-items:center;
  gap:10px;
  height:65px;
  padding:8px 13px;
  text-align:left;
  border:1px solid #b7bbb1;
  background:#fffdf6;
  box-shadow:0 3px 0 #ded7c6
}
.tool.selected {
  outline:3px solid #197c51;
  background:#edf8e9
}
.tool .icon {
  font-size:25px;
  line-height:1;
  min-width:25px;
  color:#b88110
}
.tool .name {
  font-size:13px;
  display:block
}
.tool .name,.tool .desc { word-break:keep-all; overflow-wrap:anywhere }
.tool .desc {
  font-size:10px;
  font-weight:400;
  color:#607078;
  margin-top:5px;
  display:block;
  line-height:1.25
}
.toolbar[data-count="6"] .tool {
  gap:6px;
  padding:8px 6px
}
.toolbar[data-count="6"] .tool .name {
  font-size:12px
}
.toolbar[data-count="6"] .tool .desc {
  font-size:9px;
  margin-top:3px
}
.tool .count {
  margin-left:auto;
  align-self:flex-start;
  background:#f0e8d5;
  padding:3px 5px;
  border-radius:4px;
  font-size:12px
}
.control-foot {
  display:flex;
  gap:8px;
  align-items:center;
  justify-content:center;
  font-size:10px;
  color:#67756f;
  margin-top:8px
}
.control-foot a {
  margin-left:auto;
  color:#385047;
  text-decoration:none;
  font-weight:700;
  font-size:14px
}
.control-foot>span:first-child {
  margin-right:auto
}
.modal {
  position:absolute;
  z-index:30;
  background:var(--cream);
  border:1px solid #d9cfb7;
  box-shadow:0 16px 80px #162b414a;
  border-radius:16px;
  padding:30px;
  max-height:calc(100dvh - 40px);
  overflow-y:auto
}
.start-panel {
  left:4%;
  top:50%;
  transform:translateY(-50%);
  width:430px
}
.start-panel h1 {
  font-size:34px;
  letter-spacing:-1.5px;
  line-height:1.25;
  margin:18px 0 20px
}
.start-panel .eyebrow,.result-panel .eyebrow {
  color:#657d76
}
.rules {
  counter-reset:rules;
  list-style:none;
  padding:0;
  margin:0 0 22px;
  display:grid;
  gap:17px
}
.rules li {
  counter-increment:rules;
  display:flex;
  align-items:flex-start;
  gap:12px;
  font-size:14px;
  line-height:1.65
}
.rules li:before {
  content:counter(rules);
  flex-shrink:0;
  background:#e9dfc4;
  border-radius:50%;
  width:25px;
  height:25px;
  text-align:center;
  font-weight:800
}
.primary {
  background:var(--navy);
  color:var(--cream);
  width:100%;
  padding:13px;
  border:0
}
.small {
  font-size:11px;
  line-height:1.6;
  color:#63736f
}
.start-panel .small {
  text-align:center;
  margin-bottom:0
}
.result-panel {
  width:620px;
  left:50%;
  top:50%;
  transform:translate(-50%,-50%)
}
.result-panel h2 {
  font-size:28px;
  line-height:1.4;
  margin:13px 0
}
.result-panel h2 b {
  font-size:42px;
  color:#b06022;
  white-space:nowrap
}
.result-panel #targetResult {
  font-size:14px;
  margin:0 0 12px;
  font-weight:700
}
.result-panel #resultList {
  padding:0;
  margin:0 0 15px;
  list-style:none
}
.result-panel li {
  padding:10px 0;
  border-bottom:1px solid #ddd8c9;
  font-size:12px;
  line-height:1.6
}
.result-panel li strong {
  display:block;
  font-size:14px;
  color:#aa3d2d
}
.result-panel li.prevented strong,.target-met {
  color:var(--green)!important
}
.result-panel .small {
  margin:9px 0
}
.outcome-line {
  position:absolute;
  z-index:16;
  left:50%;
  transform:translateX(-50%);
  top:calc(var(--header-h) + 47px);
  padding:10px 16px;
  background:#edf9e7;
  border:1px solid #287545;
  border-radius:8px;
  font-size:13px;
  font-weight:700;
  color:#21643d;
  max-width:90%;
  white-space:nowrap
}
.accident-overlay {
  position:absolute;
  bottom:calc(var(--control-h) + 12px);
  left:50%;
  transform:translateX(-50%);
  z-index:18;
  width:max-content;
  max-width:calc(100% - 24px);
  pointer-events:none
}
.accident-card {
  background:#fff6e8;
  border-left:6px solid #b83e2e;
  box-shadow:0 4px 20px #26304055;
  border-radius:8px;
  padding:12px 18px;
  animation:slide-in .25s ease-out
}
.accident-card strong {
  font-size:15px;
  color:#ad3a2d
}
.accident-card p {
  margin:6px 0 0;
  font-size:12px;
  line-height:1.5
}
.incident-log {
  position:absolute;
  right:10px;
  top:calc(var(--header-h) + 55px);
  padding:0;
  margin:0;
  z-index:15;
  list-style:none;
  pointer-events:none;
  max-width:200px
}
.incident-log li {
  font-size:10px;
  margin:4px 0;
  background:#fff6e8e8;
  border-left:3px solid #b83e2e;
  padding:5px 7px;
  border-radius:3px;
  animation:slide-in .25s
}
.incident-log time {
  font-weight:bold;
  margin-right:5px
}
#loadError {
  position:absolute;
  z-index:50;
  inset:25%;
  background:white;
  padding:30px
}
@keyframes pulse {
  50% {
    box-shadow:0 0 0 5px #3bba6744
  }
}
@keyframes blink {
  50% {
    opacity:.25
  }
}
@keyframes slide-in {
  from {
    transform:translateY(7px);
    opacity:.5
  }
}
@media(max-width:600px) and (min-height:501px) {
  :root {
    --header-h:76px;
    --control-h:207px
  }
  .top-bar {
    gap:8px;
    padding:10px 12px
  }
  .heading strong {
    font-size:11px
  }
  .heading .eyebrow {
    font-size:9px
  }
  .brand img {
    width:22px;
    height:22px
  }
  .hud {
    display:grid;
    gap:2px;
    text-align:center
  }
  .hud time {
    font-size:22px
  }
  .hud span {
    font-size:9px
  }
  #langBtn {
    padding:6px;
    font-size:10px
  }
  .controls {
    padding:10px 10px 7px
  }
  .control-top {
    align-items:flex-start;
    gap:8px
  }
  .control-top p {
    font-size:11px;
    line-height:1.5;
    max-width:47%
  }
  .time-controls {
    gap:3px
  }
  .time-controls button {
    font-size:10px;
    padding:8px
  }
  .toolbar {
    gap:5px
  }
  .tool {
    height:95px;
    display:flex;
    flex-direction:column;
    justify-content:flex-start;
    gap:4px;
    padding:8px 2px;
    text-align:center
  }
  .tool .icon {
    font-size:23px
  }
  .tool .name {
    font-size:10px;
    letter-spacing:-.4px;
    white-space:nowrap
  }
  .tool .desc {
    display:none
  }
  .tool .count {
    margin:0;
    align-self:center;
    font-size:11px;
    padding:1px 6px
  }
  .control-foot {
    font-size:9px;
    gap:4px;
    flex-wrap:wrap;
    justify-content:space-between
  }
  .control-foot>span:first-child {
    width:100%;
    text-align:center
  }
  .control-foot a {
    margin-left:0;
    font-size:12px
  }
  .start-panel {
    left:12px;
    width:calc(100% - 24px);
    padding:18px 16px;
    max-height:calc(100dvh - 24px)
  }
  .start-panel h1 {
    font-size:26px;
    margin-top:8px;
    margin-bottom:12px
  }
  .rules {
    gap:15px
  }
  .rules li {
    font-size:13px
  }
  .result-panel {
    width:calc(100% - 24px);
    padding:22px
  }
  .result-panel h2 {
    font-size:22px
  }
  .result-panel h2 b {
    font-size:34px
  }
  .result-panel li {
    font-size:11px;
    padding:8px 0
  }
  .result-panel li strong {
    font-size:12px
  }
  .stage-caption {
    left:10px;
    right:10px;
    top:10px;
    font-size:9px
  }
  .stage-caption span:last-child {
    display:none
  }
  #panHint,#mapNav {
    display:block
  }
  .outcome-line {
    font-size:11px;
    white-space:normal;
    width:max-content
  }
  .accident-card {
    padding:10px 12px
  }
  .accident-card strong {
    font-size:12px
  }
  .accident-card p {
    font-size:10px
  }
  .incident-log {
    max-width:150px
  }
  .incident-log li {
    font-size:9px
  }
}
@media(max-height:500px) {
  :root {
    --header-h:48px;
    --control-h:100px
  }
  .top-bar {
    padding:5px 16px
  }
  .heading {
    display:flex;
    gap:12px;
    align-items:center
  }
  .heading strong {
    font-size:13px
  }
  .heading .eyebrow {
    font-size:9px
  }
  .hud time {
    font-size:22px
  }
  .hud span {
    font-size:11px
  }
  .controls {
    padding:5px 12px
  }
  .control-top {
    margin-bottom:4px
  }
  .control-top p {
    font-size:10px
  }
  .time-controls button {
    padding:4px 9px;
    font-size:10px
  }
  .toolbar {
    gap:6px
  }
  .tool {
    height:42px;
    padding:5px 8px;
    gap:6px
  }
  .tool .icon {
    font-size:20px
  }
  .tool .name {
    font-size:10px
  }
  .tool .desc {
    display:none
  }
  .tool .count {
    font-size:10px
  }
  .control-foot {
    margin-top:4px;
    font-size:9px
  }
  .control-foot a {
    font-size:11px
  }
  .stage-caption {
    top:5px;
    font-size:8px
  }
  .stage-caption span {
    padding:3px 5px
  }
  .start-panel {
    width:550px;
    padding:17px 24px;
    left:50%;
    transform:translate(-50%,-50%)
  }
  .start-panel h1 {
    font-size:23px;
    margin:8px 0 12px
  }
  .start-panel h1 br {
    display:none
  }
  /* One line in short landscape: keep the space between the two words (M5.1). */
  .start-panel h1 span+br+span::before {
    content:' '
  }
  .rules {
    gap:7px;
    margin-bottom:12px
  }
  .rules li {
    font-size:11px;
    line-height:1.5
  }
  .rules li:before {
    height:19px;
    width:19px
  }
  .start-panel .small {
    font-size:9px;
    margin-top:6px
  }
  .primary {
    padding:9px
  }
  .modal {
    max-height:calc(100dvh - 16px)
  }
  .result-panel {
    width:640px;
    padding:16px 24px
  }
  .result-panel h2 {
    font-size:18px;
    margin:7px 0
  }
  .result-panel h2 b {
    font-size:26px
  }
  .result-panel #targetResult {
    font-size:11px;
    margin-bottom:5px
  }
  .result-panel li {
    font-size:10px;
    padding:4px 0
  }
  .result-panel li strong {
    display:inline;
    font-size:10px;
    margin-right:8px
  }
  .result-panel .small {
    font-size:9px;
    margin:5px 0
  }
  .result-panel #resultList {
    margin-bottom:6px
  }
  .outcome-line {
    font-size:10px;
    padding:6px 10px;
    top:calc(var(--header-h) + 28px)
  }
  .incident-log {
    top:calc(var(--header-h) + 28px);
    max-width:160px
  }
  .incident-log li {
    font-size:8px;
    padding:3px 5px
  }
  .accident-card {
    padding:7px 12px
  }
  .accident-card strong {
    font-size:11px
  }
  .accident-card p {
    font-size:10px;
    margin-top:3px
  }
}
@media(prefers-reduced-motion:reduce) {
  .impact,.accident-card,.incident-log li {
    animation:none
  }
}
.accident-overlay {
  transition:transform .25s,opacity .25s
}
.accident-overlay.folding {
  transform:translateX(-40%) scale(.75);
  opacity:.2
}
.accident-overlay[data-side=left] { left:12px; transform:none; transform-origin:left bottom }
.accident-overlay[data-side=right] { left:auto; right:12px; transform:none; transform-origin:right bottom }
.accident-overlay[data-side=left].folding,.accident-overlay[data-side=right].folding { transform:scale(.75) }

#stagePicker { display:grid; grid-template-columns:repeat(auto-fit,minmax(84px,1fr)); gap:6px; margin:0 0 12px; }
#stagePicker button { font-size:12px; word-break:keep-all; overflow-wrap:anywhere; padding:7px 5px; line-height:1.25; }
#stagePicker button .nowrap { white-space:nowrap; } /* whole words per line (M5.1) */
#stagePicker button[aria-pressed="true"] { background:var(--navy); color:var(--cream); border-color:var(--navy); }
@media(max-width:600px) {
  #stagePicker { grid-template-columns:repeat(4,minmax(0,1fr)); gap:5px; margin:0 0 8px; }
  #stagePicker button { font-size:11px; padding:6px 3px; }
}
/* Buttons stay visible when a long result list scrolls (M1.2 #7). */
.result-actions { display:flex; gap:8px; margin-top:4px; position:sticky; bottom:0; padding-top:8px; background:var(--cream); }
.result-actions button { flex:1; width:auto; margin:0; }
.result-actions .secondary { flex:0 0 auto; padding:0 18px; min-height:48px; border:1px solid currentColor; border-radius:10px; background:transparent; font:inherit; cursor:pointer; }

@media(max-height:500px) { #stagePicker {margin-bottom:8px;} #stagePicker button {padding:6px;} }

/* Object names remain readable and let taps reach the scene beneath them. */
#objectLabels { position:absolute; inset:0; pointer-events:none; overflow:hidden; }
.object-label { position:absolute; visibility:hidden; white-space:nowrap; pointer-events:none;
  color:#253643; background:#fff5e3f2; border:1px solid #637a86;
  box-shadow:0 2px 4px #182d3926;
  border-radius:3px; padding:3px 6px; font-size:12px; line-height:1.25; font-weight:600; }
#labelsBtn { position:absolute; top:calc(var(--header-h) + 52px); left:20px; z-index:20;
  font-size:11px; padding:7px 10px; min-height:32px; }
#labelsBtn[aria-pressed="true"] { background:#e8f1e6; border-color:#7e9984; }
@media(max-width:600px) { .object-label { font-size:11px; padding:3px 5px; } }
@media(max-height:500px) { #labelsBtn { top:calc(var(--header-h) + 29px); padding:5px 8px; }
  .object-label { font-size:10px; padding:2px 5px; } }

/* The shallow excavation pans on wider screens as well as on phones. */
#stage.can-pan #panHint,#stage.can-pan #mapNav { display:block; }

.control-foot a.how-link{margin-left:auto;font-size:11px;font-weight:400;text-decoration:underline}
.control-foot a.how-link+a{margin-left:0}
