/* 구구단 스피드 — 픽셀 글꼴(Galmuri, OFL) + 계단식 테두리. 벌레 잡기와 같은 크림색 바탕 */
@font-face { font-family: 'Galmuri11'; src: url('/assets/fonts/Galmuri11.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Galmuri11'; font-weight: 700; src: url('/assets/fonts/Galmuri11-Bold.woff2') format('woff2'); font-display: swap; }

:root {
  --bg: #F6F3EC; --card: #FFFDF7; --ink: #1F2420; --muted: #7A7F78; --line: #E4DFD3;
  --accent: #3E9B3A; --accent-dark: #2B6E28; --danger: #D9483B; --gold: #E8A317;
  --px: 3px;   /* 픽셀 테두리 두께 */
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font-family: 'Galmuri11', -apple-system, 'Apple SD Gothic Neo', sans-serif; -webkit-font-smoothing: none; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
h1, h2 { margin: 0; font-weight: 700; }
b { font-weight: 700; }

/* 픽셀 상자: 모서리를 깎은 테두리 */
.card, .btn, .panel, .levels .lv, .keypad button, .pill, .board, .timer {
  border: var(--px) solid var(--ink);
  box-shadow: 0 var(--px) 0 var(--ink);
}

.screen { display: none; min-height: 100%; }
.screen.active { display: block; }

/* ---------- 홈 ---------- */
#home { max-width: 480px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 18px) 16px calc(env(safe-area-inset-bottom) + 28px); }
.hero { text-align: center; padding: 8px 0 16px; }
.hero-sign { display: inline-block; font-size: 30px; font-weight: 700; background: var(--ink); color: #9BE07A; padding: 8px 16px; letter-spacing: 2px; }
.hero h1 { font-size: 30px; margin-top: 12px; }
.tagline { color: var(--muted); margin: 6px 0 0; font-size: 14px; }

.btn { background: var(--card); padding: 12px 14px; font-weight: 700; font-size: 16px; }
.btn:active { transform: translateY(var(--px)); box-shadow: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.big { width: 100%; padding: 16px; font-size: 20px; margin: 4px 0 18px; }
.btn.ghost { padding: 8px 12px; font-size: 14px; }

.card { background: var(--card); padding: 14px; margin-bottom: 16px; }
.label { font-size: 12px; color: var(--muted); }
.nick { font-size: 18px; font-weight: 700; margin-top: 2px; }
.profile-top { display: flex; justify-content: space-between; align-items: center; }
.icon-btn { font-size: 22px; padding: 6px; }
.profile-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 2px dashed var(--line); }
.num { font-size: 18px; font-weight: 700; margin-top: 2px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; gap: 8px; }
.section-head h2 { font-size: 17px; }
.hint { font-size: 12px; color: var(--muted); text-align: right; }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.modes .mode { background: var(--card); border: var(--px) solid var(--ink); box-shadow: 0 var(--px) 0 var(--ink); padding: 8px 4px; display: flex; flex-direction: column; align-items: center; }
.modes .mode b { font-size: 15px; }
.modes .mode small { font-size: 11px; color: var(--muted); margin-top: 2px; }
.modes .mode.selected { background: var(--ink); color: #fff; }
.modes .mode.selected small { color: #9BE07A; }
.modes .mode.locked { opacity: .45; box-shadow: none; }
.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.levels .lv { background: var(--card); aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 2px 0 var(--ink); border-width: 2px; }
.levels .lv b { font-size: 17px; }
.levels .lv small { font-size: 11px; color: var(--muted); margin-top: 2px; }
.levels .lv.cleared { background: #E4F3DC; }
.levels .lv.selected { background: var(--accent); color: #fff; }
.levels .lv.selected small { color: #E4F3DC; }
.levels .lv.locked { opacity: .4; box-shadow: none; }
.levels .lv.bonus { background: #FFF3CF; border-style: dashed; }
.levels .lv.bonus.cleared { background: var(--gold); }
.levels .lv.bonus.selected { background: var(--ink); color: var(--gold); }

.ranking, .plays { list-style: none; margin: 0; padding: 0; }
.ranking li, .plays li { display: grid; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 2px dashed var(--line); font-size: 14px; }
.ranking li { grid-template-columns: 26px 1fr auto; }
.plays li { grid-template-columns: 76px 1fr auto; }
.ranking li:last-child, .plays li:last-child { border-bottom: 0; }
.ranking .rank { font-weight: 700; color: var(--muted); text-align: center; }
.ranking .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking li.me .who, .ranking li.me .rank { color: var(--accent-dark); font-weight: 700; }
.ranking .ms, .plays .ms { font-weight: 700; font-variant-numeric: tabular-nums; }
.ranking .mine-rank { display: block; text-align: right; color: var(--muted); font-size: 13px; border: 0; }
.ranking .empty, .plays .empty { display: block; text-align: center; color: var(--muted); padding: 14px 0; border: 0; }
.plays .when { color: var(--muted); font-size: 12px; }
.plays li.fail .what { color: var(--danger); }
.foot { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.foot a { color: inherit; }

/* ---------- 게임 ---------- */
#game { position: fixed; inset: 0; display: none; flex-direction: column; max-width: 480px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 16px); }
#game.active { display: flex; }
.topbar { display: flex; justify-content: space-between; align-items: center; }
.pill { background: var(--ink); color: var(--bg); padding: 6px 12px; font-size: 13px; font-weight: 700; box-shadow: none; }

.timer { position: relative; height: 26px; background: var(--card); margin-top: 14px; overflow: hidden; }
.timer-fill { position: absolute; inset: 0; background: var(--accent); transform-origin: left; }
.timer.low .timer-fill { background: var(--danger); }
.timer-text { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: var(--ink); color: var(--bg); padding: 1px 8px; font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }

.dots { display: flex; justify-content: center; gap: 10px; margin: 14px 0 6px; }
.dots i { width: 16px; height: 16px; border: var(--px) solid var(--ink); background: var(--card); }
.dots i.done { background: var(--accent); }
.dots i.now { background: var(--gold); }

.board { flex: 1; min-height: 160px; background: var(--card); display: flex; flex-direction: column; align-items: center; justify-content: center; margin: 8px 0 14px; }
.question { font-size: clamp(44px, 14vw, 64px); font-weight: 700; letter-spacing: 2px; }
.answer { font-size: clamp(40px, 12vw, 56px); font-weight: 700; color: var(--accent-dark); min-height: 1.2em; margin-top: 6px; border-bottom: var(--px) solid var(--ink); min-width: 2.4em; text-align: center; }
.board.wrong { animation: shake .3s; }
.board.wrong .answer { color: var(--danger); }
.board.right .answer { color: var(--accent); }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button { background: var(--card); font-size: 28px; font-weight: 700; padding: 12px 0; touch-action: manipulation; }
.keypad button:active, .keypad button.press { transform: translateY(var(--px)); box-shadow: none; background: var(--press, #E4F3DC); }
.keypad .del { background: var(--key2, #EFEAE0); }

.overlay { position: fixed; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--veil, rgba(246, 243, 236, .75)); }
.overlay[hidden] { display: none; }
.panel { width: 100%; max-width: 440px; background: var(--card); padding: 22px 18px 18px; text-align: center; }
.kicker { font-size: 14px; color: var(--muted); font-weight: 700; }
.panel-title { font-size: 24px; margin: 6px 0 14px; }
.rules-list { text-align: left; margin: 0 auto; padding: 0 0 0 22px; max-width: 300px; font-size: 15px; line-height: 1.6; }
.big { font-size: 46px; font-weight: 700; margin: 6px 0; font-variant-numeric: tabular-nums; }
.big.fail { font-size: 28px; color: var(--danger); margin: 10px 0 6px; }
.sub { font-size: 14px; color: var(--muted); line-height: 1.6; }
.sub b { color: var(--ink); }
.actions { display: flex; gap: 8px; margin-top: 18px; }
.actions .btn { flex: 1; }
.actions #homeBtn, .actions #rulesHomeBtn { flex: 0 0 auto; }
.actions [hidden] { display: none; }
.overlay.solid { background: var(--bg); }
.count-box { text-align: center; }
.count { font-size: 120px; font-weight: 700; color: var(--ink); line-height: 1; animation: pop .5s; }
.count-hint { margin-top: 16px; font-size: 18px; font-weight: 700; color: var(--muted); }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } }

@media (prefers-reduced-motion: reduce) { .board.wrong, .count { animation: none; } }

/* ---------- 고급·마스터 테마 (게임 화면에서만 body에 붙는다) ---------- */
body.theme-adv {      /* 고급: 블루블랙 + 하늘색 */
  --bg: #0E1626; --card: #17243B; --ink: #DCE8FA; --muted: #7F95B8; --line: #26395C;
  --accent: #3FB6E8; --accent-dark: #8FDAF7; --danger: #FF6B5E; --gold: #FFD34D;
  --press: #26395C; --key2: #101B2E; --veil: rgba(14, 22, 38, .82);
}
body.theme-master {   /* 마스터: 완전 검정 + 금색 */
  --bg: #050505; --card: #121212; --ink: #F2C94C; --muted: #9A8350; --line: #2A2A2A;
  --accent: #F2C94C; --accent-dark: #FFE08A; --danger: #FF4D5E; --gold: #F2C94C;
  --press: #2A2414; --key2: #0B0B0B; --veil: rgba(5, 5, 5, .85);
}
body.theme-adv, body.theme-master { background: var(--bg); color: var(--ink); }
body.theme-master .btn.primary { color: #050505; }
body.theme-master .timer-fill, body.theme-adv .timer-fill { opacity: .9; }
body.theme-master .question { text-shadow: 0 3px 0 #5C4A14; }
body.theme-adv .question { text-shadow: 0 3px 0 #0A3550; }
