*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #fdf0e0;
  --surface: #fff5e8;
  --surface2: #f0dcc0;
  --border: #d4b898;
  --text: #3a2818;
  --text-muted: #6b5a4a;
  --primary: #d03828;
  --secondary: #b05820;
  --green: #5a9a5a;
  --yellow: #e8b830;
  --orange: #d47830;
  --red: #c84030;
  --glow: rgba(232,96,48,.12);
  --radius: 0;
}

html, body {
  height: 100%;
}

body {
  background:
    radial-gradient(circle at 15% 25%, rgba(255,215,180,.5) 0, transparent 40px),
    radial-gradient(circle at 75% 35%, rgba(255,225,190,.4) 0, transparent 50px),
    radial-gradient(circle at 45% 60%, rgba(255,220,185,.3) 0, transparent 35px),
    linear-gradient(180deg, #fce4c8 0%, #fdf0e0 60%, #f5e8d8 100%);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  font-size: 15px;
  min-height: 100vh;
  position: relative;
  image-rendering: pixelated;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  width: 8px;
  height: 8px;
  image-rendering: pixelated;
  box-shadow:
    /* cloud 1 top-left */
    60px 50px 0 0 rgba(255,255,255,.85),
    68px 50px 0 0 rgba(255,255,255,.85),
    76px 50px 0 0 rgba(255,255,255,.85),
    84px 50px 0 0 rgba(255,255,255,.85),
    52px 58px 0 0 rgba(255,255,255,.85),
    60px 58px 0 0 rgba(255,255,255,.85),
    68px 58px 0 0 rgba(255,255,255,.85),
    76px 58px 0 0 rgba(255,255,255,.85),
    84px 58px 0 0 rgba(255,255,255,.85),
    92px 58px 0 0 rgba(255,255,255,.85),
    60px 66px 0 0 rgba(255,255,255,.85),
    68px 66px 0 0 rgba(255,255,255,.85),
    76px 66px 0 0 rgba(255,255,255,.85),
    84px 66px 0 0 rgba(255,255,255,.85),
    /* cloud 2 center-right */
    420px 110px 0 0 rgba(255,255,255,.75),
    428px 110px 0 0 rgba(255,255,255,.75),
    436px 110px 0 0 rgba(255,255,255,.75),
    444px 110px 0 0 rgba(255,255,255,.75),
    412px 118px 0 0 rgba(255,255,255,.75),
    420px 118px 0 0 rgba(255,255,255,.75),
    428px 118px 0 0 rgba(255,255,255,.75),
    436px 118px 0 0 rgba(255,255,255,.75),
    444px 118px 0 0 rgba(255,255,255,.75),
    452px 118px 0 0 rgba(255,255,255,.75),
    420px 126px 0 0 rgba(255,255,255,.75),
    428px 126px 0 0 rgba(255,255,255,.75),
    436px 126px 0 0 rgba(255,255,255,.75),
    444px 126px 0 0 rgba(255,255,255,.75),
    /* cloud 3 bottom center */
    180px 280px 0 0 rgba(255,255,255,.65),
    188px 280px 0 0 rgba(255,255,255,.65),
    172px 288px 0 0 rgba(255,255,255,.65),
    180px 288px 0 0 rgba(255,255,255,.65),
    188px 288px 0 0 rgba(255,255,255,.65),
    196px 288px 0 0 rgba(255,255,255,.65),
    172px 296px 0 0 rgba(255,255,255,.65),
    180px 296px 0 0 rgba(255,255,255,.65),
    188px 296px 0 0 rgba(255,255,255,.65),
    /* cloud 4 mid-left */
    40px 160px 0 0 rgba(255,240,220,.6),
    48px 160px 0 0 rgba(255,240,220,.6),
    36px 168px 0 0 rgba(255,240,220,.6),
    44px 168px 0 0 rgba(255,240,220,.6),
    52px 168px 0 0 rgba(255,240,220,.6),
    36px 176px 0 0 rgba(255,240,220,.6),
    44px 176px 0 0 rgba(255,240,220,.6),
    52px 176px 0 0 rgba(255,240,220,.6),
    /* cloud 5 far right */
    700px 200px 0 0 rgba(255,255,255,.55),
    708px 200px 0 0 rgba(255,255,255,.55),
    696px 208px 0 0 rgba(255,255,255,.55),
    704px 208px 0 0 rgba(255,255,255,.55),
    712px 208px 0 0 rgba(255,255,255,.55),
    720px 208px 0 0 rgba(255,255,255,.55),
    696px 216px 0 0 rgba(255,255,255,.55),
    704px 216px 0 0 rgba(255,255,255,.55),
    712px 216px 0 0 rgba(255,255,255,.55);
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  color: #d05020;
}

input, button, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* ─── Pixel box helper ─── */

.pixel-box {
  background: var(--surface);
  border: 2px solid var(--border);
  padding: 16px;
}

.pixel-box .title {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--primary);
  margin-bottom: 12px;
  text-transform: uppercase;
}

