*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f5f5f7;
  --bg-card: #ffffff;
  --border: #d2d2d7;
  --text: #1d1d1f;
  --text-muted: #6e6e73;
  --accent: #0071e3;
  --accent-soft: #e8f1fc;
  --success: #34c759;
  --danger: #ff3b30;
  --fill: #f2f2f7;
  --radius: 18px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}

html,
body {
  min-height: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.background {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--bg);
}

.screen {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 1.5rem clamp(1rem, 3vw, 2.5rem) 1.75rem;
}

.hidden {
  display: none !important;
}

.menu-card {
  margin: auto;
  width: min(720px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: clamp(1.75rem, 4vw, 2.75rem);
}

.brand-mark {
  color: var(--text-muted);
  letter-spacing: 0.02em;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 0.45rem;
}

.brand-mark-play {
  margin-bottom: 0.7rem;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.1rem);
  font-weight: 650;
  letter-spacing: -0.035em;
  line-height: 1.08;
}

.lede {
  margin-top: 0.7rem;
  color: var(--text-muted);
  font-size: 1.1rem;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin: 1.7rem 0 1.35rem;
}

.mode-btn,
.btn-primary,
.btn-ghost {
  font: inherit;
  cursor: pointer;
  border-radius: 16px;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.mode-btn {
  text-align: left;
  padding: 1.15rem 1.15rem;
  background: var(--fill);
  border: 1px solid transparent;
  color: var(--text);
}

.mode-btn:hover,
.mode-btn:focus-visible {
  background: var(--accent-soft);
  border-color: var(--accent);
  outline: none;
}

.mode-name {
  display: block;
  font-size: 1.3rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin-bottom: 0.3rem;
}

.mode-copy {
  display: block;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.bests {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
}

.bests div,
.recap-stats div {
  background: var(--fill);
  border-radius: 14px;
  padding: 0.8rem 0.75rem;
}

.best-label {
  display: block;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.bests strong {
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}

.menu-hint {
  margin-top: 1.1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem 1.5rem;
}

.hud-block {
  min-width: 4.5rem;
}

.hud-label {
  display: block;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.hud-block strong {
  font-size: 1.45rem;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.hud-sub {
  display: block;
  color: var(--accent);
  font-size: 0.84rem;
  font-weight: 500;
}

.hud-actions {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.stage-panel {
  margin: 0.85rem 0 0.4rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-card);
}

.stage-panel-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  margin-bottom: 0.7rem;
}

.stage-now {
  font-size: 1rem;
}

.stage-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.7rem;
  margin-left: auto;
}

.switch-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 999px;
  padding: 0.35rem 0.8rem 0.35rem 0.4rem;
  font: inherit;
  cursor: pointer;
}

.switch-btn.on {
  border-color: #b7ebc6;
  background: #f2fff6;
}

.switch-track {
  position: relative;
  width: 46px;
  height: 28px;
  border-radius: 999px;
  background: #e5e5ea;
  flex-shrink: 0;
}

.switch-btn.on .switch-track {
  background: var(--success);
}

.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  transition: transform 0.2s ease;
}

.switch-btn.on .switch-knob {
  transform: translateX(18px);
}

.switch-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
}

.switch-copy strong {
  font-size: 0.9rem;
  font-weight: 600;
}

