:root {
  color-scheme: light;
  --ink: #17324a;
  --muted: #5f7180;
  --blue: #174f70;
  --blue-light: #dceff4;
  --cream: #f8f4e9;
  --gold: #efb650;
  --coral: #e77b60;
  --green: #2f8b70;
  --card: rgba(255,255,255,.94);
  --shadow: 0 14px 38px rgba(28, 57, 71, .12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 18%, rgba(239,182,80,.18) 0 90px, transparent 91px),
    radial-gradient(circle at 92% 80%, rgba(23,79,112,.10) 0 130px, transparent 131px),
    linear-gradient(145deg, #f9f6ec, #eef5f3);
  font-family: "Malgun Gothic", "맑은 고딕", sans-serif;
}
button { font: inherit; }
button:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; }
[hidden] { display: none !important; }

.start-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(10,47,70,.72), rgba(10,47,70,.78)),
    url("images/book-12/illust-12-02.webp") center/cover;
}
.start-card {
  width: min(680px, 100%);
  padding: clamp(32px, 7vw, 64px);
  text-align: center;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 30px;
  color: white;
  background: rgba(15,58,81,.86);
  box-shadow: 0 28px 80px rgba(0,0,0,.35);
  backdrop-filter: blur(10px);
}
.start-mark, .brand-mark { color: var(--gold); }
.start-mark { font-size: 46px; }
.eyebrow { color: #ffdc91; font-weight: 800; letter-spacing: .12em; }
.start-card h1 { margin: 8px 0 20px; font-size: clamp(34px, 7vw, 58px); }
.start-card > p:not(.eyebrow,.small-note) { font-size: clamp(18px, 3vw, 23px); line-height: 1.8; }
.small-note { opacity: .82; font-size: 14px; }
.primary-button {
  border: 0;
  border-radius: 999px;
  padding: 16px 28px;
  min-height: 58px;
  color: #17324a;
  background: var(--gold);
  font-weight: 900;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 9px 0 #bd8030;
  transition: transform .15s;
}
.primary-button:hover { transform: translateY(-2px); }
.primary-button:active { transform: translateY(5px); box-shadow: 0 4px 0 #bd8030; }

.game-shell { min-height: 100vh; }
.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(18px, calc((100vw - 1200px)/2));
  color: white;
  background: var(--blue);
  box-shadow: 0 5px 18px rgba(14,47,67,.18);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; }
.round-button, .sound-button, .text-button, .nav-button, .modal-close {
  cursor: pointer;
  border: 0;
}
.round-button { width: 48px; height: 48px; border-radius: 50%; font-size: 26px; color: white; background: rgba(255,255,255,.15); }
.sound-button { min-height: 44px; border-radius: 999px; padding: 0 18px; color: white; background: rgba(255,255,255,.16); font-weight: 800; }
main { width: min(1200px, calc(100% - 32px)); margin: 22px auto 48px; }
.progress-card, .story-card, .play-area, .time-nudge { background: var(--card); box-shadow: var(--shadow); }
.progress-card { display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: center; border-radius: 18px; padding: 15px 20px; }
.progress-copy { display: flex; gap: 12px; align-items: baseline; white-space: nowrap; }
.progress-copy span { font-weight: 800; color: var(--blue); }
.progress-track { height: 12px; border-radius: 99px; background: #e2e9e9; overflow: hidden; }
#progress-fill { height: 100%; width: 1%; border-radius: inherit; background: linear-gradient(90deg, var(--gold), var(--coral)); transition: width .35s; }
.piece-label { min-width: 70px; padding: 7px 10px; border-radius: 99px; text-align: center; color: var(--blue); background: var(--blue-light); font-weight: 900; }
.story-card { margin: 15px 0; display: flex; align-items: center; justify-content: center; gap: 12px; border-left: 7px solid var(--gold); border-radius: 18px; padding: 14px 20px; }
.story-card span { color: var(--gold); font-size: 22px; }
.story-card p { margin: 0; font-size: clamp(17px, 2.2vw, 22px); font-weight: 800; line-height: 1.5; text-align: center; }
.play-area { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, .8fr); gap: 26px; padding: clamp(18px, 3vw, 30px); border-radius: 22px; }
.section-heading { min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-heading h2 { margin: 0; font-size: 20px; }
.section-heading span { color: var(--muted); font-weight: 700; }
.text-button { min-height: 42px; padding: 8px 14px; border-radius: 12px; color: var(--blue); background: var(--blue-light); font-weight: 900; }
.puzzle-board {
  position: relative;
  width: 100%;
  margin-top: 12px;
  display: grid;
  gap: 5px;
  padding: 7px;
  border: 3px solid #234d61;
  border-radius: 14px;
  background: #dbe3df;
  overflow: hidden;
}
.slot { position: relative; min-width: 0; min-height: 0; padding: 0; border: 2px dashed rgba(23,79,112,.22); background: rgba(255,255,255,.55); overflow: hidden; }
.slot::after { content: attr(data-number); position: absolute; inset: 0; display: grid; place-items: center; color: rgba(23,79,112,.32); font-weight: 900; font-size: 22px; }
.slot.drop-ready { background: #fff1bb; border-color: var(--gold); }
.slot.correct { border: 0; }
.slot.correct::after { display: none; }
.piece-tray {
  min-height: 260px;
  margin-top: 12px;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(75px, 1fr));
  align-content: start;
  gap: 12px;
  border: 2px solid #dfe8e7;
  border-radius: 14px;
  background: #f4f8f6;
}
.piece {
  width: 100%;
  padding: 0;
  border: 3px solid white;
  border-radius: 9px;
  background-repeat: no-repeat;
  box-shadow: 0 4px 10px rgba(24,57,70,.24);
  cursor: grab;
  touch-action: none;
  transition: transform .15s, box-shadow .15s;
}
.piece:hover, .piece.selected { transform: translateY(-3px) scale(1.025); box-shadow: 0 8px 18px rgba(24,57,70,.3); outline: 4px solid var(--gold); }
.slot .piece { height: 100%; border: 0; border-radius: 0; box-shadow: none; pointer-events: none; }
.drag-ghost { position: fixed; z-index: 1000; pointer-events: none; opacity: .9; transform: rotate(2deg) scale(1.05); }
.help-copy { margin: 12px 2px 0; color: var(--muted); line-height: 1.6; font-size: 14px; }
.feedback { height: 44px; display: grid; place-items: center; font-weight: 900; font-size: 20px; }
.feedback.good { color: var(--green); }
.feedback.bad { color: #a33e35; }
.feedback-pop { animation: pop .45s ease; }
@keyframes pop { 50% { transform: scale(1.16); } }
.game-nav { display: flex; justify-content: center; gap: 14px; margin-top: 18px; }
.nav-button { min-width: 130px; min-height: 52px; padding: 10px 18px; border-radius: 999px; color: white; background: var(--blue); font-weight: 900; }
.nav-button.soft { color: var(--blue); background: var(--blue-light); }
.nav-button:disabled { opacity: .36; cursor: not-allowed; }
.time-nudge { margin-top: 18px; display: flex; align-items: center; gap: 14px; padding: 16px 20px; border-radius: 16px; border-left: 6px solid var(--gold); }
.time-nudge p { flex: 1; margin: 0; font-weight: 800; }
.modal { position: fixed; inset: 0; z-index: 1200; display: grid; place-items: center; padding: 20px; background: rgba(13,39,55,.7); }
.modal-card { position: relative; width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 34px; border-radius: 24px; background: white; box-shadow: 0 28px 80px rgba(0,0,0,.32); text-align: center; }
.modal-card h2 { font-size: 28px; }
.modal-card ol { text-align: left; line-height: 1.9; font-size: 17px; }
.modal-close { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; border-radius: 50%; color: var(--ink); background: #edf3f2; font-size: 27px; }
.picture-card { width: min(760px, 100%); }
.picture-card img { display: block; max-width: 100%; max-height: 62vh; margin: 0 auto 16px; border-radius: 14px; }
.picture-card p { font-weight: 800; line-height: 1.6; }
.celebration { color: var(--gold); font-size: 42px; }
.finish-card p { font-size: 18px; line-height: 1.7; }
.trophy { width: 100px; height: 100px; margin: 0 auto; display: grid; place-items: center; border-radius: 50%; color: #17324a; background: var(--gold); font-size: 52px; box-shadow: 0 0 0 12px #fff3cf; }
.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }

@media (max-width: 820px) {
  .play-area { grid-template-columns: 1fr; }
  .piece-tray { min-height: 170px; grid-template-columns: repeat(4, minmax(60px, 1fr)); }
  .topbar { height: 66px; }
  .brand strong { font-size: 16px; }
  main { width: min(100% - 20px, 680px); margin-top: 12px; }
}
@media (max-width: 520px) {
  .brand-mark { display: none; }
  .sound-button { padding: 0 10px; font-size: 14px; }
  .progress-card { grid-template-columns: 1fr auto; gap: 10px; }
  .progress-track { grid-column: 1 / -1; grid-row: 2; }
  .play-area { padding: 14px; }
  .piece-tray { grid-template-columns: repeat(3, minmax(60px, 1fr)); gap: 8px; padding: 9px; }
  .game-nav { gap: 7px; }
  .nav-button { min-width: 0; flex: 1; padding: 8px; }
  .time-nudge { align-items: flex-start; flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