.back-link {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--text-muted);
  text-decoration: none;
  display: inline-block;
  margin-bottom: 4px;
}
.back-link:hover {
  color: var(--text);
}

/* ─── Header ─── */

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 960px;
  margin: 0 auto 8px;
  padding: 10px 20px;
  position: relative;
}

.brand {
  font-family: 'Press Start 2P', monospace;
  font-size: 13px;
  color: var(--primary);
  letter-spacing: 1px;
}

.brand span {
  color: var(--secondary);
}

.profile-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

.profile-btn .avatar {
  width: 28px; height: 28px;
  background: var(--surface2);
  border: 2px solid var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}

.profile-btn .avatar svg {
  width: 18px;
  height: 18px;
  color: var(--primary);
}

.profile-btn .pname {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--text);
}

.profile-btn .ptitle {
  font-size: 9px;
  color: var(--yellow);
  padding: 2px 6px;
  background: rgba(232,184,48,.12);
  border: 1px solid rgba(232,184,48,.2);
  font-family: 'Press Start 2P', monospace;
}

.profile-btn .chevron {
  font-size: 8px;
  color: var(--text-muted);
  margin-left: 2px;
}

/* ─── Profile Dropdown ─── */

#dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 20px;
  width: 340px;
  background: var(--surface);
  border: 2px solid var(--border);
  z-index: 100;
  max-height: 70vh;
  overflow-y: auto;
}

#dropdown.open {
  display: block;
}

.dropdown-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-bottom: 2px solid var(--border);
}

.dropdown-avatar {
  width: 40px; height: 40px;
  background: var(--surface2);
  border: 2px solid var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}

.dropdown-avatar svg {
  width: 26px;
  height: 26px;
  color: var(--primary);
}

.dropdown-info .dname {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  color: var(--text);
  margin-bottom: 2px;
}

.dropdown-info .dtitle {
  font-size: 10px;
  color: var(--yellow);
  font-family: 'Press Start 2P', monospace;
}

.dropdown-info .dlevel {
  font-size: 10px;
  color: var(--text-muted);
}

.dropdown-badges {
  padding: 12px;
}

.dropdown-badges .section-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.badge-mini-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.badge-mini {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 2px;
  background: var(--surface2);
  border: 1px solid var(--border);
  cursor: default;
}

.badge-mini.locked {
  opacity: .35;
  filter: grayscale(1);
}

.badge-mini svg {
  width: 22px; height: 22px;
  color: var(--text);
}

.badge-mini .bname {
  font-size: 7px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.2;
  font-family: 'Press Start 2P', monospace;
}

.dropdown-footer {
  padding: 8px 14px;
  border-top: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dropdown-footer a {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--text-muted);
  text-decoration: none;
}

.dropdown-footer a:hover {
  color: var(--text);
}

/* ─── Nav tabs ─── */

#nav {
  max-width: 960px;
  margin: 0 auto;
  display: none;
}

#nav.show {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 20px 0 20px;
}

#nav a {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 8px 14px;
  background: var(--surface);
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  border-top: 2px solid var(--border);
  border-left: 2px solid var(--border);
  border-right: 2px solid var(--border);
  text-decoration: none;
  transition: .15s;
}

#nav a:hover {
  color: var(--text);
  background: rgba(60,40,20,.04);
}

#nav a.active {
  color: var(--primary);
  border-top-color: var(--primary);
  border-left-color: var(--primary);
  border-right-color: var(--primary);
}