.switch-state {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.switch-btn.on .switch-state {
  color: #248a3d;
}

.btn-next {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: none;
  background: var(--accent);
  color: #ffffff;
  border-radius: 999px;
  padding: 0.5rem 0.95rem 0.5rem 0.55rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn-next-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  font-size: 1.15rem;
  line-height: 1;
}

.btn-next:hover,
.btn-next:focus-visible {
  background: #0077ed;
  outline: none;
}

.btn-next:disabled {
  opacity: 0.35;
  cursor: default;
}

.stage-groups {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
}

.stage-group {
  min-width: 0;
}

.stage-group-name {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.stage-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.stage-pill {
  border: none;
  background: var(--fill);
  color: var(--text);
  border-radius: 999px;
  padding: 0.32rem 0.65rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.stage-pill:hover,
.stage-pill:focus-visible {
  background: #e5e5ea;
  outline: none;
}

.stage-pill.current {
  background: var(--text);
  color: #ffffff;
}

.playfield.struck {
  outline: 2px solid var(--danger);
  animation: strike-shake 0.4s ease-in-out 2;
}

.screen.ending .playfield {
  background: #fff5f5;
}

@keyframes strike-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

.target.dropped .target-word {
  color: var(--danger);
}

.strike-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: rgba(255, 255, 255, 0.92);
  z-index: 5;
}

.strike-word {
  font-size: clamp(2.6rem, 8vw, 4.6rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--danger);
}

.strike-sub {
  color: var(--text-muted);
  font-size: 1.05rem;
}

.recap-dramatic {
  border-color: #f5c2c0;
}

.strike-mark {
  color: var(--danger);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-warm {
  background: #fff1f0;
  color: var(--danger);
}

.btn-primary,
.btn-ghost {
  border: 1px solid transparent;
  padding: 0.7rem 1.15rem;
  font-weight: 600;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover,
.btn-primary:focus-visible {
  background: #0077ed;
  outline: none;
}

.btn-ghost {
  background: var(--fill);
  color: var(--text);
}

.btn-ghost:hover,
.btn-ghost:focus-visible {
  background: #e8e8ed;
  outline: none;
}

.prompt {
  font-size: clamp(1.45rem, 3vw, 2rem);
  font-weight: 650;
  letter-spacing: -0.03em;
  margin: 0.75rem 0 0.1rem;
}

.wave-progress {
  color: var(--text-muted);
  margin-bottom: 0.7rem;
}

.playfield {
  position: relative;
  flex: 1;
  min-height: 220px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: #ffffff;
  overflow: hidden;
}

.playfield.wrong {
  outline: 2px solid var(--danger);
}

.playfield.lanes .danger-line {
  top: 8%;
  bottom: 8%;
  left: auto;
  right: 7%;
  width: 2px;
  height: auto;
}

.danger-line {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 8%;
  height: 2px;
  background: var(--danger);
  opacity: 0.7;
}

.target {
  position: absolute;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  user-select: none;
}

.target-word {
  font-size: clamp(5.2rem, 16vw, 9.2rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--text);
}

.target-word .typed {
  color: var(--accent);
}

.target-word .next {
  color: var(--text);
  border-bottom: 6px solid var(--accent);
}

.target-word .rest {
  color: #a1a1a6;
}

.banner {
  position: absolute;
  left: 50%;
  top: 12%;
  transform: translateX(-50%);
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  background: var(--fill);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  z-index: 3;
}

.pep {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 0.55rem 1.15rem;
  border-radius: 999px;
  background: #fff4e5;
  color: #b25000;
  font-size: clamp(1.15rem, 3vw, 1.55rem);
  font-weight: 650;
  letter-spacing: -0.02em;
  z-index: 3;
  pointer-events: none;
  white-space: nowrap;
}

.pep-in {
  animation: pep-in 0.22s ease-out;
}

.pep-out {
  animation: pep-out 0.22s ease-in forwards;
}

@keyframes pep-in {
  from { opacity: 0; transform: translate(-50%, -40%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

@keyframes pep-out {
  from { opacity: 1; transform: translate(-50%, -50%); }
  to { opacity: 0; transform: translate(-50%, -62%); }
}

.pause-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  background: rgba(255, 255, 255, 0.86);
  z-index: 4;
}

.pause-overlay p {
  font-size: 2rem;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.coach {
  margin-top: 0.9rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
}

.keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.key-row {
  display: flex;
  gap: 0.4rem;
}

.key {
  min-width: 58px;
  height: 62px;
  padding: 0 0.5rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-size: 1.25rem;
  font-weight: 600;
  text-transform: uppercase;
  cursor: pointer;
  position: relative;
  box-shadow: 0 1px 0 #d2d2d7;
}

.key.out-row {
  opacity: 0.28;
}

.key:hover {
  background: var(--fill);
}

.key.hint {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  box-shadow: none;
}

.key-space {
  min-width: 220px;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  text-transform: none;
}

.space-target .target-word {
  font-size: clamp(3.2rem, 10vw, 5.5rem);
}

.key.home::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 8px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transform: translateX(-50%);
  opacity: 0.35;
}

.hands-wrap {
  width: min(760px, 100%);
  text-align: center;
}

.finger-label {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.1rem;
}

.hands {
  width: 100%;
  height: auto;
  max-height: 210px;
  overflow: visible;
}

.hands .palm,
.hands .finger {
  fill: #8e8e93;
  opacity: 0.35;
}

.hands .finger.active {
  fill: var(--accent);
  opacity: 1;
}

.help-line {
  margin-top: 0.5rem;
  color: var(--text-muted);
  font-size: 0.86rem;
  text-align: center;
}

.recap-card h1 {
  font-size: clamp(1.8rem, 5vw, 2.5rem);
}

.recap-stats {
  grid-template-columns: repeat(5, 1fr);
  margin: 1.5rem 0;
}

.recap-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.board {
  margin: 0 0 1.4rem;
  padding-top: 0.25rem;
}

.board-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.board-head h2 {
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.board-note {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.board-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.board-form input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  font: inherit;
  color: var(--text);
  background: var(--fill);
}

.board-form input:focus {
  outline: none;
  border-color: var(--accent);
  background: #ffffff;
}

.board-status {
  min-height: 1.2em;
  margin-bottom: 0.65rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.board-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.board-empty,
.board-row {
  display: grid;
  grid-template-columns: 2rem 1fr auto minmax(7rem, 0.9fr);
  gap: 0.55rem;
  align-items: center;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  background: var(--fill);
  font-size: 0.92rem;
}

.board-empty {
  color: var(--text-muted);
  grid-template-columns: 1fr;
}

.board-rank {
  color: var(--text-muted);
  font-weight: 650;
}

.board-name {
  font-weight: 650;
}

.board-score {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.board-meta {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: right;
}

.board-row.mine {
  background: var(--accent-soft);
}

.board-row.mine .board-rank,
.board-row.mine .board-name {
  color: var(--accent);
}

@media (max-width: 760px) {
  .mode-grid,
  .bests,
  .recap-stats {
    grid-template-columns: 1fr 1fr;
  }

  .hud-actions {
    margin-left: 0;
    width: 100%;
  }

  .key {
    min-width: 36px;
    height: 46px;
    font-size: 1.02rem;
  }

  .key-space {
    min-width: 140px;
  }

  .target-word {
    font-size: clamp(3.6rem, 18vw, 6.5rem);
  }

  .hands {
    max-height: 150px;
  }

  .finger-label {
    font-size: 0.95rem;
  }

  .stage-groups {
    grid-template-columns: 1fr 1fr;
  }
}
