:root {
  --ink: #243044;
  --muted: #6b7280;
  --paper: #fffaf0;
  --cream: #fff7e8;
  --blue: #4a9ff5;
  --green: #36b37e;
  --pink: #f36f9f;
  --yellow: #ffc94a;
  --orange: #ff8a4c;
  --line: rgba(36, 48, 68, 0.14);
  --shadow: rgba(40, 50, 70, 0.18);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 201, 74, 0.35), transparent 26%),
    radial-gradient(circle at 86% 18%, rgba(74, 159, 245, 0.25), transparent 28%),
    linear-gradient(135deg, #fff7e8 0%, #eaf8ff 50%, #fff0f6 100%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 540px;
  padding: max(22px, env(safe-area-inset-top)) max(26px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(26px, env(safe-area-inset-left));
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  padding: inherit;
}

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

.setup-screen {
  place-items: center;
}

.setup-panel {
  width: min(780px, 86vw);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 26px 60px var(--shadow);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--blue);
  font-size: 1rem;
  font-weight: 900;
}

h1 {
  margin: 0 0 24px;
  font-size: 2.6rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.setup-form {
  display: grid;
  gap: 22px;
}

.field {
  display: grid;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 900;
}

.field input {
  width: 100%;
  height: 76px;
  padding: 0 22px;
  border: 3px solid rgba(74, 159, 245, 0.34);
  border-radius: 8px;
  outline: 0;
  background: #ffffff;
  color: var(--ink);
  font-size: 2.15rem;
  font-weight: 950;
}

.field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 6px rgba(74, 159, 245, 0.16);
}

.count-field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.count-field legend {
  margin-bottom: 10px;
  font-size: 1.05rem;
  font-weight: 900;
}

.count-options {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 10px;
}

.count-option {
  height: 58px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 950;
}

.count-option.is-selected {
  border-color: var(--green);
  background: #dcfce8;
  color: #116b49;
}

.error-message {
  min-height: 24px;
  margin: -4px 0 0;
  color: #d7354d;
  font-size: 1.05rem;
  font-weight: 900;
}

.primary-button {
  height: 76px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--green), var(--blue));
  color: #ffffff;
  box-shadow: 0 18px 34px rgba(54, 179, 126, 0.25);
  font-size: 1.7rem;
  font-weight: 950;
}

.learn-screen,
.game-screen {
  grid-template-rows: auto 1fr;
  gap: 18px;
}

.top-bar {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  align-items: center;
  gap: 14px;
  min-height: 72px;
}

.icon-button,
.speaker-button {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 12px 28px rgba(40, 50, 70, 0.11);
  color: var(--ink);
  font-size: 2.1rem;
  font-weight: 950;
}

.speaker-button span {
  line-height: 1;
}

.speaker-button.is-muted {
  opacity: 0.45;
}

.right-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-self: end;
}

.score-panel {
  height: 72px;
  display: grid;
  grid-template-columns: repeat(2, 76px);
  gap: 8px;
}

.score-panel div {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  border: 2px solid rgba(36, 48, 68, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 12px 28px rgba(40, 50, 70, 0.09);
}

.score-panel span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 900;
}

.score-panel strong {
  color: var(--ink);
  font-size: 1.7rem;
  line-height: 1;
  font-weight: 950;
}

.target-chip {
  justify-self: center;
  width: min(520px, 58vw);
  min-height: 72px;
  display: grid;
  align-items: center;
  justify-content: center;
  padding: 8px 18px;
  border: 2px solid rgba(36, 48, 68, 0.12);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 12px 28px rgba(40, 50, 70, 0.1);
}

.target-chip > * {
  grid-area: 1 / 1;
}

.target-chip strong {
  min-width: 210px;
  min-height: 48px;
  display: grid;
  place-items: center;
  font-size: 2.5rem;
  line-height: 1;
  font-weight: 950;
}

.hint-button {
  min-width: 164px;
  height: 48px;
  border: 0;
  border-radius: 8px;
  background: #dcfce8;
  color: #116b49;
  font-size: 1.25rem;
  font-weight: 950;
}

.hero-word-card {
  align-self: center;
  justify-self: center;
  width: min(780px, 82vw);
  min-height: min(430px, 62vh);
  display: grid;
  place-items: center;
  padding: 34px;
  border: 5px solid rgba(74, 159, 245, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 250, 240, 0.94)),
    linear-gradient(135deg, rgba(255, 201, 74, 0.18), rgba(243, 111, 159, 0.12));
  box-shadow: 0 34px 80px rgba(40, 50, 70, 0.22);
  color: var(--ink);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.hero-word-card:active {
  transform: scale(0.98);
}

