:root {
  --bg: #13161f;
  --bg-soft: #1a1f2c;
  --panel: #1e2431;
  --panel-hi: #262d3d;
  --ink: #eef1f6;
  --ink-dim: #a3adbe;
  --dim: #6f7a8c;
  --line: #2c3446;
  --accent: #ffb454;
  --accent-hi: #ffc978;
  --accent-deep: #b87a28;
  --win:  #ffb454;
  --hot:  #ff6b6b;
  --warm: #ffb454;
  --cool: #6cc4b6;
  --cold: #5b6578;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink);
  font-family: "Inter", "Noto Sans Arabic", "Noto Sans Bengali",
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
header {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 20px 28px 18px;
  max-width: 1200px; margin: 0 auto;
}
header h1 {
  margin: 0; font-family: "Fraunces", serif; font-weight: 700;
  font-size: 34px; letter-spacing: -0.01em;
  background: linear-gradient(135deg, var(--accent) 0%, #ff7e6b 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#meta { color: var(--dim); font-size: 12.5px; font-variant-numeric: tabular-nums; }

main {
  display: grid; grid-template-columns: 1fr 360px; gap: 20px;
  padding: 4px 28px 28px; max-width: 1200px; margin: 0 auto;
}

#plot-wrap {
  position: relative; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 18px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 8px 24px rgba(0,0,0,0.25);
}
canvas { display: block; width: 100%; height: auto; cursor: default; border-radius: 8px; }
#tooltip {
  position: absolute; pointer-events: none;
  background: #0f1115; border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 9px; font-size: 12px; color: var(--ink);
  font-variant-numeric: tabular-nums; white-space: nowrap;
  transform: translate(-50%, -100%); margin-top: -10px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.5);
}
#tooltip .tt-word { font-weight: 600; }
#tooltip .tt-rank { font-weight: 700; margin-left: 8px; }
#tooltip .tt-rank.win  { color: var(--win);  }
#tooltip .tt-rank.hot  { color: var(--hot);  }
#tooltip .tt-rank.warm { color: var(--warm); }
#tooltip .tt-rank.cool { color: var(--cool); }
#tooltip .tt-rank.cold { color: var(--cold); }
#tooltip .tt-sim { color: var(--dim); margin-left: 6px; font-size: 11px; }
#tooltip .tt-lang {
  font-size: 9px; color: var(--dim); text-transform: uppercase;
  letter-spacing: 0.08em; margin-left: 6px;
  border: 1px solid var(--line); border-radius: 3px; padding: 0 4px;
}
.axis-label {
  position: absolute; color: var(--dim); font-size: 11px;
  text-transform: lowercase; letter-spacing: 0.06em; pointer-events: none;
}
.axis-label.y { top: 20px; left: 22px; }
.axis-label.x { bottom: 8px; right: 22px; }

#side { display: flex; flex-direction: column; gap: 14px; }

#guess-form { display: flex; gap: 8px; }
#guess-input {
  flex: 1; padding: 14px 16px; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px;
  font-size: 16px; font-weight: 500;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
#guess-input::placeholder { color: var(--dim); font-weight: 400; }
#guess-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,180,84,0.15);
}
button {
  padding: 14px 20px; border: none; border-radius: 12px; cursor: pointer;
  font-size: 15px; font-weight: 600; font-family: inherit;
  background: var(--accent); color: #1a1205;
  transition: background .15s, transform .05s;
}
button:hover { background: var(--accent-hi); }
button:active { transform: translateY(1px); }

#toolbar { display: flex; justify-content: flex-end; margin-top: 4px; }
button.ghost {
  padding: 6px 12px; font-size: 12px; font-weight: 500;
  color: var(--dim); background: transparent;
  border: 1px solid var(--line); border-radius: 8px;
}
button.ghost:hover { background: transparent; color: var(--hot); border-color: var(--hot); }

#status {
  min-height: 20px; font-size: 13px; color: var(--ink-dim);
  padding: 0 4px;
}
#status.win { color: var(--accent); font-weight: 600; }
#status.err { color: var(--hot); }

