:root {
  --bg: #FCEFAF;
  --bg-deep: #F7E48C;
  --card: #FFFBEE;
  --ink: #2E2417;
  --ink-soft: #7A6C50;
  --accent: #E85B2D;
  --accent-soft: #F2A98A;
  --custard: #F0C550;
  --custard-light: #F7DA8C;
  --caramel: #7A4A22;
  --correct: #4C8C5A;
  --wrong: #C4462B;
  --border: #E9DDB5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 15% -10%, var(--bg-deep) 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: 'Noto Sans KR', sans-serif;
  word-break: keep-all;
  overflow-wrap: break-word;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.stage {
  width: 100%;
  max-width: 780px;
  display: flex;
  gap: 22px;
  align-items: stretch;
}

/* ---------- 왼쪽 게이지: 캐러멜 게이지 + 완성된 푸딩 ---------- */
.gauge-panel {
  flex: 0 0 92px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding-top: 2px;
}

.pudding-counter {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--caramel);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.pudding-wrap {
  position: relative;
  width: 64px;
  height: 155px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.pudding-cup {
  position: relative;
  width: 56px;
  height: 140px;
  border: 2.5px solid var(--caramel);
  border-radius: 12px 12px 26px 26px;
  background: rgba(255, 255, 255, .5);
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(122, 74, 34, .12);
}

.pudding-fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 0%;
  background: linear-gradient(180deg, #E3AE66, #C9853D 55%, var(--caramel) 100%);
  transition: height .5s cubic-bezier(.34,1.4,.5,1);
  border-radius: 0 0 22px 22px;
}

.pudding-fill::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 6px;
  background: var(--caramel);
  opacity: .5;
  border-radius: 50%;
}

/* 접시 + 완성되는 푸딩 (실제 이미지로 교체: 사진 느낌의 꽃모양 몰드 푸딩) */
.plate-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 14px; /* 캐러멜 게이지 컵과 살짝 떨어뜨려요 */
}

.plated-pudding {
  position: relative;
  width: 108px;
  transform-origin: 50% 85%;
}
.plated-pudding.complete {
  animation: puddingPop .6s ease;
}
@keyframes puddingPop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.pudding-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
}

/* 완성 전(커스터드)과 완성 후(캐러멜) 이미지를 겹쳐두고 opacity로 자연스럽게 전환해요 */
.pudding-img-empty {
  position: relative;
}
.pudding-img-caramel {
  position: absolute;
  top: 0; left: 0;
  opacity: 0;
  transition: opacity .6s ease;
}
.pudding-img-caramel.show {
  opacity: 1;
}

.sparkle {
  position: absolute;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
}
.sparkle.s1 { top: 2px; left: 8px; }
.sparkle.s2 { top: -2px; right: 6px; }
.sparkle.s3 { top: 14px; left: 50%; margin-left: -7px; }
.sparkle.s1.show { animation: sparklePop .8s ease .05s; }
.sparkle.s2.show { animation: sparklePop .8s ease .15s; }
.sparkle.s3.show { animation: sparklePop .8s ease .25s; }
@keyframes sparklePop {
  0%   { opacity: 0; transform: translateY(4px) scale(.5); }
  40%  { opacity: 1; transform: translateY(-4px) scale(1.15); }
  100% { opacity: 0; transform: translateY(-10px) scale(.9); }
}

/* ---------- 메인 카드 ---------- */
.card {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 34px 32px;
  display: flex;
  flex-direction: column;
  min-height: 420px;
  box-shadow: 0 18px 40px rgba(122, 74, 34, .08);
}

.brand {
  display: flex;
  align-self: flex-start;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  text-decoration: none;
}
.brand img {
  width: 34px;
  height: 34px;
  border-radius: 9px;
}
.brand span {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 15px;
  color: var(--ink-soft);
  letter-spacing: .01em;
}

/* 시작 화면 */
.start-screen {
  margin: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.start-screen img.hero-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  margin-bottom: 2px;
}
.start-screen .kicker {
  color: var(--accent);
  font-size: 13px;
  letter-spacing: .04em;
}
.start-screen h1 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 32px;
  margin: 0;
  line-height: 1.35;
  color: var(--ink);
}
.start-screen p {
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.7;
  max-width: 380px;
}

