:root {
  --felt: #0d3b2e;
  --felt-2: #0a2f24;
  --ink: #f2f6f4;
  --muted: #9db3ab;
  --card: #12352b;
  --card-2: #164033;
  --line: rgba(255, 255, 255, 0.09);
  --gold: #f2b134;
  --good: #4ade80;
  --bad: #f87171;
  --radius: 16px;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  overscroll-behavior-x: none;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 700px at 15% -10%, #17513e 0%, transparent 60%),
    radial-gradient(900px 600px at 100% 0%, #0f4536 0%, transparent 55%),
    var(--felt-2);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

body.modal-open { overflow: hidden; }

h1, h2, h3, h4 { margin: 0; line-height: 1.25; overflow-wrap: anywhere; }
p { margin: 0; }
.muted { color: var(--muted); font-size: 0.9rem; }
.tiny { font-size: 0.75rem; }
.hidden { visibility: hidden; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 28px;
  padding-left: max(28px, env(safe-area-inset-left));
  padding-right: max(28px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
  background: rgba(6, 32, 25, 0.72);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.brand h1 { font-size: 1.15rem; letter-spacing: 0.2px; }
.brand p { font-size: 0.75rem; color: var(--muted); }
.logo { font-size: 1.8rem; }
.stats { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.stat {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 999px; font-size: 0.9rem;
}

/* ---------- buttons ---------- */
button { font: inherit; cursor: pointer; touch-action: manipulation; }
a { color: var(--gold); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}
.primary-btn {
  background: var(--gold); color: #221a05; border: 0;
  padding: 12px 20px; border-radius: 12px; font-weight: 650; min-height: 44px;
}
.primary-btn:hover { filter: brightness(1.07); }
.secondary-btn, .ghost-btn {
  background: rgba(255, 255, 255, 0.07); color: var(--ink);
  border: 1px solid var(--line); padding: 11px 18px; border-radius: 12px; min-height: 44px;
}
.ghost-btn { padding: 8px 12px; font-size: 0.85rem; min-height: 38px; }
.secondary-btn:active, .ghost-btn:active, .primary-btn:active { transform: translateY(1px); }

/* ---------- dashboard ---------- */
main {
  width: 100%; max-width: 1140px; margin: 0 auto; flex: 1;
  padding: 28px 24px 72px;
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
}
.hero {
  display: flex; justify-content: space-between; align-items: center;
  gap: 24px; flex-wrap: wrap; margin-bottom: 18px;
}
.hero h2 { font-size: 1.5rem; margin-bottom: 6px; }
.hero p { max-width: 620px; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.overall { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.overall-bar {
  flex: 1; height: 8px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.09); overflow: hidden;
}
.overall-fill { height: 100%; background: linear-gradient(90deg, #4ade80, var(--gold)); transition: width .4s; }

.level { margin-bottom: 34px; }
.level-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.level-head h3 { font-size: 1.05rem; }
.level-count {
  margin-left: auto; font-size: 0.78rem; color: var(--muted);
  border: 1px solid var(--line); padding: 3px 10px; border-radius: 999px;
}

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.card {
  text-align: left; color: inherit;
  background: linear-gradient(160deg, var(--card-2), var(--card));
  border: 1px solid var(--line); border-left: 3px solid var(--accent, var(--gold));
  border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 8px;
  transition: transform .15s, box-shadow .15s;
}
.card:active { transform: scale(0.985); }
.card.is-mastered { box-shadow: inset 0 0 0 1px rgba(242, 177, 52, 0.5); }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; }
.card-icon { font-size: 1.6rem; }
.card h4 { font-size: 1rem; }
.card-desc { font-size: 0.83rem; color: var(--muted); flex: 1; }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.strand-tag { font-size: 0.7rem; color: var(--muted); }
.mastery { font-size: 0.72rem; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.m-none { color: var(--muted); }
.m-started, .m-practicing { color: #8ab6f9; }
.m-proficient { color: #6ee7dc; }
.m-excellent { color: var(--good); }
.m-master { color: var(--gold); border-color: rgba(242, 177, 52, 0.5); }

.ring { width: 48px; height: 48px; }
.ring circle { fill: none; stroke-width: 5; transform: rotate(-90deg); transform-origin: 50% 50%; }
.ring-bg { stroke: rgba(255, 255, 255, 0.12); }
.ring-fg { stroke: var(--accent, var(--gold)); stroke-linecap: round; transition: stroke-dashoffset .5s; }
.ring text { fill: var(--ink); font-size: 13px; font-weight: 650; }

/* ---------- practice ---------- */
.practice-head { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-bottom: 22px; }
.practice-title { flex: 1; min-width: 220px; }
.practice-title h2 { font-size: 1.25rem; }
.smartscore {
  width: 190px; background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px;
}
.ss-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; }
.ss-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.ss-bar { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.ss-fill { height: 100%; width: 0; background: linear-gradient(90deg, #8ab6f9, var(--good)); transition: width .35s; }
.smartscore[data-band='m-master'] .ss-fill, .smartscore[data-band='m-excellent'] .ss-fill {
  background: linear-gradient(90deg, var(--good), var(--gold));
}

.qcard {
  background: linear-gradient(165deg, var(--card-2), var(--card));
  border: 1px solid var(--line); border-radius: 20px; padding: 26px;
}
.qmeta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.pill {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.8px;
  background: rgba(242, 177, 52, 0.16); color: var(--gold);
  padding: 4px 10px; border-radius: 999px;
}
.qtext { font-size: 1.28rem; margin-bottom: 20px; }
.options { display: grid; gap: 10px; }
.option {
  text-align: left; color: inherit; padding: 15px 16px; border-radius: 12px; min-height: 52px;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line);
  transition: background .12s, border-color .12s;
}
.option:disabled { cursor: default; opacity: 0.75; }
.option.right { background: rgba(74, 222, 128, 0.18); border-color: var(--good); opacity: 1; }
.option.wrong { background: rgba(248, 113, 113, 0.18); border-color: var(--bad); opacity: 1; }

.feedback { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.fb-head { font-weight: 650; margin-bottom: 6px; }
.ok { color: var(--good); }
.no { color: var(--bad); }
.streak { color: var(--gold); font-size: 0.85rem; margin-left: 6px; }
.feedback p { color: var(--muted); margin-bottom: 16px; line-height: 1.55; }

/* ---------- results ---------- */
.done { text-align: center; max-width: 620px; margin: 40px auto; }
.trophy { font-size: 4rem; margin-bottom: 10px; }
.done h2 { font-size: 1.6rem; margin-bottom: 8px; }
.done-stats { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin: 26px 0; }
.done-stats div {
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px 20px; min-width: 110px;
}
.done-stats b { display: block; font-size: 1.5rem; }
.done-stats span { font-size: 0.75rem; color: var(--muted); }
.done .hero-actions { justify-content: center; }

/* ---------- back to top ---------- */
.to-top {
  position: fixed; z-index: 20;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 46px; height: 46px; border-radius: 50%;
  font-size: 1.2rem; line-height: 1; color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(6px);
  opacity: 0.55;
  transition: opacity .2s, background .2s, transform .15s;
}
.to-top:active { transform: scale(0.94); }
.to-top[hidden] { display: none; }

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--line);
  background: rgba(6, 32, 25, 0.6);
  padding: 26px 24px calc(26px + env(safe-area-inset-bottom));
}
.footer-inner {
  max-width: 1140px; margin: 0 auto;
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px 24px;
}
.footer-brand strong { display: block; font-size: 0.95rem; }
.footer-brand p { font-size: 0.75rem; }
.footer-links { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.link-btn {
  display: inline-flex; align-items: center; min-height: 40px;
  padding: 8px 14px; border-radius: 10px; font-size: 0.85rem;
  color: var(--ink); text-decoration: none;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line);
}
.link-btn:active { transform: translateY(1px); }
.copyright { flex-basis: 100%; font-size: 0.75rem; color: var(--muted); }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(3, 18, 14, 0.72); backdrop-filter: blur(3px); }
.modal-card {
  position: relative; width: min(560px, 100%); max-height: min(86vh, 720px);
  display: flex; flex-direction: column;
  background: linear-gradient(165deg, var(--card-2), var(--card));
  border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.modal-head, .modal-foot { padding: 16px 20px; display: flex; align-items: center; gap: 10px; }
.modal-head { border-bottom: 1px solid var(--line); justify-content: space-between; }
.modal-foot { border-top: 1px solid var(--line); justify-content: flex-end; flex-wrap: wrap; }
.modal-body { padding: 18px 20px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; display: grid; gap: 8px; }
.modal-body label { font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.modal-body input, .modal-body select, .modal-body textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink);
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; resize: vertical;
}
.modal-body textarea { min-height: 110px; }
.icon-btn {
  background: transparent; border: 0; color: var(--muted);
  font-size: 1.1rem; width: 40px; height: 40px; border-radius: 10px;
}
.res-list { list-style: none; margin: 6px 0 12px; padding: 0; display: grid; gap: 12px; }.res-list li { display: grid; gap: 3px; padding-left: 14px; border-left: 2px solid rgba(242, 177, 52, 0.35); }
.res-list a { font-size: 0.92rem; }
.res-list span { font-size: 0.78rem; color: var(--muted); line-height: 1.45; }

/* ---------- player hub ---------- */
.social-card, .battle-card { max-width: 620px; }
.social-card .modal-body, .battle-card .modal-body, #socialPanel { min-width: 0; }
.social-intro { text-align: center; display: grid; gap: 8px; margin: 4px 0 8px; }
.social-intro h4, .battle-question { font-size: 1.1rem; }
.social-hero { font-size: 2.5rem; }
.check-row { display: flex; align-items: center; gap: 9px; color: var(--ink) !important; }
.check-row input { width: 19px !important; height: 19px; accent-color: var(--gold); }
.social-privacy { font-size: 0.78rem; color: var(--muted); line-height: 1.45; }
.profile-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 6px; }
.player-summary { display: flex; align-items: center; gap: 10px; padding: 4px 0 12px; }
.player-summary > div:nth-child(2), .player-row > div, .battle-row > div { min-width: 0; flex: 1; display: grid; gap: 2px; }
.player-summary b, .player-row b, .battle-row b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-summary span:not(.player-avatar), .player-row span:not(.player-avatar), .battle-row span { color: var(--muted); font-size: 0.77rem; }
.player-avatar { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; flex: 0 0 auto; color: #211705; background: var(--gold); font-weight: 750; }
.player-avatar.small { width: 35px; height: 35px; font-size: 0.8rem; }
.compact { min-height: 34px; padding: 5px 9px; white-space: nowrap; }
.social-tabs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; padding: 4px; background: rgba(255,255,255,.05); border-radius: 10px; }
.social-tabs button { min-width: 0; border: 0; border-radius: 7px; min-height: 38px; color: var(--muted); background: transparent; font-size: 0.8rem; overflow-wrap: anywhere; }
.social-tabs button.active { color: var(--ink); background: rgba(255,255,255,.12); }
#socialPanel { display: grid; gap: 8px; margin-top: 14px; }
.player-row, .battle-row { display: flex; align-items: center; gap: 9px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.score-gap, .social-state { white-space: nowrap; }
.score-gap { font-size: 0.7rem !important; }
.social-empty { padding: 22px 10px; text-align: center; font-size: 0.85rem; color: var(--muted); line-height: 1.5; }
.battle-score { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 0.8rem; }
.battle-score b { color: var(--gold); white-space: nowrap; }
.battle-question { margin: 10px 0 18px; line-height: 1.42; }
.battle-result { display: grid; gap: 10px; justify-items: center; text-align: center; padding: 28px 8px; }
.battle-result > span { font-size: 3rem; }
.history-summary { display: grid; gap: 2px; padding: 14px; border-radius: 12px; background: rgba(255,255,255,.05); }
.history-summary b { font-size: 1.7rem; }
.history-summary span, .history-summary strong { font-size: 0.78rem; color: var(--muted); }
.history-summary .positive { color: var(--good); }
.history-summary .negative { color: var(--bad); }
.history-list { display: grid; gap: 6px; }
.history-list > div { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: baseline; padding: 9px 11px; border-bottom: 1px solid var(--line); }
.history-list span, .history-list small { color: var(--muted); font-size: 0.75rem; }
.history-list .win { color: var(--good); }
.history-list .loss { color: var(--bad); }
.history-list .tie { color: var(--gold); }
.history-trigger { width: 100%; min-height: 42px; color: var(--muted); background: transparent; border: 1px dashed var(--line); border-radius: 10px; }
.ranking-row > strong:first-child { width: 28px; color: var(--gold); text-align: center; }
.ranking-row > strong:last-child { color: var(--gold); font-size: 1.1rem; }
.ranking-row.is-me { border-color: rgba(242, 177, 52, .5); background: rgba(242, 177, 52, .08); }

.fb-fallback {
  margin-top: 12px; padding: 12px; border-radius: 12px;
  background: rgba(242, 177, 52, 0.08); border: 1px solid rgba(242, 177, 52, 0.35);
  display: grid; gap: 10px;
}
.fb-status {
  margin-top: 8px; padding: 10px 12px; border-radius: 10px; font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line);
}
.fb-status[hidden] { display: none; }
.fb-status.ok { background: rgba(74, 222, 128, 0.14); border-color: rgba(74, 222, 128, 0.45); color: var(--good); }
.fb-status.warn { background: rgba(242, 177, 52, 0.12); border-color: rgba(242, 177, 52, 0.4); color: var(--gold); }
.fb-fallback[hidden] { display: none; }
.fb-fallback p { line-height: 1.5; }
.fb-fallback-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.fb-fallback-actions .link-btn { flex: 1 1 auto; justify-content: center; font-size: 0.8rem; }

/* ---------- pointer-capable devices only ---------- */
@media (hover: hover) and (pointer: fine) {
  .card:hover { transform: translateY(-3px); box-shadow: 0 12px 26px rgba(0, 0, 0, 0.35); }
  .option:hover:enabled { background: rgba(255, 255, 255, 0.11); border-color: rgba(255, 255, 255, 0.25); }
  .primary-btn:hover { filter: brightness(1.07); }
  .secondary-btn:hover, .ghost-btn:hover, .link-btn:hover, .icon-btn:hover { background: rgba(255, 255, 255, 0.13); }
  .to-top:hover { opacity: 1; background: rgba(255, 255, 255, 0.16); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition-duration: 0.01ms !important; }
}

@media (max-width: 860px) {
  .footer-links { margin-left: 0; }
}

@media (max-width: 620px) {
  .topbar { padding: 10px 14px; gap: 8px; flex-wrap: nowrap; }
  .brand { min-width: 0; gap: 8px; overflow: hidden; }
  .brand p { display: none; }
  .brand h1 { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .logo { font-size: 1.35rem; }
  .stats { gap: 5px; flex-wrap: nowrap; flex: 0 0 auto; }
  .stat { padding: 5px 8px; font-size: 0.78rem; gap: 4px; }
  #feedbackTop { display: none; }
  main { padding: 18px 14px 56px; }
  .hero h2 { font-size: 1.25rem; }
  .hero-actions { width: 100%; }
  .hero-actions button { flex: 1; }
  .grid { grid-template-columns: 1fr; }
  .practice-head { gap: 12px; }
  .practice-title h2 { font-size: 1.1rem; }
  .smartscore { width: 100%; display: flex; align-items: center; gap: 12px; }
  .smartscore .ss-label { flex: 0 0 auto; }
  .smartscore .ss-value { font-size: 1.25rem; }
  .smartscore .ss-bar { flex: 1; }
  .qcard { padding: 18px 16px; border-radius: 16px; }
  .qtext { font-size: 1.08rem; }
  .qmeta { flex-wrap: wrap; gap: 6px; }
  .done-stats div { flex: 1 1 40%; padding: 12px; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-card { width: 100%; max-height: 92vh; border-radius: 18px 18px 0 0; }
  .modal-foot { justify-content: stretch; }
  .modal-foot button { flex: 1; }
  .player-row, .battle-row { flex-wrap: wrap; }
  .player-row > .compact, .battle-row > .compact { margin-left: auto; }
  .score-gap { margin-left: 44px; }
  .profile-actions button { flex: 1; }
  .social-tabs { grid-template-columns: repeat(3, 1fr); }
  .social-tabs button { font-size: 0.76rem; min-height: 42px; }
  .history-list > div { gap: 8px; padding: 10px 4px; }
  .site-footer { padding: 22px 16px calc(22px + env(safe-area-inset-bottom)); }
  .footer-links { width: 100%; }
  .link-btn { flex: 1 1 45%; justify-content: center; }
  .to-top { width: 44px; height: 44px; bottom: calc(14px + env(safe-area-inset-bottom)); }
}

@media (max-width: 430px) {
  .brand h1 { display: none; }
  #socialTop { display: none; }
  .social-tabs { grid-template-columns: repeat(2, 1fr); }
  .player-row { align-items: flex-start; }
  .ranking-row > strong:last-child { margin-left: auto; }
}