/* ─── Login ─── */

#view-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-box {
  background: var(--surface);
  border: 2px solid var(--border);
  padding: 40px;
  width: 100%;
  max-width: 380px;
}

.login-box h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  color: var(--primary);
  margin-bottom: 8px;
}

.login-box h1 span {
  color: var(--secondary);
}

.login-box p {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 14px;
}

.login-box label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.login-box input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  background: #fff;
  color: var(--text);
  margin-bottom: 16px;
  outline: none;
}

.login-box input:focus {
  border-color: var(--primary);
}

.login-box button {
  width: 100%;
  padding: 11px;
  border: 2px solid var(--border);
  background: var(--primary);
  color: #ffffff;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  cursor: pointer;
  transition: background .2s;
}

.login-box button:hover {
  background: #d05020;
}

.login-box button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-error {
  color: var(--red);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
}

/* ─── Layout ─── */

#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 20px 24px;
}

#app .view {
  display: none;
}

#app .view.active {
  display: block;
}

/* ─── User Title Display (Dashboard) ─── */

.user-title-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 8px 0;
  max-width: 100%;
  overflow: hidden;
}

.user-title-display svg {
  width: 28px;
  height: 28px;
  color: var(--yellow);
}

.user-title-text {
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  color: var(--yellow);
  text-transform: uppercase;
  letter-spacing: 2px;
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
}

@media (max-width: 640px) {
  .user-title-text {
    font-size: 13px;
    letter-spacing: 1px;
  }
}

/* ─── XP & Level Section ─── */

.xp-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
}

.level-display {
  font-family: 'Press Start 2P', monospace;
  font-size: 24px;
  color: var(--yellow);
  min-width: 80px;
  text-align: center;
  line-height: 1.3;
}

.level-display small {
  display: block;
  font-size: 8px;
  color: var(--text-muted);
  font-family: 'Press Start 2P', monospace;
}

.xp-right {
  flex: 1;
}

.xp-label {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-family: 'Press Start 2P', monospace;
}

.progress-bar {
  width: 100%;
  height: 24px;
  border: 2px solid var(--border);
  background: var(--surface2);
  position: relative;
  overflow: hidden;
}

.progress-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  transition: width .4s;
}

.xp-earned {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: 'Press Start 2P', monospace;
}

/* ─── Stats Grid ─── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.stat-card {
  background: var(--surface2);
  border: 2px solid var(--border);
  padding: 12px;
  text-align: center;
}

.stat-card .stat-value {
  font-family: 'Press Start 2P', monospace;
  font-size: 18px;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: 8px;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: 'Press Start 2P', monospace;
}

/* ─── XP History Chart ─── */

.chart-wrap {
  background: var(--surface);
  border: 2px solid var(--border);
  padding: 16px;
  margin-top: 16px;
}

.chart-wrap h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--primary);
  margin-bottom: 12px;
  text-transform: uppercase;
}

.chart-wrap canvas {
  max-height: 200px;
}

/* ─── Range filters ─── */

.range-filters {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.range-filters button {
  padding: 5px 14px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  cursor: pointer;
  transition: .15s;
}

.range-filters button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.range-filters button:hover:not(.active) {
  border-color: var(--primary);
  color: var(--primary);
}

/* ─── Chart stats ─── */

.chart-stats {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.chart-stats .label {
  margin-right: 2px;
}

.chart-stats strong {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--text);
}

/* ─── Leaderboard ─── */

.table-hint {
  font-size: 9px;
  color: var(--text-muted);
  font-family: 'Press Start 2P', monospace;
  margin-bottom: 8px;
  opacity: 0.7;
}

.table-wrap {
  background: var(--surface);
  border: 2px solid var(--border);
  margin-top: 16px;
  overflow-x: auto;
}

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

th, td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th:first-child,
td:first-child {
  width: 30px;
  text-align: center;
}

th:nth-child(3),
td:nth-child(3) {
  border-left: 2px solid var(--border);
}

.level-cell,
.xp-cell {
  width: 1%;
}

th {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--text-muted);
  background: var(--surface2);
}

tr[data-user-id] {
  cursor: pointer;
}

tr[data-user-id] .uname {
  color: var(--primary);
}

