/* palli — brend: iliq to'q jigarrang, krem matn, Taegeuk qizil/ko'k urg'ular, oq chizma doodle'lar */
:root {
  --bg: #1b1315;
  --bg-2: #231a1c;
  --card: #2b1f23;
  --card-2: #35272b;
  --card-3: #3f2f34;
  --line: rgba(255, 232, 224, 0.08);
  --line-2: rgba(255, 232, 224, 0.16);
  --text: #f8eee8;
  --muted: #bba59e;
  --faint: #8c7770;
  --rose: #eaa5ab;
  --rose-2: #d97f8a;
  --gold: #f3c56f;
  --red: #e5525c;
  --blue: #6b93ec;
  --ok: #67d39a;
  --bad: #f0707a;
  --r-lg: 24px;
  --r: 18px;
  --r-sm: 12px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --ko: 'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --vh: var(--tg-viewport-stable-height, 100dvh);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { color-scheme: dark; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: var(--vh);
  overscroll-behavior-y: none;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 520px at 115% -12%, rgba(229, 82, 92, 0.16), transparent 62%),
    radial-gradient(760px 480px at -25% 112%, rgba(107, 147, 236, 0.12), transparent 62%),
    var(--bg);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
img { display: block; max-width: 100%; }
.ko { font-family: var(--ko); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.hidden { display: none !important; }

#app { max-width: 520px; margin: 0 auto; min-height: var(--vh); }

.screen {
  min-height: var(--vh);
  padding: 18px 18px calc(28px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: enter 0.28s ease-out backwards;
}
.screen.with-nav { padding-bottom: calc(96px + var(--safe-b)); }
@keyframes enter { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- icons ---------- */
.ic { display: inline-flex; width: 20px; height: 20px; flex: none; }
.ic svg { width: 100%; height: 100%; }
.ic-lg { width: 26px; height: 26px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 54px; padding: 0 22px; border-radius: 16px;
  font-weight: 800; font-size: 17px; letter-spacing: 0.01em;
  transition: transform 0.12s ease, background 0.2s ease, opacity 0.2s;
  user-select: none;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.55; pointer-events: none; }
.btn-primary { background: var(--text); color: #2a1c1f; box-shadow: 0 8px 24px rgba(248, 238, 232, 0.12); }
.btn-rose { background: linear-gradient(135deg, #f0b2b7, #d97f8a); color: #2a1418; }
.btn-ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--line-2); }
.btn-text { color: var(--muted); font-weight: 700; min-height: 44px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
}
.icon-btn:active { transform: scale(0.95); }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- loading / error ---------- */
.center-screen { min-height: var(--vh); display: grid; place-items: center; text-align: center; padding: 24px; }
.loading-logo { width: 160px; animation: float 1.6s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-6px) rotate(-2deg); } }
.error-box { display: grid; gap: 14px; max-width: 320px; }
.error-box h2 { margin: 0; font-size: 22px; }

/* ---------- welcome ---------- */
.hero {
  position: relative; border-radius: 28px; overflow: hidden; aspect-ratio: 1 / 1;
  box-shadow: var(--shadow), 0 0 0 1px var(--line);
  max-height: 46vh; margin: 0 auto; width: 100%;
}
.hero img { width: 100%; height: 100%; object-fit: cover; }
.hero::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 55%, rgba(27, 19, 21, 0.9)); }
.hero-badge {
  position: absolute; left: 16px; bottom: 14px; z-index: 1; display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 999px; background: rgba(27, 19, 21, 0.72); backdrop-filter: blur(8px);
  font-weight: 800; font-size: 13px; border: 1px solid var(--line-2);
}
.welcome-title { margin: 4px 0 0; font-size: 28px; line-height: 1.15; font-weight: 900; letter-spacing: -0.01em; }
.welcome-sub { margin: 0; color: var(--muted); }

