:root {
  --ink: #273044;
  --muted: #6d6a67;
  --paper: #fffdf8;
  --paper-warm: #fff8e9;
  --line: #ded6c7;
  --coral: #e85d4a;
  --coral-dark: #bd3f31;
  --teal: #237d78;
  --teal-soft: #dff3ee;
  --gold: #f2b84b;
  --blue: #4169a8;
  --danger: #c64848;
  --shadow: 0 14px 36px rgba(68, 53, 35, 0.18);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-width: 320px;
  overflow-x: hidden;
  color: var(--ink);
  background-color: #f7efe1;
  background-image:
    linear-gradient(rgba(65, 105, 168, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(65, 105, 168, 0.08) 1px, transparent 1px);
  background-size: 28px 28px;
  font-family: "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  letter-spacing: 0;
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  font: inherit;
}

button {
  color: inherit;
}

button,
.card-button {
  touch-action: manipulation;
}

button:focus {
  outline: none;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(65, 105, 168, 0.42);
  outline-offset: 3px;
}

.game-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
}

.game-header {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.brand-link img {
  display: block;
  border-radius: 8px;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 4px 12px rgba(68, 53, 35, 0.1);
  cursor: pointer;
}

.sound-button span {
  font-size: 20px;
  font-weight: 900;
}

.screen {
  min-height: calc(100dvh - 90px);
  display: none;
  align-items: center;
  justify-content: center;
}

.screen.is-active {
  display: flex;
}

.paper-card {
  width: min(100%, 620px);
  padding: clamp(24px, 5vw, 48px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.98);
  box-shadow: var(--shadow);
  text-align: center;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--coral-dark);
  font-size: 13px;
  font-weight: 900;
}

.title-mark,
.result-sparkle {
  color: var(--gold);
  font-size: 34px;
  line-height: 1;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(32px, 8vw, 58px);
  line-height: 1.12;
  letter-spacing: 0;
}

.lead {
  max-width: 440px;
  margin: 0 auto 22px;
  color: #57514b;
  font-size: clamp(16px, 3.5vw, 19px);
  line-height: 1.7;
}

.home-record {
  width: min(100%, 360px);
  min-height: 96px;
  margin: 0 auto 20px;
  padding: 14px 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 12px;
  border: 1px solid #efd493;
  border-radius: 8px;
  background: #fff5d8;
  text-align: left;
}

.home-record span {
  color: #6d5930;
  font-size: 14px;
  font-weight: 700;
}

.home-record strong {
  grid-row: span 2;
  color: var(--coral-dark);
  font-size: 26px;
}

.home-record small {
  color: var(--muted);
}

.how-to {
  width: min(100%, 420px);
  margin: 0 auto 18px;
  padding: 16px 18px;
  border-top: 1px dashed #c9bcaa;
  border-bottom: 1px dashed #c9bcaa;
  text-align: left;
}

.how-to h2 {
  margin-bottom: 8px;
  font-size: 16px;
}

.how-to ol {
  margin: 0;
  padding-left: 22px;
  color: #5f5a54;
  font-size: 14px;
  line-height: 1.7;
}

.loading-status {
  min-height: 21px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.primary-button,
.secondary-button {
  min-height: 50px;
  padding: 12px 22px;
  border-radius: 8px;
  font-weight: 900;
  cursor: pointer;
}

.primary-button {
  width: min(100%, 320px);
  border: 1px solid var(--coral-dark);
  color: #fff;
  background: var(--coral);
  box-shadow: 0 6px 0 var(--coral-dark);
}

.primary-button:hover {
  background: #ef6856;
}

.primary-button:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 var(--coral-dark);
}

.primary-button:disabled {
  border-color: #a8a19a;
  background: #b8b2ac;
  box-shadow: 0 4px 0 #8e8984;
  cursor: wait;
}

.secondary-button {
  border: 1px solid var(--teal);
  color: var(--teal);
  background: #fff;
}

.play-screen {
  align-items: flex-start;
  flex-direction: column;
  justify-content: flex-start;
  gap: 12px;
  position: relative;
}

.play-toolbar {
  width: 100%;
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 8px;
}

.stat-pill {
  min-height: 60px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 4px 12px rgba(68, 53, 35, 0.09);
}

.stat-pill span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stat-pill strong {
  font-size: 20px;
  white-space: nowrap;
}

.timer-pill.is-urgent {
  border-color: #e8948d;
  color: var(--danger);
  background: #fff0ee;
  animation: timer-pulse 0.8s ease-in-out infinite alternate;
}

.game-board {
  width: 100%;
  flex: 1;
  min-height: 0;
  padding: clamp(14px, 3vw, 24px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.98);
  box-shadow: var(--shadow);
}

.target-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 4vw, 32px);
  min-height: 98px;
  padding-bottom: 14px;
  border-bottom: 1px dashed #c9bcaa;
}

.target-label {
  color: var(--coral-dark);
  font-size: 15px;
  font-weight: 900;
}

.target-card {
  width: 116px;
  min-height: 82px;
  padding: 8px;
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 8px;
  border: 2px solid var(--gold);
  border-radius: 8px;
  background: #fff8dc;
  font-weight: 900;
}

.target-card img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.card-fallback {
  display: grid;
  place-items: center;
  color: var(--gold);
  font-size: 34px;
}

.feedback {
  min-height: 24px;
  margin: 12px 0 10px;
  color: #5f5a54;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
}

.feedback.is-correct {
  color: var(--teal);
}

.feedback.is-wrong {
  color: var(--danger);
}

