/* ══════════════════════════════════════════════════
   WORDMANTICS — Navigating meaning.
   Design language: calm, intelligent, warm, minimal.
   ══════════════════════════════════════════════════ */

/* ── Light theme (default) ── */
:root {
  --bg: #F4F5F8;
  --bg-gradient: linear-gradient(160deg, #F4F5F8 0%, #E8EAF0 100%);
  --surface: #ffffff;
  --text: #1F2937;
  --muted: #6b7280;
  --border: #e0e3ea;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --primary: #2B8A8A;
  --primary-hover: #237272;
  --primary-glow: rgba(43,138,138,0.15);
  --danger: #b02929;
  --ok: #1f7a47;

  /* Semantic proximity scale: blue → teal → yellow → orange → red */
  --cold: #5B8DEF;
  --cool: #3ABAB4;
  --warm: #F0C040;
  --hot: #F09040;
  --max: #E04848;

  --input-bg: #ffffff;
  --input-border: #d1d5db;
  --input-focus: #2B8A8A;
  --card-accent: #fafbfd;
  --hint-bg: #f0faf9;
  --hint-border: #b2dfdb;
  --secondary-bg: #f0faf9;
  --secondary-border: #b2dfdb;
  --secondary-text: #1a6e6e;

  /* Dot field */
  --dot-color: rgba(43,138,138,0.06);

  --radius: 16px;
}

/* ── Dark theme ── */
[data-theme="dark"] {
  --bg: #121A3A;
  --bg-gradient: linear-gradient(160deg, #121A3A 0%, #1B2555 100%);
  --surface: #1a2248;
  --text: #F4F5F8;
  --muted: #9CA3AF;
  --border: #2a3362;
  --shadow: 0 2px 16px rgba(0,0,0,0.3);
  --primary: #4ECDC4;
  --primary-hover: #3ABAB4;
  --primary-glow: rgba(78,205,196,0.2);
  --danger: #f87171;
  --ok: #4ade80;

  --cold: #5B8DEF;
  --cool: #3ABAB4;
  --warm: #F0C040;
  --hot: #F09040;
  --max: #E04848;

  --input-bg: #1e2750;
  --input-border: #2a3362;
  --input-focus: #4ECDC4;
  --card-accent: #1e2750;
  --hint-bg: rgba(78,205,196,0.08);
  --hint-border: rgba(78,205,196,0.2);
  --secondary-bg: rgba(78,205,196,0.08);
  --secondary-border: rgba(78,205,196,0.2);
  --secondary-text: #4ECDC4;

  --dot-color: rgba(78,205,196,0.05);
}

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

body {
  background: var(--bg-gradient);
  color: var(--text);
  font-family: "Nunito", "SF Pro Display", -apple-system, system-ui, sans-serif;
  line-height: 1.55;
  min-height: 100vh;
  transition: background 0.4s, color 0.3s;
  -webkit-font-smoothing: antialiased;
}

/* ── Dot field background ── */
.dot-field {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: radial-gradient(circle, var(--dot-color) 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.7;
}

/* ── Layout: two-column on desktop ── */
.app {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header  header"
    "left    right";
  gap: 16px;
  align-items: start;
}

.topbar       { grid-area: header; }
.col-left     { grid-area: left; display: grid; gap: 16px; }
.col-right    { grid-area: right; display: grid; gap: 16px; }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  animation: cardIn 0.4s ease-out forwards;
  transition: background 0.3s, border-color 0.3s;
}
.card:nth-child(1) { animation-delay: 0s; }
.card:nth-child(2) { animation-delay: 0.06s; }
.card:nth-child(3) { animation-delay: 0.12s; }
.card:nth-child(4) { animation-delay: 0.18s; }
@keyframes cardIn { to { opacity: 1; transform: none; } }

/* ── Topbar ── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}
.topbar-left { display: flex; flex-direction: column; gap: 2px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { border-radius: 50%; }
.brand-name {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--text);
}
.header-score {
  display: inline-block;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--hint-bg);
  border: 1px solid var(--hint-border);
  border-radius: 99px;
  padding: 2px 12px;
  margin-left: 10px;
  vertical-align: middle;
  letter-spacing: 0.02em;
}
.muted { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.target-word { font-weight: 600; color: var(--danger); font-size: 0.85rem; margin-top: 2px; }
.actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ── Buttons ── */
.btn {
  border: 1px solid transparent;
  border-radius: 99px;
  padding: 7px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s, box-shadow 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: var(--primary);
  color: #fff;
  border: none;
}
.btn.primary:hover {
  box-shadow: 0 4px 16px var(--primary-glow);
  transform: translateY(-1px);
}
.btn.secondary { background: var(--secondary-bg); border-color: var(--secondary-border); color: var(--secondary-text); }
.btn.secondary:hover { opacity: 0.85; }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.ghost:hover { background: var(--card-accent); }
.btn.ghost.danger-btn { color: var(--danger); }
.btn.ghost.danger-btn:hover { background: rgba(176,41,41,0.08); }
.btn.ghost.danger-btn:disabled { opacity: 0.4; pointer-events: none; }
.theme-btn { font-size: 16px; padding: 6px 10px; min-width: 34px; text-align: center; }

/* ── Stats row ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px;
}
.stats-grid article {
  text-align: center;
  padding: 8px 4px;
  border-radius: 12px;
  background: var(--card-accent);
  border: 1px solid var(--border);
}
.label { color: var(--muted); font-size: 0.75rem; font-weight: 600; }
.value { font-weight: 800; margin-top: 2px; }
.value-text { font-size: 1rem; }
.value-big { font-size: 1.5rem; }

/* ── Progress bar ── */
.progress-card { padding: 12px 16px; }
.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.progress-bar-wrap {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 99px;
  width: 0%;
  transition: width 0.6s cubic-bezier(.4,0,.2,1), background 0.4s;
}
.progress-bar-fill.heat-cold { background: var(--cold); }
.progress-bar-fill.heat-cool { background: var(--cool); }
.progress-bar-fill.heat-warm { background: var(--warm); }
.progress-bar-fill.heat-hot  { background: var(--hot); }
.progress-bar-fill.heat-max  { background: var(--max); }

/* ── Guess form ── */
.guess-form { display: flex; gap: 8px; margin-top: 8px; }
.hidden { display: none !important; }

#guess-input {
  flex: 1;
  border: 1px solid var(--input-border);
  border-radius: 99px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}
#guess-input:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-5px); }
  40%,80% { transform: translateX(5px); }
}
#guess-input.shake { animation: shake 0.35s ease; border-color: var(--danger); }

