:root {
  --bg: #0f1226;
  --card: #1a1f3d;
  --text: #f3f4ff;
  --muted: #9aa0c7;
  --accent: #ffcc33;
  --glow: #23295a;
  --inset: #141834;
  --control: #262c55;
  --control-hover: #313871;
  --empty-ball: #2a2f57;
  --shadow: rgba(0,0,0,0.35);
  --toast-bg: #ffffff;
  --toast-text: #111111;
  --c1: #fbc400;   /* 1~10 */
  --c2: #69c8f2;   /* 11~20 */
  --c3: #ff7272;   /* 21~30 */
  --c4: #aaaaaa;   /* 31~40 */
  --c5: #b0d840;   /* 41~45 */
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f5fb;
  --card: #ffffff;
  --text: #1c2040;
  --muted: #646a8f;
  --accent: #c98a00;
  --glow: #e3e7ff;
  --inset: #f0f2fa;
  --control: #e6e9f5;
  --control-hover: #d8dcee;
  --empty-ball: #dfe2f0;
  --shadow: rgba(30,40,90,0.10);
  --toast-bg: #1c2040;
  --toast-text: #ffffff;
  color-scheme: light;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  background: radial-gradient(circle at top, var(--glow) 0%, var(--bg) 60%);
  color: var(--text);
  transition: background-color .3s, color .3s;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 40px 16px;
}
.container { width: 100%; max-width: 640px; }
header { text-align: center; margin-bottom: 28px; }
header h1 { font-size: 2rem; letter-spacing: -0.02em; }
header h1 span { color: var(--accent); }
header p { color: var(--muted); margin-top: 8px; }

.card {
  background: var(--card);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: 0 10px 40px var(--shadow);
  transition: background-color .3s;
  margin-bottom: 20px;
}

