/* =========================================================
   클라라 영어공부방 — 아이 화면
   로고의 크레용 꽃처럼: 크림 종이 위에 초록 줄기, 노란 꽃잎
   ========================================================= */
:root {
  --paper: #fffaf5;
  --surface: #ffffff;
  --ink: #2b2a22;
  --muted: #6d6a5c;
  --line: #ebe2d5;
  --green: #55732a;
  --green-mid: #91b05f;
  --green-soft: #eef4e2;
  --yellow: #ffc000;
  --yellow-soft: #fff3cc;
  --red: #c0442f;
  --red-soft: #fbe3dd;
  --on-green: #ffffff;
  --shadow: 0 2px 0 rgba(85, 115, 42, 0.18);
  --display: "Jua", "IBM Plex Sans KR", "Apple SD Gothic Neo", sans-serif;
  --font: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1a1b14;
    --surface: #24261c;
    --ink: #f1efe6;
    --muted: #b0ad9b;
    --line: #3a3c2e;
    --green: #a9c67a;
    --green-mid: #91b05f;
    --green-soft: #2b361d;
    --yellow: #ffc94a;
    --yellow-soft: #3a3012;
    --red: #f1806f;
    --red-soft: #3d1f1b;
    --on-green: #1a1b14;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh;
  background: var(--paper); color: var(--ink);
  font-family: var(--font); font-size: 17px; line-height: 1.55;
  word-break: keep-all; overflow-wrap: anywhere;
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--display); font-weight: 400; margin: 0; line-height: 1.2; letter-spacing: 0; }
p { margin: 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.wrap { max-width: 34rem; margin: 0 auto; padding: 1rem 1rem 3rem; }
.loading { text-align: center; color: var(--muted); padding: 4rem 1rem; }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 52px; padding: 0 1.3rem; border-radius: 16px;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink);
  font-family: var(--display); font-size: 1.15rem; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--green); border-color: var(--green); color: var(--on-green); box-shadow: 0 3px 0 rgba(0,0,0,0.15); }
.btn.yellow { background: var(--yellow); border-color: var(--yellow); color: #2b2a22; box-shadow: 0 3px 0 rgba(0,0,0,0.12); }
.btn.block { width: 100%; }
.btn.small { min-height: 40px; font-size: 1rem; padding: 0 0.9rem; border-radius: 12px; }
.btn:disabled { opacity: 0.45; cursor: default; box-shadow: none; }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.link { background: none; border: 0; color: var(--green); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 0.4rem; }
input {
  width: 100%; min-height: 56px; padding: 0 1rem;
  border: 2px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink);
  font: inherit; font-size: 1.25rem;
}
input:focus { border-color: var(--green-mid); outline: none; }

/* 상단 */
.bar { display: flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0 0.75rem; }
.bar img { width: 34px; height: 46px; object-fit: contain; }
.bar .name { font-family: var(--display); font-size: 1.2rem; }
.bar .spacer { flex: 1; }
.back { background: none; border: 0; font-family: var(--display); font-size: 1.1rem; color: var(--muted); cursor: pointer; padding: 0.5rem 0.5rem 0.5rem 0; min-height: 44px; }
.starpill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  background: var(--yellow-soft); border-radius: 99px; padding: 0.25rem 0.8rem 0.25rem 0.55rem;
  font-family: var(--display); font-size: 1.15rem;
}
.starpill .star { width: 22px; height: 22px; }

/* 로그인 */
.login { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 1.5rem 1.25rem; max-width: 26rem; margin: 0 auto; text-align: center; }
.login .logo { width: min(280px, 78%); margin: 0 auto 1.5rem; }
.login h1 { font-size: 1.6rem; margin-bottom: 1rem; }
.login form { display: flex; flex-direction: column; gap: 0.8rem; }
.login input { text-align: center; text-transform: lowercase; }
.login .err { color: var(--red); font-weight: 600; min-height: 1.6em; }
.dots { display: flex; justify-content: center; gap: 0.9rem; margin: 0.5rem 0 1rem; }
.dots i { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--green-mid); }
.dots i.on { background: var(--green); border-color: var(--green); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.7rem; max-width: 20rem; margin: 0 auto; width: 100%; }
.keypad button {
  min-height: 64px; border-radius: 18px; border: 2px solid var(--line); background: var(--surface);
  font-family: var(--display); font-size: 1.8rem; cursor: pointer;
}
.keypad button:active { background: var(--green-soft); }
.keypad .fn { font-size: 1.05rem; color: var(--muted); }

