:root {
  --bg-paper: #FFF8E7;
  --bg-card: #FFFFFF;
  --ink: #1A1D29;
  --ink-soft: #4A4F5C;
  --accent-sun: #FFD23F;
  --accent-coral: #FF6B6B;
  --accent-mint: #4ECDC4;
  --accent-sky: #5B8FF9;
  --line: #1A1D29;
  --shadow-hard: 4px 4px 0 var(--ink);
  --shadow-hard-sm: 3px 3px 0 var(--ink);
  --radius: 18px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg-paper);
  color: var(--ink);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}
body::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.1  0 0 0 0 0.11  0 0 0 0 0.16  0 0 0 0.6 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/></svg>");
  opacity: 0.06;
  z-index: 0;
  mix-blend-mode: multiply;
}
body > * { position: relative; z-index: 1; }

a { color: var(--ink); text-decoration: none; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 2px solid var(--ink);
  background: var(--bg-paper);
}
.wordmark {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.02em;
}
.wordmark span { color: var(--accent-coral); margin: 0 2px; }
.nav-link {
  font-weight: 600;
  border: 2px solid var(--ink);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-card);
  box-shadow: var(--shadow-hard-sm);
  transition: transform .15s ease;
}
.nav-link:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 24px 96px;
}

/* Hero */
.hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  align-items: center;
  margin: 16px 0 40px;
}
.hero h1 {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 800;
  font-size: clamp(36px, 6vw, 72px);
  line-height: 0.95;
  letter-spacing: -0.03em;
  margin: 0 0 12px;
}
.hero h1 em {
  font-style: normal;
  background: var(--accent-sun);
  border: 2px solid var(--ink);
  padding: 0 .15em;
  box-shadow: var(--shadow-hard-sm);
  display: inline-block;
  transform: rotate(-1.5deg);
}
.lead {
  font-size: 17px;
  color: var(--ink-soft);
  max-width: 56ch;
  line-height: 1.5;
  margin: 0 0 20px;
}
.rules {
  list-style: none;
  padding: 0; margin: 0;
  display: grid;
  gap: 10px;
}
.rules li {
  display: flex; align-items: baseline; gap: 12px;
  font-weight: 500;
}
.rules .num {
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  background: var(--ink);
  color: var(--accent-sun);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 13px;
}

/* Query widget — mini terminal */
.query-widget {
  width: min(360px, 80vw);
  margin: 0 auto;
  border: 2px solid var(--ink);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 6px 6px 0 var(--ink);
  animation: bob 6s ease-in-out infinite;
  flex-shrink: 0;
}
.qw-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: #0d1017;
  border-bottom: 1px solid #1e2535;
}
.qw-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}
.qw-fname {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: #4a5570;
  margin-left: 6px;
}
.qw-live {
  margin-left: auto;
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--accent-mint);
  letter-spacing: 0.05em;
  animation: live-blink 2s ease-in-out infinite;
}
@keyframes live-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
.qw-body {
  background: var(--ink);
  padding: 16px 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.qw-ln {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: #2e3650;
  user-select: none;
  flex-shrink: 0;
}
.qw-code {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: #8892a4;
  white-space: nowrap;
  overflow-x: auto;
}
.qw-kw { color: #7eb8f7; font-weight: 700; }
.qw-match {
  background: var(--accent-sun);
  color: var(--ink);
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 700;
  font-style: normal;
}
.qw-cursor {
  display: inline-block;
  width: 9px;
  height: 1em;
  background: var(--accent-mint);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: cursor-blink 1s step-end infinite;
}
@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
.qw-results {
  background: var(--ink);
  border-top: 1px solid #1e2535;
  padding: 10px 14px 16px;
}
.qw-row {
  font-family: 'Space Mono', monospace;
  font-size: 14px;
  color: #c9d1e0;
  padding: 5px 0;
  opacity: 0;
  animation: name-cycle 9s ease infinite both;
}
.qw-row-1 { animation-delay: 0.8s; }
.qw-row-2 { animation-delay: 1.5s; }
.qw-row-3 { animation-delay: 2.2s; }
.qw-check {
  color: var(--accent-mint);
  margin-right: 8px;
}
.qw-row-count {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--accent-mint);
  padding-top: 8px;
  margin-top: 4px;
  border-top: 1px solid #1e2535;
  opacity: 0;
  animation: name-cycle 9s ease infinite both;
}
.qw-row-3-delay { animation-delay: 2.9s; }
@keyframes name-cycle {
  0%, 8%  { opacity: 0; transform: translateY(5px); }
  18%     { opacity: 1; transform: translateY(0); }
  72%     { opacity: 1; transform: translateY(0); }
  82%     { opacity: 0; transform: translateY(-2px); }
  100%    { opacity: 0; }
}

@keyframes bob {
  0%, 100% { transform: rotate(-3deg) translateY(0); }
  50% { transform: rotate(2deg) translateY(-8px); }
}

@media (min-width: 1024px) {
  .hero { grid-template-columns: 1.4fr 1fr; }
  .query-widget { margin: 0; justify-self: end; }
}

.hero-board { grid-template-columns: 1fr; }
.hero-board h1 { font-size: clamp(36px, 5.5vw, 64px); }

/* Cards */
.card {
  background: var(--bg-card);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hard);
  padding: 24px;
}