.card-grid {
  width: min(100%, 640px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(7px, 1.8vw, 13px);
}

.card-button {
  aspect-ratio: 1 / 0.82;
  min-width: 0;
  min-height: 88px;
  padding: 8px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  overflow: hidden;
  border: 2px solid #cfd7df;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 4px 0 #c3ccd5;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.card-button:hover {
  border-color: var(--blue);
  background: #f1f6ff;
}

.card-button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #c3ccd5;
}

.card-button img {
  width: clamp(42px, 10vw, 70px);
  height: clamp(42px, 10vw, 70px);
  display: block;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}

.card-button .card-name {
  font-size: clamp(12px, 2.8vw, 15px);
  font-weight: 900;
  pointer-events: none;
}

.card-button.is-correct {
  border-color: var(--teal);
  background: var(--teal-soft);
  animation: correct-pop 180ms ease-out;
}

.card-button.is-wrong {
  border-color: var(--danger);
  background: #fff0ee;
  animation: wrong-shake 180ms ease-out;
}

.card-button:disabled {
  opacity: 1;
  cursor: default;
}

.score-burst {
  position: absolute;
  top: 8px;
  right: 10px;
  color: var(--teal);
  font-size: 18px;
  font-weight: 900;
  animation: score-rise 420ms ease-out forwards;
}

.countdown-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(39, 48, 68, 0.42);
  backdrop-filter: blur(3px);
}

.countdown-overlay[hidden] {
  display: none;
}

.countdown-overlay strong {
  width: 120px;
  height: 120px;
  display: grid;
  place-items: center;
  border: 4px solid #fff;
  border-radius: 50%;
  color: #fff;
  background: var(--coral);
  box-shadow: var(--shadow);
  font-size: 64px;
}

.result-card {
  max-width: 620px;
}

.final-score {
  margin-bottom: 6px;
  color: var(--coral-dark);
}

.final-score strong {
  font-size: clamp(64px, 18vw, 104px);
  line-height: 1;
}

.final-score span {
  margin-left: 5px;
  font-size: 22px;
  font-weight: 900;
}

.record-message {
  min-height: 25px;
  margin-bottom: 22px;
  color: var(--teal);
  font-weight: 900;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 22px;
}

.result-stats div {
  min-height: 76px;
  padding: 12px;
  display: grid;
  place-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-warm);
}

.result-stats span {
  color: var(--muted);
  font-size: 13px;
}

.result-stats strong {
  font-size: 20px;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.result-actions .primary-button {
  width: 100%;
}

.text-link {
  grid-column: 1 / -1;
  padding: 8px;
  color: var(--blue);
  font-weight: 800;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

noscript {
  display: block;
  padding: 20px;
  text-align: center;
}

@keyframes correct-pop {
  50% { transform: scale(1.06); }
}

@keyframes wrong-shake {
  33% { transform: translateX(-4px); }
  66% { transform: translateX(4px); }
}

@keyframes score-rise {
  to { transform: translateY(-18px); opacity: 0; }
}

@keyframes timer-pulse {
  to { transform: scale(1.015); }
}

@media (max-width: 640px) {
  .game-shell {
    padding-right: 10px;
    padding-left: 10px;
  }

  .game-header {
    margin-bottom: 6px;
  }

  .brand-link span {
    font-size: 14px;
  }

  .screen {
    min-height: calc(100dvh - 72px);
  }

  .paper-card {
    padding: 24px 18px;
  }

  .play-toolbar {
    gap: 5px;
  }

  .stat-pill {
    min-height: 52px;
    padding: 7px 8px;
    display: grid;
    gap: 2px;
  }

  .stat-pill span {
    font-size: 11px;
  }

  .stat-pill strong {
    font-size: 17px;
  }

  .game-board {
    padding: 10px;
  }

  .target-panel {
    min-height: 78px;
    padding-bottom: 8px;
  }

  .target-label {
    max-width: 96px;
    font-size: 13px;
  }

  .target-card {
    width: 108px;
    min-height: 68px;
    grid-template-columns: 40px 1fr;
    font-size: 14px;
  }

  .target-card img {
    width: 40px;
    height: 40px;
  }

  .feedback {
    margin: 7px 0 6px;
    font-size: 12px;
  }

  .card-grid {
    gap: 6px;
  }

  .card-button {
    min-height: 78px;
    padding: 5px;
    box-shadow: 0 3px 0 #c3ccd5;
  }
}

@media (max-height: 720px) and (orientation: portrait) {
  .game-header {
    min-height: 40px;
  }

  .game-header img {
    width: 36px;
    height: 36px;
  }

  .screen {
    min-height: calc(100dvh - 62px);
  }

  .play-screen {
    gap: 7px;
  }

  .stat-pill {
    min-height: 46px;
  }

  .target-panel {
    min-height: 66px;
  }

  .target-card {
    min-height: 58px;
  }

  .card-button {
    min-height: 66px;
  }

  .card-button img {
    width: 38px;
    height: 38px;
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  .game-shell {
    width: min(100%, 940px);
  }

  .game-header {
    min-height: 38px;
    margin-bottom: 4px;
  }

  .screen {
    min-height: calc(100dvh - 56px);
  }

  .play-screen {
    display: grid;
    grid-template-columns: 170px 1fr;
    align-items: start;
  }

  .play-toolbar {
    grid-template-columns: 1fr;
  }

  .game-board {
    padding: 8px 14px;
  }

  .target-panel {
    min-height: 58px;
    padding-bottom: 5px;
  }

  .feedback {
    margin: 4px 0;
  }

  .card-button {
    min-height: 54px;
    aspect-ratio: 1 / 0.55;
    flex-direction: row;
  }

  .card-button img {
    width: 36px;
    height: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