/* 홈 */
.hello { margin: 0.5rem 0 1.2rem; }
.hello h1 { font-size: 2.1rem; }
.hello p { color: var(--muted); margin-top: 0.3rem; }
.stars-big { display: flex; align-items: center; gap: 0.8rem; background: var(--surface); border: 2px solid var(--line); border-radius: 22px; padding: 0.9rem 1.1rem; margin-bottom: 1.4rem; box-shadow: var(--shadow); }
.stars-big .star { width: 48px; height: 48px; flex: none; }
.stars-big b { font-family: var(--display); font-weight: 400; font-size: 2.4rem; line-height: 1; }
.stars-big small { display: block; color: var(--muted); font-size: 0.9rem; }

.section-title { font-size: 1.35rem; margin: 1.4rem 0 0.7rem; display: flex; align-items: baseline; gap: 0.5rem; }
.section-title small { font-family: var(--font); font-size: 0.9rem; color: var(--muted); }

.hw { background: var(--surface); border: 2px solid var(--line); border-radius: 24px; padding: 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.hw.done { border-color: var(--green-mid); }
.hw-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.6rem; }
.hw-head h3 { font-size: 1.35rem; }
.hw-head .class { color: var(--muted); font-size: 0.9rem; }
.due { flex: none; font-size: 0.85rem; font-weight: 600; padding: 0.2rem 0.65rem; border-radius: 99px; background: var(--green-soft); color: var(--green); white-space: nowrap; }
.due.today { background: var(--yellow-soft); color: #8a5a00; }
.due.over { background: var(--red-soft); color: var(--red); }
@media (prefers-color-scheme: dark) { .due.today { color: var(--yellow); } }
.hw-note { margin-top: 0.6rem; background: var(--paper); border-radius: 12px; padding: 0.6rem 0.8rem; font-size: 0.95rem; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin-top: 0.9rem; }
.tile {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.25rem;
  min-height: 112px; padding: 0.8rem 0.5rem; border-radius: 20px;
  border: 2px solid transparent; background: var(--green-soft); cursor: pointer; text-align: center;
}
.tile svg { width: 34px; height: 34px; stroke: var(--green); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tile b { font-family: var(--display); font-weight: 400; font-size: 1.15rem; }
.tile small { color: var(--muted); font-size: 0.82rem; }
.tile.done { background: var(--yellow-soft); }
.tile.done::after {
  content: "✓"; position: absolute; top: 8px; right: 10px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--yellow); color: #2b2a22; display: grid; place-items: center; font-weight: 700; font-size: 0.95rem;
}
.tile.locked { background: var(--paper); border: 2px dashed var(--line); cursor: default; }
.tile.locked svg { stroke: var(--muted); }
.tile.wide { grid-column: 1 / -1; min-height: 80px; flex-direction: row; gap: 0.7rem; }
.feedback { margin-top: 0.9rem; display: flex; gap: 0.6rem; align-items: flex-start; background: var(--yellow-soft); border-radius: 16px; padding: 0.75rem 0.9rem; }
.feedback img { width: 30px; height: 40px; object-fit: contain; flex: none; }
.feedback b { display: block; font-size: 0.82rem; color: var(--muted); font-weight: 600; }

.nothing { text-align: center; background: var(--surface); border: 2px dashed var(--line); border-radius: 24px; padding: 2rem 1rem; }
.nothing img { width: 70px; height: 90px; object-fit: contain; }
.nothing h3 { font-size: 1.3rem; margin: 0.5rem 0 0.3rem; }

.books { background: var(--surface); border: 2px solid var(--line); border-radius: 24px; padding: 1rem 1.1rem; }
.books ul { list-style: none; margin: 0.6rem 0 0; padding: 0; }
.books li { display: flex; justify-content: space-between; gap: 0.6rem; padding: 0.55rem 0; border-top: 1px solid var(--line); }
.books li span { font-weight: 600; }
.books li small { flex: none; color: var(--muted); }
.books li small.over { color: var(--red); font-weight: 600; }
.books .count { font-family: var(--display); font-size: 1.1rem; }
.logout { display: block; margin: 2rem auto 0; color: var(--muted); }

/* 공부 화면 공통 */
.study-head { margin: 0.3rem 0 1rem; }
.study-head h1 { font-size: 1.7rem; }
.study-head p { color: var(--muted); }
.progress { height: 12px; border-radius: 99px; background: var(--green-soft); overflow: hidden; margin: 0.8rem 0 1.2rem; }
.progress i { display: block; height: 100%; background: var(--green-mid); border-radius: 99px; transition: width 0.3s; }

/* 단어 카드 */
.flash {
  position: relative; min-height: 260px; border-radius: 28px; border: 2px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; padding: 1.5rem 1rem;
  cursor: pointer; box-shadow: var(--shadow); text-align: center; width: 100%;
}
.flash .en { font-family: var(--display); font-size: clamp(2.2rem, 11vw, 3.4rem); line-height: 1.1; }
.flash .ko { font-size: 1.5rem; font-weight: 600; color: var(--green); min-height: 1.6em; }
.flash .hint { color: var(--muted); font-size: 0.9rem; }
.speak {
  width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--yellow); color: #2b2a22;
  display: grid; place-items: center; cursor: pointer; box-shadow: 0 3px 0 rgba(0,0,0,0.12); flex: none;
}
.speak svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.speak.sm { width: 48px; height: 48px; }
.speak.sm svg { width: 24px; height: 24px; }
.nav-row { display: flex; gap: 0.6rem; align-items: center; justify-content: space-between; margin-top: 1rem; }
.nav-row .btn { flex: 1; }

