/* ChipMatch — LGND brand. Light theme, palette mirrors wow-mcp. */

:root {
  /* Brand palette — copied from wow-mcp/web/src/styles/utils/variables/_colors.scss */
  --color-white: #ffffff;
  --color-pale: #f5f5f5;
  --color-grey-2: #e0e0e0;       /* page background */
  --color-grey-4: #cfcfcf;
  --color-grey-5: #bbbbbb;
  --color-grey-8: #9f9f9f;
  --color-grey-9: #999999;
  --color-grey-10: #686868;
  --color-dark: #3a3a3a;
  --color-black: #000000;
  --color-blue: #105dfb;
  --color-blue-hover: #6ea4f4;
  --color-blue-dark: #0c45b8;
  --color-purple: #9c70fc;
  --color-yellow: #ffdd00;
  --color-green: #79cd7c;
  --color-green-light: #a0f7a2;
  --color-red: rgb(230, 69, 33);
  --color-red-hover: rgb(190, 54, 23);

  /* Semantic aliases used by chipmatch */
  --bg: var(--color-grey-2);
  --surface: var(--color-pale);
  --surface-elevated: var(--color-white);
  --text: var(--color-dark);
  --text-strong: var(--color-black);
  --muted: var(--color-grey-10);
  --border: var(--color-grey-4);
  --primary: var(--color-blue);
  --primary-hover: var(--color-blue-hover);
  --primary-text: #ffffff;
  --accent: var(--color-green);
  --warn: var(--color-yellow);
  --bad: var(--color-red);

  --radius: 20px;
  --radius-small: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, sans-serif;
  font-feature-settings: "ss01", "cv11";
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Topographic backdrop — same image LGND Discover uses on its landing.
   The image's top quarter is solid black, so we pull it up out of the
   viewport with `top: -400px` and fade it into the page bg at the bottom
   so cards and text stay readable. Behind everything via z-index: -1. */
.page-bg {
  position: fixed;
  top: -400px;
  left: 0;
  right: 0;
  height: calc(100% + 400px);
  background-image: url('/static/background.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: -1;
  pointer-events: none;
}
.page-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    transparent 30%,
    rgba(224, 224, 224, 0.55) 70%,
    rgba(224, 224, 224, 0.95) 100%
  );
}

/* Surface bg of the topbar so it doesn't bleed into the topo image. */
.topbar { position: relative; z-index: 1; }
main { position: relative; z-index: 1; }
.footer { position: relative; z-index: 1; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

/* Hide trial-budget badges (and anything else marked) when BYOK is on.
   `app.js` toggles `body.byok-active` whenever a key is in localStorage. */
body.byok-active [data-hide-on-byok] { display: none !important; }

/* Hide the brand topbar on in-game pages — the game-header carries all
   the navigation needed (back to mode select, BYOK badge, mode label). */
body.in-game .topbar { display: none; }

/* Top loading bar */
#loading-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  background-position: -40% 0;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease;
}
body.loading #loading-bar {
  opacity: 1;
  animation: loading-slide 1.2s linear infinite;
}
@keyframes loading-slide {
  0%   { background-position: -40% 0; }
  100% { background-position: 140% 0; }
}

/* Active htmx requests */
.mode-card.htmx-request button,
.candidate-form.htmx-request .candidate,
button.primary.htmx-request {
  opacity: 0.55;
  cursor: wait;
  position: relative;
}
.mode-card.htmx-request button::after {
  content: "loading…";
  display: block;
  margin-top: 4px;
  color: var(--primary);
  font-size: 12px;
  letter-spacing: 1px;
}

/* Topbar — transparent so the topographic backdrop reads through. */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: transparent;
  border-bottom: 0;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 16px;
  color: var(--text-strong);
}
.brand:hover { color: var(--text-strong); text-decoration: none; }
.brand-logo {
  display: inline-block;
  width: 24px;
  height: 24px;
  color: var(--text-strong);
}
.brand-name { letter-spacing: 0.4px; }
.brand-product { color: var(--muted); font-weight: 400; margin-left: 4px; }
.topbar nav { display: flex; gap: 16px; align-items: center; font-size: 14px; }
.topbar nav a { color: var(--text); }