.controls {
  display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap;
  margin-bottom: 24px;
}
.controls label { color: var(--muted); font-size: 0.95rem; }
select, button {
  font: inherit; border: none; border-radius: 12px; cursor: pointer;
}
select {
  background: var(--control); color: var(--text); padding: 10px 14px;
}
.btn-draw {
  background: linear-gradient(135deg, #ffd84d, #ff9f1a);
  color: #2a1a00; font-weight: 700; padding: 12px 28px; font-size: 1.05rem;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 6px 20px rgba(255,170,30,0.35);
}
.btn-draw:hover:not(:disabled) { transform: translateY(-2px); }
.btn-draw:disabled { opacity: .5; cursor: not-allowed; }

.games { display: flex; flex-direction: column; gap: 14px; }
.game {
  display: flex; align-items: center; gap: 10px;
  background: var(--inset); border-radius: 14px; padding: 12px 14px;
}
.game-label {
  width: 28px; font-weight: 700; color: var(--accent); flex-shrink: 0;
}
.balls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ball {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.05rem; color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
  box-shadow: inset -4px -6px 10px rgba(0,0,0,.25), inset 4px 4px 8px rgba(255,255,255,.35);
  animation: pop .45s cubic-bezier(.2,1.6,.4,1) both;
}
.ball.empty { background: var(--empty-ball); box-shadow: none; animation: none; color: var(--muted); }
.plus { color: var(--muted); font-weight: 700; margin: 0 2px; }
@keyframes pop {
  0% { transform: scale(0) rotate(-180deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.r1 { background: var(--c1); }
.r2 { background: var(--c2); }
.r3 { background: var(--c3); }
.r4 { background: var(--c4); }
.r5 { background: var(--c5); }

.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.btn-sub {
  background: var(--control); color: var(--text); padding: 8px 14px; font-size: .9rem;
}
.btn-sub:hover { background: var(--control-hover); }

h2 { font-size: 1.1rem; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
.history { list-style: none; display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.history li {
  display: flex; align-items: center; gap: 10px; font-size: .9rem;
  padding: 8px 10px; background: var(--inset); border-radius: 10px;
}
.history time { color: var(--muted); font-size: .8rem; width: 64px; flex-shrink: 0; }
.history .ball { width: 30px; height: 30px; font-size: .8rem; animation: none; }
.history .balls { gap: 5px; }
.empty-msg { color: var(--muted); text-align: center; padding: 12px 0; font-size: .9rem; }

.legend { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: .8rem; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

footer { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 10px; }

.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--toast-bg); color: var(--toast-text); padding: 10px 18px; border-radius: 10px; font-size: .9rem;
  opacity: 0; transition: all .25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 480px) {
  .ball { width: 36px; height: 36px; font-size: .9rem; }
  .balls { gap: 5px; }
  header h1 { font-size: 1.6rem; }
}

.topbar { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.theme-toggle {
  background: var(--card); color: var(--text);
  padding: 8px 16px; border-radius: 999px; font-size: .9rem; font-weight: 600;
  border: 1px solid var(--control-hover);
  box-shadow: 0 4px 16px var(--shadow);
  transition: transform .2s, background-color .3s;
}
.theme-toggle:hover { transform: translateY(-2px); }

/* ---------- 화면 전환 탭 ---------- */
.topbar { justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.tabs {
  display: inline-flex; gap: 4px; padding: 4px;
  background: var(--control); border-radius: 999px;
}
.tab {
  background: transparent; color: var(--muted);
  padding: 8px 16px; border-radius: 999px; font-size: .9rem; font-weight: 600;
  transition: background-color .2s, color .2s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--card); color: var(--text); box-shadow: 0 2px 8px var(--shadow); }
.view[hidden] { display: none; }

/* ---------- 메뉴 추천 ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 24px; }
.chip {
  background: var(--control); color: var(--text);
  padding: 7px 14px; border-radius: 999px; font-size: .9rem;
  border: 2px solid transparent; transition: background-color .2s, border-color .2s;
}
.chip:hover { background: var(--control-hover); }
.chip.active { border-color: var(--accent); font-weight: 700; }

.menu-result {
  background: var(--inset); border-radius: 16px;
  padding: 32px 16px; text-align: center; margin-bottom: 20px;
}
.menu-emoji { font-size: 4rem; line-height: 1.2; }
.menu-name { font-size: 1.8rem; font-weight: 800; margin-top: 8px; }
.menu-cat { color: var(--muted); margin-top: 6px; font-size: .95rem; }
.menu-result.rolling .menu-emoji,
.menu-result.rolling .menu-name { opacity: .6; }
.menu-result.done .menu-emoji { animation: pop .45s cubic-bezier(.2,1.6,.4,1) both; }
.menu-controls { margin-bottom: 0; }

.menu-photo { margin: 0 auto 4px; max-width: 420px; }
.menu-photo[hidden], .menu-emoji[hidden] { display: none; }
.menu-photo img {
  display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover;
  border-radius: 14px; box-shadow: 0 6px 20px var(--shadow);
  background: var(--control);
}
.menu-result.done .menu-photo img { animation: photoIn .4s ease-out both; }
@keyframes photoIn {
  from { opacity: 0; transform: scale(.96); }
  to { opacity: 1; transform: scale(1); }
}
.menu-photo figcaption { margin-top: 6px; font-size: .7rem; }
.menu-photo figcaption a { color: var(--muted); text-decoration: none; }
.menu-photo figcaption a:hover { text-decoration: underline; }

.menu-history { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
.menu-history li {
  background: var(--inset); border-radius: 999px; padding: 6px 12px; font-size: .9rem;
}
.menu-history li time { color: var(--muted); font-size: .8rem; margin-left: 6px; }

/* ---------- 제휴 문의 폼 ---------- */
.contact-form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .9rem; font-weight: 600; }
.field label em { color: var(--c3); font-style: normal; }
.field input, .field select, .field textarea {
  font: inherit; color: var(--text); background: var(--inset);
  border: 1px solid var(--control-hover); border-radius: 12px; padding: 11px 14px;
  transition: border-color .2s, box-shadow .2s;
}
.field textarea { resize: vertical; min-height: 120px; }
.field input::placeholder, .field textarea::placeholder { color: var(--muted); opacity: .8; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 204, 51, .25);
}
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.form-status { font-size: .9rem; min-height: 1.2em; text-align: center; }
.form-status.success { color: #2e9d5b; font-weight: 600; }
.form-status.error { color: var(--c3); font-weight: 600; }
.form-controls { margin-bottom: 0; }

/* ---------- 댓글 (Disqus) ---------- */
.comments { margin-top: 28px; }
.comments[hidden] { display: none; }
.comments h2 { margin-bottom: 8px; }
#disqus_thread { min-height: 120px; }

/* ---------- 동물상 테스트 ---------- */
.mode-switch { display: flex; justify-content: center; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.animal-pane[hidden], .animal-result[hidden], #animalPreview[hidden], .dropzone-text[hidden] { display: none; }

.dropzone {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 260px; padding: 16px; cursor: pointer;
  background: var(--inset); border: 2px dashed var(--control-hover); border-radius: 16px;
  color: var(--muted); transition: border-color .2s, background-color .2s;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); }
.dropzone.has-image { border-style: solid; padding: 8px; }
.dropzone strong { color: var(--text); }
#animalPreview { max-width: 100%; max-height: 360px; border-radius: 12px; object-fit: contain; }

.webcam-box {
  display: flex; align-items: center; justify-content: center; min-height: 260px;
  background: var(--inset); border-radius: 16px; overflow: hidden; color: var(--muted);
}
.webcam-box canvas { display: block; max-width: 100%; height: auto; border-radius: 12px; }
.webcam-controls { margin: 16px 0 0; }

.animal-status { text-align: center; color: var(--muted); font-size: .9rem; min-height: 1.2em; margin: 14px 0 0; }
.animal-status.error { color: var(--c3); font-weight: 600; }

.animal-result { text-align: center; margin-top: 20px; padding: 24px 16px; background: var(--inset); border-radius: 16px; }
.animal-emoji { font-size: 4rem; line-height: 1.2; animation: pop .45s cubic-bezier(.2,1.6,.4,1) both; }
.animal-title { font-size: 1.6rem; font-weight: 800; margin-top: 6px; }
.animal-desc { color: var(--muted); margin: 10px auto 18px; max-width: 440px; line-height: 1.6; font-size: .95rem; }
.bars { display: flex; flex-direction: column; gap: 10px; max-width: 440px; margin: 0 auto; }
.bar-row { display: grid; grid-template-columns: 92px 1fr 44px; align-items: center; gap: 10px; font-size: .9rem; }
.bar-label { text-align: left; font-weight: 600; }
.bar-track { height: 14px; background: var(--control); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 999px; transition: width .8s cubic-bezier(.2,.8,.2,1); }
.bar-pct { text-align: right; font-weight: 700; }
.animal-result .actions { justify-content: center; margin-top: 18px; }
.privacy-note { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 16px; }

/* 탭이 많아져도 휴대폰에서 넘치지 않게 옆으로 스크롤 */
.tabs { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { white-space: nowrap; flex-shrink: 0; }
