:root {
  --ink:             #0E0F12;
  --ink-soft:        #15171c;
  --panel:           #1B2530;
  --panel-line:      #2B3A4A;
  --parchment:       #EDE6D6;
  --gold:            #C9A24B;
  --gold-bright:     #E0BD6C;
  --silver:          #A8B2BC;
  --bronze:          #B87333;
  --burgundy:        #5C1A2B;
  --burgundy-bright: #8C2C45;
  --green:           #6fc98a;
  --ash:             #8B8F94;

  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body:    'Inter', system-ui, sans-serif;
  --font-mono:    'IBM Plex Mono', 'Courier New', monospace;
}

html {
  scroll-behavior: smooth;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--parchment);
  font-family: var(--font-body);
  line-height: 1.55;
  position: relative;
  overflow-x: hidden;
}

a { color: var(--gold-bright); text-decoration: none; }
a:hover { text-decoration: underline; }

.crest-watermark {
  position: fixed;
  top: -120px; right: -80px;
  font-size: 640px;
  color: var(--gold);
  opacity: 0.035;
  z-index: 0;
  pointer-events: none;
  user-select: none;
  line-height: 1;
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--panel-line);
}

.topbar-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--parchment);
  text-decoration: none;
}
.topbar-brand:hover { color: var(--gold-bright); text-decoration: none; }

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.topbar-link {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--ash);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}
.topbar-link:hover        { color: var(--parchment); background: rgba(255,255,255,0.04); text-decoration: none; }
.topbar-link--active      { color: var(--parchment); background: rgba(255,255,255,0.06); }

.topbar-divider {
  width: 1px; height: 18px;
  background: var(--panel-line);
  margin: 0 6px;
}

.topbar-user { color: var(--ash); padding: 6px 12px; font-family: var(--font-mono); font-size: 0.82rem; }

.topbar-cta {
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  padding: 6px 14px;
  border-radius: 999px;
  text-decoration: none;
}
.topbar-cta:hover { background: rgba(201,162,75,0.12); text-decoration: none; }

/* ── Hero ─────────────────────────────────────────────────────────────────── */

.hero {
  position: relative; z-index: 1;
  padding: 76px 24px 56px;
  text-align: center;
  border-bottom: 1px solid var(--panel-line);
  background: radial-gradient(ellipse at 50% -10%, rgba(201,162,75,0.10), transparent 60%);
}

.hero-inner { max-width: 720px; margin: 0 auto; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--ash); margin: 0 0 18px;
}

.wordmark {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(3rem, 9vw, 5.5rem);
  letter-spacing: 0.01em; margin: 0;
  color: var(--parchment);
  text-shadow: 0 0 40px rgba(201,162,75,0.25);
}

.slogan {
  font-family: var(--font-display); font-style: italic;
  font-size: 1.3rem; color: var(--gold-bright);
  letter-spacing: 0.03em; margin: 6px 0 36px;
}

.scoreboard {
  display: inline-flex; align-items: center; gap: 14px;
  padding: 10px 22px;
  border: 1px solid var(--panel-line); border-radius: 999px;
  background: rgba(27,37,48,0.6);
  font-family: var(--font-mono); font-size: 0.85rem;
}

.scoreboard-label { color: var(--gold-bright); font-weight: 600; }
.scoreboard-score { color: var(--gold-bright); }
.scoreboard-score strong { color: var(--parchment); font-size: 1rem; }

