/* =====================================================================
   CS2 Higher/Lower — design tokens
   Palette is intentionally NOT a single fixed accent color: each panel
   tints itself using the rarity color of the item it's showing right
   now (the same color-coding CS2 itself uses), so the page's mood
   shifts round to round with what actually turns up.
   ===================================================================== */
:root {
  --ink:            #0a0b0d;
  --panel:          #16181c;
  --panel-edge:     #2a2d33;
  --text:           #e8e9eb;
  --text-muted:     #8b8f97;
  --stattrak:       #cf6a32;
  --correct:        #4caf6d;
  --incorrect:      #d4483f;

  --font-display: 'Teko', 'Arial Narrow', sans-serif;
  --font-ui:      'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }

/* The `hidden` attribute is how every show/hide toggle in game.js works.
   Several classes below (.modal-overlay, .center-message, .duel) set an
   explicit `display: flex`, which — without this rule — silently wins
   over the browser's default `[hidden]{display:none}`, since an author
   rule that sets `display` otherwise overrides it regardless of the
   hidden attribute. This makes `hidden` behave as expected everywhere. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-ui);
  height: 100%;
  overflow: hidden;
}

.mono { font-family: var(--font-mono); }
.muted { color: var(--text-muted); }

button { font-family: inherit; cursor: pointer; }

/* ---------------------------------------------------------------------
   Top bar
   --------------------------------------------------------------------- */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--panel-edge);
  position: relative;
  z-index: 20;
}

.brand {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.5px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.brand-mark { color: var(--stattrak); }
.brand-sep { color: var(--panel-edge); font-weight: 400; }
.brand-name { color: var(--text); }

.icon-btn {
  background: transparent;
  border: 1px solid var(--panel-edge);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}
.icon-btn:hover, .icon-btn:focus-visible { color: var(--text); border-color: var(--text-muted); }
.icon-btn:focus-visible { outline: 2px solid var(--stattrak); outline-offset: 2px; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn-wide {
  width: auto;
  padding: 0 12px;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
}

/* ---------------------------------------------------------------------
   Round history bar — one dot per guess made this game
   --------------------------------------------------------------------- */
.history-bar {
  height: 34px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid var(--panel-edge);
  overflow: hidden;
}
.history-label {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 1.5px;
  flex-shrink: 0;
}
.history-track {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}
.history-track::-webkit-scrollbar { display: none; }
.history-dot {
  flex-shrink: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--panel-edge);
  animation: dotIn 0.25s ease both;
}
.history-dot.correct { background: var(--correct); }
.history-dot.incorrect { background: var(--incorrect); }
.history-dot.tie { background: var(--stattrak); }
@keyframes dotIn {
  from { opacity: 0; transform: scale(0.4); }
  to { opacity: 1; transform: scale(1); }
}

/* ---------------------------------------------------------------------
   Arena / duel layout
   --------------------------------------------------------------------- */
.arena {
  position: relative;
  height: calc(100vh - 56px - 34px);
  overflow: hidden;
}

.center-message {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  letter-spacing: 1px;
}
.center-message code {
  background: var(--panel);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--panel-edge);
}
.center-message .start-btn { margin-top: 10px; }

.duel {
  display: flex;
  height: 100%;
  position: relative;
}

.panel {
  flex: 1;
  position: relative;
  display: flex;
  align-items: stretch;
  justify-content: center;
  overflow: hidden;
  border-left: 1px solid var(--panel-edge);
  transition: transform 0.45s cubic-bezier(0.65, 0, 0.35, 1);
}
.panel-left { border-left: none; }

/* Round-advance slide: the revealed right panel becomes the new left
   panel by sliding one panel-width to the left (exactly covering the
   old left panel's spot, since both panels are equal width); the old
   left panel slides fully off-screen in the same motion. A fresh
   challenger then slides in from the right to become the new panel-right. */
.panel-exit-left   { transform: translateX(-100%); }
.panel-shift-left   { transform: translateX(-100%); }
.panel-enter-right  { transform: translateX(100%); }
.panel-no-transition { transition: none !important; }