main {
  max-width: 1100px;
  margin: 12px auto;
  padding: 0 24px;
}
.footer {
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: 13px;
}

/* Landing */
.landing h1 {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--text-strong);
  margin-bottom: 4px;
}
.landing .lede { color: var(--text); max-width: 680px; }

.status-row { display: flex; gap: 8px; margin: 18px 0; flex-wrap: wrap; }
.trial-badge, .byok-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}
.trial-badge.exhausted { color: var(--bad); border-color: var(--bad); }
.byok-badge.ok { color: var(--accent); border-color: var(--accent); }

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.mode-card button {
  width: 100%;
  background: var(--surface-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font: inherit;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.mode-card button:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(16, 93, 251, 0.08);
}
.mode-card strong { font-size: 16px; color: var(--text-strong); font-weight: 600; }
.mode-card span { color: var(--muted); font-size: 14px; }

.byok-section {
  margin-top: 32px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-elevated);
}
.byok-form { display: flex; gap: 8px; margin-top: 8px; }
.byok-form input {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--radius-small);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font: inherit;
}
.byok-form input:focus {
  outline: none;
  border-color: var(--primary);
}
.byok-form button, .primary, button.primary {
  padding: 10px 18px;
  border: 0;
  background: var(--primary);
  color: var(--primary-text);
  border-radius: var(--radius-small);
  font-weight: 500;
  cursor: pointer;
  font: inherit;
  transition: background .15s ease;
}
.byok-form button:hover, .primary:hover, button.primary:hover {
  background: var(--primary-hover);
  text-decoration: none;
  color: var(--primary-text);
}

.key-ok { margin-top: 8px; color: var(--accent); }
.key-error { margin-top: 8px; color: var(--bad); }

/* Game shell */
.game-header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.game-header .mode { color: var(--text-strong); font-weight: 600; }
.game-header .back { margin-left: auto; }

.round-header {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
}
.round-header .prompt {
  color: var(--text-strong);
  font-weight: 500;
  font-size: 14px;
  margin-right: auto;
}
.round-header .score strong { color: var(--primary); font-weight: 600; }

.play-round { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.play-round .label { color: var(--muted); margin-bottom: 2px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.query-chip {
  width: 180px; height: 180px;
  object-fit: cover;
  border-radius: var(--radius-small);
  border: 2px solid var(--primary);
  box-shadow: 0 4px 16px rgba(16, 93, 251, 0.15);
}

.candidates {
  --candidate-gap: 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--candidate-gap);
  width: 100%;
  max-width: 720px;
}
.candidate {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border-radius: var(--radius-small);
  border: 2px solid var(--border);
  background: var(--surface-elevated);
  cursor: pointer;
  overflow: hidden;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.candidate img { width: 100%; height: 100%; object-fit: cover; display: block; }
.candidate .cnum {
  position: absolute; top: 6px; left: 6px;
  background: rgba(0, 0, 0, 0.65);
  color: white;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}
.candidate:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(16, 93, 251, 0.12);
}

/* Reveal */
.reveal-header {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 12px; flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--surface-elevated);
  border-radius: var(--radius-small);
}
.reveal-header-action { margin-left: auto; }
.result.hit { color: var(--accent); font-size: 22px; font-weight: 600; }
.result.close { color: var(--color-blue-dark); font-size: 22px; font-weight: 600; }
.result.miss { color: var(--bad); font-size: 22px; font-weight: 600; }
.banner { padding: 10px 14px; border-radius: var(--radius-small); margin-bottom: 12px; }
.banner.warn { background: rgba(255, 221, 0, 0.18); border: 1px solid var(--warn); color: var(--color-grey-10); }

/* Reveal "round" — same skeleton as the play view (query on top, candidate
   grid below) but with score + outcome overlays so the screenshot tells the
   whole story. */
.reveal-round { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 16px; }

