/* ColorMix 디자인 시스템 — 무채색 UI. 색 있는 픽셀은 목표색·내 색·팔레트·별뿐. */
:root {
  --bg: #101014;
  --surface: #1b1b21;
  --line: #2e2e36;
  --text: #ededf0;
  --text-dim: #8a8a93;
  --star: #f5c84b;

  --radius: 12px;
  --tabbar-h: 60px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, "Pretendard", "Noto Sans JP", monospace;
  /* 본문: 라틴=Poppins, 한글=Pretendard, 일본어=Noto Sans JP (글리프별 폴백) */
  --sans: "Poppins", "Pretendard", "Noto Sans JP", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  /* 디스플레이(제목·버튼·큰 숫자 라벨): 둥근 게임체 Fredoka + 한글 Jua + 일본어 Noto Sans JP */
  --display: "Fredoka", "Jua", "Noto Sans JP", "Pretendard", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

/* 폼 요소(button/input 등)는 기본적으로 폰트를 상속하지 않으므로 강제 상속 */
button, input, textarea, select { font-family: inherit; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--display);
  font-size: 14px;
  line-height: 1.5;
  overscroll-behavior: none;
}
body { user-select: none; -webkit-user-select: none; }

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

#screen {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 16px calc(16px + var(--safe-b));
  -webkit-overflow-scrolling: touch;
}
#screen.with-tabbar { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); }

h1 { font-size: 19px; font-weight: 600; font-family: var(--display); letter-spacing: 0.01em; }
h2 { font-size: 16px; font-weight: 600; font-family: var(--display); }
.dim { color: var(--text-dim); }
.mono { font-family: var(--mono); }
.caption { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; }
.spread { display: flex; align-items: center; justify-content: space-between; }
.muted-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

/* ── 버튼 ── */
.btn {
  height: 48px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-family: var(--display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 18px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn.ghost { border-color: rgba(255, 255, 255, 0.6); }
.btn.primary { border-color: var(--text); background: var(--text); color: var(--bg); }
.btn.full { width: 100%; }
.btn.sm { height: 38px; font-size: 13px; padding: 0 14px; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }

/* ── 탭바 ── */
.tabbar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: rgba(16, 16, 20, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 20;
}
.tabbar button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--display);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
}
.tabbar button .ico { line-height: 0; opacity: 0.9; }
.tabbar button .ico svg { width: 23px; height: 23px; display: block; }
.tabbar button.active { color: var(--text); }
.tabbar button.active .ico { opacity: 1; }
.tabbar button .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--star); position: absolute; top: 8px; margin-left: 16px; }

/* ── 색 원 (목표색/현재색) ── */
.color-circle { width: 34vw; max-width: 160px; aspect-ratio: 1; border-radius: 50%; }
.swatch-label { font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; color: var(--text-dim); }

/* ── 게임 화면 ── */
.game-header { display: flex; align-items: center; justify-content: space-between; min-height: 36px; margin-bottom: 8px; }
.iconbtn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 18px; cursor: pointer; display: grid; place-items: center; }
.game-main { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 8px 0; }
.target-block, .current-block { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.current-wrap { position: relative; display: grid; place-items: center; }
.gauge { position: absolute; inset: 0; transform: rotate(-90deg); pointer-events: none; }
.match-num { font-family: var(--mono); font-size: 40px; font-weight: 700; line-height: 1; }
.match-num .pct { font-size: 18px; color: var(--text-dim); }

.history { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-height: 28px; justify-content: center; }
.history .chip { width: 20px; height: 20px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.15); }
.history .arrow { color: var(--text-dim); font-size: 12px; }
.history .q { color: var(--text-dim); font-family: var(--mono); }
.moves-left { font-family: var(--mono); font-size: 13px; color: var(--text-dim); }

.palette { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; padding: 4px 0; }
.pbtn {
  width: 60px; height: 60px; border: none; background: none; cursor: pointer;
  display: grid; place-items: center; position: relative;
}
.pbtn .disc {
  width: 52px; height: 52px; border-radius: 50%;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 0 0 0 rgba(255,255,255,0);
}
.pbtn.selected .disc { transform: scale(1.08); box-shadow: 0 0 0 2px #fff; }
.pbtn .cb-label { position: absolute; bottom: -2px; font-family: var(--mono); font-size: 8px; color: var(--text-dim); white-space: nowrap; }
.pbtn:disabled { opacity: 0.35; cursor: default; }

/* 혼합 애니메이션: 팔레트 → 현재색 흡입 */
.fly {
  position: fixed; border-radius: 50%; z-index: 50; pointer-events: none;
  transition: transform 240ms cubic-bezier(0.4, 0, 0.2, 1), opacity 240ms;
}

/* ── 월드맵 ── */
.worldmap-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.world-switch { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 6px 0 2px; }
.world-switch .wname { font-size: 19px; font-weight: 600; min-width: 120px; text-align: center; font-family: var(--display); }
.world-switch .navbtn { font-size: 22px; color: var(--text); background: none; border: none; cursor: pointer; padding: 4px 8px; }
.world-switch .navbtn:disabled { color: var(--line); cursor: default; }
.world-desc { text-align: center; color: var(--text-dim); margin-bottom: 18px; font-size: 13px; }
.node-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px 6px; margin-bottom: 20px; }
.node { display: flex; flex-direction: column; align-items: center; gap: 5px; background: none; border: none; cursor: pointer; padding: 4px 0; }
.node .disc { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--line); position: relative; }
.node .disc.locked { background: var(--line) !important; color: var(--text-dim); font-size: 16px; }
.node .disc.current { box-shadow: 0 0 0 2px #fff; }
.node .num { position: absolute; font-family: var(--mono); font-size: 10px; color: rgba(0,0,0,0.55); font-weight: 700; }
.node .num.onlight { color: rgba(0,0,0,0.6); }
.node .num.ondark { color: rgba(255,255,255,0.75); }
.node .stars { font-size: 10px; letter-spacing: 1px; height: 12px; }
.node.shake { animation: shake 0.4s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-5px)} 75%{transform:translateX(5px)} }
.unlock-hint { text-align: center; color: var(--text-dim); font-family: var(--mono); font-size: 12px; margin-top: 8px; }