.logout-btn {
  background: none;
  border: 1px solid var(--panel-line); border-radius: 6px;
  color: var(--ash);
  font-family: var(--font-mono); font-size: 0.68rem;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 4px 10px; cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.logout-btn:hover { border-color: var(--burgundy-bright); color: var(--burgundy-bright); }

/* ── Main / Sections ─────────────────────────────────────────────────────── */

main {
  position: relative; z-index: 1;
  max-width: 1000px; margin: 0 auto;
  padding: 64px 24px 40px;
}

.section-title {
  font-family: var(--font-display); font-weight: 600;
  font-size: 1.9rem; margin: 0 0 6px; color: var(--parchment);
}

.section-sub { color: var(--ash); margin: 0 0 28px; max-width: 560px; }

/* ── Gates ───────────────────────────────────────────────────────────────── */

.gates { margin-bottom: 64px; }

.gate-row {
  display: grid; grid-template-columns: repeat(3,1fr); gap: 14px;
}
@media (max-width: 720px) { .gate-row { grid-template-columns: repeat(2,1fr); } }

.gate {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 18px; border-radius: 10px;
  border: 1px solid var(--panel-line);
  background: var(--panel); font-family: var(--font-body); text-align: left;
}
.gate-rune   { font-size: 1.3rem; color: var(--gold); }
.gate-name   { font-weight: 600; color: var(--parchment); font-size: 0.95rem; }
.gate-status {
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--ash);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.gate--open {
  cursor: default; border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(201,162,75,0.25), 0 12px 30px -16px rgba(201,162,75,0.4);
}
.gate--open .gate-status { color: var(--gold-bright); }
.gate--locked { opacity: 0.5; filter: saturate(0.6); }
.gate--locked .gate-rune { color: var(--ash); }

/* ── Challenge list ──────────────────────────────────────────────────────── */

.challenge-list {
  list-style: none; margin: 0 0 28px; padding: 0;
  border: 1px solid var(--panel-line); border-radius: 10px; overflow: hidden;
}
.challenge-list-item {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; background: var(--panel);
}
.challenge-list-item {
  animation: none;
}

.corridor--visible .challenge-list-item {
  animation: fadeSlideIn 0.3s ease both;
}

.corridor--visible .challenge-list-item:nth-child(1) { animation-delay: 0.08s; }
.corridor--visible .challenge-list-item:nth-child(2) { animation-delay: 0.14s; }
.corridor--visible .challenge-list-item:nth-child(3) { animation-delay: 0.20s; }
.corridor--visible .challenge-list-item:nth-child(4) { animation-delay: 0.26s; }
.corridor--visible .challenge-list-item:nth-child(5) { animation-delay: 0.32s; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

.challenge-list-name  { font-weight: 600; color: var(--parchment); }
.challenge-list-crown { color: var(--gold-bright); font-size: 1rem; }
.challenge-list-points {
  margin-left: auto; font-family: var(--font-mono); font-size: 0.82rem; color: var(--ash);
}

/* ── Door card ───────────────────────────────────────────────────────────── */

.door-card {
  display: grid; grid-template-columns: 220px 1fr; gap: 36px;
  padding: 32px;
  border: 1px solid var(--panel-line); border-radius: 14px;
  background: linear-gradient(160deg, var(--panel), var(--ink-soft));
  transition: box-shadow 0.4s ease, border-color 0.4s ease;
}

.corridor--visible .door-card {
  animation: fadeSlideIn 0.4s ease both;
  animation-delay: 0.15s;
}

.door-card.is-solved {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(201,162,75,0.3), 0 20px 60px -30px rgba(201,162,75,0.45);
}
@media (max-width: 640px) { .door-card { grid-template-columns: 1fr; } }

.door-card-visual { position: relative; display: flex; align-items: center; justify-content: center; }
.door-illustration { width: 100%; max-width: 200px; }

.crown-pin {
  position: absolute; top: -18px; font-size: 1.6rem;
  color: var(--gold-bright);
  filter: drop-shadow(0 0 10px rgba(201,162,75,0.6));
  animation: settle 0.5s ease;
}
@keyframes settle {
  from { transform: translateY(-10px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

.door-card-heading {
  display: flex; align-items: baseline; justify-content: space-between;
  flex-wrap: wrap; gap: 10px; margin-bottom: 14px;
}
.door-card-heading h3 {
  font-family: var(--font-display); font-size: 1.7rem; margin: 0; color: var(--parchment);
}
.crown-inline { margin-left: 10px; font-size: 1.1rem; color: var(--gold-bright); }

.door-meta { display: flex; gap: 8px; }
.pill {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.04em;
  text-transform: uppercase; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--panel-line);
}
.pill--difficulty { color: var(--gold-bright); border-color: rgba(201,162,75,0.4); }
.pill--points     { color: var(--ash); }
.pill--blood {
  color: #e07070;
  border-color: rgba(224,112,112,0.35);
  background: rgba(224,112,112,0.08);
}

.door-lore { color: #cfc8b8; margin: 0 0 22px; max-width: 560px; }
.door-lore a { color: var(--gold-bright); }

.hint-block { margin-bottom: 22px; }
.hint-toggle {
  background: none; border: none; color: var(--gold-bright);
  font-family: var(--font-mono); font-size: 0.82rem; cursor: pointer; padding: 0;
}
.hint-toggle:hover { text-decoration: underline; }
.hint-text {
  margin: 10px 0 0; padding: 12px 14px;
  border-left: 2px solid var(--gold); background: rgba(201,162,75,0.07);
  color: #d9d2c1; font-size: 0.92rem; max-width: 540px;
}

.instance-block {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 26px; font-size: 0.88rem;
}
.instance-label {
  font-family: var(--font-mono); font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--ash);
}
.instance-url {
  font-family: var(--font-mono); background: var(--ink);
  border: 1px solid var(--panel-line); padding: 3px 8px;
  border-radius: 5px; color: var(--gold-bright); text-decoration: none;
}
.instance-url:hover { text-decoration: underline; }
.instance-note { color: var(--ash); }

.flag-label {
  display: block; font-family: var(--font-mono); font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--ash); margin-bottom: 8px;
}
.flag-row { display: flex; gap: 10px; max-width: 460px; }

.flag-input {
  flex: 1; background: var(--ink); border: 1px solid var(--panel-line);
  border-radius: 8px; padding: 11px 14px; color: var(--parchment);
  font-family: var(--font-mono); font-size: 0.92rem;
}
.flag-input:focus    { outline: 2px solid var(--gold); outline-offset: 1px; }
.flag-input:disabled { opacity: 0.55; }

.flag-submit-btn {
  background: var(--gold); color: var(--ink); border: none;
  border-radius: 8px; padding: 11px 20px;
  font-family: var(--font-body); font-weight: 600; cursor: pointer;
  transition: background 0.2s ease;
}
.flag-submit-btn:hover    { background: var(--gold-bright); }
.flag-submit-btn:disabled { opacity: 0.55; pointer-events: none; }
.flag-submit-btn:focus-visible { outline: 2px solid var(--parchment); outline-offset: 2px; }

.flag-format-note { margin: 10px 0 0; font-size: 0.78rem; color: var(--ash); }
.flag-format-note code { font-family: var(--font-mono); color: var(--gold-bright); }

.flag-feedback { margin: 12px 0 0; font-size: 0.88rem; min-height: 1.2em; }
.flag-feedback.is-correct { color: var(--green); }
.flag-feedback.is-wrong   { color: var(--burgundy-bright); animation: shake 0.3s ease; }
.flag-feedback.is-solved  { color: var(--gold-bright); }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  25%     { transform: translateX(-4px); }
  75%     { transform: translateX(4px); }
}

.door-card.is-solved .flag-input,
.door-card.is-solved .flag-submit-btn { opacity: 0.55; pointer-events: none; }

/* ── Leaderboard ─────────────────────────────────────────────────────────── */

.lb-header {
  display: flex; align-items: flex-start;
  justify-content: space-between;
  gap: 16px; margin-bottom: 28px; flex-wrap: wrap;
}

.live-badge {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 14px;
  border: 1px solid var(--panel-line); border-radius: 999px;
  font-family: var(--font-mono); font-size: 0.72rem;
  color: var(--ash); align-self: center;
}

.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; flex-shrink: 0;
  transition: background 0.4s ease;
}
.live-dot--on {
  background: var(--green);
  box-shadow: 0 0 6px rgba(111,201,138,0.6);
  animation: pulse 2s ease infinite;
}
.live-dot--off { background: var(--ash); }

@keyframes pulse {
  0%,100% { opacity: 1; }
  50%     { opacity: 0.5; }
}

.live-label { text-transform: uppercase; letter-spacing: 0.06em; }

.leaderboard-card {
  border: 1px solid var(--panel-line); border-radius: 14px;
  background: linear-gradient(160deg, var(--panel), var(--ink-soft));
  overflow: hidden;
}

.leaderboard-table { width: 100%; border-collapse: collapse; }

.leaderboard-table th {
  text-align: left; font-family: var(--font-mono);
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ash); padding: 14px 18px;
  border-bottom: 1px solid var(--panel-line);
  background: rgba(0,0,0,0.15);
}

