:root {
  color-scheme: light;
  --ink: #17211d;
  --muted: #5b6862;
  --paper: #f4f6f2;
  --panel: #ffffff;
  --line: #aab8b1;
  --deep: #13221d;
  --green: #0a7d55;
  --green-bright: #4de1a4;
  --gold: #d7a42c;
  --coral: #d94a4a;
  --cyan: #208ea2;
  --stage-size: min(430px, calc(100vw - 40px), calc(100vh - 270px));
  font-family: "Yu Gothic UI", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
  scroll-behavior: auto;
}

body {
  min-width: 320px;
  margin: 0;
  overflow-x: clip;
  color: var(--ink);
  background: var(--paper);
  font-size: 16px;
  line-height: 1.6;
  letter-spacing: 0;
}

button,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
textarea:focus-visible {
  outline: 3px solid #f0b836;
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.site-header {
  min-height: 48px;
  padding: 9px max(18px, calc((100vw - 1100px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: #f6fbf8;
  background: var(--deep);
  border-bottom: 4px solid var(--green-bright);
}

.site-header .brand {
  color: inherit;
  font-weight: 800;
  text-decoration: none;
}

.site-header p {
  margin: 0;
  color: #b7d6c9;
  font-size: 0.78rem;
  font-weight: 700;
}

.app-shell {
  width: min(1100px, calc(100% - 36px));
  margin: 0 auto;
  padding: 18px 0 52px;
}

.mode-intro {
  min-height: 138px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: 4px 0 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1.15;
  letter-spacing: 0;
}

h1 small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.42em;
  font-weight: 700;
}

.lead {
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.start-controls {
  width: min(290px, 100%);
  display: grid;
  gap: 8px;
  justify-items: stretch;
}

.start-controls p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.primary-button,
.secondary-button {
  min-height: 46px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 900;
}

.primary-button {
  color: #ffffff;
  background: var(--green);
  box-shadow: 0 4px 0 #07573d;
}

.secondary-button {
  min-height: 38px;
  padding: 7px 13px;
  color: var(--deep);
  background: #dce8e2;
  border: 1px solid #91aa9e;
}

.primary-button:hover,
.secondary-button:hover {
  filter: brightness(1.05);
}

.primary-button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #07573d;
}

button:disabled {
  cursor: default;
  opacity: 0.52;
}

.game-shell {
  display: grid;
  gap: 10px;
  padding-top: 14px;
}

.status-panel {
  padding: 10px 12px;
  color: #f4faf6;
  background: var(--deep);
  border-left: 6px solid var(--green-bright);
}

.status-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-head > div {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

#status-code {
  flex: none;
  color: var(--green-bright);
  font-size: 0.78rem;
  font-weight: 900;
}

#status-message {
  min-width: 0;
  font-size: 0.96rem;
}

.status-metrics {
  margin: 8px 0 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.status-metrics div {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding-top: 5px;
  border-top: 1px solid #365148;
}

.status-metrics dt {
  color: #a8c1b6;
  font-size: 0.66rem;
  font-weight: 800;
}

.status-metrics dd {
  min-width: 0;
  margin: 0;
  color: #ffffff;
  font-size: 0.86rem;
  font-weight: 900;
  white-space: nowrap;
}

#shield-count {
  color: #f3c64e;
}

.stage-wrap {
  min-width: 0;
  display: grid;
  place-items: center;
}

.intercept-stage {
  position: relative;
  width: var(--stage-size);
  height: var(--stage-size);
  isolation: isolate;
  overflow: visible;
  border: 3px solid #45675b;
  border-radius: 50%;
  background-color: #0d211a;
  background-image:
    radial-gradient(circle at center, rgba(77, 225, 164, 0.12) 0 2px, transparent 3px),
    radial-gradient(circle at center, transparent 0 61%, rgba(77, 225, 164, 0.05) 62% 63%, transparent 64%);
  box-shadow: inset 0 0 0 1px #101a17, 0 8px 24px rgba(20, 39, 32, 0.15);
}

.radar-ring,
.radar-axis,
.radar-sweep,
.stage-flash {
  position: absolute;
  pointer-events: none;
}

.radar-ring {
  z-index: 0;
  top: 50%;
  left: 50%;
  border: 1px solid rgba(77, 225, 164, 0.34);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.ring-outer {
  width: 76%;
  height: 76%;
}

.ring-middle {
  width: 54%;
  height: 54%;
}

.ring-defense {
  width: 32%;
  height: 32%;
  border: 2px solid rgba(243, 198, 78, 0.88);
  box-shadow: 0 0 12px rgba(243, 198, 78, 0.28);
}

.radar-axis {
  z-index: 0;
  top: 50%;
  left: 50%;
  width: 92%;
  height: 1px;
  background: rgba(77, 225, 164, 0.22);
  transform-origin: center;
}

.axis-horizontal {
  transform: translate(-50%, -50%);
}

.axis-vertical {
  transform: translate(-50%, -50%) rotate(90deg);
}

.axis-diagonal-a {
  transform: translate(-50%, -50%) rotate(45deg);
}

.axis-diagonal-b {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.radar-sweep {
  z-index: 0;
  inset: 4%;
  border-radius: 50%;
  overflow: clip;
}

.radar-sweep::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 82%, rgba(77, 225, 164, 0.18) 96%, rgba(77, 225, 164, 0.58) 100%);
  animation: sweep 5s linear infinite;
}

.target-layer {
  position: absolute;
  z-index: 4;
  inset: 0;
  pointer-events: none;
}

.target-card {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 112px;
  min-height: 34px;
  padding: 5px 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #102119;
  background: #f9fff9;
  border: 2px solid var(--green-bright);
  border-radius: 7px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.34), 0 0 12px rgba(77, 225, 164, 0.22);
  font-size: 0.96rem;
  font-weight: 900;
  line-height: 1.2;
  white-space: nowrap;
  transform: translate(calc(var(--target-x, 0px) - 50%), calc(var(--target-y, 0px) - 50%));
  transform-origin: center;
  will-change: opacity, transform;
}

.target-card.is-intercepted {
  opacity: 0;
  color: #ffffff;
  background: var(--green);
  transform: translate(calc(var(--target-x, 0px) - 50%), calc(var(--target-y, 0px) - 50%)) scale(0.72);
  transition: opacity 180ms ease, transform 180ms ease;
}

.target-card.is-impact {
  opacity: 0;
  color: #ffffff;
  background: var(--coral);
  border-color: #ff8e78;
  transform: translate(calc(var(--target-x, 0px) - 50%), calc(var(--target-y, 0px) - 50%)) scale(0.78);
  transition: opacity 220ms ease, transform 220ms ease;
}

.defense-core {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: 20%;
  height: 20%;
  display: grid;
  place-items: center;
  color: #ffe38d;
  background: #17372c;
  border: 2px solid #d7a42c;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.defense-core span {
  font-size: clamp(0.54rem, 1.5vw, 0.72rem);
  font-weight: 900;
}

.stage-guide {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 9%;
  width: 78%;
  margin: 0;
  padding: 5px 8px;
  color: #dff6ea;
  background: rgba(9, 28, 21, 0.88);
  border: 1px solid #426c5c;
  border-radius: 5px;
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
  transform: translateX(-50%);
}

.stage-flash {
  z-index: 5;
  inset: 0;
  border-radius: 50%;
  opacity: 0;
}

.stage-flash.is-hit {
  animation: intercept-flash 260ms ease-out;
}

.stage-flash.is-impact {
  animation: impact-flash 340ms ease-out;
}

.input-panel {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(170px, 0.9fr) minmax(0, 2fr);
  gap: 6px 14px;
  align-items: center;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.input-panel label {
  grid-column: 1;
  grid-row: 1;
  font-size: 0.8rem;
  font-weight: 900;
}

#typing-input {
  grid-column: 2;
  grid-row: 1 / span 2;
  width: 100%;
  min-width: 0;
  min-height: 56px;
  max-height: 76px;
  padding: 11px 12px;
  resize: none;
  color: var(--ink);
  background: #fbfdfb;
  border: 2px solid #6c8a7c;
  border-radius: 6px;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.35;
}

#typing-input:disabled {
  color: #748079;
  background: #e8ece9;
}