.star { color: var(--star); }
.star.off { color: var(--line); }

/* ── 리더보드 ── */
.segment { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 3px; margin-bottom: 14px; }
.segment button { flex: 1; height: 34px; border: none; background: none; color: var(--text-dim); font-family: var(--display); font-size: 13px; font-weight: 600; border-radius: 9px; cursor: pointer; }
.segment button.active { background: var(--line); color: var(--text); }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 11px 8px; border-bottom: 1px solid var(--line); }
.lb-row .rank { font-family: var(--mono); font-size: 13px; width: 34px; color: var(--text-dim); }
.lb-row .nick { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .score { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.lb-row.me { background: var(--surface); border-radius: 10px; position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b)); border-bottom: 1px solid var(--line); }
.lb-row.me .nick { font-weight: 600; }
.lb-foot { text-align: center; color: var(--text-dim); font-family: var(--mono); font-size: 12px; padding: 12px; }

/* ── 결과 오버레이 ── */
.overlay { position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; gap: 14px; }
.result-stars { font-size: 40px; letter-spacing: 8px; height: 48px; }
.result-stars .s { opacity: 0; transform: scale(0.4); display: inline-block; }
.result-stars .s.in { animation: starpop 0.34s forwards; }
@keyframes starpop { to { opacity: 1; transform: scale(1); } }
.result-title { font-size: 23px; font-weight: 700; letter-spacing: 0.03em; font-family: var(--display); }
.result-line { font-family: var(--mono); font-size: 15px; }
.result-sub { color: var(--text-dim); font-size: 13px; }
.scrim { background: rgba(16,16,20,0.55); backdrop-filter: blur(2px); }
.result-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; align-items: center; }

.fullscreen-celebrate { position: absolute; inset: 0; z-index: 60; display: grid; place-items: center; text-align: center; padding: 30px; }

/* 클리어 시그니처 확장 */
.expand-circle { position: fixed; border-radius: 50%; z-index: 40; transition: transform 600ms cubic-bezier(0.5, 0, 0.2, 1); pointer-events: none; }

/* ── 토스트 ── */
.toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + 20px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 80; pointer-events: none; }
.toast { background: var(--surface); border: 1px solid var(--line); color: var(--text); padding: 10px 16px; border-radius: 20px; font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,0.4); animation: toastin 0.2s; max-width: 88%; }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } }

/* ── 다이얼로그 ── */
.dialog-scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.6); z-index: 70; display: grid; place-items: center; padding: 24px; }
.dialog { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 14px; }

/* ── 폼 ── */
input[type="text"] { width: 100%; height: 46px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; color: var(--text); font-family: var(--display); font-size: 15px; padding: 0 14px; }
input[type="text"]:focus { outline: none; border-color: var(--text-dim); }
.switch { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }

/* 언어 인라인 국기 선택 — 버튼 자체가 국기 모양(SVG) */
.lang-flags { display: flex; gap: 8px; }
.lang-flags button {
  width: 36px; height: 24px; padding: 0; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 5px; background: none; cursor: pointer;
  opacity: 0.45; filter: grayscale(0.6);
  transition: opacity 0.15s, filter 0.15s, box-shadow 0.15s, transform 0.1s;
  display: block; line-height: 0;
}
.lang-flags button svg { width: 100%; height: 100%; display: block; }
.lang-flags button:active { transform: scale(0.92); }
.lang-flags button.active { opacity: 1; filter: none; border-color: var(--text); box-shadow: 0 0 0 2px var(--text); }
.toggle { width: 46px; height: 28px; border-radius: 14px; background: var(--line); border: none; position: relative; cursor: pointer; transition: background 0.2s; flex-shrink: 0; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--text-dim); transition: transform 0.2s, background 0.2s; }
.toggle.on { background: var(--text); }
.toggle.on::after { transform: translateX(18px); background: var(--bg); }

