:root {
  --background: #0a0a12;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-strong: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.1);
  --text: #f4f4fb;
  --text-muted: #9d9db5;
  --green: #1ed760;
  --pink: #ff3ea5;
  --purple: #7c5cff;
  --orange: #ffb020;
  --blue: #29b6ff;
  --radius: 20px;
  --font-body: 'Manrope', system-ui, sans-serif;
  --font-display: 'Unbounded', 'Manrope', sans-serif;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(124, 92, 255, 0.28), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, rgba(30, 215, 96, 0.16), transparent 60%),
    radial-gradient(700px 500px at 50% 110%, rgba(255, 62, 165, 0.14), transparent 60%),
    var(--background);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.story-open { overflow: hidden; }

h1, h2 { font-family: var(--font-display); margin: 0; letter-spacing: -0.02em; }
h1 { font-size: clamp(1.5rem, 4vw, 2.2rem); }
h2 { font-size: 1.05rem; margin-bottom: 16px; }
p { margin: 0 0 12px; }
a { color: inherit; text-decoration: none; }
code { background: var(--surface-strong); padding: 2px 6px; border-radius: 6px; font-size: 0.85em; }
.muted { color: var(--text-muted); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px max(16px, env(safe-area-inset-left));
  backdrop-filter: blur(18px);
  background: rgba(10, 10, 18, 0.72);
  border-bottom: 1px solid var(--border);
}

.brand { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 800; font-size: 1.1rem; white-space: nowrap; }
.brand-large { font-size: 1.4rem; }
.brand-muted { color: var(--text-muted); }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, var(--green), var(--blue)); box-shadow: 0 0 14px var(--green); }