button {
  font-family: 'Noto Sans KR', sans-serif;
  font-weight: 700;
  font-size: 15.5px;
  letter-spacing: .01em;
  border: none;
  border-radius: 999px;
  padding: 13px 32px;
  cursor: pointer;
  background: var(--accent);
  color: #FFF8EA;
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
}
button:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(232, 91, 45, .28); }
button:active { transform: translateY(0); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

button.secondary {
  background: transparent;
  color: var(--ink-soft);
  border: 1.5px solid var(--border);
}
button.ghost {
  background: transparent;
  color: var(--ink-soft);
  padding: 13px 20px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
}
button.ghost:hover { color: var(--accent); box-shadow: none; }

/* 퀴즈 화면 */
.quiz-screen { display: none; flex-direction: column; height: 100%; gap: 22px; }
.quiz-screen.active { display: flex; }

.quiz-top {
  display: flex;
  align-items: center;
  gap: 10px;
}
.category-badge {
  display: inline-block;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  color: var(--caramel);
  font-size: 13px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
}
.level-badge {
  font-size: 12px;
  color: var(--ink-soft);
  margin-left: auto;
}

.combo-badge {
  display: none;
  align-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #F2914D);
  padding: 5px 11px;
  border-radius: 999px;
}
.combo-badge.pop {
  animation: comboPop .4s ease;
}
@keyframes comboPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.question-box { flex: 1; display: flex; align-items: center; }
.question-box p {
  font-family: 'Noto Sans KR', sans-serif;
  font-weight: 700;
  font-size: 21px;
  line-height: 1.85;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
  word-break: keep-all;
  overflow-wrap: break-word;
  white-space: pre-line;
}

.answer-row { display: flex; gap: 10px; flex-wrap: wrap; }
#answer-input,
.key-field input {
  flex: 1;
  min-width: 160px;
  background: #FFFDF6;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 16px;
  color: var(--ink);
  font-family: inherit;
}
#answer-input:focus,
.key-field input:focus { outline: none; border-color: var(--accent); }
#answer-input::placeholder,
.key-field input::placeholder { color: var(--ink-soft); opacity: .7; }

.result-box {
  display: none;
  border-radius: 16px;
  padding: 18px 20px;
  flex-direction: column;
  gap: 8px;
}
.result-box.show { display: flex; }
.result-box.correct { background: rgba(76, 140, 90, .10); border: 1px solid var(--correct); }
.result-box.wrong { background: rgba(196, 70, 43, .08); border: 1px solid var(--wrong); }

.result-title {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 20px;
}
.result-box.correct .result-title { color: var(--correct); }
.result-box.wrong .result-title { color: var(--wrong); }

.result-explain { color: var(--ink-soft); font-size: 14.5px; line-height: 1.6; }

.voice-status {
  font-size: 12.5px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 16px;
}
.voice-status.speaking::before {
  content: "";
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.quiz-bottom { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
/* 채점 전에는 '다음 문제'를 숨겨요 (스크립트가 채점 뒤에 보여줘요) */
#next-btn { display: none; }

/* ---------- API 키 입력 (시작 화면) ---------- */
.key-form {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}
.key-field { display: flex; flex-direction: column; gap: 7px; }
.key-label {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}
.tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.tag.req { background: var(--accent); color: #FFF8EA; }
.tag.opt { background: var(--bg-deep); color: var(--caramel); border: 1px solid var(--border); }
.key-link {
  margin-left: auto;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.key-link:hover { text-decoration: underline; }
.key-field input { width: 100%; font-size: 16px; }
.key-hint { font-size: 12px; color: var(--ink-soft); line-height: 1.5; }
.remember {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
}
.remember input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.remember span { font-size: 12px; color: var(--ink-soft); }
#start-btn { align-self: center; margin-top: 4px; min-width: 160px; }
.start-screen .key-error { margin: 0; color: var(--wrong); font-size: 13.5px; text-align: center; line-height: 1.5; }
.start-screen .key-error:empty { display: none; }
.start-screen .key-note { margin: 0; color: var(--ink-soft); font-size: 12px; text-align: center; line-height: 1.6; }

/* ---------- 퀴즈 화면 아래: 지금 목소리 + 키 변경 ---------- */
.voice-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  font-size: 12px;
  color: var(--ink-soft);
}
button.link-btn {
  background: transparent;
  color: var(--ink-soft);
  padding: 4px 0;
  font-size: 12px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  white-space: nowrap;
}
button.link-btn:hover { color: var(--accent); transform: none; box-shadow: none; }

@media (max-width: 560px) {
  .stage { flex-direction: column; }
  .gauge-panel { flex-direction: row; width: 100%; padding-top: 0; gap: 14px; }
  .pudding-wrap { width: 60px; height: 60px; }
  .pudding-cup { width: 56px; height: 56px; border-radius: 10px 10px 16px 16px; }
  .plate-wrap { margin-top: 0; width: auto; }
  .plated-pudding { width: 76px; }
  /* 좁은 화면에선 문장 중간의 강제 줄바꿈이 한 단어짜리 줄을 만들어서, 문단 구분만 남겨요 */
  .br-wide { display: none; }
}