/* Play grid */
/* Mobile: single flex column, wrapper divs become transparent (display:contents)
   so inner cards participate directly and can be reordered via `order`.
   Desktop: two independent flex columns — heights never shared across columns. */
.play-grid {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.pg-col-left,
.pg-col-right { display: contents; }

/* Mobile order: form → top5 → result → history */
.pg-form    { order: 1; }
.pg-board   { order: 2; }
.pg-result  { order: 3; }
.pg-history { order: 4; }

@media (min-width: 1024px) {
  .play-grid { flex-direction: row; align-items: flex-start; }
  .pg-col-left,
  .pg-col-right {
    display: flex; flex-direction: column; gap: 24px;
  }
  .pg-col-left  { flex: 1.05; }
  .pg-col-right { flex: 1; }
  .pg-form, .pg-board, .pg-result, .pg-history { order: unset; }
}

.field { display: block; margin-bottom: 16px; }
.label {
  display: block;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
input[type="text"], textarea {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg-paper);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  outline: none;
  transition: box-shadow .15s ease, transform .15s ease;
}
input[type="text"]:focus, textarea:focus {
  box-shadow: var(--shadow-hard-sm);
  transform: translate(-1px, -1px);
}
textarea { resize: vertical; line-height: 1.45; font-family: 'Space Mono', ui-monospace, monospace; font-size: 15px; }

.counter b { font-family: 'Space Mono', monospace; font-size: 18px; color: var(--accent-coral); }
.counter b.at-limit { color: #b53b3b; }
.limit-warn {
  margin-bottom: 8px;
  padding: 10px 12px;
  background: #FFE8E8;
  border: 2px solid #b53b3b;
  border-radius: var(--radius-sm);
  box-shadow: 3px 3px 0 #b53b3b;
  font-weight: 700; font-size: 14px;
  color: #b53b3b;
  animation: pop-in .2s cubic-bezier(.5,1.7,.5,1);
}

/* Chips */
.chips-wrap {
  position: relative;
  margin: 6px 0 18px;
}
.chips-wrap::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 32px;
  background: linear-gradient(transparent, var(--bg-card));
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
}
.chips-wrap.has-scroll::after { opacity: 1; }
.chips {
  display: flex; flex-wrap: wrap; gap: 8px;
  min-height: 8px;
  max-height: 154px;
  overflow-y: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
  scrollbar-color: #bbb transparent;
}
.chips::-webkit-scrollbar { width: 4px; }
.chips::-webkit-scrollbar-thumb { background: #bbb; border-radius: 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-mint);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 5px 10px 5px 12px;
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  animation: pop-in .25s cubic-bezier(.5,1.7,.5,1) both;
  box-shadow: 2px 2px 0 var(--ink);
}
.chip:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--ink); }
.chip--invalid { background: #FFC1C1; }
.chip .x { font-weight: 800; opacity: 0.6; }

@keyframes pop-in {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* Buttons */
.btn-primary {
  width: 100%;
  font: inherit;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.04em;
  background: var(--accent-coral);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  box-shadow: var(--shadow-hard);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.btn-primary:hover:not(:disabled) { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--ink); }
.btn-primary:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: var(--shadow-hard-sm); }
.btn-primary.is-loading .btn-label { opacity: 0.4; }
.btn-spinner { display: none; width: 18px; height: 18px; border: 3px solid var(--ink); border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn-primary.is-loading .btn-spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn-ghost {
  display: inline-block;
  border: 2px solid var(--ink);
  background: var(--bg-paper);
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 700;
  box-shadow: var(--shadow-hard-sm);
  margin-top: 6px;
}
.btn-ghost:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }

.add-row {
  display: flex; align-items: center; gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}
.btn-add {
  font: inherit; font-weight: 700; font-size: 14px;
  background: var(--accent-mint);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  box-shadow: var(--shadow-hard-sm);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn-add:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); }
