/* ── Reset & base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --page-bg:    #2F2F2F;
  --card-bg:    #0d0d0d;
  --text:       #ffffff;
  --text-dim:   rgba(255,255,255,0.45);
  --mint:       #b8f5e8;
  --mint-dark:  #0d0d0d;
  --cream:      #f5f0e8;
  --yellow:     #f5c518;
  --green:      #22c55e;
  --red:        #ef4444;
  --card-r:     20px;
  --btn-size:   56px;
  --font-title: 'Space Grotesk', -apple-system, sans-serif;
  --font-body:  'Manrope', -apple-system, sans-serif;
  --font-small: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font-body);
  background: var(--page-bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
button:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── Desktop shell ──────────────────────────────────────────── */
.shell-logo {
  position: fixed;
  top: 28px;
  left: 32px;
  font-size: 21.6px;
  cursor: pointer;
  font-weight: 700;
  font-family: var(--font-title);
  line-height: 21.6px;
  letter-spacing: -0.64px;
  color: #FAFAFA;
  z-index: 10;
}

.shell-links {
  position: fixed;
  bottom: 24px;
  left: 32px;
  font-size: 12px;
  font-family: Helvetica, Arial, sans-serif;
  font-weight: 700;
  line-height: 12px;
  letter-spacing: -0.48px;
  color: #595959;
  z-index: 10;
}

.shell-theme {
  position: fixed;
  bottom: 20px;
  right: 32px;
  color: var(--text-dim);
  z-index: 10;
  transition: color 0.2s;
}
.shell-theme:hover { color: var(--text); }

/* ── Game card ──────────────────────────────────────────────── */
.game-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 500px;
  height: 500px;
  background: var(--card-bg);
  border-radius: var(--card-r);
  overflow: hidden;
  box-shadow: 0 20px 70px rgba(0,0,0,0.65), 0 4px 18px rgba(0,0,0,0.45);
}

/* ── Screens ─────────────────────────────────────────────────── */
.screen {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  border-radius: var(--card-r);
  overflow: hidden;
}
.screen.active {
  opacity: 1;
  pointer-events: auto;
}

/* Flash screens (Ready/Set/Go) */
.screen-flash {
  background: var(--flash-bg);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
}
.flash-content {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 28px 28px 0 0;
}
.flash-value {
  font-size: 88px;
  font-weight: 700;
  font-family: var(--font-title);
  line-height: 77.44px;
  color: #FAFAFA;
  letter-spacing: -4.4px;
}
.flash-label {
  font-size: 19px;
  font-weight: 700;
  font-family: var(--font-title);
  color: #EBEBEB;
  margin-top: 4px;
  letter-spacing: -0.64px;
}

/* ── HOME screen ─────────────────────────────────────────────── */
#screen-home {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 28px;
}

.home-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.home-title {
  font-size: 88px;
  font-weight: 700;
  font-family: var(--font-title);
  color: #FAFAFA;
  line-height: 77.44px;
  letter-spacing: -4.4px;
  margin-bottom: 16px;
}

.home-desc {
  font-size: 19px;
  font-family: var(--font-body);
  font-weight: 600;
  line-height: 24.7px;
  color: #BDBDBD;
  letter-spacing: -0.285px;
  max-width: 360px;
  margin-bottom: 8px;
}

.home-bottom {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.home-mode-label {
  font-size: 19px;
  font-weight: 700;
  font-family: var(--font-title);
  color: #EBEBEB;
  letter-spacing: -0.64px;
  margin-bottom: 12px;
}

.home-btns {
  display: flex;
  gap: 12px;
}

.mode-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.mode-btn:not(:disabled):hover { transform: scale(1.06); }
.mode-btn:not(:disabled):active { transform: scale(0.95); }

.mode-btn.mint {
  background: var(--mint);
  color: var(--mint-dark);
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
}
.mode-btn.cream {
  background: var(--cream);
  color: #333;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.4);
}
.icon-btn:not(:disabled):hover { color: var(--text); }
.icon-btn.ghost { background: transparent; }

/* ── CHART screen ────────────────────────────────────────────── */
#screen-chart {
  display: flex;
  flex-direction: column;
  padding: 0;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px 8px;
  flex-shrink: 0;
}

.chart-label {
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-small);
  color: rgba(255,255,255,0.8);
}