.input-feedback {
  grid-column: 1;
  grid-row: 2;
  min-width: 0;
}

.input-feedback p {
  margin: 0;
}

#input-note {
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
}

#input-note[data-tone="miss"],
#input-note[data-tone="impact"] {
  color: var(--coral);
}

.mode-safety-note {
  margin-top: 3px !important;
  color: var(--muted);
  font-size: 0.67rem;
}

.result-panel {
  margin-top: 18px;
  padding: 20px;
  background: var(--panel);
  border: 2px solid var(--green);
}

.result-panel h2 {
  margin: 0;
  font-size: 1.55rem;
}

.result-grid {
  margin: 16px 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.result-grid div {
  min-width: 0;
  padding: 10px;
  border-left: 4px solid var(--gold);
  background: #f1f5f2;
}

.result-grid dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.result-grid dd {
  margin: 2px 0 0;
  font-size: 1.35rem;
  font-weight: 900;
}

#result-summary {
  margin: 0 0 14px;
  color: var(--muted);
}

.how-to,
.related-modes {
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.how-to h2,
.related-modes h2 {
  margin: 0 0 10px;
  font-size: 1.22rem;
}

.how-to p:not(.eyebrow) {
  margin: 6px 0;
  color: #435048;
}

.related-links {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.related-links a {
  min-width: 0;
  padding: 12px;
  display: grid;
  color: var(--ink);
  text-decoration: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.related-links strong,
.related-links small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.related-links small {
  color: var(--muted);
  font-size: 0.72rem;
}

.mode-list-link {
  margin-top: 12px;
  display: inline-block;
  color: var(--green);
  font-weight: 800;
}

.site-footer {
  padding: 22px 18px;
  color: #dce8e2;
  background: var(--deep);
}

.site-footer nav {
  width: min(1100px, 100%);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
}

.site-footer a {
  color: inherit;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

body.is-active .mode-intro,
body.is-result .mode-intro {
  display: none;
}

body.is-active,
body.is-result {
  overflow-anchor: none;
}

body.is-active .app-shell,
body.is-result .app-shell {
  padding-top: 8px;
}

body.is-active .site-header,
body.is-result .site-header {
  min-height: 42px;
  padding-top: 6px;
  padding-bottom: 6px;
}

body[data-outcome="defense-down"] .status-panel {
  border-left-color: var(--coral);
}

body[data-outcome="defense-down"] #status-code {
  color: #ff9b8d;
}

@keyframes sweep {
  to { transform: rotate(360deg); }
}

@keyframes intercept-flash {
  0% { opacity: 0; box-shadow: inset 0 0 0 0 rgba(77, 225, 164, 0); }
  45% { opacity: 1; box-shadow: inset 0 0 36px 8px rgba(77, 225, 164, 0.34); }
  100% { opacity: 0; box-shadow: inset 0 0 0 0 rgba(77, 225, 164, 0); }
}

@keyframes impact-flash {
  0% { opacity: 0; box-shadow: inset 0 0 0 0 rgba(217, 74, 74, 0); }
  40% { opacity: 1; box-shadow: inset 0 0 42px 11px rgba(217, 74, 74, 0.46); }
  100% { opacity: 0; box-shadow: inset 0 0 0 0 rgba(217, 74, 74, 0); }
}

@media (min-width: 641px) and (max-height: 760px) {
  :root {
    --stage-size: min(400px, calc(100vw - 40px), calc(100vh - 300px));
  }

  .game-shell {
    gap: 7px;
  }

  .status-panel {
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .status-metrics {
    margin-top: 5px;
  }

  .input-panel {
    padding-top: 7px;
    padding-bottom: 7px;
  }
}

@media (max-width: 640px) {
  :root {
    --stage-size: min(430px, calc(100vw - 36px), calc(100vh - 310px));
  }

  .site-header {
    min-height: 44px;
    padding: 7px 18px;
  }

  .site-header p {
    display: none;
  }

  .app-shell {
    width: calc(100% - 28px);
    padding-top: 12px;
  }

  .mode-intro {
    min-height: 0;
    grid-template-columns: 1fr;
    gap: 14px;
    padding-bottom: 14px;
  }

  h1 {
    font-size: 1.78rem;
  }

  .lead {
    font-size: 0.88rem;
  }

  .start-controls {
    width: 100%;
  }

  .game-shell {
    gap: 7px;
    padding-top: 8px;
  }

  .status-panel {
    padding: 7px 8px;
    border-left-width: 4px;
  }

  .status-head {
    align-items: flex-start;
  }

  .status-head > div {
    display: grid;
    gap: 0;
  }

  #status-message {
    font-size: 0.82rem;
  }

  .secondary-button {
    min-height: 34px;
    padding: 5px 9px;
    font-size: 0.75rem;
  }

  .status-metrics {
    margin-top: 5px;
    gap: 5px;
  }

  .status-metrics div {
    display: grid;
    gap: 0;
    padding-top: 3px;
  }

  .status-metrics dt {
    font-size: 0.55rem;
  }

  .status-metrics dd {
    font-size: 0.74rem;
  }

  .target-card {
    max-width: 96px;
    min-height: 31px;
    padding: 4px 7px;
    font-size: 0.86rem;
  }

  .input-panel {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 7px 8px;
  }

  .input-panel label,
  #typing-input,
  .input-feedback {
    grid-column: 1;
    grid-row: auto;
  }

  .input-panel label {
    font-size: 0.7rem;
  }

  #typing-input {
    min-height: 48px;
    padding: 8px 10px;
    font-size: 1rem;
  }

  .input-feedback {
    display: grid;
    grid-template-columns: 1fr;
  }

  #input-note {
    font-size: 0.7rem;
  }

  .mode-safety-note {
    font-size: 0.58rem;
  }

  .result-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .related-links {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }

  .radar-sweep::before {
    animation: none;
    opacity: 0.32;
  }

  .target-card,
  .stage-flash {
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
  }
}