.list-item { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--line); }
.archive-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.archive-item .disc { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); flex-shrink: 0; }
.archive-item .meta { flex: 1; }
.archive-item .play { font-size: 18px; color: var(--text-dim); }

.section-title { font-size: 13px; color: var(--text-dim); margin: 22px 0 8px; font-weight: 600; }
.stat-line { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14px; }
.stat-line .v { font-family: var(--mono); }

.empty { text-align: center; color: var(--text-dim); padding: 50px 20px; }

/* ── 게임 테마 로더: 빛 혼합(screen)으로 색 방울이 돌며 겹쳐 섞임 ── */
.cm-loader { display: flex; flex-direction: column; align-items: center; gap: 18px; margin: 64px auto; }
.cm-loader-orbit { position: relative; width: 86px; height: 86px; animation: cm-spin 2.6s linear infinite; }
.cm-loader-orbit .b {
  position: absolute; width: 48px; height: 48px; border-radius: 50%;
  filter: blur(1.5px); mix-blend-mode: screen;
  animation: cm-pulse 1.6s ease-in-out infinite;
}
.cm-loader-orbit .b1 { background: #ff4d57; top: 0; left: 19px; animation-delay: 0s; }
.cm-loader-orbit .b2 { background: #41d488; bottom: 0; left: 0; animation-delay: 0.53s; }
.cm-loader-orbit .b3 { background: #4d8bff; bottom: 0; right: 0; animation-delay: 1.06s; }
.cm-loader-label {
  font-family: var(--display); font-size: 13px; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--text-dim); animation: cm-fade 1.6s ease-in-out infinite;
}
@keyframes cm-spin { to { transform: rotate(360deg); } }
@keyframes cm-pulse { 0%, 100% { transform: scale(0.8); } 50% { transform: scale(1.14); } }
@keyframes cm-fade { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.85; } }

/* 모션 최소화 시: 정적이지만 색이 겹친 채로 보이도록 */
body.reduce-motion .cm-loader-orbit, body.reduce-motion .cm-loader-orbit .b, body.reduce-motion .cm-loader-label { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .cm-loader-orbit, .cm-loader-orbit .b, .cm-loader-label { animation: none; }
}

/* 구형 스피너 (호환용, 미사용) */
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--text); border-radius: 50%; animation: spin 0.7s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { display: inline-block; font-size: 11px; font-family: var(--mono); padding: 2px 8px; border-radius: 10px; border: 1px solid var(--line); color: var(--text-dim); }
.badge.warn { border-color: var(--star); color: var(--star); }

.code-box { font-family: var(--mono); font-size: 20px; letter-spacing: 0.1em; text-align: center; padding: 16px; background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; }

/* ── 스플래시 (초기 접속 랜딩) ── */
#splash {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; text-align: center; padding: 32px;
  cursor: pointer;
  /* 배경 이미지 경로 — public/img/landing.webp 에 파일을 넣으면 자동 적용, 없으면 색 그라데이션 폴백 */
  --splash-img: url('/img/landing.webp');
  /* 위→아래: 텍스트 가독용 스크림 / 배경 이미지(있으면) / 색 혼합 폴백 그라데이션 / 기본 배경 */
  background:
    linear-gradient(180deg, rgba(16,16,20,0.30) 0%, rgba(16,16,20,0.78) 100%),
    var(--splash-img, none) center / cover no-repeat,
    radial-gradient(circle at 24% 28%, rgba(255,77,87,0.55), transparent 46%),
    radial-gradient(circle at 78% 32%, rgba(77,139,255,0.50), transparent 46%),
    radial-gradient(circle at 50% 80%, rgba(245,200,75,0.45), transparent 50%),
    var(--bg);
  transition: opacity 0.5s ease;
}
#splash.hide { opacity: 0; pointer-events: none; }
.splash-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.splash-title {
  font-family: var(--display); font-size: 52px; font-weight: 700; letter-spacing: 0.02em;
  color: #fff; text-shadow: 0 3px 24px rgba(0,0,0,0.5);
}
.splash-tagline { font-family: var(--display); font-size: 15px; color: rgba(255,255,255,0.85); margin-top: -6px; }
.splash-play {
  margin-top: 24px; width: 72px; height: 72px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.9); background: rgba(255,255,255,0.12);
  backdrop-filter: blur(4px); display: grid; place-items: center;
  animation: splash-pulse 1.8s ease-in-out infinite;
}
.splash-play svg { width: 30px; height: 30px; margin-left: 4px; }
.splash-hint { font-family: var(--display); font-size: 13px; letter-spacing: 0.16em; text-transform: uppercase; color: rgba(255,255,255,0.7); margin-top: 6px; }
@keyframes splash-pulse { 0%,100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,255,255,0.3); } 50% { transform: scale(1.06); box-shadow: 0 0 0 14px rgba(255,255,255,0); } }
body.reduce-motion .splash-play { animation: none; }
@media (prefers-reduced-motion: reduce) { .splash-play { animation: none; } }

/* 접근성: 모션 최소화 */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
body.reduce-motion * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