.chart-timer {
  font-size: 42px;
  font-weight: 800;
  font-family: var(--font-title);
  letter-spacing: -1px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s;
}
.chart-timer.urgent { color: var(--red); }

.timer-dim {
  color: rgba(255,255,255,0.35);
}
.chart-timer.urgent .timer-dim {
  color: var(--red);
}

.chart-area {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.lock-btn {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: var(--btn-size);
  height: var(--btn-size);
  border-radius: 50%;
  background: var(--mint);
  color: var(--mint-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, opacity 0.3s;
  z-index: 5;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
}
.lock-btn:hover { transform: scale(1.06); }
.lock-btn:active { transform: scale(0.95); }
.lock-btn.hidden { opacity: 0; pointer-events: none; }

/* ── ROUND RESULT screen ─────────────────────────────────────── */
#screen-round-result {
  display: flex;
  flex-direction: column;
  padding: 24px 24px 24px;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-shrink: 0;
}

.result-round {
  font-size: 13px;
  font-family: var(--font-small);
  color: var(--text-dim);
  font-weight: 500;
  margin-top: 4px;
}

.result-score-block {
  text-align: right;
}

.result-score {
  font-size: 72px;
  font-weight: 900;
  font-family: var(--font-title);
  letter-spacing: -3px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.result-flavor {
  font-size: 17px;
  font-family: var(--font-title);
  font-weight: 700;
  color: #FAFAFA;
  max-width: 200px;
  text-align: right;
  line-height: 16px;
  letter-spacing: -1px;
  margin-top: 6px;
}

.result-canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
}

#result-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

.next-btn {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: var(--btn-size);
  height: var(--btn-size);
  border-radius: 50%;
  background: var(--mint);
  color: var(--mint-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
}
.next-btn:hover { transform: scale(1.06); }
.next-btn:active { transform: scale(0.95); }

/* ── FINAL RESULTS screen ────────────────────────────────────── */
#screen-final {
  display: flex;
  flex-direction: column;
  padding: 24px;
  gap: 16px;
}

.final-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-shrink: 0;
}

.final-header-left { display: flex; flex-direction: column; gap: 4px; }
.final-header-right { display: flex; align-items: center; gap: 12px; }

.final-rank {
  font-size: 18px;
  font-weight: 700;
  font-family: var(--font-title);
  color: var(--yellow);
}

.final-flavor {
  font-size: 17px;
  font-family: var(--font-title);
  font-weight: 700;
  color: #FAFAFA;
  line-height: 16px;
  letter-spacing: -1px;
}

.score-denom {
  color: var(--text-dim);
  font-weight: inherit;
}

.final-total {
  font-size: 22px;
  font-weight: 800;
  font-family: var(--font-title);
  letter-spacing: -0.5px;
}

.final-cards {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  justify-content: center;
  flex-shrink: 0;
}

.mini-card {
  width: 78px;
  height: 78px;
  flex-shrink: 0;
  border: 1.5px solid var(--yellow);
  border-radius: 10px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.mini-card-score {
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-small);
  color: var(--text);
  flex-shrink: 0;
}

.mini-card canvas {
  display: block;
  flex: 1;
  min-height: 0;
}

.final-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  margin-top: auto;
}

.action-btn {
  flex: 1;
  height: 44px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-body);
  transition: opacity 0.2s;
}
.action-btn.outline {
  border: 1.5px solid rgba(255,255,255,0.4);
  color: var(--text);
}
.action-btn.filled {
  background: var(--text);
  color: #000;
}
.action-btn:not(:disabled):hover { opacity: 0.85; }

/* ── Mobile ──────────────────────────────────────────────────── */
@media (max-width: 599px) {
  .shell-logo,
  .shell-links,
  .shell-theme { display: none; }

  .game-card {
    position: fixed;
    inset: 0;
    top: 0;
    left: 0;
    transform: none;
    width: 100%;
    height: 100%;
    border-radius: 0;
  }

  .screen { border-radius: 0; }

  .flash-value { font-size: 16vw; }
  .home-title { font-size: 18vw; }
  .chart-timer { font-size: 11vw; }
  .result-score { font-size: 18vw; }

  .mini-card {
    width: calc((100vw - 48px - 32px) / 5);
    height: calc((100vw - 48px - 32px) / 5);
  }

  .multi-title { font-size: 14vw; }

  .multi-close-float {
    width: 44px;
    height: 44px;
    background: rgba(255,255,255,0.15);
    border-radius: 50%;
    color: var(--text);
  }
}