.form { display: grid; gap: 14px; }
.field { display: grid; gap: 7px; }
.field label { font-weight: 800; font-size: 14px; color: var(--muted); }
.input {
  width: 100%; min-height: 54px; padding: 0 16px; border-radius: 16px;
  background: var(--card); border: 1.5px solid var(--line-2); outline: none; font-size: 17px; font-weight: 700;
  transition: border-color 0.2s;
}
.input:focus { border-color: var(--rose); }
.input-wrap { position: relative; }
.input-wrap .at { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--faint); font-weight: 800; }
.input-wrap .input { padding-left: 34px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); }
.seg button { min-height: 44px; border-radius: 12px; font-weight: 800; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: background 0.2s, color 0.2s; }
.seg button.on { background: var(--card-3); color: var(--text); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25); }
.tg-id { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); }
.tg-id b { font-weight: 800; }
.form-error { color: var(--bad); font-weight: 700; font-size: 14px; min-height: 0; }
.note { font-size: 13px; color: var(--faint); text-align: center; margin: 0; }
.verified { display: inline-flex; color: var(--blue); width: 16px; height: 16px; vertical-align: -2px; }

/* ---------- header ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand-logo { height: 44px; width: auto; }
.avatar {
  flex: none; border-radius: 50%; display: inline-grid; place-items: center; overflow: hidden;
  font-weight: 900; color: #2a1c1f; text-transform: uppercase; background: var(--rose);
}
.avatar { position: relative; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.me-btn { border-radius: 50%; padding: 2px; border: 1.5px solid var(--line-2); }

.hello h1 { margin: 0; font-size: 26px; font-weight: 900; line-height: 1.15; }
.hello p { margin: 4px 0 0; color: var(--muted); }

/* ---------- level cards ---------- */
.levels { display: grid; gap: 14px; }
.level-card {
  position: relative; overflow: hidden; text-align: left; width: 100%;
  border-radius: var(--r-lg); padding: 20px; background: var(--card); border: 1px solid var(--line);
  display: grid; gap: 14px; transition: transform 0.15s ease;
}
.level-card:active { transform: scale(0.985); }
.level-card::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(420px 220px at 100% 0%, var(--accent-glow), transparent 70%);
}
.level-card.l1 { --accent: var(--rose); --accent-glow: rgba(229, 82, 92, 0.28); }
.level-card.l2 { --accent: var(--blue); --accent-glow: rgba(107, 147, 236, 0.28); }
.level-row { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.level-name { font-family: var(--ko); font-weight: 900; font-size: 44px; line-height: 1; letter-spacing: -0.03em; color: var(--accent); }
.level-meta { font-weight: 800; }
.level-meta small { display: block; color: var(--muted); font-weight: 700; font-size: 14px; }
.level-stats { position: relative; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px;
  background: rgba(255, 232, 224, 0.06); border: 1px solid var(--line); font-weight: 800; font-size: 13px; color: var(--muted);
}
.chip b { color: var(--text); }
.chip.gold b { color: var(--gold); }
.go {
  position: relative; display: inline-flex; align-items: center; gap: 8px; justify-self: start;
  padding: 10px 16px; border-radius: 12px; background: var(--accent); color: #23161a; font-weight: 900;
}

.rules { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.rule { padding: 12px 10px; border-radius: var(--r); background: var(--card); border: 1px solid var(--line); text-align: center; }
.rule b { display: block; font-size: 20px; font-weight: 900; }
.rule span { font-size: 12.5px; color: var(--muted); font-weight: 700; line-height: 1.25; display: block; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.section-head h2 { margin: 0; font-size: 18px; font-weight: 900; display: flex; align-items: center; gap: 8px; }
.link { color: var(--rose); font-weight: 800; font-size: 14px; }

/* ---------- list rows ---------- */
.list { display: grid; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--line);
}
.row.me { border-color: rgba(234, 165, 171, 0.55); background: linear-gradient(90deg, rgba(234, 165, 171, 0.12), var(--card)); }
.rank { width: 30px; text-align: center; font-weight: 900; color: var(--muted); flex: none; }
.who { flex: 1; min-width: 0; }
.who b { display: block; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { display: flex; align-items: center; gap: 4px; color: var(--faint); font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; }
.who small .ic { width: 14px; height: 14px; }
.pts { font-weight: 900; font-size: 17px; }
.pts small { color: var(--faint); font-weight: 700; font-size: 12px; margin-left: 2px; }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); border: 1.5px dashed var(--line-2); border-radius: var(--r-lg); }
.skeleton { height: 62px; border-radius: 16px; background: linear-gradient(90deg, var(--card) 0%, var(--card-2) 50%, var(--card) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- bottom nav ---------- */
.nav {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--safe-b)); z-index: 10;
  display: flex; gap: 6px; padding: 6px; border-radius: 20px;
  background: rgba(43, 31, 35, 0.86); backdrop-filter: blur(14px); border: 1px solid var(--line-2); box-shadow: var(--shadow);
}
.nav button { display: inline-flex; align-items: center; gap: 8px; min-height: 46px; padding: 0 20px; border-radius: 14px; font-weight: 800; color: var(--muted); }
.nav button.on { background: var(--text); color: #2a1c1f; }

/* ---------- quiz ---------- */
.quiz { gap: 14px; }
.quiz-top { display: flex; align-items: center; gap: 12px; }
.progress { flex: 1; display: grid; gap: 6px; }
.progress-txt { display: flex; justify-content: space-between; font-weight: 800; font-size: 14px; color: var(--muted); }
.progress-bar { height: 8px; border-radius: 99px; background: var(--card-2); overflow: hidden; }
.progress-bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--rose), var(--rose-2)); transition: width 0.35s ease; }
.score-pill { position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); font-weight: 900; }
.score-pill .ic { color: var(--gold); width: 18px; height: 18px; }
.float-pts { position: absolute; right: 6px; top: -4px; font-weight: 900; color: var(--ok); animation: floatup 0.9s ease-out forwards; pointer-events: none; }
@keyframes floatup { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-28px); } }

