: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(420px, calc(100vw - 44px), calc(100vh - 328px));
  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: hidden;
  color: var(--ink);
  background: var(--paper);
  font-size: 16px;
  line-height: 1.55;
  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: 46px;
  padding: 8px 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: 10px 0 48px;
}

.mode-intro {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 2px 0 10px;
  border-bottom: 1px solid var(--line);
}

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

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

h1 {
  margin: 0;
  font-size: 38px;
  line-height: 1.08;
  letter-spacing: 0;
}

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

.daily-brief {
  flex: none;
  min-width: 220px;
  padding: 8px 12px;
  display: grid;
  grid-template-columns: auto auto;
  gap: 0 12px;
  background: #eef4f0;
  border-left: 4px solid var(--gold);
}

.daily-brief strong,
.daily-brief time {
  font-size: 0.83rem;
}

.daily-brief time {
  color: var(--green);
  font-weight: 900;
}

.daily-brief span {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.72rem;
}

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

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

.secondary-button {
  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 1px 0 #07573d;
}

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

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

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

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

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

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

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

.status-actions {
  flex: none;
}

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

.status-metrics > div {
  position: relative;
  min-width: 0;
  min-height: 27px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding-top: 3px;
  border-top: 1px solid #365148;
}

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

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

.timer-metric span {
  color: #a8c1b6;
  font-size: 0.54rem;
  font-weight: 800;
}

.timer-metric.is-danger {
  background: #3c1a18;
  border-top-color: #ff8e78;
}

.timer-metric.is-danger dt,
.timer-metric.is-danger span,
.timer-metric.is-danger dd {
  color: #ffb1a5;
}

#timer-value.is-gain {
  animation: timer-gain 380ms ease-out;
}

#timer-value.is-combo {
  animation: timer-combo 420ms ease-out;
}

#timer-value.is-loss {
  animation: timer-loss 380ms ease-out;
}

.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: #0d211a;
  box-shadow: inset 0 0 0 1px #101a17, 0 7px 18px 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.38);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

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

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

.ring-defense {
  width: 30%;
  height: 30%;
  border: 2px solid rgba(243, 198, 78, 0.9);
  box-shadow: 0 0 10px rgba(243, 198, 78, 0.25);
}

.radar-axis {
  z-index: 0;
  top: 50%;
  left: 50%;
  width: 92%;
  height: 1px;
  background: rgba(77, 225, 164, 0.24);
  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: 1;
  inset: 5%;
  border-radius: 50%;
}

.radar-sweep::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48%;
  height: 2px;
  background: rgba(77, 225, 164, 0.46);
  transform-origin: left center;
  animation: sweep 5s linear infinite;
}

.target-layer,
.effect-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.target-layer {
  z-index: 4;
  overflow: clip;
}

.effect-layer {
  z-index: 7;
  overflow: visible;
}

.target-card {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 74px;
  min-height: 27px;
  padding: 3px 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #102119;
  background: #f9fff9;
  border: 2px solid var(--green-bright);
  border-radius: 6px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.34);
  font-size: 13.5px;
  font-weight: 900;
  line-height: 1.15;
  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-danger {
  color: #4a1714;
  background: #fff2ef;
  border-color: #ff8e78;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.34), 0 0 0 2px rgba(217, 74, 74, 0.25);
}

.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.7);
  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.76);
  transition: opacity 220ms ease, transform 220ms ease;
}

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

.defense-core span {
  font-size: 11px;
  font-weight: 900;
}

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

.stage-flash {
  z-index: 6;
  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;
}

.time-pop {
  position: absolute;
  min-width: 72px;
  padding: 3px 6px;
  color: #102119;
  background: #effff6;
  border: 1px solid var(--green-bright);
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  animation: time-pop 680ms ease-out both;
}

.time-pop.is-danger {
  color: #4a1714;
  background: #fff2ef;
  border-color: #ff8e78;
}

.time-pop.is-combo {
  color: #30240a;
  background: #fff7d8;
  border-color: var(--gold);
}

.time-pop.is-impact {
  color: #ffffff;
  background: var(--coral);
  border-color: #ffb1a5;
}

.time-pop.is-max {
  color: #102119;
  background: #ffffff;
  border-color: #7a8b82;
}

.time-beam {
  position: absolute;
  height: 3px;
  background: var(--green-bright);
  box-shadow: 0 0 8px rgba(77, 225, 164, 0.8);
  transform-origin: left center;
  animation: time-beam 400ms ease-out both;
}