.leaderboard-table td {
  padding: 13px 18px;
  border-bottom: 1px solid rgba(43,58,74,0.5);
  font-size: 0.92rem;
}
.leaderboard-table tbody tr:last-child td { border-bottom: none; }
.leaderboard-table tbody tr:hover td     { background: rgba(201,162,75,0.04); }

.lb-rank { width: 52px; }

.medal {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  font-size: 0.95rem; background: var(--panel-line);
}
.medal--gold   { background: rgba(201,162,75,0.2);  color: var(--gold-bright); border: 1px solid rgba(201,162,75,0.5); }
.medal--silver { background: rgba(168,178,188,0.15); color: var(--silver);      border: 1px solid rgba(168,178,188,0.4); }
.medal--bronze { background: rgba(184,115,51,0.15);  color: var(--bronze);      border: 1px solid rgba(184,115,51,0.4); }
.medal--plain  { color: var(--ash); font-size: 0.78rem; border: 1px solid var(--panel-line); }

.lb-name   { color: var(--parchment); font-weight: 500; min-width: 140px; }
.lb-solves { font-family: var(--font-mono); color: var(--ash); width: 70px; }
.lb-last   { font-family: var(--font-mono); font-size: 0.8rem; color: var(--ash); width: 110px; }
.lb-score  { width: 160px; }