tr[data-user-id] td:last-child::after {
  content: "›";
  margin-left: 6px;
  opacity: 0.25;
  font-size: 18px;
  font-weight: bold;
  color: var(--primary);
}

tr[data-user-id]:hover td {
  background: rgba(60,40,20,.08);
}

tr[data-user-id]:hover td:last-child::after {
  opacity: 0.8;
}

tr[data-user-id]:active td:last-child::after {
  opacity: 1;
}

tr.highlight td {
  background: var(--glow);
}

tr.highlight:hover td {
  background: var(--glow);
}

.rank {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  width: 40px;
  text-align: center;
}

.rank.gold { color: #d4a040; }
.rank.silver { color: #8a8a8a; }
.rank.bronze { color: #cd7f32; }
.rank.highlight-rank { color: var(--primary); }

.user-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.user-avatar {
  width: 24px; height: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}

.user-avatar svg {
  width: 16px;
  height: 16px;
  color: var(--primary);
}

.uname {
  font-weight: 600;
}

.utitle {
  font-size: 9px;
  color: var(--text-muted);
  font-family: 'Press Start 2P', monospace;
}

.me-tag {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--primary);
}

.level-cell {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: var(--yellow);
}

.xp-cell {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
}

/* ─── Badge Progress Grid ─── */

.badge-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.badge-card {
  background: var(--surface);
  border: 2px solid var(--border);
  padding: 14px;
  display: flex;
  gap: 12px;
}

.badge-card.locked {
  opacity: .5;
}

.badge-card svg {
  width: 32px; height: 32px;
  min-width: 32px;
  color: var(--text);
}

.badge-info {
  flex: 1;
  min-width: 0;
}

.badge-info .bname {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--text);
  margin-bottom: 2px;
}

.badge-info .bdesc {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.badge-info .progress-text {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 3px;
  font-family: 'Press Start 2P', monospace;
}

.badge-info .mini-bar {
  width: 100%;
  height: 12px;
  border: 1px solid var(--border);
  background: var(--surface2);
  position: relative;
  overflow: hidden;
}

.badge-info .mini-bar .fill {
  height: 100%;
  background: var(--primary);
  transition: width .4s;
}

.badge-info .completed {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--green);
  margin-top: 4px;
}

/* ─── Title Cards ─── */

.title-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.title-card {
  background: var(--surface);
  border: 2px solid var(--border);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.title-card.title-card-current {
  border-color: var(--primary);
  background: rgba(232,96,48,.05);
}

.title-card .title-icon svg {
  width: 32px;
  height: 32px;
  color: var(--primary);
}

.title-info {
  flex: 1;
  min-width: 0;
}

.title-info .tname {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--text);
  margin-bottom: 2px;
}

.title-info .tcond {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.title-info .progress-text {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 3px;
  font-family: 'Press Start 2P', monospace;
}

.title-info .mini-bar {
  width: 100%;
  height: 12px;
  border: 1px solid var(--border);
  background: var(--surface2);
  position: relative;
  overflow: hidden;
}

.title-info .mini-bar .fill {
  height: 100%;
  background: var(--secondary);
  transition: width .4s;
}

.title-info .completed {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--green);
  margin-top: 4px;
}

@media (max-width: 640px) {
  .title-grid {
    grid-template-columns: 1fr;
  }
}

/* ─── Status Badges ─── */

.badge-tag {
  display: inline-block;
  padding: 2px 8px;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  border: 1px solid;
}

.badge-tag.green {
  background: rgba(90,154,90,.15);
  color: var(--green);
  border-color: var(--green);
}

.badge-tag.red {
  background: rgba(200,64,48,.15);
  color: var(--red);
  border-color: var(--red);
}

.badge-tag.orange {
  background: rgba(212,120,48,.15);
  color: var(--orange);
  border-color: var(--orange);
}

.badge-tag.gray {
  background: rgba(138,117,96,.1);
  color: var(--text-muted);
  border-color: var(--border);
}

/* ─── Loading ─── */

.loading {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
}

.loading::after {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 0;
  animation: spin .7s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Error ─── */

.error-msg {
  color: var(--red);
  padding: 16px;
  text-align: center;
}

/* ─── Calendar ─── */

.cal-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.month-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  flex: 1;
}

.cal-stats {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--text-muted);
  display: flex;
  gap: 10px;
  align-items: center;
}