/* ── Multiplayer lobby screen ────────────────────────────────── */
#screen-multi {
  display: flex;
  flex-direction: column;
  padding: 30px 20px 28px;
}

.multi-close {
  position: absolute;
  top: 30px;
  right: 20px;
  color: var(--text-dim);
  transition: color 0.2s;
}
.multi-close:hover { color: var(--text); }

.multi-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding-right: 44px;
}

.multi-title {
  font-size: 64px;
  font-weight: 700;
  font-family: var(--font-title);
  color: #FAFAFA;
  line-height: 0.88;
  letter-spacing: -3.2px;
  margin-bottom: 16px;
}

.multi-desc {
  font-size: 19px;
  font-family: var(--font-body);
  font-weight: 600;
  line-height: 24.7px;
  color: #BDBDBD;
  letter-spacing: -0.285px;
}

.multi-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.multi-name-input {
  height: 56px;
  border-radius: 999px;
  border: 1.5px solid rgba(255,255,255,0.4);
  background: transparent;
  color: var(--text);
  padding: 0 20px;
  font-size: 16px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.2s;
}
.multi-name-input::placeholder { color: var(--text-dim); }
.multi-name-input:focus { border-color: rgba(255,255,255,0.7); }

.multi-action-btn {
  height: 56px;
  border-radius: 999px;
  background: var(--text);
  color: #000;
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-body);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.2s, background 0.2s, color 0.2s;
  cursor: pointer;
  border: none;
}
.multi-action-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.multi-action-btn:not(:disabled):hover { opacity: 0.88; }
.multi-action-btn.copied { background: var(--green); color: #fff; opacity: 1; }

/* ── Multiplayer final results screen ────────────────────────── */
#screen-final-multi {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.multi-close-float {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  z-index: 10;
  transition: color 0.2s;
  flex-shrink: 0;
}
.multi-close-float:hover { color: var(--text); }

.multi-leaderboard-wrap {
  flex: 1;
  overflow-y: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
  padding: 0 20px;
  /* Fade top and bottom edges */
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0px,
    black 36px,
    black calc(100% - 36px),
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0px,
    black 36px,
    black calc(100% - 36px),
    transparent 100%
  );
}
.multi-leaderboard-wrap::-webkit-scrollbar { display: none; }

.multi-leaderboard {
  padding: 52px 0 44px;
}

.multi-player-entry {
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.multi-player-entry:last-child { border-bottom: none; }

.multi-player-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.multi-player-rank {
  font-size: 17px;
  font-weight: 700;
  font-family: var(--font-title);
  color: var(--yellow);
  flex-shrink: 0;
  min-width: 32px;
}

.multi-player-name {
  font-size: 17px;
  font-weight: 700;
  font-family: var(--font-title);
  color: #FAFAFA;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.multi-player-score {
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font-title);
  color: #FAFAFA;
  flex-shrink: 0;
  margin-left: auto;
  letter-spacing: -0.3px;
}

.multi-cards-row {
  display: flex;
  gap: 6px;
}

.multi-mini-card {
  flex: 1;
  min-width: 0;
  aspect-ratio: 1;
  width: auto;
  height: auto;
}

/* ── Solo final: initials input ───────────────────────────────── */
.initials-input {
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.4);
  border-radius: 999px;
  color: var(--text);
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-body);
  outline: none;
  flex: 0 0 90px;
  cursor: text;
  transition: border-color 0.2s;
}
.initials-input::placeholder { color: var(--text-dim); }
.initials-input:focus { border-color: rgba(255,255,255,0.7); }

/* ── "Link copied" flash on any button ───────────────────────── */
.action-btn.copied {
  background: var(--green) !important;
  color: #fff !important;
  border-color: var(--green) !important;
  opacity: 1 !important;
}

/* ── Game card height transition ────────────────────────────── */
.game-card {
  transition: height 0.35s ease;
}
.game-card--highscores {
  height: 680px;
}
@media (max-width: 599px) {
  .game-card--highscores { height: 100%; }
}

/* ── Daily lobby screen ─────────────────────────────────────── */
#screen-daily {
  display: flex;
  flex-direction: column;
  padding: 30px 20px 28px;
}