.panel-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 30%, var(--rarity, #4b69ff) 0%, transparent 62%);
  opacity: 0.16;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.panel-inner {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 28px 40px;
  text-align: center;
  gap: 6px;
}

.badges {
  display: flex;
  gap: 8px;
  min-height: 22px;
  margin-bottom: 6px;
}
.badge {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.6px;
  padding: 3px 8px;
  border-radius: 3px;
  border: 1px solid currentColor;
}
.badge-rarity {
  color: var(--rarity, #8a8a8a);
}
.badge-stattrak {
  color: var(--stattrak);
  border-color: var(--stattrak);
}

.item-image-wrap {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
}
.item-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 24px rgba(0,0,0,0.55));
}

.item-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 30px;
  line-height: 1.05;
  margin: 4px 0 0;
  letter-spacing: 0.3px;
}
.item-wear {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 4px;
  letter-spacing: 0.5px;
}
.item-price {
  font-size: 34px;
  font-weight: 700;
  margin: 4px 0 0;
  color: var(--text);
}

/* ---------------------------------------------------------------------
   Streak badge — hexagonal nod to CS2 rank icons, straddles both panels
   --------------------------------------------------------------------- */
.streak-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 84px;
  height: 84px;
  clip-path: polygon(50% 0%, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%);
  background: var(--panel);
  border: 2px solid var(--stattrak);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  box-shadow: 0 0 0 6px var(--ink);
}
#streakNumber {
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 700;
}
.streak-badge.pulse-correct { animation: pulseGood 0.5s ease; }
.streak-badge.pulse-incorrect { animation: pulseBad 0.5s ease; }
@keyframes pulseGood {
  0% { border-color: var(--stattrak); }
  40% { border-color: var(--correct); transform: translate(-50%, -50%) scale(1.12); }
  100% { border-color: var(--stattrak); transform: translate(-50%, -50%) scale(1); }
}
@keyframes pulseBad {
  0% { border-color: var(--stattrak); }
  40% { border-color: var(--incorrect); transform: translate(-50%, -50%) scale(0.9); }
  100% { border-color: var(--stattrak); transform: translate(-50%, -50%) scale(1); }
}

/* ---------------------------------------------------------------------
   Guess controls + feedback
   --------------------------------------------------------------------- */
.guess-controls {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.guess-prompt {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin: 0 0 2px;
}
.guess-prompt span { color: var(--text); }

.guess-btn {
  width: 100%;
  max-width: 220px;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  color: var(--text);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.1s, border-color 0.15s, background 0.15s;
}
.guess-btn:hover:not(:disabled) { border-color: var(--text-muted); transform: translateY(-1px); }
.guess-btn:active:not(:disabled) { transform: translateY(0); }
.guess-btn:focus-visible { outline: 2px solid var(--stattrak); outline-offset: 2px; }
.guess-btn:disabled { opacity: 0.5; cursor: default; }
.guess-higher svg { color: var(--correct); }
.guess-lower svg { color: var(--incorrect); }

.feedback {
  margin-top: 8px;
  font-size: 13px;
  letter-spacing: 0.5px;
  padding: 6px 12px;
  border-radius: 4px;
}
.feedback.correct { color: var(--correct); border: 1px solid var(--correct); }
.feedback.incorrect { color: var(--incorrect); border: 1px solid var(--incorrect); }
.feedback.tie { color: var(--text-muted); border: 1px solid var(--panel-edge); }

/* ---------------------------------------------------------------------
   HUD corners
   --------------------------------------------------------------------- */
.hud-corner {
  position: absolute;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  z-index: 15;
  line-height: 1.3;
}
.hud-left { left: 22px; align-items: flex-start; }
.hud-right { right: 22px; align-items: flex-end; }
.hud-label {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--text-muted);
}
.hud-value {
  font-size: 20px;
  font-weight: 700;
}