/* ── Suggestions ── */
.suggestions-wrap {
  margin-top: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-accent);
  animation: fadeIn 0.15s ease-out;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.suggestions-label { font-size: 0.75rem; color: var(--muted); margin-bottom: 6px; }
.suggestions-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.suggestion-btn {
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.8rem;
  font-family: inherit;
  padding: 4px 12px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.suggestion-btn:hover { border-color: var(--input-focus); transform: scale(1.03); }

/* ── Status ── */
.status { min-height: 18px; margin-top: 6px; font-weight: 600; font-size: 0.85rem; }
.status.error { color: var(--danger); }
.status.ok { color: var(--ok); }

/* ── Hints card ── */
.hints-card { border-left: 3px solid var(--primary); }
.hint-category {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  padding: 8px 12px;
  background: var(--hint-bg);
  border-radius: 12px;
  border: 1px solid var(--hint-border);
  margin-bottom: 10px;
}
.hints-grid { display: flex; gap: 12px; flex-wrap: wrap; }
.hint-item { flex: 1; min-width: 140px; }
.hint-item .label { font-size: 0.75rem; color: var(--muted); margin-bottom: 2px; }
.hint-list { list-style: none; padding: 0; }
.hint-list li {
  padding: 2px 0;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--warm);
  animation: fadeIn 0.3s ease-out;
}
.hint-row { opacity: 0.8; border-left-color: var(--warm) !important; }
.hint-row .guess-word { font-style: italic; }

