/* Miracle English — 워크북(PDF) 디자인을 그대로 옮긴 팔레트 */
:root {
  --ink: #222;
  --line: #2b2b2b;
  --muted: #545454;
  --paper: #fff;
  --strip: #FFF6D5;      /* 표지 왼쪽 노란 띠 */
  --blue: #ECF5FB;       /* LISTENING 박스 */
  --cream: #FFFAEC;      /* WRITING 박스 */
  --pink: #FDF1F1;       /* REPETITION 박스 */
  --dot-pink: #F08A9A;   /* 표지 점선 이름칸 */
  --v-red: #F0313C;      /* VISUALIZATION 프레임 */
  --v-yellow: #FFD21F;
  --v-cyan: #1CC4EA;
  --v-blue: #1BA6DF;
  --ok: #2fa84f;
  --bad: #e5484d;
  --radius: 22px;
  --display: "Fredoka", "Gaegu", system-ui, sans-serif;
  --hand: "Gaegu", "Fredoka", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: #f4efe2;
  color: var(--ink);
  font-family: var(--hand);
  font-size: 18px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }

#app {
  max-width: 520px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--paper);
  box-shadow: 0 0 0 1px #e6dfcc, 0 10px 40px rgba(80, 60, 20, .08);
  position: relative;
  overflow-x: hidden;
}

/* ---------- 표지(홈) ---------- */
.cover {
  position: relative;
  padding: 28px 20px 20px 52px;
  text-align: center;
}
.cover::before {
  content: "";
  position: absolute; inset: 0 auto 0 0;
  width: 32px;
  background: var(--strip);
}
.brand {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  font-family: var(--display); font-weight: 600; color: #8f8f8f; font-size: 15px;
  margin-right: 40px;
}
.brand img { width: 40px; }
.cover h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(40px, 12vw, 56px);
  line-height: 1;
  margin: 6px 0 14px;
  letter-spacing: -.5px;
}
.cover-bears {
  display: flex; justify-content: center; align-items: flex-end; gap: 2%;
  background: var(--pink); border-radius: 50% 50% 24px 24px / 60% 60% 24px 24px;
  padding: 22px 6% 14px; margin: 0 4%;
}
.cover-bears img { width: 22%; animation: hop 1.6s ease-in-out infinite; }
.cover-bears img:nth-child(2) { animation-delay: .2s; }
.cover-bears img:nth-child(3) { animation-delay: .4s; }
.cover-bears img:nth-child(4) { animation-delay: .6s; }
.name-pill {
  display: block;
  width: 70%; max-width: 260px;
  margin: 14px auto 6px;
  border: 1.5px dashed var(--dot-pink);
  border-radius: 999px;
  padding: 10px 16px;
  text-align: center;
  font-family: var(--hand); font-size: 22px; font-weight: 700;
  background: #fff;
  outline: none;
}
.name-pill:focus { border-style: solid; }
.cover .flowers { width: 62%; margin: 14px auto 4px; }
.tagline { font-size: 17px; margin: 0; border-top: 1px dotted #bbb; display: inline-block; padding-top: 4px; }
.tagline small { display: block; font-family: var(--hand); font-size: 16px; }

.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  padding: 6px 20px 0;
}
.stat {
  border: 1.5px solid var(--line); border-radius: 18px;
  padding: 10px 6px; text-align: center; background: var(--cream);
}
.stat:nth-child(2) { background: var(--blue); }
.stat:nth-child(3) { background: var(--pink); }
.stat b { display: block; font-family: var(--display); font-size: 26px; line-height: 1.1; }
.stat span { font-size: 15px; color: var(--muted); }

.cta {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin: 16px 20px 0;
  width: calc(100% - 40px);
  border: 2px solid var(--line); border-radius: 999px;
  background: var(--v-yellow);
  padding: 14px 18px;
  font-family: var(--display); font-weight: 600; font-size: 20px;
  box-shadow: 0 4px 0 var(--line);
  transition: transform .1s, box-shadow .1s;
}
.cta:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }

.section-title {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--display); font-weight: 600; font-size: 15px; letter-spacing: .5px;
  margin: 26px 20px 10px;
}
.section-title img { width: 30px; }
.section-title small { font-family: var(--hand); font-weight: 400; color: var(--muted); font-size: 15px; letter-spacing: 0; }