.reveal-candidates { /* uses base .candidates grid */ }

.candidate-result {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-small);
  border: 2px solid var(--border);
  background: var(--surface-elevated);
  overflow: hidden;
}
.candidate-result img { width: 100%; height: 100%; object-fit: cover; display: block; }

.candidate-result .cnum {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0, 0, 0, 0.65);
  color: white;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}

.candidate-result .score-badge {
  position: absolute; bottom: 8px; right: 8px;
  background: rgba(0, 0, 0, 0.78);
  color: white;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}

.candidate-result .badge-stack {
  position: absolute;
  top: 8px; right: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}
.candidate-result .result-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}
.candidate-result .result-badge.model {
  background: var(--accent);
  color: #08231a;
}
.candidate-result .result-badge.user.hit {
  background: var(--accent);
  color: #08231a;
}
.candidate-result .result-badge.user.miss {
  background: var(--bad);
  color: white;
}

/* State-driven borders */
.candidate-result.is-correct { border-color: var(--accent); border-width: 3px; }
.candidate-result.is-wrong-guess { border-color: var(--bad); border-width: 3px; }
.candidate-result.is-guess.is-correct { border-color: var(--accent); border-width: 3px; }

.reveal-map {
  width: 100%;
  height: 40vh;
  min-height: 280px;
  border-radius: var(--radius-small);
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  margin-bottom: 16px;
}

.reveal-actions { display: flex; justify-content: flex-end; }

/* End-game */
.end-game {
  text-align: center;
  padding: 32px 24px;
  background: var(--surface-elevated);
  border-radius: var(--radius);
  margin-top: 24px;
}
.score-big {
  font-size: 64px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -2px;
}
.trial-msg { color: var(--muted); margin: 16px auto; max-width: 480px; }
.leaderboard-submit { display: flex; flex-direction: column; gap: 10px; align-items: center; margin-top: 20px; }
.leaderboard-submit input {
  text-align: center; text-transform: uppercase;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); padding: 10px 14px; border-radius: var(--radius-small);
  font: inherit; letter-spacing: 4px; font-weight: 600;
}
.leaderboard-submit input:focus { outline: none; border-color: var(--primary); }
.leaderboard-submit .skip { color: var(--muted); margin-top: 8px; font-size: 14px; }

/* Leaderboard */
.leaderboards .disclaimer { color: var(--muted); font-size: 14px; }
.lb-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; }
.lb-tab {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-elevated);
  color: var(--muted);
  font-size: 14px;
}
.lb-tab:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.leaderboard-table {
  width: 100%; border-collapse: collapse;
  background: var(--surface-elevated);
  border-radius: var(--radius-small); overflow: hidden;
}
.leaderboard-table th, .leaderboard-table td {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  font-size: 14px;
}
.leaderboard-table th { background: var(--surface); color: var(--muted); font-weight: 500; }
.leaderboard-table tr.highlight { background: rgba(16, 93, 251, 0.08); }
.leaderboard-table tr:last-child td { border-bottom: 0; }
.empty { color: var(--muted); }

.error-box, .byok-required {
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
}

.rate-limit-card {
  border: 1px solid var(--warn);
  background: rgba(255, 221, 0, 0.08);
  border-radius: var(--radius);
  padding: 24px 28px;
  max-width: 560px;
  margin: 32px auto;
}
.rate-limit-card h2 {
  margin-top: 0;
  margin-bottom: 12px;
  color: var(--text-strong);
  font-size: 22px;
}
.rate-limit-card p { margin: 8px 0; }
.rate-limit-card strong { color: var(--text-strong); font-variant-numeric: tabular-nums; }
.rate-limit-card .primary { margin-top: 8px; }
.rate-limit-card .muted.small { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }

@media (max-width: 600px) {
  .candidates { grid-template-columns: repeat(2, 1fr); }
  .query-chip { width: 200px; height: 200px; }
  .reveal-map { height: 320px; }
  main { margin: 16px auto; }
  .score-big { font-size: 48px; }
  .landing h1 { font-size: 32px; }
}