/* ---------------------------------------------------------------------
   Settings modal
   --------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal {
  width: 320px;
  max-height: calc(100vh - 48px);
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-wide { width: 380px; max-width: calc(100vw - 32px); }
.modal-body { padding: 18px 16px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--panel-edge);
}
.modal-header h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 1px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  cursor: pointer;
}
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch-track {
  position: absolute; inset: 0;
  background: var(--panel-edge);
  border-radius: 999px;
  transition: background 0.15s;
}
.switch-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.15s;
}
.switch input:checked + .switch-track { background: var(--stattrak); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--stattrak); outline-offset: 2px; }

.modal-note { font-size: 11px; margin: 0; letter-spacing: 0.3px; line-height: 1.5; }
.modal-divider { border: none; border-top: 1px solid var(--panel-edge); margin: 2px 0; }

.filter-section { margin-top: 6px; }
.filter-section-title {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 1.5px;
  margin: 0 0 8px;
}
.filter-chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.filter-chip {
  background: transparent;
  border: 1px solid var(--panel-edge);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 5px 11px;
  border-radius: 999px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.filter-chip:hover { border-color: var(--text-muted); color: var(--text); }
.filter-chip.active { border-color: var(--stattrak); color: var(--stattrak); background: rgba(207, 106, 50, 0.12); }
.filter-chip:focus-visible { outline: 2px solid var(--stattrak); outline-offset: 2px; }
#applyFiltersBtn { margin-top: 4px; }

.filter-chip-grade {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.filter-chip-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chip-color, #8a8a8a);
  flex-shrink: 0;
}
.filter-chip-grade.active {
  border-color: var(--chip-color, var(--stattrak));
  color: var(--chip-color, var(--stattrak));
  background: rgba(255, 255, 255, 0.06);
  background: color-mix(in srgb, var(--chip-color, var(--stattrak)) 18%, transparent);
}
.filter-chip-grade.active:focus-visible { outline-color: var(--chip-color, var(--stattrak)); }

.start-btn {
  background: transparent;
  border: 1px solid var(--stattrak);
  color: var(--stattrak);
  padding: 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
}
.start-btn:hover { background: rgba(207, 106, 50, 0.12); }
.start-btn:focus-visible { outline: 2px solid var(--stattrak); outline-offset: 2px; }

/* ---------------------------------------------------------------------
   Leaderboard
   --------------------------------------------------------------------- */
.lb-current {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 1px;
  margin: 0 0 8px;
}
.lb-current span { color: var(--stattrak); font-weight: 700; }

.lb-submit-row {
  display: flex;
  gap: 8px;
}
.lb-name-input {
  flex: 1;
  min-width: 0;
  background: var(--ink);
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 10px;
  font-family: var(--font-ui);
  font-size: 13px;
}
.lb-name-input:focus-visible { outline: 2px solid var(--stattrak); outline-offset: 1px; }
.lb-submit-btn { width: auto; white-space: nowrap; padding: 0 14px; }
.lb-submit-msg { margin: 8px 0 0; font-size: 11px; letter-spacing: 0.5px; }
.lb-submit-msg.success { color: var(--correct); }
.lb-submit-msg.error { color: var(--incorrect); }

.lb-tabs {
  display: flex;
  gap: 4px;
  margin: 16px 0 10px;
  border-bottom: 1px solid var(--panel-edge);
}
.lb-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  padding: 8px 4px 10px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.lb-tab:hover { color: var(--text); }
.lb-tab.active { color: var(--stattrak); border-bottom-color: var(--stattrak); }
.lb-tab:focus-visible { outline: 2px solid var(--stattrak); outline-offset: 2px; }

.lb-list {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.lb-loading, .lb-empty { text-align: center; padding: 18px 0; font-size: 12px; }

.lb-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 13px;
}
.lb-rank {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 11px;
}
.lb-row:nth-child(1) .lb-rank { color: var(--stattrak); }
.lb-name {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
  min-width: 0;
}
.lb-name-primary {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-name-filter {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-name .lb-stattrak-mark { color: var(--stattrak); font-size: 10px; margin-left: 4px; }
.lb-streak {
  font-family: var(--font-mono);
  font-weight: 700;
  text-align: right;
}

/* ---------------------------------------------------------------------
   Motion & responsiveness
   --------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.panel-inner, .item-image-wrap { animation: riseIn 0.35s ease both; }
@keyframes riseIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 760px) {
  html, body { overflow: auto; }
  .arena { height: auto; min-height: calc(100vh - 56px - 34px); }
  .duel { flex-direction: column; }
  .panel { border-left: none; border-top: 1px solid var(--panel-edge); min-height: 62vh; }
  .panel-left { border-top: none; }
  /* Panels stack vertically here, so the slide direction follows suit. */
  .panel-exit-left, .panel-shift-left { transform: translateY(-100%); }
  .panel-enter-right { transform: translateY(100%); }
  .streak-badge { top: 50%; }
  .item-name { font-size: 24px; }
  .item-price { font-size: 28px; }
  .hud-corner { position: static; flex-direction: row; gap: 6px; padding: 10px 16px; }
  .icon-btn-wide span { display: none; }
  .icon-btn-wide { width: 36px; padding: 0; }
  .history-label { display: none; }
}