/* 문제 */
.q-card { background: var(--surface); border: 2px solid var(--line); border-radius: 28px; padding: 1.4rem 1rem; text-align: center; box-shadow: var(--shadow); }
.q-card .ask { color: var(--muted); font-size: 0.95rem; margin-bottom: 0.4rem; }
.q-card .prompt { font-family: var(--display); font-size: 2rem; line-height: 1.2; }
.q-card .speak { margin: 0.3rem auto 0; }
.choices { display: grid; gap: 0.6rem; margin-top: 1rem; }
.choice {
  min-height: 60px; border-radius: 18px; border: 2px solid var(--line); background: var(--surface);
  font-family: var(--display); font-size: 1.4rem; cursor: pointer;
}
.choice.right { background: var(--green-soft); border-color: var(--green); color: var(--green); }
.choice.wrong { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.spell { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.spell input { text-align: center; font-family: var(--display); font-size: 1.7rem; letter-spacing: 0.04em; }
.spell input.right { border-color: var(--green); background: var(--green-soft); }
.spell input.wrong { border-color: var(--red); background: var(--red-soft); }
.answer { min-height: 2.2em; margin-top: 0.6rem; font-weight: 600; text-align: center; }
.answer.good { color: var(--green); }
.answer.bad { color: var(--red); }
.result { text-align: center; padding: 1rem 0; }
.result .big { font-family: var(--display); font-size: 4rem; line-height: 1; color: var(--green); }
.result h2 { font-size: 1.7rem; margin: 0.6rem 0 0.4rem; }
.result .actions { display: grid; gap: 0.6rem; margin-top: 1.4rem; }

/* 문장 녹음 */
.sent { background: var(--surface); border: 2px solid var(--line); border-radius: 24px; padding: 1.1rem; margin-bottom: 0.9rem; box-shadow: var(--shadow); }
.sent.sent-done { border-color: var(--green-mid); }
.sent .num { font-family: var(--display); color: var(--muted); font-size: 0.95rem; }
.sent .en { font-family: var(--display); font-size: 1.6rem; line-height: 1.3; margin: 0.2rem 0; }
.sent .ko { color: var(--muted); font-size: 0.95rem; }
.sent .ctrl { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.8rem; }
.rec {
  display: inline-flex; align-items: center; gap: 0.45rem; min-height: 48px; padding: 0 1.1rem; border-radius: 99px;
  border: 0; background: var(--red); color: #fff; font-family: var(--display); font-size: 1.1rem; cursor: pointer;
}
.rec i { width: 14px; height: 14px; border-radius: 50%; background: #fff; }
.rec.on i { border-radius: 3px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
.sent .status { width: 100%; font-size: 0.9rem; font-weight: 600; color: var(--green); }
.sent .status.warn { color: var(--red); }

/* 체크리스트 */
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.checklist button {
  width: 100%; display: flex; align-items: center; gap: 0.9rem; text-align: left;
  min-height: 70px; padding: 0.8rem 1rem; border-radius: 20px; border: 2px solid var(--line); background: var(--surface);
  font-size: 1.1rem; font-weight: 600; cursor: pointer;
}
.checklist .box { width: 34px; height: 34px; border-radius: 10px; border: 3px solid var(--green-mid); flex: none; display: grid; place-items: center; color: transparent; font-weight: 700; font-size: 1.2rem; }
.checklist [aria-checked="true"] { background: var(--green-soft); border-color: var(--green-mid); }
.checklist [aria-checked="true"] .box { background: var(--green); border-color: var(--green); color: var(--on-green); }
.checklist [aria-checked="true"] .txt { text-decoration: line-through; text-decoration-thickness: 2px; color: var(--muted); }

/* 게임 */
.game-top { display: flex; justify-content: space-between; align-items: center; font-family: var(--display); font-size: 1.2rem; margin-bottom: 0.8rem; }
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.55rem; }
@media (min-width: 480px) { .board { grid-template-columns: repeat(4, 1fr); } }
.tilecard {
  min-height: 84px; border-radius: 18px; border: 2px solid var(--line); background: var(--surface);
  font-size: 1.05rem; font-weight: 700; padding: 0.4rem; cursor: pointer; line-height: 1.25;
  transition: transform 0.15s, opacity 0.25s;
}
.tilecard.en { font-family: var(--display); font-weight: 400; font-size: 1.3rem; }
.tilecard.sel { border-color: var(--yellow); background: var(--yellow-soft); transform: scale(1.04); }
.tilecard.gone { opacity: 0; pointer-events: none; transform: scale(0.85); }
.tilecard.miss { animation: shake 0.35s; border-color: var(--red); }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.board-list { list-style: none; margin: 1rem 0 0; padding: 0; text-align: left; }
.board-list li { display: flex; justify-content: space-between; padding: 0.5rem 0.2rem; border-top: 1px solid var(--line); }
.board-list li.me { font-weight: 700; color: var(--green); }

/* 별 받기 */
.cheer {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; pointer-events: none;
  background: rgba(255, 250, 245, 0.7);
}
@media (prefers-color-scheme: dark) { .cheer { background: rgba(26, 27, 20, 0.7); } }
.cheer div { text-align: center; animation: pop 1.6s ease-out forwards; }
.cheer .star { width: 140px; height: 140px; filter: drop-shadow(0 6px 0 rgba(0,0,0,0.1)); }
.cheer b { display: block; font-family: var(--display); font-weight: 400; font-size: 2.2rem; color: var(--green); }
@keyframes pop {
  0% { transform: scale(0.3) rotate(-25deg); opacity: 0; }
  25% { transform: scale(1.12) rotate(6deg); opacity: 1; }
  40% { transform: scale(1) rotate(0); }
  80% { opacity: 1; }
  100% { transform: translateY(-40px); opacity: 0; }
}

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 1.5rem); z-index: 60;
  transform: translate(-50%, 1rem); opacity: 0; pointer-events: none;
  max-width: min(26rem, calc(100vw - 2rem)); width: max-content;
  padding: 0.8rem 1.1rem; border-radius: 14px; background: var(--ink); color: var(--paper);
  font-weight: 600; text-align: center; transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--red); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .cheer div { opacity: 1; }
}
