:root {
  --ink: #262626;
  --muted: #6b6b6b;
  --accent: #ef3829;
  --border: #e7e7e7;
  --bg: #fafafa;
  --card: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

header {
  padding: 36px 20px 26px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.logo {
  height: 48px;
  width: auto;
}

.page-title {
  font-weight: 900;
  font-size: 1.4rem;
  color: var(--ink);
  letter-spacing: -0.01em;
  margin: 16px 0 0;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 4px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
}

.tab {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--muted);
  padding: 16px 18px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab:hover {
  color: var(--ink);
}

.tab.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
  animation: fade-in 0.15s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.subtab {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--card);
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--ink);
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.subtab:hover {
  border-color: var(--accent);
}

.subtab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.bucket-panel {
  display: none;
}

.bucket-panel.active {
  display: block;
  animation: fade-in 0.15s ease;
}

.note {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: -8px;
  margin-bottom: 16px;
}

.progress-track {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.progress-bar-outer {
  flex: 1 1 auto;
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-inner {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #ff7a5c);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.progress-label {
  flex: none;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.gamebar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}

/* ---- Tier gradients, shared by the level shield and earned badge medals ---- */
.tier-bronze {
  background: linear-gradient(145deg, #e3a469, #a5651f);
  border-color: #7a4715;
}

.tier-silver {
  background: linear-gradient(145deg, #eef1f5, #a9b0bb);
  border-color: #8a8f97;
}

.tier-gold {
  background: linear-gradient(145deg, #ffe08a, #d79f1e);
  border-color: #a97914;
}

.tier-platinum {
  background: linear-gradient(145deg, #d9ecff, #7ea8d8);
  border-color: #5c80a8;
}

.tier-champion {
  background: linear-gradient(145deg, #ff8a6f, #c81f0f);
  border-color: #8f1409;
}

/* ---- Level rank shield ---- */
.level-shield {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px 6px 6px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.shield-icon {
  width: 42px;
  height: 42px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  clip-path: polygon(50% 0%, 100% 20%, 100% 78%, 50% 100%, 0% 78%, 0% 20%);
  box-shadow: inset 0 3px 4px rgba(255, 255, 255, 0.45);
}

.shield-icon svg {
  width: 20px;
  height: 20px;
  color: #fff;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.shield-info {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.shield-level {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.shield-name {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink);
}

/* ---- Points scoreboard stat ---- */
.points-stat {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 18px;
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
  min-width: 70px;
}

.points-value {
  font-size: 1.4rem;
  font-weight: 900;
  line-height: 1;
  display: inline-block;
  transition: transform 0.2s ease;
}

.points-value.bump {
  animation: bump 0.35s ease;
}

@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

.points-caption {
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.7;
  font-weight: 700;
  margin-top: 2px;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 500;
}

.link-btn {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* ---- Level progress-to-next bar ---- */
.level-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 420px;
  margin: 14px auto 0;
}

.level-progress-bar {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.level-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #ff9466);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.level-progress-label {
  flex: none;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

/* ---- Achievement badges (medallions) ---- */
.badge-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  margin-top: 18px;
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
}

.badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 78px;
  text-align: center;
}

.badge-medal {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.18);
}

.badge-medal::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 9px;
  right: 9px;
  height: 42%;
  border-radius: 50% 50% 60% 60% / 100% 100% 40% 40%;
  background: linear-gradient(rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0));
  pointer-events: none;
}

.badge-medal svg {
  width: 22px;
  height: 22px;
  color: #fff;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
}

.badge.locked {
  opacity: 0.55;
}

.badge.locked .badge-medal {
  background: #dcdcdc;
  border: 2px solid #cfcfcf;
  box-shadow: none;
}

.badge.locked .badge-medal::before {
  display: none;
}

.badge.locked .badge-medal svg {
  color: #8f8f8f;
}

.badge.earned .badge-medal {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.28);
}

.lock-badge {
  position: absolute;
  bottom: -3px;
  right: -3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #949494;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--card);
}

.lock-badge svg {
  width: 10px;
  height: 10px;
  color: #fff;
}

.badge-name {
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  line-height: 1.2;
  color: var(--ink);
}

.badge.locked .badge-name {
  color: #b5b5b5;
}

/* ---- Login gate ---- */
#login-gate[hidden], #app[hidden] {
  display: none;
}

#login-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #fff5f3, var(--bg) 60%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.08);
  padding: 32px 28px;
  text-align: center;
}

.login-card .logo {
  height: 40px;
  margin-bottom: 16px;
}

.login-card h1 {
  font-size: 1.3rem;
  font-weight: 900;
  margin: 0 0 8px;
}

.login-tagline {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 24px;
}

.login-step {
  display: none;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.login-step.active {
  display: flex;
}

.login-step label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.login-step input {
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
}

.login-step input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#code-input {
  letter-spacing: 0.3em;
  text-align: center;
  font-weight: 700;
  font-size: 1.3rem;
}

.btn-primary {
  appearance: none;
  border: none;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 800;
  padding: 12px 16px;
  border-radius: 10px;
  cursor: pointer;
  margin-top: 4px;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.btn-primary:hover {
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
  transform: none;
}

.login-hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin: -4px 0 0;
}

.login-error {
  color: var(--accent);
  font-size: 0.82rem;
  margin: 0;
  min-height: 1em;
}

.dev-code {
  font-size: 0.8rem;
  background: #fff9e6;
  border: 1px dashed #ffd666;
  border-radius: 8px;
  padding: 8px 10px;
  color: #8a6d00;
  margin: 0;
}

/* ---- Confetti ---- */
#confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  animation: confetti-fly 0.85s ease-out forwards;
}

@keyframes confetti-fly {
  0% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate(var(--dx), var(--dy)) rotate(var(--rot));
    opacity: 0;
  }
}

.video-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.04);
}

.video-list li {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s ease;
}

.video-list li:last-child {
  border-bottom: none;
}

.video-list li.done {
  background: #fff5f4;
}

.video-list .num {
  color: var(--accent);
  font-weight: 700;
  display: inline-block;
  width: 28px;
  flex: none;
}

.video-list a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
}

.video-list li.done a {
  color: var(--muted);
  text-decoration: line-through;
}

.video-list a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.bucket-panel ul {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.04);
}

.bucket-panel li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s ease;
}

.bucket-panel li:last-child {
  border-bottom: none;
}

.bucket-panel li.done {
  background: #fff5f4;
}

.bucket-panel li.done .res-label {
  color: var(--muted);
  text-decoration: line-through;
}

.res-label {
  flex: 1 1 260px;
}

.check {
  display: inline-flex;
  align-items: center;
  flex: none;
  margin-right: 12px;
  cursor: pointer;
}

.check input {
  appearance: none;
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  display: grid;
  place-content: center;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
  flex: none;
}

.check input:hover {
  border-color: var(--accent);
}

.check input:checked {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.05);
}

.check input:checked::after {
  content: "";
  width: 6px;
  height: 11px;
  border: solid white;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

.res-links {
  flex: 0 0 auto;
  font-size: 0.9rem;
  white-space: nowrap;
}

.bucket-panel a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

.bucket-panel a:hover {
  text-decoration: underline;
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 24px 20px 40px;
}

@media (max-width: 600px) {
  .wordmark { font-size: 1.25rem; }
  .bucket-panel li { flex-direction: column; align-items: flex-start; }
  .bucket-panel .res-label { flex: none; }
  .tabs { gap: 0; }
  .tab { padding: 14px 12px; font-size: 0.85rem; }
}