.cal-stats .stat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.cal-stats .stat-dot.fee { background: var(--primary); }
.cal-stats .stat-dot.payment { background: var(--green); }

.cal-nav {
  display: flex;
  gap: 6px;
  align-items: center;
}

.cal-nav button {
  background: none;
  border: 2px solid var(--border);
  padding: 4px 8px;
  cursor: pointer;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--text-muted);
  line-height: 1;
  transition: .15s;
}

.cal-nav button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.cal-nav .cal-today {
  font-size: 7px;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-top: 2px solid var(--border);
  border-left: 2px solid var(--border);
}

.cal-dow {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--text-muted);
  text-align: center;
  padding: 8px 2px;
  border-right: 2px solid var(--border);
  border-bottom: 2px solid var(--border);
  background: var(--surface2);
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-right: 2px solid var(--border);
  border-bottom: 2px solid var(--border);
  cursor: pointer;
  transition: .15s;
  padding: 2px;
  min-width: 0;
}

.cal-day:hover { background: rgba(208,56,40,.06); }

.cal-day.other-month { opacity: .3; pointer-events: none; }

.cal-day.today { border: 2px solid var(--primary); }

.cal-day.selected {
  background: rgba(208,56,40,.10);
  border-color: var(--primary);
}

.cal-day .day-num {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  line-height: 1;
}

.cal-day .dots {
  display: flex;
  gap: 3px;
  align-items: center;
  min-height: 7px;
}

.cal-day .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.cal-day .dot.fee { background: var(--primary); }
.cal-day .dot.payment { background: var(--green); }

.cal-day .dot-count {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--green);
  line-height: 1;
}

/* ─── Day detail ─── */

.day-detail {
  margin-top: 14px;
}

.detail-header {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.detail-empty {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 14px 0;
}

.event-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.event-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 13px;
}

.event-item .ev-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.event-item .ev-dot.fee { background: var(--primary); }
.event-item .ev-dot.payment { background: var(--green); }

.event-item .ev-text { flex: 1; }
.event-item .ev-text strong { font-weight: 600; }

.event-item .ev-amount {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ─── Admin pages (users, fees, payments) ─── */

.admin-section {
  margin-top: 16px;
}

.admin-section h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--primary);
  margin-bottom: 12px;
}

/* ─── Responsive ─── */

@media (max-width: 640px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .badge-grid {
    grid-template-columns: 1fr;
  }

  .xp-wrap {
    flex-direction: column;
    text-align: center;
  }

  .level-display {
    min-width: auto;
  }

  #dropdown {
    width: 280px;
    right: 10px;
  }

  .profile-btn .pname,
  .profile-btn .ptitle {
    display: none;
  }

  #nav.show {
    padding: 4px 12px 0 12px;
  }

  #nav a {
    font-size: 8px;
    padding: 6px 10px;
    flex: 1 0 auto;
  }

  #app {
    padding: 0 12px 16px;
  }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  th, td {
    padding: 6px 6px;
    font-size: 12px;
  }

  td.rank {
    min-width: 20px;
    text-align: center;
  }

  .level-cell {
    text-align: center;
  }

  .xp-cell {
    text-align: right;
  }

  .utitle {
    font-size: 7px;
  }

  .user-avatar {
    width: 20px;
    height: 20px;
  }

  .user-avatar svg {
    width: 14px;
    height: 14px;
  }

  /* Calendar mobile */
  .month-label {
    font-size: 9px;
  }
  .cal-nav button {
    font-size: 8px;
    padding: 3px 6px;
  }
  .cal-day .day-num {
    font-size: 9px;
  }
  .cal-day .dot {
    width: 5px;
    height: 5px;
  }
  .cal-dow {
    font-size: 7px;
    padding: 6px 1px;
  }
  .event-item {
    font-size: 12px;
    padding: 6px 10px;
  }
  .event-item .ev-amount {
    font-size: 8px;
  }
  .cal-stats span.stat-dot {
    width: 6px;
    height: 6px;
  }

  .table-hint {
    font-size: 7px;
  }

  tr[data-user-id] td:last-child::after {
    font-size: 14px;
    margin-left: 3px;
  }
}