.daily-close {
  position: absolute;
  top: 30px;
  right: 20px;
  color: var(--text-dim);
  transition: color 0.2s;
}
.daily-close:hover { color: var(--text); }

.daily-header {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding-right: 44px;
}

.daily-date {
  font-size: 19px;
  font-family: var(--font-title);
  font-weight: 700;
  color: #EBEBEB;
  letter-spacing: -0.64px;
  margin-bottom: 4px;
}

.daily-title {
  font-size: 88px;
  font-family: var(--font-title);
  font-weight: 700;
  letter-spacing: -4.4px;
  line-height: 0.88;
  color: var(--text);
  margin: 0 0 16px;
}

.daily-desc {
  font-size: 19px;
  font-family: var(--font-body);
  font-weight: 600;
  line-height: 24.7px;
  color: #BDBDBD;
  letter-spacing: -0.285px;
  margin: 0;
  max-width: 360px;
}

.daily-charts-row {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.daily-chart-box {
  flex: 1;
  aspect-ratio: 1;
  border: 1.5px solid var(--yellow);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(255,255,255,0.03);
}

.daily-chart-box canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.daily-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: auto;
}

.daily-countdown {
  font-size: 13px;
  color: var(--text-dim);
  font-family: var(--font-body);
}

.daily-action-btn {
  width: 100%;
  height: 56px;
  border-radius: 999px;
  background: var(--text);
  color: var(--card-bg);
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-body);
  border: none;
  cursor: pointer;
  transition: opacity 0.2s;
}
.daily-action-btn:disabled { opacity: 0.35; cursor: default; }
.daily-action-btn:not(:disabled):hover { opacity: 0.88; }

@media (max-width: 599px) {
  .daily-title { font-size: 18vw; }
}

/* ── High Scores screen ─────────────────────────────────────── */
#screen-highscores {
  display: flex;
  flex-direction: column;
  padding: 20px 24px 0;
  overflow: hidden;
}

.hs-close {
  align-self: flex-end;
  color: var(--text-dim);
  transition: color 0.2s;
  margin-bottom: 4px;
}
.hs-close:hover { color: var(--text); }

.hs-header { margin-bottom: 4px; }

.hs-title {
  font-size: 56px;
  font-family: var(--font-title);
  font-weight: 700;
  letter-spacing: -2.8px;
  line-height: 1;
  margin: 0 0 4px;
  color: var(--text);
}

.hs-subtitle {
  font-size: 14px;
  color: var(--text-dim);
  font-family: var(--font-body);
  margin: 0 0 16px;
}

.hs-tabs {
  display: flex;
  gap: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: 0;
  flex-shrink: 0;
}

.hs-tab {
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-body);
  color: var(--text-dim);
  background: none;
  border: none;
  padding: 0 0 10px;
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
}
.hs-tab.active { color: var(--text); }
.hs-tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
}

.hs-list-wrap {
  flex: 1;
  overflow-y: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0px, black 32px, black calc(100% - 32px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0px, black 32px, black calc(100% - 32px), transparent 100%);
}
.hs-list-wrap::-webkit-scrollbar { display: none; }

.hs-list { padding: 32px 0 40px; }

.hs-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 11px 0;
}

.hs-rank-cell {
  width: 28px;
  flex-shrink: 0;
  font-size: 14px;
  font-family: var(--font-title);
  font-weight: 600;
  color: var(--text-dim);
  text-align: right;
}

.hs-initials {
  flex: 1;
  font-size: 17px;
  font-family: var(--font-title);
  font-weight: 700;
  color: var(--text);
}

.hs-score {
  flex-shrink: 0;
  font-size: 17px;
  font-family: var(--font-title);
  font-weight: 700;
  color: var(--text);
}

.hs-tied-group { position: relative; }

.hs-tied-cont .hs-rank-cell {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

.hs-tied-cont .hs-rank-cell::before {
  content: '';
  display: block;
  width: 2px;
  background: rgba(255,255,255,0.28);
  align-self: stretch;
  border-radius: 1px;
}

.hs-loading {
  padding: 48px 0;
  text-align: center;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 14px;
}

/* ── Shell link (Privacy etc.) ──────────────────────────────── */
.shell-link {
  color: inherit;
  text-decoration: none;
}
.shell-link:hover { color: rgba(255,255,255,0.5); }