.time-beam.is-danger {
  background: #ff8e78;
  box-shadow: 0 0 8px rgba(255, 142, 120, 0.8);
}

.time-beam.is-combo {
  background: #f3c64e;
  box-shadow: 0 0 8px rgba(243, 198, 78, 0.8);
}

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

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

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

#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.72rem;
  font-weight: 800;
}

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

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

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

.result-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

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

.result-date {
  display: grid;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: right;
}

.result-date time {
  color: var(--green);
  font-size: 0.88rem;
  font-weight: 900;
}

.result-grid {
  margin: 12px 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

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

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

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

#result-summary {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.result-panel .primary-button {
  min-width: 180px;
}

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

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

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

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

.related-links a {
  min-width: 0;
  padding: 11px;
  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.7rem;
}

.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: 7px;
}

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

body.is-result #game-shell {
  display: none;
}

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

body[data-outcome="defense-held"] .result-panel {
  border-color: var(--gold);
}

@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 34px 8px rgba(77, 225, 164, 0.32); }
  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 40px 10px rgba(217, 74, 74, 0.44); }
  100% { opacity: 0; box-shadow: inset 0 0 0 0 rgba(217, 74, 74, 0); }
}

@keyframes time-pop {
  0% { opacity: 0; transform: translate(-50%, -35%); }
  20% { opacity: 1; transform: translate(-50%, -60%); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -115%); }
}

@keyframes time-beam {
  0% { opacity: 0; scale: 0 1; }
  35% { opacity: 1; }
  100% { opacity: 0; scale: 1 1; }
}

@keyframes timer-gain {
  45% { color: var(--green-bright); transform: scale(1.2); }
}

@keyframes timer-combo {
  45% { color: #f3c64e; transform: scale(1.24); }
}

@keyframes timer-loss {
  45% { color: #ff8e78; transform: scale(1.2); }
}

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

  .app-shell {
    padding-top: 7px;
  }

  .mode-intro {
    min-height: 72px;
    padding-bottom: 7px;
  }

  .status-panel,
  .input-panel {
    padding-top: 5px;
    padding-bottom: 5px;
  }
}

@media (max-width: 640px) {
  :root {
    --stage-size: min(346px, calc(100vw - 44px), calc(100vh - 356px));
  }

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

  .site-header p {
    display: none;
  }

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

  .mode-intro {
    min-height: 82px;
    gap: 10px;
    padding-bottom: 7px;
  }

  h1 {
    font-size: 30px;
  }

  h1 small {
    margin-top: 2px;
    font-size: 13px;
  }

  .daily-brief {
    min-width: 112px;
    padding: 5px 7px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
  }

  .daily-brief span {
    display: none;
  }

  .daily-brief strong,
  .daily-brief time {
    font-size: 0.7rem;
  }

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

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

  .status-head {
    min-height: 34px;
    align-items: center;
  }

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

  #status-code {
    font-size: 0.64rem;
  }

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

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

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

  .status-metrics > div {
    min-height: 25px;
    display: grid;
    gap: 0;
    padding-top: 2px;
  }

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

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

  .timer-metric span {
    display: none;
  }

  .target-card {
    max-width: 68px;
    min-height: 25px;
    padding: 2px 4px;
    font-size: 12.5px;
  }

  .time-pop {
    min-width: 64px;
    font-size: 0.64rem;
  }

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

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

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

  #typing-input {
    min-height: 43px;
    padding: 6px 9px;
    font-size: 0.94rem;
  }

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

  .mode-safety-note {
    display: none;
  }

  .result-panel {
    margin-top: 6px;
    padding: 13px;
  }

  .result-panel h2 {
    font-size: 1.3rem;
  }

  .result-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin: 9px 0;
  }

  .result-grid div {
    min-height: 54px;
    padding: 6px;
  }

  .result-grid dt {
    font-size: 0.62rem;
  }

  .result-grid dd {
    font-size: 1rem;
  }

  #result-summary {
    font-size: 0.8rem;
  }

  .result-panel .primary-button {
    width: 100%;
    min-width: 0;
  }

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

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

  .radar-sweep::before,
  .time-beam {
    animation: none !important;
  }

  .time-beam {
    display: none;
  }

  .target-card,
  .stage-flash,
  .time-pop,
  #timer-value {
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
  }

  .time-pop {
    opacity: 1;
    animation: none !important;
  }
}