.hero-word {
  max-width: 100%;
  font-size: clamp(5.6rem, 16vw, 12rem);
  line-height: 1;
  letter-spacing: 0;
  font-weight: 950;
  word-break: keep-all;
}

.card-grid {
  width: min(1180px, 96vw);
  height: 100%;
  max-height: calc(100vh - 126px);
  justify-self: center;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: 18px;
}

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

.card-grid.count-5,
.card-grid.count-6 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.word-card {
  min-width: 0;
  min-height: 112px;
  display: grid;
  place-items: center;
  padding: 12px;
  border: 3px solid rgba(36, 48, 68, 0.13);
  border-radius: 8px;
  background: #f4fff4;
  box-shadow: 0 18px 38px rgba(40, 50, 70, 0.14);
  color: var(--ink);
  font-size: clamp(2.4rem, 6vw, 5.3rem);
  font-weight: 950;
  line-height: 1.08;
  letter-spacing: 0;
  word-break: keep-all;
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
}

.word-card:active {
  transform: scale(0.96);
}

.word-card.is-correct {
  border-color: var(--green);
  box-shadow: 0 0 0 8px rgba(54, 179, 126, 0.18), 0 22px 46px rgba(40, 50, 70, 0.18);
}

.word-card.is-wrong {
  border-color: #ef4444;
  animation: shake 0.28s ease;
}

.feedback {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  pointer-events: none;
}

.feedback.is-visible {
  display: grid;
}

.feedback p {
  position: relative;
  z-index: 2;
  margin: 0;
  padding: 24px 42px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 26px 70px rgba(40, 50, 70, 0.2);
  color: var(--ink);
  font-size: clamp(3.8rem, 9vw, 8rem);
  font-weight: 950;
  animation: pop 0.5s cubic-bezier(0.2, 1.35, 0.3, 1);
}

.feedback-burst {
  position: absolute;
  width: 52vmin;
  height: 52vmin;
  border-radius: 50%;
  background:
    conic-gradient(from 12deg, var(--yellow), var(--pink), var(--blue), var(--green), var(--yellow));
  opacity: 0.82;
  animation: burst 0.9s ease both;
}

.feedback.is-wrong .feedback-burst {
  background: rgba(239, 68, 68, 0.22);
  animation: wrongPulse 0.55s ease both;
}

.rotate-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 28px;
  background: #fff7e8;
  text-align: center;
}

.rotate-overlay div {
  display: grid;
  gap: 12px;
}

.rotate-overlay strong {
  font-size: 2rem;
  line-height: 1.2;
}

.rotate-overlay span {
  color: var(--muted);
  font-size: 1.1rem;
  font-weight: 800;
}

@keyframes pop {
  from {
    transform: scale(0.64) rotate(-2deg);
    opacity: 0;
  }
  to {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

@keyframes burst {
  from {
    transform: scale(0.2) rotate(0deg);
    opacity: 0;
  }
  65% {
    opacity: 0.86;
  }
  to {
    transform: scale(1.45) rotate(48deg);
    opacity: 0;
  }
}

@keyframes wrongPulse {
  from {
    transform: scale(0.72);
    opacity: 0;
  }
  to {
    transform: scale(1.15);
    opacity: 0;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-10px);
  }
  75% {
    transform: translateX(10px);
  }
}

@media (orientation: portrait) and (max-width: 1024px) {
  .rotate-overlay {
    display: grid;
  }
}

@media (max-height: 620px) {
  .app-shell {
    min-height: 420px;
    padding: 14px 18px;
  }

  .setup-panel {
    padding: 22px;
  }

  h1 {
    font-size: 2rem;
    margin-bottom: 16px;
  }

  .field input,
  .primary-button {
    height: 62px;
  }

  .top-bar {
    min-height: 58px;
  }

  .icon-button,
  .speaker-button {
    width: 58px;
    height: 58px;
    font-size: 1.7rem;
  }

  .score-panel {
    height: 58px;
    grid-template-columns: repeat(2, 62px);
  }

  .score-panel span {
    font-size: 0.78rem;
  }

  .score-panel strong {
    font-size: 1.35rem;
  }

  .hero-word-card {
    min-height: min(330px, 58vh);
  }

  .card-grid {
    gap: 12px;
  }
}