.btn-add:active { transform: translate(1px,1px); box-shadow: none; }
.btn-replace {
  font: inherit; font-weight: 600; font-size: 13px;
  background: var(--bg-card);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  box-shadow: var(--shadow-hard-sm);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn-replace:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); background: #f5f5f5; }
.btn-replace:active { transform: translate(1px,1px); box-shadow: none; }
.small { font-size: 12px; }

.meta-row {
  display: flex; flex-wrap: wrap; gap: 8px;
  align-items: center; justify-content: space-between;
  margin: 4px 0 4px;
  font-size: 14px;
}
.btn-clear {
  font: inherit; font-size: 13px; font-weight: 700;
  background: none; border: none; padding: 0;
  color: var(--accent-coral); cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}
.btn-clear:hover { opacity: 0.7; }
.invalid-warn { color: #b53b3b; font-weight: 600; font-size: 13px; margin-bottom: 6px; }

.hints {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 14px 0 0;
}
.hint-item {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 13px; font-weight: 500; line-height: 1.4;
  padding: 10px 12px;
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  box-shadow: 3px 3px 0 var(--ink);
}
.hint-item--sun { background: var(--accent-sun); }
.hint-item--coral { background: #FFE8E8; }
.hint-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
kbd {
  font-family: 'Space Mono', monospace; font-size: 12px;
  background: var(--bg-paper); border: 1.5px solid var(--ink);
  border-radius: 5px; padding: 1px 5px;
}

/* Result */
.result-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.result-eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; color: var(--ink-soft); }
.result-num {
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  font-size: clamp(56px, 12vw, 96px);
  line-height: 1;
  color: var(--ink);
  margin: 4px 0;
  animation: pop-in .4s cubic-bezier(.5,1.7,.5,1);
}
.badges { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.badge {
  display: inline-block;
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 6px 12px;
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 2px 2px 0 var(--ink);
}
.badge[hidden] { display: none; }
.badge-rank { background: var(--accent-mint); }
.badge-pb {
  background: var(--accent-sun);
  transform: rotate(2deg);
  animation: pb-pulse 1.6s ease-in-out infinite;
}
@keyframes pb-pulse {
  0%, 100% { transform: rotate(2deg) scale(1); box-shadow: 2px 2px 0 var(--ink); }
  50% { transform: rotate(2deg) scale(1.06); box-shadow: 4px 4px 0 var(--ink); }
}

.diff-wrap {
  margin-top: 12px;
  padding: 14px 16px;
  background: var(--bg-paper);
  border: 2px dashed var(--ink);
  border-radius: var(--radius-sm);
}
.diff-row {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 6px;
  font-size: 14px;
}
.diff-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 700; color: var(--ink-soft);
}
.diff-val { font-family: 'Space Mono', monospace; font-weight: 700; }
.diff-row-full { display: block; }
.diff-row-full .diff-val { display: block; white-space: normal; }
.diff-val b { font-size: 18px; color: var(--accent-coral); }
.diff-lead {
  background: var(--accent-sun);
  border: 1.5px solid var(--ink);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 13px;
}
.diff-bar {
  margin-top: 8px;
  height: 14px;
  background: var(--bg-card);
  border: 2px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
}
.diff-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-mint), var(--accent-sun));
  border-right: 2px solid var(--ink);
  transition: width .8s cubic-bezier(.2,.7,.2,1);
}
.muted { color: var(--ink-soft); }
.center { text-align: center; }

.kept-secret {
  margin: 16px 0 14px;
  padding: 10px 12px;
  background: var(--bg-paper);
  border: 1.5px dashed var(--ink);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--ink-soft);
}