#guess-list {
  list-style: none; padding: 0; margin: 0;
  max-height: 58vh; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
}
#guess-list::-webkit-scrollbar { width: 8px; }
#guess-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
#guess-list li {
  display: grid; grid-template-columns: 26px 1fr auto auto;
  gap: 10px; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums; font-size: 14px;
  transition: background .15s;
}
#guess-list li:last-child { border-bottom: none; }
#guess-list li.latest { background: var(--panel-hi); }
#guess-list .n { color: var(--dim); font-size: 12px; }
#guess-list .word {
  font-weight: 600; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#guess-list .word[dir="rtl"] { text-align: right; }
#guess-list .lang {
  font-size: 9.5px; color: var(--dim); text-transform: uppercase;
  letter-spacing: 0.08em; padding: 2px 6px;
  border: 1px solid var(--line); border-radius: 4px;
  font-weight: 600;
}
#guess-list .lang.ar { color: #a5b4fc; border-color: #3b3f66; }
#guess-list .lang.bn { color: #f5a1d6; border-color: #66324f; }
#guess-list .rank {
  font-size: 14px; font-weight: 700;
  min-width: 50px; text-align: right;
}
#guess-list .rank.win  { color: var(--win);  }
#guess-list .rank.hot  { color: var(--hot);  }
#guess-list .rank.warm { color: var(--warm); }
#guess-list .rank.cool { color: var(--cool); }
#guess-list .rank.cold { color: var(--cold); }
#guess-list li.tier-win .word { color: var(--win); }

/* ===== Win overlay / recap ===== */
#win-overlay[hidden] { display: none; }
#win-overlay {
  position: fixed; inset: 0; background: rgba(10, 12, 17, 0.72);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
  animation: fade-in .25s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.win-card {
  position: relative;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px 32px 24px;
  max-width: 680px; width: 100%;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  animation: pop-in .35s cubic-bezier(.2,.9,.3,1.2);
}
.win-close {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px; padding: 0;
  background: transparent; color: var(--dim);
  border-radius: 8px; font-size: 22px; line-height: 1;
  font-weight: 400;
}
.win-close:hover { background: var(--panel-hi); color: var(--ink); }
.win-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; margin-bottom: 22px;
  padding-bottom: 18px; border-bottom: 1px solid var(--line);
}
.win-solved { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; }
.win-eyebrow {
  font-size: 13px; font-weight: 600; color: var(--dim);
  letter-spacing: 0.02em;
}
.win-title {
  font-family: "Fraunces", serif; font-weight: 700;
  font-size: 34px; letter-spacing: -0.01em;
  color: var(--accent); line-height: 1.1;
}
.win-brand { text-align: right; flex-shrink: 0; }
.win-wordmark {
  font-family: "Fraunces", serif; font-weight: 700;
  font-size: 26px; color: var(--ink); letter-spacing: -0.01em;
  display: inline-flex; align-items: center; gap: 8px;
}
.win-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
}
.win-hsep {
  width: 42px; height: 2px; background: var(--accent-deep);
  margin: 6px 0 6px auto;
}
.win-tagline {
  font-size: 12px; color: var(--dim); font-weight: 500;
  letter-spacing: 0.01em;
}
.win-stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin-bottom: 20px;
}
.stat {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 16px; text-align: center;
}
.stat-val {
  font-family: "Fraunces", serif; font-weight: 700;
  font-size: 28px; color: var(--accent); line-height: 1.1;
}
.stat-label {
  font-size: 11px; color: var(--dim);
  text-transform: uppercase; letter-spacing: 0.1em;
  margin-top: 4px; font-weight: 600;
}
#recap-plot {
  width: 100%; height: auto;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 12px;
}
.win-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px;
}
.win-actions button {
  padding: 10px 18px; font-size: 14px;
}
.win-actions button.secondary {
  background: transparent; color: var(--ink-dim);
  border: 1px solid var(--line);
}
.win-actions button.secondary:hover {
  background: var(--panel-hi); color: var(--ink); border-color: var(--accent);
}

@media (max-width: 820px) {
  main { grid-template-columns: 1fr; }
  #guess-list { max-height: 42vh; }
  .win-title { font-size: 28px; }
  .stat-val { font-size: 22px; }
  .win-header { flex-direction: column; }
  .win-brand { text-align: left; }
  .win-hsep { margin-left: 0; }
}
