: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-height: min(390px, calc(100vh - 278px));
  --lane-count: 3;
  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:
    linear-gradient(#edf2ee 1px, transparent 1px) 0 0 / 100% 42px,
    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: 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(310px, 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 {
  padding: 9px 18px;
  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: 8px;
  padding-top: 12px;
}

.status-panel {
  padding: 8px 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.92rem;
}

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

.status-metrics div {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding-top: 4px;
  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.82rem;
  font-weight: 900;
  white-space: nowrap;
}

#danger-count {
  color: #f3c64e;
}

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

.avalanche-stage {
  position: relative;
  width: min(720px, 100%);
  height: max(270px, var(--stage-height));
  isolation: isolate;
  overflow: hidden;
  border: 3px solid #45675b;
  border-radius: 7px;
  background:
    linear-gradient(180deg, rgba(32, 142, 162, 0.11), transparent 42%),
    linear-gradient(90deg, rgba(77, 225, 164, 0.04), rgba(255, 255, 255, 0.02)),
    #0d211a;
  box-shadow: inset 0 0 0 1px #101a17, 0 8px 24px rgba(20, 39, 32, 0.15);
}

.lane-layer,
.block-layer,
.stage-flash {
  position: absolute;
  inset: 0;
}

.lane-layer {
  z-index: 0;
  padding: 0 8px 12px;
  display: grid;
  grid-template-columns: repeat(var(--lane-count), minmax(0, 1fr));
  gap: 6px;
}

.lane {
  position: relative;
  min-width: 0;
  border-right: 1px solid rgba(77, 225, 164, 0.2);
  border-left: 1px solid rgba(77, 225, 164, 0.2);
  background: rgba(255, 255, 255, 0.018);
}

.lane::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 6px;
  background: #d7a42c;
  box-shadow: 0 -3px 0 rgba(215, 164, 44, 0.2);
}

.danger-line {
  position: absolute;
  z-index: 1;
  top: 64%;
  right: 0;
  left: 0;
  height: 0;
  border-top: 2px dashed #ff8e78;
  pointer-events: none;
}

.danger-line span {
  position: absolute;
  top: -24px;
  right: 8px;
  padding: 1px 5px;
  color: #ffffff;
  background: #b83333;
  border-radius: 3px;
  font-size: 0.6rem;
  font-weight: 900;
}

.block-layer {
  z-index: 3;
  pointer-events: none;
}

.word-block {
  position: absolute;
  top: 0;
  left: var(--block-x, 0);
  width: var(--block-width, 80px);
  height: 42px;
  padding: 5px 5px 4px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: #102119;
  background: #f9fff9;
  border: 2px solid var(--green-bright);
  border-radius: 6px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.36);
  font-size: 0.96rem;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  transform: translate3d(0, var(--block-y, -48px), 0);
  transition: transform 210ms cubic-bezier(0.22, 0.8, 0.3, 1);
  will-change: transform;
}

.word-block.is-falling {
  border-color: #8beac3;
  background: #ffffff;
  transition: none;
}

.word-block.is-crushed {
  opacity: 0;
  color: #ffffff;
  background: var(--green);
  transform: translate3d(0, var(--block-y, 0), 0) scale(0.75);
  transition: opacity 170ms ease, transform 170ms ease;
}

.word-block.is-cascading {
  border-color: #f3c64e;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.36), 0 0 0 2px rgba(243, 198, 78, 0.22);
}

.stage-guide {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 42%;
  width: min(420px, calc(100% - 32px));
  margin: 0;
  padding: 8px 10px;
  color: #dff6ea;
  background: rgba(9, 28, 21, 0.9);
  border: 1px solid #426c5c;
  border-radius: 5px;
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
  transform: translate(-50%, -50%);
}

.stage-flash {
  z-index: 6;
  opacity: 0;
  pointer-events: none;
}

.stage-flash.is-crushed {
  animation: crush-flash 260ms ease-out;
}

.stage-flash.is-buried {
  animation: buried-flash 500ms ease-out forwards;
}

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

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

#typing-input {
  grid-column: 2;
  grid-row: 1 / span 2;
  width: 100%;
  min-width: 0;
  min-height: 54px;
  max-height: 70px;
  padding: 10px 12px;
  resize: none;
  color: var(--ink);
  background: #fbfdfb;
  border: 2px solid #6c8a7c;
  border-radius: 6px;
  font-size: 1.04rem;
  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.74rem;
  font-weight: 800;
}

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

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

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

.result-panel.is-highlighted {
  box-shadow: 0 0 0 5px rgba(77, 225, 164, 0.18);
}

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

.result-grid {
  margin: 16px 0;
  display: grid;
  grid-template-columns: repeat(3, 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: 7px;
}

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

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

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

@keyframes crush-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.3); }
  100% { opacity: 0; box-shadow: inset 0 0 0 0 rgba(77, 225, 164, 0); }
}

@keyframes buried-flash {
  0% { opacity: 0; box-shadow: inset 0 0 0 0 rgba(217, 74, 74, 0); }
  50% { opacity: 1; box-shadow: inset 0 0 50px 16px rgba(217, 74, 74, 0.48); }
  100% { opacity: 0.28; box-shadow: inset 0 0 28px 8px rgba(217, 74, 74, 0.24); }
}

@media (min-width: 641px) and (max-height: 760px) {
  :root {
    --stage-height: min(360px, calc(100vh - 278px));
  }
}

@media (max-width: 640px) {
  :root {
    --stage-height: min(350px, calc(100vh - 320px));
  }

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

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

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

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

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

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

  .secondary-button {
    min-height: 32px;
    padding: 4px 8px;
    font-size: 0.7rem;
  }

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

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

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

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

  .avalanche-stage {
    min-height: 270px;
  }

  .lane-layer {
    padding-right: 5px;
    padding-left: 5px;
    gap: 3px;
  }

  .word-block {
    padding-right: 2px;
    padding-left: 2px;
    font-size: 0.78rem;
  }

  .danger-line span {
    right: 4px;
    font-size: 0.52rem;
  }

  .input-panel {
    grid-template-columns: 1fr;
    gap: 3px;
    padding: 6px 7px 16px;
  }

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

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

  #typing-input {
    min-height: 46px;
    padding: 7px 9px;
    font-size: 0.96rem;
  }

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

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

  .result-grid {
    grid-template-columns: 1fr;
  }

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

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

  .word-block {
    transition-duration: 1ms;
  }

  .word-block.is-falling {
    transition: none;
  }

  .stage-flash {
    animation-duration: 1ms !important;
  }
}