/* Podium */
.podium {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin: 8px 0 28px;
}
.podium .p1 { order: 1; }
.podium .p2 { order: 2; }
.podium .p3 { order: 3; }
@media (min-width: 720px) {
  .podium { grid-template-columns: 1fr 1.2fr 1fr; align-items: end; }
  .podium .p2 { order: 1; }
  .podium .p1 { order: 2; }
  .podium .p3 { order: 3; }
}
.podium-card {
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-hard);
  background: var(--bg-card);
  position: relative;
  text-align: center;
}
.podium-card .crown {
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  font-size: 14px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 3px 10px;
  background: var(--bg-paper);
  position: absolute;
  top: -14px; left: 50%;
  transform: translateX(-50%);
}
.podium-card .nick {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 800;
  font-size: clamp(20px, 3vw, 28px);
  margin: 8px 0 4px;
  word-break: break-word;
}
.podium-card .big {
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  font-size: clamp(44px, 7vw, 72px);
  line-height: 1;
}
.podium-card .sub {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-soft); font-weight: 700;
}
.podium-card.p1 { background: var(--accent-sun); transform: rotate(-1deg); }
.podium-card.p2 { background: var(--accent-mint); transform: rotate(1deg); }
.podium-card.p3 { background: var(--accent-coral); transform: rotate(-1.5deg); }

.table-card { padding: 0; overflow: hidden; }
.rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}
.rank-table th, .rank-table td { padding: 14px 16px; text-align: left; border-bottom: 1.5px solid var(--ink); }
.rank-table th { background: var(--accent-sun); font-family: 'Bricolage Grotesque', sans-serif; font-weight: 800; letter-spacing: 0.02em; }
.rank-table td.num, .rank-table th.num { font-family: 'Space Mono', monospace; text-align: right; }
.rank-table tr:last-child td { border-bottom: none; }
.rank-table tr.me { background: rgba(78, 205, 196, 0.25); }
.rank-table tr td:first-child { font-family: 'Space Mono', monospace; font-weight: 700; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(26,29,41,.45);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fade-up .18s ease;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
  background: var(--bg-card);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 8px 8px 0 var(--ink);
  padding: 28px 28px 24px;
  max-width: 340px; width: 100%;
}
.modal-msg {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 700; font-size: 18px;
  margin: 0 0 20px;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.btn-modal-cancel {
  font: inherit; font-weight: 600; font-size: 15px;
  background: var(--bg-paper);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: var(--shadow-hard-sm);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn-modal-cancel:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); }
.btn-modal-ok {
  font: inherit; font-weight: 700; font-size: 15px;
  background: var(--accent-coral);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: var(--shadow-hard-sm);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn-modal-ok:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); }

/* Mini leaderboard */
.mini-board { padding: 18px 20px; }
.mini-board-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.mini-board-title {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 800; font-size: 18px;
}
.mini-board-more {
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-soft);
  border: 1.5px solid var(--ink);
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-paper);
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform .12s ease, box-shadow .12s ease;
}
.mini-board-more:hover { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--ink); }

.mini-board-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.mini-board-empty { color: var(--ink-soft); font-size: 14px; text-align: center; padding: 12px 0; }

.mb-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  background: var(--bg-paper);
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform .15s ease, box-shadow .15s ease;
}
.mb-row:hover { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--ink); }
.mb-row.mb-me {
  background: var(--accent-sun);
  animation: mb-enter .5s cubic-bezier(.3,1.5,.5,1) both;
}
.mb-row.mb-gold { background: var(--accent-sun); }
.mb-row.mb-silver { background: #E8F8F7; }
.mb-row.mb-bronze { background: #FFE8E8; }

.mb-rank {
  font-family: 'Space Mono', monospace;
  font-weight: 700; font-size: 14px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--bg-card);
}
.mb-nick {
  font-weight: 700; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mb-score {
  font-family: 'Space Mono', monospace;
  font-weight: 700; font-size: 15px;
  white-space: nowrap;
}
.mb-score span { font-size: 11px; font-weight: 400; color: var(--ink-soft); }
.mb-kw {
  font-size: 11px; font-weight: 400;
  color: var(--ink-soft);
}

@keyframes mb-enter {
  0%   { transform: scale(.85) translateX(12px); opacity: 0; box-shadow: 0 0 0 var(--ink); }
  60%  { transform: scale(1.03) translateX(-2px); }
  100% { transform: scale(1) translateX(0); opacity: 1; box-shadow: 2px 2px 0 var(--ink); }
}

/* Top-5 toast */
.top5-toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%) translateY(0);
  z-index: 800;
  background: var(--accent-sun);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 12px 24px;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 800; font-size: 18px;
  box-shadow: 5px 5px 0 var(--ink);
  animation: toast-in .45s cubic-bezier(.3,1.6,.5,1) forwards;
  white-space: nowrap;
}
.top5-toast[hidden] { display: none; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(20px) scale(.9); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0)    scale(1); }
}

/* Confetti */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 999; }