.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav-link { padding: 8px 11px; border-radius: 999px; color: var(--text-muted); font-weight: 600; font-size: 0.92rem; white-space: nowrap; transition: 0.2s; }
.nav-link:hover { color: var(--text); background: var(--surface); }
.nav-active { color: var(--text); background: var(--surface-strong); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.view { max-width: 1120px; margin: 0 auto; padding: 28px 16px 80px; animation: fade-up 0.4s ease both; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.view-head .chips { margin-bottom: 0; }
.chip, .tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 999px;
  font: 600 0.88rem var(--font-body);
  cursor: pointer;
  transition: 0.2s;
}
.chip:hover, .tab:hover { color: var(--text); background: var(--surface-strong); }
.chip-active, .tab-active { color: #04140b; background: var(--green); border-color: var(--green); }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; }

.button {
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 999px;
  font: 700 0.9rem var(--font-body);
  cursor: pointer;
  transition: transform 0.15s, filter 0.2s;
}
.button:hover { transform: translateY(-1px); filter: brightness(1.15); }
.button:disabled { opacity: 0.5; cursor: wait; }
.button-primary { background: linear-gradient(135deg, var(--green), #19b8a0); color: #03140b; border-color: transparent; }
.button-danger { color: #ff7a8a; border-color: rgba(255, 122, 138, 0.4); }
.button-large { padding: 14px 28px; font-size: 1rem; }
.button-row { display: flex; gap: 12px; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
  backdrop-filter: blur(10px);
}

.grid-two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-two .card { margin-bottom: 0; }
.grid-two { margin-bottom: 16px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile {
  display: flex; flex-direction: column; gap: 4px; padding: 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  position: relative; overflow: hidden;
}
.tile::after { content: ''; position: absolute; inset: auto -30% -60% auto; width: 120px; height: 120px; border-radius: 50%; background: radial-gradient(circle, rgba(124, 92, 255, 0.35), transparent 70%); }
.tile-label { color: var(--text-muted); font-size: 0.82rem; font-weight: 600; }
.tile-value { font-family: var(--font-display); font-size: 1.7rem; letter-spacing: -0.03em; }
.tile-hint { color: var(--text-muted); font-size: 0.8rem; }

.notice { padding: 14px 18px; border-radius: 14px; background: rgba(255, 176, 32, 0.12); border: 1px solid rgba(255, 176, 32, 0.35); color: #ffd98a; margin-bottom: 16px; }
.notice-error { background: rgba(255, 90, 110, 0.12); border-color: rgba(255, 90, 110, 0.4); color: #ff9aa6; }

.cover { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; flex: none; background: var(--surface-strong); }
.cover-round { border-radius: 50%; }
.cover-small { width: 38px; height: 38px; }
.cover-large { width: 84px; height: 84px; }
.cover-placeholder { display: grid; place-items: center; font: 800 1.2rem var(--font-display); color: var(--text); background: linear-gradient(135deg, var(--purple), var(--pink)); }

.ranked { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.ranked-row { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 12px; animation: fade-up 0.4s ease both; transition: background 0.2s; }
.ranked-row:hover { background: var(--surface-strong); }
.ranked-position { width: 26px; text-align: center; font: 800 0.9rem var(--font-display); color: var(--text-muted); }
.ranked-row:nth-child(1) .ranked-position { color: var(--orange); }
.ranked-row:nth-child(2) .ranked-position { color: #c9d1e0; }
.ranked-row:nth-child(3) .ranked-position { color: #d9915a; }
.ranked-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ranked-text strong, .ranked-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranked-text small { color: var(--text-muted); }
.ranked-count { text-align: right; font-weight: 800; display: flex; flex-direction: column; line-height: 1.1; }
.ranked-count small { color: var(--text-muted); font-weight: 600; font-size: 0.72rem; }

.facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.facts li { display: flex; gap: 14px; align-items: flex-start; }
.facts li > span { font-size: 1.5rem; }
.facts strong { display: block; }
.facts div { color: var(--text-muted); font-size: 0.92rem; }
.facts strong { color: var(--text); }

.hero-card { display: flex; align-items: center; gap: 20px; background: linear-gradient(135deg, rgba(124, 92, 255, 0.25), rgba(255, 62, 165, 0.15)); }
.hero-card h2 { margin-bottom: 4px; font-size: 1.4rem; }
.hero-card p { margin: 0; color: var(--text-muted); }
.hero-emoji { font-size: 3.2rem; }

.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 200px; }
.bar-chart-compact { gap: 3px; }
.bar-column { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.bar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.bar-fill { width: 100%; border-radius: 6px 6px 2px 2px; background: linear-gradient(180deg, var(--purple), rgba(124, 92, 255, 0.35)); transform-origin: bottom; animation: grow 0.7s cubic-bezier(0.2, 0.9, 0.3, 1) both; }
.bar-peak .bar-fill { background: linear-gradient(180deg, var(--green), rgba(30, 215, 96, 0.35)); }
.bar-label { color: var(--text-muted); font-size: 0.7rem; height: 14px; white-space: nowrap; }

.horizontal-bars { display: grid; gap: 12px; }
.horizontal-bar-head { display: flex; justify-content: space-between; gap: 12px; font-size: 0.9rem; margin-bottom: 4px; }
.horizontal-bar-track { height: 8px; border-radius: 999px; background: var(--surface-strong); overflow: hidden; }
.horizontal-bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--pink), var(--orange)); animation: slide-in 0.8s cubic-bezier(0.2, 0.9, 0.3, 1) both; transform-origin: left; }

.heatmap-scroll { overflow-x: auto; padding-bottom: 6px; }
.heatmap { display: grid; grid-template-rows: repeat(7, 13px); grid-auto-flow: column; grid-auto-columns: 13px; gap: 3px; width: max-content; }
.heat-cell { border-radius: 3px; background: var(--surface-strong); }
.heat-empty { background: transparent; }
.heat-level-1 { background: rgba(30, 215, 96, 0.3); }
.heat-level-2 { background: rgba(30, 215, 96, 0.5); }
.heat-level-3 { background: rgba(30, 215, 96, 0.75); }
.heat-level-4 { background: var(--green); box-shadow: 0 0 8px rgba(30, 215, 96, 0.6); }

.versus { display: flex; align-items: center; justify-content: space-around; gap: 16px; flex-wrap: wrap; }
.versus-person { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.versus-person small { color: var(--text-muted); }
.ring { --percent: 50; width: 170px; height: 170px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--green) calc(var(--percent) * 1%), var(--surface-strong) 0); }
.ring-inner { width: 140px; height: 140px; border-radius: 50%; background: #12121f; display: grid; place-content: center; text-align: center; }
.ring-inner strong { font: 800 2rem var(--font-display); }
.ring-inner small { color: var(--text-muted); }

.achievement-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.achievement { display: flex; flex-direction: column; gap: 6px; padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); opacity: 0.55; }
.achievement small { color: var(--text-muted); }
.achievement-unlocked { opacity: 1; border-color: rgba(30, 215, 96, 0.5); background: linear-gradient(160deg, rgba(30, 215, 96, 0.14), var(--surface)); }
.achievement-icon { font-size: 2rem; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-strong); overflow: hidden; }
.progress div { height: 100%; background: linear-gradient(90deg, var(--green), var(--blue)); }

.game-card { text-align: center; }
.game-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.game-option { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 18px; border-radius: 16px; border: 2px solid var(--border); background: var(--surface); color: var(--text); font: 700 1rem var(--font-body); cursor: pointer; transition: 0.2s; }
.game-option:hover:not(:disabled) { border-color: var(--purple); transform: translateY(-2px); }
.game-option .cover { width: 96px; height: 96px; }
.game-option small { color: var(--text-muted); font-weight: 600; }
.game-reveal { color: var(--text-muted); font-weight: 600; min-height: 1.2em; }
.game-correct { border-color: var(--green); background: rgba(30, 215, 96, 0.14); }
.game-wrong { border-color: rgba(255, 90, 110, 0.6); opacity: 0.75; }

input[type='file'] { color: var(--text-muted); margin: 8px 0; max-width: 100%; }

.loading { display: flex; gap: 8px; justify-content: center; padding: 80px 0; }
.loading span { width: 12px; height: 12px; border-radius: 50%; background: var(--green); animation: bounce 1s infinite ease-in-out; }
.loading span:nth-child(2) { animation-delay: 0.15s; background: var(--purple); }
.loading span:nth-child(3) { animation-delay: 0.3s; background: var(--pink); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; position: relative; overflow: hidden; }
.login-blob { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.5; animation: float 12s ease-in-out infinite; }
.login-blob-one { width: 420px; height: 420px; background: var(--purple); top: -100px; left: -80px; }
.login-blob-two { width: 380px; height: 380px; background: var(--green); bottom: -120px; right: -60px; animation-delay: -6s; }
.login-card { position: relative; max-width: 520px; text-align: center; display: grid; gap: 20px; justify-items: center; padding: 40px 28px; border-radius: 28px; background: rgba(15, 15, 28, 0.7); border: 1px solid var(--border); backdrop-filter: blur(24px); }
.login-card p { color: var(--text-muted); margin: 0; }
.slide-accent { background: linear-gradient(90deg, var(--green), var(--blue)); -webkit-background-clip: text; background-clip: text; color: transparent; }

.story-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(0, 0, 0, 0.86); animation: fade-in 0.3s ease; }
.story-frame { position: relative; width: min(440px, 100vw); height: min(860px, 100dvh); border-radius: 28px; overflow: hidden; display: flex; flex-direction: column; justify-content: center; padding: 70px 32px 40px; transition: background 0.6s; }
@media (max-width: 480px) { .story-frame { border-radius: 0; } }
.slide-green { background: linear-gradient(160deg, #0b5d3b, #0b1f2e 80%); }
.slide-purple { background: linear-gradient(160deg, #4a1f9c, #170a33 85%); }
.slide-pink { background: linear-gradient(160deg, #a3135f, #2a0a28 85%); }
.slide-orange { background: linear-gradient(160deg, #b8560a, #2b1305 85%); }
.slide-blue { background: linear-gradient(160deg, #0b57a8, #08142e 85%); }
.slide-final { background: linear-gradient(160deg, #1b0b3a, #0c6b4a); }
.story-progress { position: absolute; top: 14px; left: 14px; right: 14px; display: flex; gap: 4px; z-index: 3; }
.story-progress span { flex: 1; height: 3px; border-radius: 2px; background: rgba(255, 255, 255, 0.25); overflow: hidden; }
.story-progress i { display: block; height: 100%; width: 0; background: #fff; }
.story-progress .done i { width: 100%; }
.story-progress .active i { animation: fill-progress linear forwards; }
.story-close { position: absolute; top: 28px; right: 18px; z-index: 5; border: 0; background: rgba(0, 0, 0, 0.35); color: #fff; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; }
.story-zone { position: absolute; top: 60px; bottom: 0; width: 38%; z-index: 2; border: 0; background: transparent; cursor: pointer; }
.story-zone-previous { left: 0; }
.story-zone-next { right: 0; width: 62%; }
.story-slide { position: relative; z-index: 4; pointer-events: none; display: flex; flex-direction: column; gap: 14px; animation: fade-up 0.6s ease both; }
.story-slide button { pointer-events: auto; }
.slide-kicker { font-weight: 800; text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.8rem; opacity: 0.8; margin: 0; }
.slide-title { font: 800 clamp(1.7rem, 7vw, 2.4rem)/1.15 var(--font-display); margin: 0; }
.slide-huge { font: 800 clamp(3.4rem, 17vw, 5.6rem)/1 var(--font-display); letter-spacing: -0.04em; }
.slide-note { opacity: 0.85; font-size: 1.05rem; margin: 0; }
.slide-emoji { font-size: 6rem; animation: bounce-in 0.8s both; }
.slide-cover { width: 220px; height: 220px; border-radius: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5); animation: bounce-in 0.8s both; }
.slide-cover-round { border-radius: 50%; }
.slide-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 16px; }
.slide-list li { display: flex; align-items: center; gap: 14px; animation: fade-up 0.6s ease both; }
.slide-rank { font: 800 1.6rem var(--font-display); width: 32px; opacity: 0.7; }
.slide-list-name { flex: 1; font-weight: 800; font-size: 1.2rem; display: flex; flex-direction: column; line-height: 1.2; }
.slide-list-name small { font-weight: 600; opacity: 0.7; font-size: 0.85rem; }
.slide-list-count { font-weight: 800; opacity: 0.8; }
.share-preview { display: grid; place-items: center; }
.share-canvas { width: auto; max-width: 100%; max-height: 52dvh; border-radius: 16px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5); }
.slide-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

@keyframes fade-up { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes slide-in { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }
@keyframes bounce-in { 0% { transform: scale(0.3); opacity: 0; } 60% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }
@keyframes float { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(40px, 30px); } }
@keyframes fill-progress { from { width: 0; } to { width: 100%; } }

@media (max-width: 760px) {
  .grid-two { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .nav { order: 3; flex-basis: 100%; }
  .brand { flex: 1; }
  .card { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-delay: 0ms !important; }
}

.ranked-clickable { cursor: pointer; }
.back-link { display: inline-block; color: var(--text-muted); font-weight: 600; margin-bottom: 14px; }
.back-link:hover, .text-link:hover { color: var(--text); }
.text-link { color: var(--green); font-weight: 700; }
.cover-xlarge { width: 140px; height: 140px; border-radius: 16px; }
.cover-xlarge.cover-round { border-radius: 50%; }
.profile-hero { display: flex; align-items: center; gap: 24px; background: linear-gradient(135deg, rgba(124, 92, 255, 0.22), rgba(30, 215, 96, 0.1)); }
.profile-hero h1 { margin: 4px 0 10px; word-break: break-word; }
.profile-hero p { margin: 0; }
.chip-static { cursor: default; }
.notice-good { background: rgba(30, 215, 96, 0.1); border-color: rgba(30, 215, 96, 0.35); color: #9bf0bb; }
.select { border: 1px solid var(--border); background: var(--surface-strong); color: var(--text); padding: 9px 14px; border-radius: 12px; font: 600 0.9rem var(--font-body); color-scheme: dark; }
.comparison-table { width: 100%; border-collapse: collapse; margin-top: 16px; }
.comparison-table th, .comparison-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.comparison-table th { color: var(--text-muted); font-size: 0.85rem; }
.delta-up { color: var(--green); font-weight: 800; }
.delta-down { color: #ff7a8a; font-weight: 800; }
.leaders { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.leader { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); animation: fade-up 0.5s ease both; }
.leader-you { border-color: rgba(30, 215, 96, 0.6); background: linear-gradient(135deg, rgba(30, 215, 96, 0.12), var(--surface)); }
.leader-place { width: 34px; text-align: center; font: 800 1.4rem var(--font-display); }
.leader-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.leader-main small { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leader-score { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.leader-score strong { font: 800 1.4rem var(--font-display); }
.leader-score small { color: var(--text-muted); }
.titles-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.title-badge { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 16px; border-radius: 16px; background: var(--surface-strong); border: 1px solid var(--border); }
.title-badge small { color: var(--green); font-weight: 700; }
.title-icon { font-size: 2rem; }
.matrix-scroll { overflow-x: auto; }
.matrix { border-collapse: separate; border-spacing: 4px; font-size: 0.85rem; }
.matrix th { color: var(--text-muted); font-weight: 600; padding: 6px 8px; text-align: center; white-space: nowrap; }
.matrix td { text-align: center; padding: 10px 12px; border-radius: 8px; min-width: 52px; font-weight: 700; }
.matrix-self { background: var(--surface); color: var(--text-muted); }
.capsule-card .view-head { margin-bottom: 10px; }
@media (max-width: 760px) {
  .profile-hero { flex-direction: column; text-align: center; }
  .leader { flex-wrap: wrap; }
}

.language-select {
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.language-select option {
  color: #111;
}
.login-language {
  margin-top: 18px;
}
