:root {
  --bg: #f7f7ff;
  --card: #ffffff;
  --text: #2d2a32;
  --muted: #6b6a72;
  --primary: #6c5ce7;
  --primary-600: #5a4bd6;
  --secondary: #00c2ff;
  --good: #2ecc71;
  --bad: #ff4757;
  --bottom-nav-h: 64px;
  --header-h: 72px;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 10% -10%, #efeaff, transparent), var(--bg);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
html { overflow-x: hidden; }
*, *::before, *::after { box-sizing: border-box; }
main.container { padding-bottom: 0; }

/* Top mode tabs (Single / Online) - base styles */
.tabs { display: flex; gap: 10px; margin: 8px 0 12px; }
.tab {
  padding: 10px 14px;
  border-radius: 12px;
  background: #f2f1ff;
  color: var(--primary);
  font-weight: 800;
  border: 1px solid #e6e2ff;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease;
  box-shadow: 0 2px 0 rgba(0,0,0,0.03);
}
.tab:hover { transform: translateY(-1px); }
.tab:active { transform: translateY(0); }
.tab.active {
  background: var(--primary);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(108,92,231,0.35);
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { width: 36px; height: 36px; }

h1 { font-size: 22px; margin: 0; }

.container {
  max-width: 100%;
  margin: 0;
  padding: 8px;
}
/* Center the single mode card like auth-box when single mode is active */
body.single-active .container { display: grid; place-items: center; min-height: calc(100vh - var(--header-h) - var(--bottom-nav-h)); padding: 0 12px; }
body.single-active #singleRoot { max-width: 520px; width: 100%; margin: 0; }
/* Single game should span full width when playing */
body.single-playing #game { margin: 0; width: 100%; max-width: none; }
body.single-playing #game .choices { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 720px) { body.single-playing #game .choices { grid-template-columns: repeat(4, 1fr); } }

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  margin: 12px 0;
  box-shadow: 0 8px 24px rgba(0,0,0,0.06);
}
/* Unify primary cards to match 방 입장/생성 카드 스타일 */
#profile.card, #leaderboardSection.card, #recentSection.card {
  background: #ffffff;
  border: 1px solid #eee;
  border-radius: 14px; /* match .online .group */
  padding: 12px;
  margin: 10px 0;
  box-shadow: 0 8px 24px rgba(0,0,0,0.06);
}