.day-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px;
  padding: 0 20px;
}
.day-cell {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1.5px dotted #777;
  background: #fff;
  font-family: var(--display); font-weight: 600; font-size: 16px;
  display: grid; place-items: center;
  position: relative;
  padding: 0;
}
.day-cell.partial {
  border: none;
  background:
    radial-gradient(circle, #fff 62%, transparent 63%),
    conic-gradient(var(--v-cyan) calc(var(--p) * 1%), #e8e8e8 0);
}
.day-cell.done {
  border: 1.5px solid var(--line);
  background: var(--pink) center 30% / 82% auto no-repeat;
  background-image: var(--bear);
  color: transparent;
}
.day-cell.done::after {
  content: attr(data-n);
  position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%);
  background: var(--line); color: #fff; font-size: 11px; padding: 0 6px; border-radius: 99px;
}
.day-cell.today { outline: 3px solid var(--v-yellow); outline-offset: 2px; }

.footer {
  text-align: center; font-family: var(--display); font-size: 12px; color: var(--muted);
  padding: 28px 0 32px;
}
.footer button { background: none; border: none; text-decoration: underline; color: var(--muted); font-size: 13px; }

/* ---------- 데이 페이지 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid #eee;
}
.icon-btn {
  width: 40px; height: 40px; flex: none;
  border: 1.5px solid var(--line); border-radius: 50%;
  background: #fff; display: grid; place-items: center; font-size: 18px;
  padding: 0;
}
.icon-btn:disabled { opacity: .3; }
.date-field {
  display: flex; align-items: center; gap: 4px;
  font-family: var(--display); font-size: 14px; color: var(--muted);
}
.date-field input {
  border: none; border-bottom: 1px solid #999; background: none;
  font-family: var(--display); font-size: 14px; width: 128px; padding: 2px 0;
}
.topbar .strip { display: flex; margin-left: auto; }
.topbar .strip img { height: 34px; margin-left: -4px; mix-blend-mode: multiply; }

.page { padding: 8px 16px 0; }
.page-head { text-align: center; margin: 14px 0 6px; }
.page-head h2 {
  font-family: var(--display); font-weight: 600; font-size: 30px; margin: 0;
  display: inline-block; padding: 0 22px 2px; border-bottom: 1.5px solid var(--line);
}
.day-pill {
  display: inline-block; margin-top: 10px;
  border: 1.5px solid var(--line); border-radius: 999px;
  padding: 2px 22px; font-family: var(--display); font-weight: 500; font-size: 15px;
}

.tabs {
  display: grid; grid-template-columns: 1fr 1fr;
  margin: 16px 0 4px;
  border: 1.5px solid var(--line); border-radius: 999px; overflow: hidden;
}
.tabs button {
  border: none; background: #fff; padding: 9px 0;
  font-family: var(--display); font-weight: 600; font-size: 15px;
}
.tabs button[aria-selected="true"] { background: var(--line); color: #fff; }

.label {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-family: var(--display); font-weight: 600; font-size: 14px; letter-spacing: .5px;
  margin: 22px 6px 8px;
}
.label img { width: 30px; height: auto; }
.label small { font-family: var(--hand); font-weight: 400; font-size: 15px; letter-spacing: 0; color: var(--muted); }
.label .check { margin-left: auto; font-size: 13px; color: var(--ok); }

.box {
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
  background: #fff;
}
.box.blue { background: var(--blue); }
.box.cream { background: var(--cream); }
.box.pink { background: var(--pink); }

.sentence {
  font-family: var(--hand); font-weight: 700;
  font-size: 24px; line-height: 1.6; margin: 0 0 10px;
}
.sentence.hidden, .ko.hidden { filter: blur(7px); user-select: none; cursor: pointer; }
.ko { font-size: 17px; color: #333; margin: 0; text-align: center; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1.5px solid var(--line); border-radius: 999px;
  background: #fff; padding: 6px 14px;
  font-family: var(--hand); font-weight: 700; font-size: 17px;
  text-decoration: none; color: var(--ink);
}
.chip.primary { background: var(--line); color: #fff; }
.chip.playing { background: var(--v-yellow); }
.chip.ghost { border-style: dashed; }
.chip:active { transform: scale(.97); }

/* 점선 줄노트 */
.lined {
  width: 100%;
  min-height: 168px;
  border: none; outline: none; resize: vertical;
  font-family: var(--hand); font-size: 22px; font-weight: 700;
  line-height: 42px; padding: 0 4px;
  background:
    linear-gradient(90deg, var(--bg, var(--cream)) 50%, transparent 0) 0 0 / 8px 100%,
    repeating-linear-gradient(transparent 0 41px, #9a9a9a 41px 42px);
  background-attachment: local;
}
.box:not(.cream) .lined { --bg: #fff; }

.result {
  margin-top: 12px; padding: 12px 14px;
  background: #fff; border-radius: 14px; border: 1.5px dashed #bbb;
  font-size: 19px; line-height: 1.7;
}
.result .score { font-family: var(--display); font-weight: 600; font-size: 16px; display: block; margin-bottom: 4px; }
.w-ok { color: var(--ok); }
.w-miss { color: var(--bad); text-decoration: underline wavy; text-underline-offset: 4px; }

/* REPETITION */
.rep-row {
  display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 8px;
  padding: 6px 0;
}
.rep-row + .rep-row { border-top: 1px dashed #e6c9c9; margin-top: 6px; padding-top: 12px; }
.rep-head { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.rep-head span { font-size: 15px; line-height: 1.2; font-weight: 700; }
.mic {
  width: 52px; height: 52px; border-radius: 50%;
  border: 1.5px solid var(--line); background: #fff; display: grid; place-items: center; padding: 0;
}
.mic.listening { animation: pulse 1s infinite; background: #fff3c4; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(255, 210, 31, .35); } }
.rep-slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.slot { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.slot img { width: 46px; height: 64px; object-fit: contain; }
.stamp {
  width: 44px; height: 44px; border-radius: 50%;
  border: 2px dotted #444; background: #fff; padding: 0;
  display: grid; place-items: center;
}
.stamp.on {
  border: 2.5px solid var(--v-red); color: var(--v-red);
  font-family: var(--display); font-weight: 700; font-size: 11px;
  transform: rotate(-14deg);
  animation: stampIn .25s ease-out;
}
@keyframes stampIn { from { transform: scale(1.8) rotate(-14deg); opacity: 0; } }
.rep-note { font-size: 15px; color: var(--muted); text-align: center; margin: 10px 0 0; }
.rep-heard { font-size: 16px; text-align: center; margin: 6px 0 0; min-height: 1.2em; }

/* CHUNKING */
.chunk-tool { font-size: 22px; font-weight: 700; line-height: 2.1; }
.tok {
  border: none; background: none; padding: 0 2px; border-radius: 6px;
  font-family: var(--hand); font-weight: 700; font-size: 22px;
}
.tok.stress { background: #fff1a8; text-decoration: underline 3px var(--v-red); text-underline-offset: 5px; }
.gap {
  border: none; background: none; padding: 0; width: 16px; height: 30px;
  vertical-align: middle; position: relative; color: #ccc; font-weight: 700;
}
.gap::before { content: "·"; }
.gap.on { color: var(--v-blue); width: 20px; font-size: 26px; }
.gap.on::before { content: "/"; }
.chunk-list { list-style: none; margin: 14px 0 0; padding: 0; counter-reset: c; }
.chunk-list li {
  counter-increment: c;
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px dashed #9a9a9a; padding: 8px 2px; font-size: 20px; font-weight: 700;
}
.chunk-list li::before { content: counter(c) "."; font-family: var(--display); font-size: 15px; width: 18px; }
.chunk-list li .say { margin-left: auto; border: none; background: none; font-size: 18px; padding: 0 4px; }

/* VISUALIZATION */
.viz-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.frame {
  position: relative; aspect-ratio: 5 / 6;
  border: 3px solid var(--c); border-radius: 16px; background: #fff;
  touch-action: none; overflow: hidden;
}
.frame canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.frame .num {
  position: absolute; top: 6px; left: 8px; z-index: 1;
  font-family: var(--display); font-weight: 700; color: var(--c); font-size: 15px; pointer-events: none;
}
.frame .clr {
  position: absolute; top: 4px; right: 4px; z-index: 1;
  border: none; background: none; color: #bbb; font-size: 16px; padding: 4px;
}
.frame:nth-child(odd)::after { content: ""; }
.frame::after {
  position: absolute; right: -3px; top: 50%; width: 12px; height: 20px;
  transform: translateY(-50%); background: #fff;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  border: none; z-index: 1;
}
.palette { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.crayon {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; padding: 0;
  box-shadow: 0 0 0 1.5px var(--line); background: var(--c);
}
.crayon[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--line); }
.palette .size { margin-left: auto; display: flex; gap: 6px; }

.nav-next { display: flex; gap: 10px; margin: 26px 0 0; }
.nav-next .cta { margin: 0; width: auto; flex: 1; font-size: 17px; padding: 12px; }
.nav-next .cta.alt { background: #fff; }

.page-foot { text-align: center; font-family: var(--display); font-size: 12px; color: var(--muted); padding: 22px 0 34px; }

/* ---------- 모달 / 축하 / 토스트 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(30, 25, 10, .45);
  display: grid; place-items: center; padding: 20px;
  animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 420px;
  background: #fff; border: 2px solid var(--line); border-radius: 26px;
  padding: 22px 20px; text-align: center; position: relative;
}
.sheet h3 { font-family: var(--display); font-size: 26px; margin: 4px 0 6px; }
.sheet p { margin: 0 0 14px; }
.sheet .bears { display: flex; justify-content: center; gap: 4px; margin: 6px 0 10px; background: var(--pink); border-radius: 20px; padding: 10px 6px 6px; }
.sheet .bears img { width: 52px; animation: hop 1s ease-in-out infinite; }
.sheet .bears img:nth-child(2) { animation-delay: .15s; }
.sheet .bears img:nth-child(3) { animation-delay: .3s; }
.sheet .bears img:nth-child(4) { animation-delay: .45s; }
@keyframes hop { 50% { transform: translateY(-10px); } }
.sheet label { display: block; text-align: left; font-family: var(--display); font-size: 14px; margin: 12px 0 4px; }
.sheet select, .sheet input[type=range] { width: 100%; }
.sheet select { border: 1.5px solid var(--line); border-radius: 12px; padding: 8px; background: #fff; }
.sheet .cta { width: 100%; margin: 18px 0 0; }
.sheet .danger { margin-top: 14px; background: none; border: none; color: var(--bad); text-decoration: underline; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti i {
  position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 3px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

#toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 70;
  transform: translate(-50%, 20px); opacity: 0;
  background: var(--line); color: #fff; border-radius: 999px;
  padding: 10px 18px; font-size: 17px; font-weight: 700;
  transition: .25s; pointer-events: none; white-space: nowrap;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- 휴대폰 터치 ---------- */
button, a, input, textarea, select { touch-action: manipulation; }
.topbar { padding-top: max(10px, env(safe-area-inset-top)); }
.page-foot, .footer { padding-bottom: max(34px, calc(env(safe-area-inset-bottom) + 20px)); }
.cover { padding-top: max(28px, calc(env(safe-area-inset-top) + 14px)); }
@media (hover: hover) {
  .chip:hover, .cta:hover { filter: brightness(.97); }
}

/* ---------- 패드 (세로) ---------- */
@media (min-width: 700px) {
  body { padding: 24px; font-size: 19px; }
  #app { max-width: 860px; min-height: calc(100vh - 48px); border-radius: 12px; }
  .cover { max-width: 620px; margin: 0 auto; padding-top: 44px; }
  .cover::before { left: -120px; width: 150px; }
  .stats, .cta, .section-title, .day-grid { max-width: 640px; margin-left: auto; margin-right: auto; }
  .cta { width: 640px; max-width: calc(100% - 40px); }
  .day-grid { gap: 14px; }

  .page { max-width: 760px; margin: 0 auto; padding: 8px 28px 0; }
  .page-head h2 { font-size: 38px; }
  .tabs { max-width: 420px; margin: 18px auto 4px; }
  .box { padding: 24px 26px; }
  .sentence { font-size: 30px; }
  .ko { font-size: 19px; }
  .lined, .tok, .chunk-tool { font-size: 26px; }
  .lined { line-height: 48px; background-size: 8px 100%, auto; background-image:
    linear-gradient(90deg, var(--bg, var(--cream)) 50%, transparent 0),
    repeating-linear-gradient(transparent 0 47px, #9a9a9a 47px 48px); }
  .rep-row { grid-template-columns: 130px 1fr; }
  .slot img { width: 64px; height: 88px; }
  .stamp { width: 58px; height: 58px; font-size: 14px; }
  .mic { width: 62px; height: 62px; }
  /* 워크북처럼 4칸을 가로로 */
  .viz-grid { grid-template-columns: repeat(4, 1fr); gap: 18px; }
  .frame { aspect-ratio: 3 / 4; }
  .frame:nth-child(-n+3)::after { content: ""; }
  .frame:nth-child(4)::after { content: none; }
  .crayon { width: 36px; height: 36px; }
}

/* ---------- 패드 (가로) · 노트북 ---------- */
@media (min-width: 1100px) {
  #app { max-width: 1040px; }
  .page { max-width: 960px; }
  /* 1 PAGE: 쓰기와 따라 말하기를 나란히 */
  .page-one { display: grid; grid-template-columns: 1fr 1fr; column-gap: 22px; }
  .page-one > .full { grid-column: 1 / -1; }
  .page-one > .col { display: flex; flex-direction: column; }
  .page-one > .col > .box { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