/* ── LLM Hints ── */
.llm-hints-section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* Locked hint states */
.hints-locked, .llm-hints-locked {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}
.hints-locked.hidden, .llm-hints-locked.hidden { display: none !important; }
.hints-locked-icon { font-size: 1.3rem; opacity: 0.6; }
.llm-unlock-bar-wrap {
  width: 100%;
  max-width: 160px;
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 4px;
}
.llm-unlock-bar {
  height: 100%;
  border-radius: 99px;
  background: var(--primary);
  width: 0%;
  transition: width 0.4s ease;
}
.llm-hint-buttons { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.llm-hint-btn {
  background: var(--hint-bg);
  border: 1px solid var(--hint-border);
  color: var(--primary);
  font-size: 0.8rem;
  padding: 6px 14px;
  border-radius: 99px;
  font-family: inherit;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
}
.llm-hint-btn:not(:disabled):hover { transform: scale(1.04); box-shadow: 0 2px 8px var(--primary-glow); }
.llm-hint-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.llm-hint-btn.used { background: var(--primary); color: #fff; border-color: var(--primary); opacity: 1; cursor: default; }
.llm-hint-btn.loading { opacity: 0.6; cursor: wait; }
.llm-hint-texts { display: grid; gap: 6px; }
.llm-hint-bubble {
  background: var(--hint-bg);
  border: 1px solid var(--hint-border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.85rem;
  line-height: 1.5;
  animation: fadeIn 0.3s ease-out;
}
.llm-hint-bubble .llm-hint-label {
  font-weight: 800;
  color: var(--primary);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 3px;
}

/* ── History ── */
.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.history-head h2 { font-size: 1rem; }
.history-wrap { display: grid; gap: 6px; max-height: 60vh; overflow-y: auto; }
.history-empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ── Guess rows ── */
.guess-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  align-items: center;
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
}
.guess-row:hover { transform: translateX(2px); box-shadow: 0 2px 10px rgba(0,0,0,0.06); }

.guess-row::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: var(--score-width, 0%);
  opacity: 0.06;
  border-radius: var(--radius) 0 0 var(--radius);
  transition: width 0.5s cubic-bezier(.4,0,.2,1);
  pointer-events: none;
}
.guess-row.heat-cold { border-left-color: var(--cold); }
.guess-row.heat-cool { border-left-color: var(--cool); }
.guess-row.heat-warm { border-left-color: var(--warm); }
.guess-row.heat-hot  { border-left-color: var(--hot); }
.guess-row.heat-max  { border-left-color: var(--max); }
.guess-row.heat-cold::before { background: var(--cold); }
.guess-row.heat-cool::before { background: var(--cool); }
.guess-row.heat-warm::before { background: var(--warm); }
.guess-row.heat-hot::before  { background: var(--hot); }
.guess-row.heat-max::before  { background: var(--max); }

.guess-row.best { box-shadow: 0 0 0 1px var(--primary-glow) inset; }
.guess-word { font-size: 0.95rem; font-weight: 700; position: relative; z-index: 1; }
.guess-meta { color: var(--muted); font-size: 0.75rem; position: relative; z-index: 1; }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
.guess-row.new-entry { animation: slideIn 0.3s ease-out; }
@keyframes flashHighlight {
  0%   { background: var(--primary-glow); }
  100% { background: transparent; }
}
.guess-row.flash { animation: flashHighlight 0.6s ease-out; }

/* ── Badges ── */
.badge {
  border-radius: 99px;
  color: #fff;
  padding: 3px 8px;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  position: relative;
  z-index: 1;
}
@keyframes badgePop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}
.badge.pop { animation: badgePop 0.3s ease; }
.badge.heat-cold { background: var(--cold); }
.badge.heat-cool { background: var(--cool); }
.badge.heat-warm { background: var(--warm); }
.badge.heat-hot  { background: var(--hot); }
.badge.heat-max  { background: var(--max); color: #1F2937; }

/* ── Win ── */
@keyframes winPulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(224,72,72,0.3); }
  50%     { box-shadow: 0 0 0 10px rgba(224,72,72,0); }
}
.win-glow { animation: winPulse 1.2s ease 2; border-color: var(--max); }

#win-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 9999;
}

/* ── Score animation ── */
@keyframes scoreFlash {
  0% { color: var(--danger); transform: scale(1.1); }
  100% { color: var(--primary); transform: scale(1); }
}
.score-change { animation: scoreFlash 0.4s ease-out; }

/* ── Responsive: single column on mobile ── */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "right"
      "left";
    padding: 12px 10px 30px;
  }
  .topbar { flex-direction: column; align-items: flex-start; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .guess-form { flex-direction: row; }
  .guess-form .btn.primary { white-space: nowrap; }
  .history-wrap { max-height: 50vh; overflow-y: auto; }
  /* Compact topbar actions on mobile */
  .actions { gap: 4px; }
  .actions .btn { padding: 6px 10px; font-size: 0.75rem; }
}

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

/* ── Auth ── */
.auth-area { display: flex; align-items: center; gap: 6px; }
.auth-btn { font-size: 0.8rem; padding: 6px 12px; }
.user-menu { display: flex; align-items: center; gap: 8px; }
.user-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Login modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: min(360px, calc(100% - 32px));
  box-shadow: 0 8px 40px rgba(0,0,0,0.2);
}
.login-provider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  margin-bottom: 8px;
  background: var(--card-accent);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.login-provider:hover { background: var(--secondary-bg); transform: scale(1.01); }

/* ── Leaderboard ── */
.lb-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.lb-tab {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
}
.lb-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}
.lb-tab:hover:not(.active) {
  background: var(--card-accent);
  color: var(--text);
}
.lb-content { min-height: 80px; }
.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.lb-table th {
  text-align: left;
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 8px 8px;
  border-bottom: 1px solid var(--border);
}
.lb-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.lb-table tr:last-child td { border-bottom: none; }
.lb-table .lb-rank { width: 36px; font-weight: 700; color: var(--muted); }
.lb-table .lb-name { font-weight: 600; }
.lb-table .lb-score { font-weight: 800; color: var(--primary); text-align: right; }
.lb-table .lb-date { font-size: 0.75rem; color: var(--muted); text-align: right; }
.lb-table .lb-highlight { background: var(--hint-bg); }
.lb-medal { font-size: 1rem; }
.lb-empty { color: var(--muted); font-size: 0.85rem; padding: 16px 0; text-align: center; }

/* ── Leaderboard overlay ── */
.lb-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease-out;
}
.lb-overlay.hidden { display: none !important; }
.leaderboard-panel {
  width: min(520px, calc(100% - 32px));
  max-height: 80vh;
  overflow-y: auto;
  animation: cardIn 0.25s ease-out forwards;
  opacity: 1;
  transform: none;
}
.lb-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.lb-close {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.lb-close:hover { background: var(--card-accent); color: var(--text); }