.levels { display: grid; grid-template-columns: 1fr; gap: 8px; }
.levels label { background: #fafaff; border: 1px solid #eee; padding: 10px 12px; border-radius: 12px; display: flex; gap: 8px; align-items: center; white-space: nowrap; }

.actions { display: flex; gap: 10px; margin-top: 12px; }
#singleRoot .actions { display: grid; grid-template-columns: 1fr; gap: 10px; }
#singleRoot .actions .btn { width: 100%; height: 52px; font-size: 18px; }
.buttons-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.buttons-grid .select select { height: 48px; font-size: 16px; }
.buttons-grid .btn { height: 48px; }
@media (max-width: 560px) { .buttons-grid { grid-template-columns: 1fr; } }
.select { display: grid; grid-template-columns: 1fr; gap: 6px; }
.select label { font-size: 12px; color: var(--muted); }
.select select { appearance: none; width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid #e6e2ff; background: #fcfbff; font-weight: 700; }
.btn-lg { padding: 14px 18px; font-size: 18px; }
.btn-half { width: 100%; }

.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
}
.btn[disabled] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:active { transform: translateY(1px); background: var(--primary-600); }
.btn-secondary { background: #e9f7ff; color: #096;
}
.btn-ghost { background: #f2f1ff; color: var(--primary); }
.btn[data-state="ready"] { background: #efeaff; color: var(--primary); border: 1px solid #e6e2ff; }
.btn-install { background: #ffeaa7; color: #6c4d00; }

.game.hidden, .how.hidden { display: none; }
.hidden { display: none; }

.hud { display: flex; gap: 12px; align-items: center; color: var(--muted); }
.hud .highlight { color: var(--text); font-weight: 800; }
.timer { background: #fff6f6; color: #b71c1c; padding: 6px 10px; border-radius: 999px; }

.question {
  font-size: clamp(28px, 6vw, 48px);
  font-weight: 800;
  text-align: center;
  margin: 18px 0 10px;
}

.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.choice {
  background: #f9f9ff;
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 22px;
  text-align: center;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}
.choice:hover { transform: translateY(-1px); }
.choice.correct { background: #ecfff4; border-color: #a7f3d0; }
.choice.wrong { background: #fff0f0; border-color: #ffb3b3; }
.choice.pulse { animation: pulseScale 240ms ease; }

@keyframes pulseScale {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.shake { animation: shakeX 320ms ease; }
@keyframes shakeX {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

.score-pop { animation: scorePop 360ms ease; }
@keyframes scorePop {
  0% { transform: scale(1); color: inherit; }
  40% { transform: scale(1.25); color: var(--good); }
  100% { transform: scale(1); color: inherit; }
}

.feedback { text-align: center; height: 28px; font-weight: 700; margin-top: 6px; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

.game-actions { display: flex; gap: 10px; justify-content: center; margin-top: 12px; }
.online #onlineGame .game-actions { position: static; background: transparent; padding-top: 12px; border-top: 1px solid #eee; box-shadow: none; margin-top: 16px; }

.app-footer { text-align: center; color: var(--muted); padding: 18px; }
/* Bottom app navigation */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; background: var(--card); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid #eee; box-shadow: 0 -8px 24px rgba(0,0,0,0.06); z-index: 3001; min-height: var(--bottom-nav-h); align-items: center; }
.bottom-nav .tab { padding: 12px 16px; border-radius: 12px; background: #f2f1ff; color: var(--primary); font-weight: 800; border: 1px solid #e6e2ff; cursor: pointer; }
.bottom-nav .tab.active { background: var(--primary); color: #fff; border-color: transparent; }

/* Fix background seam when scrolling */
html { background-color: var(--bg); }
body { background-attachment: fixed; }

.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200; /* above fullscreen game */
}

/* Overlay - restored styles */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.35); display: flex; align-items: center; justify-content: center; z-index: 2000; }
.overlay.hidden { display: none !important; }
.overlay .loader { background: #ffffff; padding: 16px 20px; border-radius: 14px; box-shadow: 0 12px 28px rgba(0,0,0,0.18); display: flex; gap: 12px; align-items: center; }
.overlay .spinner { width: 20px; height: 20px; border: 3px solid #eee; border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
.overlay .msg { font-weight: 800; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Online section */
.online .input { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid #ddd; background: #fff; box-sizing: border-box; font-size: 16px; min-height: 48px; }
.online .online-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
/* Join/Create row specifically in online setup: stacked input + full-width button */
#onlineSetup .online-row { display: grid; grid-template-columns: 1fr; gap: 10px; }
#onlineSetup .online-row .btn { width: 100%; }
.online .group { background: #fcfbff; border: 1px solid #eee; border-radius: 14px; padding: 10px 12px; margin: 10px 0; }
.online .group.card { background: #ffffff; border: 1px solid #eee; box-shadow: 0 8px 24px rgba(0,0,0,0.06); }
.online .group h3 { margin: 0 0 6px; font-size: 16px; color: var(--muted); }
.online .input { width: 100%; }
.online .btn.wide { width: 100%; justify-content: center; }
.online .hidden { display: none !important; }
.online .players { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
@media (max-width: 560px) { .online .players { grid-template-columns: 1fr; } }
.online .players .pill { background: #f2f1ff; color: var(--primary); padding: 6px 10px; border-radius: 999px; }

/* Player cards (lobby & in-game) */
.online .player-card, .online .players .player-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #ffffff;
  border: 1px solid #eee;
  border-radius: 12px;
}
.online .player-card.me, .online .players .player-card.me { border-color: #c4b8ff; box-shadow: 0 0 0 3px rgba(108,92,231,0.15) inset; }
.online .avatar, .online .players .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: #fff; border: 1px solid #eee;
  display: grid; place-items: center; font-weight: 900; font-size: 18px;
}
.online .name, .online .players .name { font-weight: 800; }
.online .host, .online .players .host { background: #fff7d6; color: #6c4d00; border: 1px solid #ffe9a8; border-radius: 999px; padding: 2px 6px; font-size: 12px; }
.online .score-meta, .online .players .score-meta { color: var(--muted); font-size: 12px; margin-left: 6px; }
.online .players .ready-toggle {
  margin-left: auto;
  border: 1px solid #e6e2ff;
  background: #f2f1ff;
  color: var(--primary);
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 800;
}
.online .players .ready-toggle[data-state="on"] {
  background: #ecfff4;
  border-color: #baf5d6;
  color: #0f7a43;
}
.online .players .ready-badge {
  margin-left: auto;
  border: 1px solid #eee;
  background: #fafaff;
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 8px;
  font-weight: 800;
  font-size: 12px;
}
.online .players .ready-badge[data-state="on"] {
  background: #ecfff4; color: #0f7a43; border-color: #baf5d6;
}
.online .lobby-line { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.online .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.online .actions.buttons-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.online .actions .lobby-level, .online .actions .lobby-rounds { background: #fafaff; border: 1px solid #eee; padding: 8px 10px; border-radius: 12px; }
.online code { background: #fff; padding: 2px 6px; border-radius: 6px; border: 1px solid #eee; }
.online .online-hint { color: var(--muted); font-size: 14px; }
.online .online-hint.error { color: #b71c1c; background: #fff6f6; padding: 6px 10px; border-radius: 8px; }
.online .tabs { display: flex; gap: 8px; margin: 8px 0; }
.online .tab { padding: 8px 12px; border-radius: 999px; background: #f2f1ff; color: var(--primary); cursor: pointer; user-select: none; }
.online .tab.active { background: var(--primary); color: #fff; }
/* Top tabs outside of .online section (Single / Online) */
#tabSingle, #tabOnline { display: inline-flex; align-items: center; justify-content: center; min-width: 120px; }
/* Center login/signup in viewport */
#onlineRoot #account { display: grid; place-items: center; min-height: calc(100vh - var(--header-h) - var(--bottom-nav-h)); }
#onlineRoot #account .auth-box { width: 100%; max-width: 520px; }
#onlineRoot #account .auth-box .tabs { justify-content: center; margin: 0; }
#onlineRoot #account .auth-form.card { background: #ffffff; border: 1px solid #eee; border-radius: 14px; box-shadow: 0 8px 24px rgba(0,0,0,0.06); padding: 12px; }
#onlineRoot #account #viewLogin, #onlineRoot #account #viewSignup { margin-top: 0; }
#onlineRoot #account #viewLogin .online-row, #onlineRoot #account #viewSignup .online-row { margin-top: 0; }
#onlineRoot #account .online-row { width: 100%; }
.copyright { display: block; text-align: center; color: var(--muted); margin-top: 8px; }
.form-toast { text-align: center; background: #fff6f6; color: #b71c1c; border: 1px solid #ffdada; padding: 8px 10px; border-radius: 10px; margin: 6px auto 8px; width: max(240px, 60%); box-shadow: 0 6px 16px rgba(0,0,0,0.06); }
.form-toast[data-tone="ok"] { background: #ecfff4; color: #0f7a43; border-color: #baf5d6; }
/* Global toast */
.app-toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--header-h) + 4px); background: #fff6f6; color: #b71c1c; border: 1px solid #ffdada; padding: 8px 14px; border-radius: 12px; box-shadow: 0 10px 24px rgba(0,0,0,0.12); z-index: 2000; max-width: 96vw; width: auto; text-align: center; font-size: 13px; opacity: 1; transition: opacity 280ms ease, transform 280ms ease; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-toast.fading { opacity: 0; transform: translateX(-50%) translateY(-6px); }
.app-toast[data-tone="ok"] { background: #ecfff4; color: #0f7a43; border-color: #baf5d6; }
/* Auth inputs/buttons bigger */
#viewLogin .input, #viewSignup .input { padding: 12px 14px; font-size: 16px; }
#viewLogin .btn, #viewSignup .btn { height: 48px; font-size: 16px; width: 100%; }
#viewLogin .online-row, #viewSignup .online-row { display: grid; grid-template-columns: 1fr; gap: 10px; }
.remember { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
/* Empty state */
.online .board .empty { background: #fafaff; border: 1px dashed #d9d6ff; border-radius: 12px; padding: 14px; text-align: center; color: var(--muted); font-weight: 500; font-size: 14px; line-height: 1.3; grid-column: 1 / -1; width: 100%; box-sizing: border-box; max-width: 100%; overflow-wrap: anywhere; word-break: keep-all; }
@media (max-width: 560px) { .online .board .empty { font-size: 13px; padding: 12px; } }

/* In-game board: use grid and player-card look */
.online .board { margin-top: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .online .board { grid-template-columns: 1fr; } }
.online .board .scorecard { background: #fafaff; border: 1px solid #eee; border-radius: 10px; padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; }
.online .board .scorecard .meta { color: var(--muted); font-size: 12px; }

/* Leaderboard cards */
.leader-card { background: #ffffff; border: 1px solid #eee; border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.leader-card .leader-left { display: flex; align-items: center; gap: 10px; background: transparent; border: none; box-shadow: none; padding: 0; }
.leader-card .rank-badge { background: #f2f1ff; color: var(--primary); border-radius: 999px; padding: 2px 8px; font-size: 12px; font-weight: 900; }
.leader-card .rank-badge.r1 { background: #fff7d6; color: #6c4d00; }
.leader-card .rank-badge.r2 { background: #eef6ff; color: #0a5; }
.leader-card .rank-badge.r3 { background: #ffe9f2; color: #c2185b; }
.leader-card .leader-right .meta { color: var(--muted); font-size: 12px; }
.leader-card .leader-right .sub { color: var(--muted); font-size: 12px; }
.leader-card .leader-right { width: 100%; display: flex; flex-direction: column; gap: 4px; }
@media (max-width: 880px) {
  .leader-card { flex-direction: column; align-items: flex-start; gap: 6px; }
  .leader-card .leader-left .name { font-size: 16px; }
  .leader-card .rank-badge { font-size: 11px; padding: 2px 6px; }
  .leader-card .leader-right { width: 100%; display: flex; flex-direction: column; gap: 4px; }
  .leader-card .leader-right .meta { font-size: 11px; }
  .leader-card .leader-right .sub { font-size: 11px; line-height: 1.3; }
}

/* Recent matches cards */
.recent-card { background: #ffffff; border: 1px solid #eee; border-radius: 14px; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.recent-left .date { font-weight: 600; font-size: 12px; color: var(--muted); }
.recent-left .room { color: var(--muted); font-size: 12px; }
.recent-right { display: flex; gap: 10px; align-items: center; }
.recent-right .score .meta { color: var(--muted); font-size: 12px; margin-right: 4px; }
.recent-right .state { border-radius: 999px; padding: 2px 8px; font-size: 12px; font-weight: 900; border: 1px solid #eee; }
.recent-right .state.live { background: #e9f7ff; color: #096; border-color: #bdeaff; }
.recent-right .state.done { background: #fafaff; color: #6c4d00; border-color: #efe6c5; }

/* Profile card - richer layout */
#profile .profile-grid { margin-top: 8px; display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
#profile .profile-stat { background: #fafaff; border: 1px solid #eee; border-radius: 12px; padding: 10px; }
#profile .profile-stat .label { color: var(--muted); font-size: 12px; }
#profile .profile-stat .value { font-size: 22px; font-weight: 900; }
.card h3 { margin: 0 0 6px; font-size: 16px; color: var(--muted); display: flex; align-items: center; justify-content: space-between; }
.card h3 .nickname { color: var(--text); font-weight: 900; }
.profile-header { display: flex; align-items: center; gap: 10px; }
.profile-header .avatar { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; border: 1px solid #eee; background: #fff; font-size: 22px; font-weight: 900; }
.profile-header .nickname { font-size: 18px; font-weight: 900; }
.online #onlineGame.fullscreen { position: fixed; inset: 64px 12px 12px 12px; z-index: 50; background: var(--card); border-radius: 18px; box-shadow: 0 12px 28px rgba(0,0,0,0.18); padding: 16px; overflow: auto; padding-bottom: 16px; }
.online h3 { margin: 0 0 6px; }

/* Floating emoji effect when another player solves */
.float-emoji {
  position: absolute;
  right: 16px;
  top: 16px;
  font-size: 28px;
  animation: floatFade 900ms ease forwards;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.2));
}
@keyframes floatFade {
  0% { opacity: 0; transform: translateY(8px) scale(0.9); }
  30% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-20px) scale(0.98); }
}

/* Big centered emoji effect when opponent solves */
.emoji-burst {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(64px, 14vw, 140px);
  animation: emojiPop 820ms ease forwards;
  z-index: 1400;
  pointer-events: none;
  text-shadow: 0 10px 28px rgba(0,0,0,0.18);
}
@keyframes emojiPop {
  0% { transform: scale(0.6); opacity: 0; }
  40% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1.0); opacity: 0; }
}

/* Rooms list - richer cards */
.online #roomsList .room-card { background: #ffffff; border: 1px solid #eee; border-radius: 14px; padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; cursor: pointer; transition: transform 120ms ease, box-shadow 160ms ease, border-color 160ms ease; }
.online #roomsList .room-card:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(0,0,0,0.08); border-color: #e7e7ff; }
.online #roomsList .room-left { display: flex; flex-direction: column; gap: 6px; }
.online #roomsList .room-code { font-weight: 800; }
.online #roomsList .room-meta { display: flex; gap: 8px; align-items: center; }
.badge { background: #f2f1ff; color: var(--primary); border-radius: 999px; padding: 4px 8px; font-size: 12px; }
.chip { background: #f7f7f7; color: #555; border-radius: 999px; padding: 4px 8px; font-size: 12px; border: 1px solid #eee; }
.chip.level-easy { background: #ecfff4; color: #09814a; border-color: #c7f7dd; }
.chip.level-normal { background: #e9f7ff; color: #096; border-color: #bdeaff; }
.chip.level-hard { background: #fff0f0; color: #b71c1c; border-color: #ffd3d3; }
.online #roomsList .room-right { color: var(--muted); font-weight: 800; }

/* Mobile: unify button/tab font sizes for consistency */
@media (max-width: 560px) {
  .btn { font-size: 15px; }
  .btn-lg { font-size: 15px; }
  .bottom-nav .tab { font-size: 15px; }
  .online .tab { font-size: 15px; }
  .online .players .ready-toggle { font-size: 15px; }
}