/* Animations */
[data-anim] {
  opacity: 0;
  transform: translateY(14px);
  animation: fade-up .55s cubic-bezier(.2,.7,.2,1) forwards;
}
[data-anim]:nth-child(1) { animation-delay: .04s; }
[data-anim]:nth-child(2) { animation-delay: .14s; }
[data-anim]:nth-child(3) { animation-delay: .24s; }
@keyframes fade-up {
  to { opacity: 1; transform: translateY(0); }
}

/* History (local keyword sets) */
.history-card { }
.history-head {
  display: flex; align-items: baseline; gap: 10px;
  margin-bottom: 12px;
}
.history-title { font-weight: 700; font-size: 15px; }
.history-sub { font-size: 12px; color: var(--ink-soft); }

.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.history-item {
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  background: var(--bg-card);
  box-shadow: 2px 2px 0 var(--ink);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.history-item:hover { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--ink); background: #FFFDE8; }
.history-item:active { transform: translate(1px,1px); box-shadow: 1px 1px 0 var(--ink); }

.history-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.history-score {
  font-family: 'Space Mono', monospace;
  font-weight: 700; font-size: 14px;
}
.history-score span { font-size: 11px; font-weight: 400; color: var(--ink-soft); }
.history-kw {
  font-size: 11px; color: var(--ink-soft);
  background: #f0f0f0; padding: 1px 7px; border-radius: 20px;
}
.history-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.hact-btn {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  border: 1.5px solid var(--ink); border-radius: 5px;
  background: var(--bg-card); cursor: pointer;
  color: var(--ink-soft); transition: background .1s, color .1s, transform .1s;
  padding: 0;
}
.hact-btn:hover { background: #f0f0f0; color: var(--ink); transform: translate(-1px,-1px); }
.hact-btn:active { transform: translate(1px,1px); }
.hact-copy.copied { background: var(--accent-mint); color: var(--ink); border-color: var(--ink); }
.hact-expand svg { transition: transform .2s ease; }
.hact-expand.expanded svg { transform: rotate(180deg); }

.history-chips-wrap {}
.history-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.history-chips.collapsed .hkw-chip:nth-child(n+36) { display: none; }
.hkw-chip {
  font-size: 11px; font-weight: 500;
  background: var(--accent-mint);
  border: 1.5px solid var(--ink);
  border-radius: 5px;
  padding: 1px 6px;
  opacity: .85;
}
.hkw-more {
  font-size: 11px; color: var(--ink-soft);
  padding: 1px 6px;
  border: 1.5px dashed #ccc;
  border-radius: 5px;
}

/* Keyword Sets */
.kwsets-card { margin-top: 24px; }
.kwsets-header {
  display: flex; align-items: baseline; gap: 12px;
  margin-bottom: 16px;
}
.kwsets-header h2 { margin: 0; font-size: 18px; }
.kwsets-sub { font-size: 12px; color: var(--ink-soft); }

.kwsets-list { display: flex; flex-direction: column; gap: 10px; }

.kwset-row {
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  background: var(--bg-card);
  box-shadow: 2px 2px 0 var(--ink);
}
.kwset-meta {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 8px; flex-wrap: wrap;
}
.kwset-rank {
  font-family: 'Space Mono', monospace;
  font-size: 12px; font-weight: 700;
  background: var(--ink); color: #fff;
  padding: 1px 7px; border-radius: 6px;
}
.kwset-score {
  font-family: 'Space Mono', monospace;
  font-weight: 700; font-size: 15px;
}
.kwset-score span { font-size: 11px; font-weight: 400; color: var(--ink-soft); }
.kwset-kw {
  font-size: 12px; color: var(--ink-soft);
  background: #f0f0f0; padding: 1px 8px; border-radius: 20px;
}
.kwset-nick {
  font-size: 12px; color: var(--ink-soft);
  margin-left: auto;
}

.kwset-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.kw-chip {
  font-size: 12px;
  background: var(--accent-sun);
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  padding: 1px 8px;
  font-weight: 500;
}
.kw-more {
  font-size: 12px; color: var(--ink-soft);
  padding: 1px 8px;
  border: 1.5px dashed #ccc;
  border-radius: 6px;
}

@media (max-width: 719px) {
  .rank-table th:nth-child(5),
  .rank-table td:nth-child(5) { display: none; }
}
@media (max-width: 480px) {
  .container { padding: 20px 16px 80px; }
  .topbar { padding: 14px 16px; }
  .nav-link { padding: 6px 10px; font-size: 13px; }
  .card { padding: 18px; }
}