.word-card {
  position: relative; flex: 1; min-height: 210px; border-radius: 28px; padding: 22px;
  background: var(--card); border: 1px solid var(--line);
  display: grid; place-items: center; text-align: center; overflow: hidden;
}
.word-card::before { content: ''; position: absolute; inset: 0; background: radial-gradient(380px 200px at 50% 0%, rgba(234, 165, 171, 0.12), transparent 70%); pointer-events: none; }
.word-card .lvl { position: absolute; left: 16px; top: 14px; }
.word-card .speak { position: absolute; right: 14px; top: 12px; }
.timer { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: rgba(255, 232, 224, 0.06); }
.timer i { display: block; height: 100%; width: 100%; background: var(--ok); transform-origin: left; }
.timer.warn i { background: var(--red); }
.timer-num { position: absolute; right: 18px; bottom: 14px; font-weight: 900; color: var(--muted); font-variant-numeric: tabular-nums; }
.timer-num.warn { color: var(--red); }
.word { font-family: var(--ko); font-weight: 700; font-size: clamp(42px, 13vw, 70px); line-height: 1.1; letter-spacing: -0.02em; word-break: keep-all; }
.word-hint { font-family: var(--ko); color: var(--muted); font-size: 18px; margin-top: 6px; }
.prompt { position: absolute; left: 0; right: 0; bottom: 18px; color: var(--faint); font-weight: 700; font-size: 13px; }
.options { display: grid; gap: 10px; }
.opt {
  position: relative; display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  min-height: 58px; padding: 10px 16px; border-radius: 16px;
  background: var(--card); border: 1.5px solid var(--line-2); font-weight: 800; font-size: 17px;
  transition: transform 0.1s ease, background 0.2s, border-color 0.2s, opacity 0.2s;
}
.opt:active { transform: scale(0.985); }
.opt .key { flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--card-3); color: var(--muted); font-size: 14px; font-weight: 900; }
.opt.pending { border-color: var(--rose); animation: pulse 0.8s ease-in-out infinite; }
@keyframes pulse { 50% { border-color: transparent; } }
.opt.ok { background: rgba(103, 211, 154, 0.16); border-color: var(--ok); }
.opt.ok .key { background: var(--ok); color: #12301f; }
.opt.bad { background: rgba(240, 112, 122, 0.14); border-color: var(--bad); }
.opt.bad .key { background: var(--bad); color: #3a1014; }
.options.locked .opt:not(.ok):not(.bad):not(.pending) { opacity: 0.45; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 13px; color: var(--muted); }
.toggle .sw { width: 36px; height: 22px; border-radius: 99px; background: var(--card-3); position: relative; transition: background 0.2s; }
.toggle .sw::after { content: ''; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform 0.2s, background 0.2s; }
.toggle.on .sw { background: var(--rose-2); }
.toggle.on .sw::after { transform: translateX(14px); background: #fff; }
.quiz-foot { display: flex; justify-content: space-between; align-items: center; min-height: 28px; }

/* ---------- result ---------- */
.result-hero { position: relative; display: grid; justify-items: center; text-align: center; gap: 8px; padding: 26px 18px 22px; border-radius: 28px; background: var(--card); border: 1px solid var(--line); overflow: hidden; }
.result-hero::before { content: ''; position: absolute; inset: 0; background: radial-gradient(420px 240px at 50% 0%, rgba(243, 197, 111, 0.16), transparent 70%); pointer-events: none; }
.ring { position: relative; width: 168px; height: 168px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .val { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; }
.ring .val b { font-size: 46px; font-weight: 900; line-height: 1; }
.ring .val small { color: var(--muted); font-weight: 800; }
.result-title { margin: 6px 0 0; font-size: 24px; font-weight: 900; }
.result-sub { margin: 0; color: var(--muted); }
.badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.record { color: var(--gold); font-weight: 900; display: inline-flex; align-items: center; gap: 6px; }
.actions { display: grid; gap: 10px; }
.actions-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.wrong-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); }
.wrong-row .w { font-family: var(--ko); font-weight: 700; font-size: 20px; min-width: 76px; }
.wrong-row .m { flex: 1; min-width: 0; }
.wrong-row .m b { display: block; font-weight: 800; }
.wrong-row .m s { color: var(--bad); font-size: 13px; font-weight: 700; opacity: 0.85; }
.wrong-row .icon-btn { width: 38px; height: 38px; border-radius: 12px; }

/* ---------- leaderboard ---------- */
.page-title { margin: 0; font-size: 28px; font-weight: 900; display: flex; align-items: center; gap: 10px; }
.chips { display: flex; gap: 8px; }
.chips button { padding: 9px 14px; border-radius: 999px; font-weight: 800; font-size: 14px; color: var(--muted); background: var(--card); border: 1px solid var(--line); }
.chips button.on { color: #2a1c1f; background: var(--rose); border-color: transparent; }
.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; align-items: end; gap: 10px; margin-top: 8px; }
.pod { display: grid; justify-items: center; gap: 6px; text-align: center; min-width: 0; }
.pod .crown { color: var(--gold); width: 34px; height: 26px; margin-bottom: -6px; }
.pod .nm { font-weight: 800; font-size: 14px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pod .sc { font-weight: 900; }
.pod .base { width: 100%; border-radius: 16px 16px 8px 8px; display: grid; place-items: center; font-weight: 900; font-size: 22px; color: var(--muted); background: var(--card); border: 1px solid var(--line); }
.pod.p1 .base { height: 92px; background: linear-gradient(180deg, rgba(243, 197, 111, 0.26), var(--card)); color: var(--gold); }
.pod.p2 .base { height: 68px; }
.pod.p3 .base { height: 54px; }
.pod.p1 .avatar { box-shadow: 0 0 0 3px var(--gold); }
.me-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--safe-b)); z-index: 9;
  width: min(484px, calc(100% - 36px));
}
.me-bar .row { box-shadow: var(--shadow); background: #3a2a2f; }

/* ---------- sheet ---------- */
.sheet-bg { position: fixed; inset: 0; z-index: 50; background: rgba(10, 6, 7, 0.6); backdrop-filter: blur(3px); display: flex; align-items: flex-end; justify-content: center; animation: fade 0.2s ease both; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--line-2); border-bottom: 0; border-radius: 28px 28px 0 0;
  padding: 10px 18px calc(22px + var(--safe-b)); display: grid; gap: 14px; animation: up 0.26s ease-out both;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet .grab { width: 44px; height: 5px; border-radius: 99px; background: var(--line-2); margin: 2px auto 4px; }
.sheet h3 { margin: 0; font-size: 20px; font-weight: 900; text-align: center; }
.card-preview { width: min(240px, 60%); margin: 0 auto; border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); aspect-ratio: 9 / 16; background: var(--card); display: grid; place-items: center; }
.card-preview img { width: 100%; height: 100%; object-fit: cover; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { padding: 14px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); }
.stat small { display: block; color: var(--muted); font-weight: 700; font-size: 13px; }
.stat b { font-size: 22px; font-weight: 900; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top, 0px)); z-index: 100;
  transform: translate(-50%, -20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 14px;
  background: #f8eee8; color: #2a1c1f; font-weight: 800; box-shadow: var(--shadow); transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 560px) {
  .screen { padding-top: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
.ic.flag { width: 22px; height: 15px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25); }
.result-title, .hello h1, .welcome-title { word-break: keep-all; overflow-wrap: anywhere; }
.wrong-row .w { flex: none; max-width: 48%; word-break: keep-all; }