.lb-score-num {
  font-family: var(--font-mono); font-weight: 600;
  color: var(--gold-bright); display: block; margin-bottom: 5px;
}

.lb-bar-track {
  height: 5px; border-radius: 999px;
  background: var(--panel-line); overflow: hidden;
}
.lb-bar-fill {
  height: 100%; border-radius: 999px;
  background: rgba(201,162,75,0.35);
  transition: width 0.6s ease;
}
.lb-bar-fill--gold   { background: rgba(201,162,75,0.75); }
.lb-bar-fill--silver { background: rgba(168,178,188,0.6); }
.lb-bar-fill--bronze { background: rgba(184,115,51,0.6);  }

.lb-you td    { background: rgba(201,162,75,0.06); }
.lb-you:hover td { background: rgba(201,162,75,0.09) !important; }
.lb-first td:first-child { border-left: 3px solid var(--gold); }

.lb-you-tag {
  font-family: var(--font-mono); font-size: 0.65rem;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--gold); border: 1px solid rgba(201,162,75,0.4);
  border-radius: 999px; padding: 1px 7px; margin-left: 7px;
}

.lb-loading {
  text-align: center; color: var(--ash);
  font-family: var(--font-mono); padding: 30px 18px !important;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */

.site-footer {
  text-align: center; padding: 30px 24px 50px;
  color: var(--ash); font-size: 0.8rem; font-family: var(--font-mono);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .lb-last { display: none; }
  .scoreboard { flex-wrap: wrap; justify-content: center; }
  .topbar { padding: 12px 16px; }
  .topbar-nav { gap: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .crown-pin, .flag-feedback.is-wrong,
  .lb-bar-fill, .live-dot--on { animation: none; transition: none; }
}

/* ── Profile username links in leaderboard ───────────────────────────────── */

.lb-username-link {
  color: var(--parchment);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}
.lb-username-link:hover {
  color: var(--gold-bright);
  text-decoration: none;
}

/* ── Gate clickable ───────────────────────────────── */
.gate--open {
  cursor: pointer;   /* overrides cursor:default from earlier */
}

/* Challenge sections hidden by default — JS reveals them on gate click */
/* Replace the two corridor rules with this: */
.corridor {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-8px);
  transition: max-height 0.5s ease, opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
}

.corridor--visible {
  max-height: 6000px;   /* large enough for any number of challenges */
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  transition: max-height 0.5s ease, opacity 0.4s ease 0.05s, transform 0.4s ease 0.05s;
}

/* Challenge list name — clickable */
.challenge-list-name {
  cursor: pointer;
  transition: color 0.15s;
}
.challenge-list-name:hover { color: var(--gold-bright); }

.gate--open {
  cursor: pointer;
  transition: box-shadow 0.2s ease, transform 0.15s ease;
}

.gate--open:active {
  transform: scale(0.97);
}

.gate--active {
  box-shadow: 0 0 0 2px var(--gold), 0 12px 30px -16px rgba(201,162,75,0.5);
}
/* ── Notifications bell & dropdown ───────────────────────────────────────── */

.notif-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.notif-bell {
  position: relative;
  background: none;
  border: none;
  color: var(--ash);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.notif-bell:hover { color: var(--parchment); background: rgba(255,255,255,0.04); }
.notif-bell[aria-expanded="true"] { color: var(--gold-bright); }

.notif-badge {
  position: absolute;
  top: 2px; right: 2px;
  background: #e07070;
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
  border: 2px solid var(--ink);
  pointer-events: none;
}

.notif-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 320px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.45);
  z-index: 200;
  overflow: hidden;
  animation: dropIn 0.2s ease;
}

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.notif-dropdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--panel-line);
}

.notif-dropdown-title {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ash);
}

.notif-mark-read {
  background: none; border: none;
  font-family: var(--font-mono); font-size: 0.68rem;
  color: var(--gold-bright); cursor: pointer; padding: 0;
}
.notif-mark-read:hover { text-decoration: underline; }

.notif-list {
  list-style: none; margin: 0; padding: 0;
  max-height: 360px; overflow-y: auto;
}

.notif-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--ash);
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.notif-item {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(43,58,74,0.5);
  transition: background 0.15s;
}
.notif-item:last-child  { border-bottom: none; }
.notif-item:hover       { background: rgba(255,255,255,0.03); }
.notif-item--new        { background: rgba(201,162,75,0.06); }

.notif-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.notif-item-title {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--parchment);
}

.notif-new-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--gold-bright);
  flex-shrink: 0;
}

.notif-item-body {
  margin: 0 0 6px;
  font-size: 0.82rem;
  color: var(--ash);
  line-height: 1.45;
}

.notif-item-date {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--panel-line);
}
