:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
  color: #fcf6eb;
  background: #141b31;
  --cream: #fcf6eb;
  --muted: #b9c4da;
  --sun: #ffcd79;
  --lilac: #d8c3fb;
  --ink: #192033;
  --lane: #3d4964;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 270px;
  min-height: 100svh;
  background: radial-gradient(ellipse at 82% 8%, #343c55 0, transparent 62%), #141b31;
}
button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible, .stage:focus-visible {
  outline: 2px solid var(--sun);
  outline-offset: 3px;
}
[hidden] { display: none !important; }

.game {
  width: min(calc(100% - 52px), 1190px);
  margin: 0 auto;
  padding: clamp(20px, 5vh, 50px) 0 20px;
}
.masthead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.setting {
  margin: 0 0 4px;
  color: var(--sun);
  font-size: .875rem;
  font-weight: 760;
  letter-spacing: .08em;
}
.setting span { margin-right: 3px; }
h1 {
  margin: 0;
  font-size: clamp(1.3rem, 4.3vw, 2.8rem);
  line-height: 1.16;
  font-weight: 900;
  letter-spacing: -.04em;
}
h1 span { color: var(--sun); }
.masthead-controls { display: flex; gap: 9px; align-items: center; }
.orientation-hint {
  display: none;
  margin: 0;
  color: var(--muted);
  font-size: .875rem;
  line-height: 1.2;
}
.audio-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: none;
  min-width: 44px;
  min-height: 42px;
  border: 1px solid #ffffff25;
  border-radius: 999px;
  background: #ffffff13;
  color: var(--cream);
  padding: 7px 13px;
  font-size: .875rem;
  font-weight: 700;
}
.audio-control:hover { background: #ffffff24; }
.audio-icon { color: var(--lilac); font-size: 1.05rem; }

.mission {
  padding: 10px 10px 0;
  border: 1px solid #8192af3d;
  border-radius: 23px;
  background: #151c30e6;
  box-shadow: 0 18px 50px #090d1b83;
}
.mission-bar, .progress, .reaction { display: flex; align-items: center; }
.mission-bar { justify-content: space-between; gap: 8px; min-height: 33px; margin: 0 6px 8px; }
.progress, .reaction { gap: 8px; }
.progress-caption, .reaction-caption { color: var(--muted); font-size: .875rem; }
#progress-count, #reaction-time {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-weight: 840;
}
#progress-count { color: var(--lilac); }
.pips { display: flex; gap: 4px; }
.pip { width: 7px; height: 7px; border-radius: 50%; background: #696981; }
.pip[data-done] { background: #aff0c8; box-shadow: 0 0 8px #aff0c890; }
.reaction { color: #dee6f3; }
.reaction[data-urgent] { color: var(--sun); }
.reaction[data-urgent] .reaction-caption { color: inherit; }

.field-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 94px;
  gap: 10px;
}
.stage {
  --scope-radius: 136px;
  position: relative;
  isolation: isolate;
  width: 100%;
  height: min(58vw, 63svh, 625px);
  min-height: 335px;
  overflow: hidden;
  border-radius: 15px;
  border: 1px solid #7d829953;
  user-select: none;
  touch-action: none;
  cursor: grab;
  background: #232b38;
}
.stage[data-dragging] { cursor: grabbing; }
.stage::before {
  position: absolute;
  inset: -18px;
  content: "";
  background: url("./assets/bedroom.jpg") center / cover no-repeat;
  filter: blur(16px) brightness(.35) saturate(.75);
  pointer-events: none;
}
.room {
  position: absolute;
  top: 0;
  left: 0;
  width: 1600px;
  height: 1000px;
  transform-origin: top left;
  background: url("./assets/bedroom.jpg") 0 0 / 100% 100% no-repeat;
  box-shadow: 0 0 65px #171525af;
  will-change: transform;
  pointer-events: none;
}
.targets, .room-effects {
  position: absolute;
  inset: 0;
}

.target {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 150px;
  height: 150px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.target[data-state="stopped"], .target[data-state="hidden"] { visibility: hidden; }
.clock {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 6px 6px #3825368c);
}
.clock[hidden] + .clock-fallback { display: block; }
.clock-fallback {
  display: none;
  position: absolute;
  inset: 10%;
  border: 7px solid #392944;
  border-radius: 50%;
  background: radial-gradient(circle at 45% 37%, #fff4db 0 39%, var(--clock-color) 40%);
  color: #392944;
  font-size: 60px;
  font-weight: 900;
  text-align: center;
  line-height: 1.65;
}
@keyframes shake {
  25% { transform: translateX(-4px) rotate(-8deg); }
  75% { transform: translateX(4px) rotate(8deg); }
}
@keyframes fake-bob { 50% { transform: translateY(-8px) rotate(-3deg); } }
.target[data-state="ringing"] .clock { animation: shake 130ms infinite; }
.target[data-state="hint"] .clock { animation: fake-bob .48s ease-in-out infinite; }
.timer-ring, .cue, .bubble {
  position: absolute;
  display: none;
  pointer-events: none;
}
.timer-ring {
  z-index: 2;
  inset: -8%;
  border-radius: 50%;
  background: conic-gradient(#ffed9c 0 var(--remaining), #332746aa var(--remaining));
  mask-image: radial-gradient(transparent 59%, black 61%, black 68%, transparent 71%);
  filter: drop-shadow(0 0 8px #ffdc73);
}
.target[data-state="ringing"] .timer-ring,
.target[data-state="late"] .timer-ring { display: block; }
.target[data-state="practice"] .timer-ring {
  display: block;
  background: #e8d8ff;
  opacity: .78;
}
.cue, .bubble {
  z-index: 3;
  bottom: 94%;
  left: 50%;
  width: max-content;
  transform: translateX(-50%);
  padding: 9px 17px 10px;
  border: 3px solid;
  border-radius: 17px;
  font-size: var(--bubble-font, 32px);
  font-weight: 870;
  line-height: 1.13;
  box-shadow: 0 5px 0 #251b3e80;
}
.cue {
  border-color: #79492c;
  background: #ffdf91;
  color: #432817;
}
.bubble {
  border-color: #8a71b3;
  background: #eee3ff;
  color: #40295e;
}
.target[data-state="ringing"] .cue,
.target[data-state="late"] .cue,
.target[data-state="hint"] .bubble { display: block; }
.sleeper {
  position: absolute;
  top: 570px;
  left: 1187px;
  font-size: 45px;
  line-height: 1;
  font-weight: 910;
  letter-spacing: .08em;
  color: #ffefdf;
  text-shadow: 0 3px 3px #302036, 0 0 20px #352a42;
  animation: drift 1.8s ease-in-out infinite alternate;
}
.sleeper[data-wake] { color: #ffdf85; animation: none; font-size: 55px; }
@keyframes drift { to { transform: translate(18px, -14px); opacity: .68; } }

.scope, .reticle, .edge-cue, .shot-flash, .overlay {
  position: absolute;
  pointer-events: none;
}
.scope {
  inset: 0;
  z-index: 2;
  background: radial-gradient(ellipse at center, transparent 60%, #1117245c 100%);
}
.stage[data-scoped] .scope {
  background: radial-gradient(circle at center,
    transparent calc(var(--scope-radius) - 2px),
    #b4c2d184 calc(var(--scope-radius) - 1px),
    #0a121cec var(--scope-radius),
    #0a0d17f2 110%);
}
.stage[data-scoped] .scope::after {
  position: absolute;
  inset: 0;
  content: "";
  background:
    repeating-linear-gradient(50deg, #8a8b9c0d 0 1px, transparent 1px 5px),
    repeating-linear-gradient(-40deg, #1d243a1c 0 1px, transparent 1px 4px);
  mask-image: radial-gradient(circle, transparent var(--scope-radius), #000 calc(var(--scope-radius) + 1px));
}
.reticle {
  top: 50%;
  left: 50%;
  z-index: 3;
  width: 54px;
  height: 54px;
  transform: translate(-50%, -50%);
  color: #fff3dd;
  background:
    linear-gradient(currentColor, currentColor) center top / 1px 12px no-repeat,
    linear-gradient(currentColor, currentColor) center bottom / 1px 12px no-repeat,
    linear-gradient(currentColor, currentColor) left center / 12px 1px no-repeat,
    linear-gradient(currentColor, currentColor) right center / 12px 1px no-repeat;
  filter: drop-shadow(0 1px 1px #0d0f1bd0);
}
.reticle-dot {
  position: absolute;
  inset: calc(50% - 2px);
  background: currentColor;
  border-radius: 50%;
}
.stage[data-aligned] .reticle {
  color: #b0ffd7;
  filter: drop-shadow(0 0 4px #44d3a9c9) drop-shadow(0 1px 1px #142331ba);
}
.stage[data-aligned] .reticle-dot {
  inset: calc(50% - 6px);
  border: 2px solid currentColor;
  background: transparent;
}
.edge-cue {
  left: var(--cue-x);
  top: var(--cue-y);
  transform: translate(-50%, -50%);
  width: 42px;
  height: 42px;
  z-index: 4;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid #734629;
  background: #ffdf91;
  color: #432817;
  box-shadow: 0 0 15px #ffcf6cb0;
  font-weight: 900;
}
.edge-cue-arrow {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transform: rotate(var(--cue-angle)) translateX(31px);
  color: #ffdf91;
  font-size: 29px;
  text-shadow: 0 1px 2px #17161d;
}
.edge-cue-icon { font-size: 19px; }
.shot-flash {
  inset: calc(50% - 12px);
  z-index: 3;
  border: 2px solid #fff3d8;
  border-radius: 50%;
  opacity: 0;
}
.shot-flash[data-flash] { animation: shot .21s ease-out both; }
.shot-flash[data-miss] { border-color: #fd9caa; }
@keyframes shot {
  15% { opacity: .95; }
  to { opacity: 0; transform: scale(1.95); }
}
.confetti, .hit-echo {
  position: absolute;
  left: var(--effect-x);
  top: var(--effect-y);
}
.confetti {
  width: 15px;
  height: 23px;
  border-radius: 3px;
  background: var(--piece-color);
  animation: paper .48s cubic-bezier(.15,.65,.4,1) both;
}
@keyframes paper {
  from { opacity: 1; transform: translate(-50%, -50%) rotate(0); }
  to { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--turn)); }
}
.hit-echo {
  width: 150px;
  height: 150px;
  transform: translate(-50%, -50%);
  animation: last-hit .49s ease-out both;
}
@keyframes last-hit {
  25% { filter: blur(1.2px); transform: translate(-50%, -72%) rotate(-8deg) scale(1.1); opacity: 1; }
  57% { filter: blur(1.8px); transform: translate(-50%, -47%) rotate(3deg) scale(.96); opacity: .86; }
  to { filter: blur(6px); transform: translate(-50%, -50%) scale(.92); opacity: 0; }
}

.overlay {
  inset: 0;
  z-index: 5;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: 12px;
  background: #15203662;
  pointer-events: auto;
}
.dialog {
  text-align: center;
  width: min(100%, 350px);
  padding: 17px 17px 19px;
  border: 1px solid #f3edfa73;
  border-radius: 20px;
  background: #1b2337ed;
  box-shadow: 0 8px 38px #11162699;
}
.dialog h2 { margin: 0; font-size: clamp(1.34rem, 3.2vw, 1.95rem); line-height: 1.18; }
.dialog p { margin: 8px 0 12px; color: #e3e5f0; font-size: 1rem; line-height: 1.52; }
.dialog p strong { color: var(--sun); }
.start-button {
  min-height: 43px;
  padding: 8px 16px;
  min-width: min(100%, 174px);
  border: 0;
  border-radius: 11px;
  background: var(--sun);
  color: var(--ink);
  box-shadow: 0 3px 0 #815d3f;
  font-size: 1rem;
  font-weight: 890;
}
.start-button:hover { background: #ffdea3; }

.controls {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}
.zoom-control {
  flex: 1;
  display: grid;
  grid-template-rows: auto minmax(68px, 1fr) auto;
  align-items: center;
  justify-items: center;
  gap: 3px;
  padding: 8px 5px;
  border: 1px solid #8192af4a;
  border-radius: 15px;
  background: #222d44;
}
.zoom-control label { color: var(--muted); font-size: .875rem; font-weight: 780; }
.zoom-control input {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 38px;
  height: 100%;
  min-height: 68px;
  margin: 0;
  accent-color: var(--lilac);
  cursor: ns-resize;
  touch-action: none;
}
.zoom-control input:disabled { cursor: default; opacity: .55; }
.zoom-control output { color: var(--lilac); font-size: .875rem; font-variant-numeric: tabular-nums; font-weight: 850; }
.fire-button {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  min-height: 82px;
  border: 1px solid #ffe5b1;
  border-radius: 14px;
  background: #ffcd79;
  color: #271e32;
  font-weight: 920;
  box-shadow: 0 3px 0 #905d3b;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.fire-button:disabled { border-color: #727f98; background: #4c5870; box-shadow: none; color: #e1e7f2; }
.fire-button:hover:not(:disabled) { background: #ffe0a4; }
.fire-button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #905d3b; }
.fire-mark {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid currentColor;
  background: radial-gradient(circle, currentColor 0 2px, transparent 3px);
}
.status {
  min-height: 38px;
  margin: 0;
  display: flex;
  align-items: center;
  padding: 6px;
  color: #d7deeb;
  font-size: .875rem;
  line-height: 1.4;
}

@media (max-width: 640px) {
  .game { width: calc(100% - 22px); padding-top: max(15px, env(safe-area-inset-top)); }
  .masthead { margin-bottom: 10px; }
  .masthead-controls { display: grid; justify-items: end; gap: 4px; }
  #audio-label { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); }
  .mission { padding: 7px 7px 0; border-radius: 17px; }
  .mission-bar { margin: 0 2px 5px; min-height: 30px; }
  .progress, .reaction { gap: 5px; }
  .stage { min-height: 245px; height: min(85vw, 50svh); border-radius: 12px; }
  .status { padding-inline: 3px; }
}
@media (max-width: 640px) and (orientation: portrait) {
  .masthead { align-items: center; gap: 7px; }
  .orientation-hint { display: block; grid-column: 1 / -1; font-size: .77rem; }
  .field-controls { grid-template-columns: 1fr; gap: 7px; }
  .controls { flex-direction: row; justify-content: flex-end; gap: 8px; }
  .zoom-control {
    flex: 0 0 104px;
    grid-template: auto auto / 1fr 38px;
    min-height: 83px;
    padding: 3px 7px;
  }
  .zoom-control label { grid-area: 1 / 1; align-self: end; }
  .zoom-control output { grid-area: 2 / 1; align-self: start; }
  .zoom-control input { grid-area: 1 / 2 / 3; height: 68px; }
  .fire-button { min-width: 103px; }
}
@media (max-width: 355px) {
  .pips { display: none; }
  .orientation-hint { max-width: 6em; }
}
@media (max-height: 530px) and (orientation: landscape) {
  .game {
    width: min(calc(100% - max(13px, env(safe-area-inset-left)) - max(13px, env(safe-area-inset-right))), 920px);
    padding: max(7px, env(safe-area-inset-top)) 0 max(5px, env(safe-area-inset-bottom));
  }
  .masthead { margin-bottom: 6px; }
  .setting { font-size: .8rem; margin-bottom: 2px; }
  h1 { font-size: 1.4rem; }
  .mission { padding: 6px 6px 0; }
  .mission-bar { min-height: 27px; margin-bottom: 4px; }
  .stage { min-height: 174px; height: max(174px, calc(100svh - 139px - env(safe-area-inset-bottom))); }
  .status { min-height: 29px; padding: 4px; }
  .controls { gap: 7px; }
  .zoom-control { padding: 4px; }
  .fire-button { min-height: 68px; }
}
@media (prefers-reduced-motion: reduce) {
  .target[data-state="ringing"] .clock,
  .target[data-state="hint"] .clock,
  .sleeper { animation: none; }
  .confetti, .hit-echo { animation-duration: 130ms; }
}
