:root {
  --ink: #171717;
  --muted: #6f716f;
  --paper: #f4f1e9;
  --card: #fffdf8;
  --line: #222321;
  --soft-line: #d8d4ca;
  --accent: #f0b45f;
  --dark: #151719;
  --light-square: #e8d3ad;
  --dark-square: #ad8153;
  --radius: 24px;
  --shadow: 0 18px 60px rgba(34, 31, 24, .09);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(240, 180, 95, .14), transparent 28rem),
    var(--paper);
  font-family: "DM Sans", sans-serif;
}
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.site-header {
  height: 82px;
  max-width: 1320px;
  padding: 0 28px;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; border: 0; background: none; font: 650 1.2rem "Fraunces", serif; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; color: var(--paper); background: var(--ink); border-radius: 50%; }
nav { display: flex; align-items: center; gap: 8px; }
nav button { border: 0; background: transparent; padding: 10px 13px; border-radius: 99px; font-weight: 600; }
nav button:hover { background: rgba(0,0,0,.06); }
.menu-button { width: 46px; height: 42px; display: grid; place-content: center; gap: 6px; }
.menu-button i { width: 22px; height: 2px; background: currentColor; display: block; }

#view { max-width: 1260px; margin: 0 auto; padding: 30px 28px 80px; }
.eyebrow { margin: 0 0 10px; color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .14em; font-weight: 700; }
h1, h2, h3 { font-family: "Fraunces", serif; }
h1 { font-size: clamp(2.6rem, 6vw, 5.4rem); line-height: .98; letter-spacing: -.04em; margin: 0; font-weight: 500; }
h2 { font-size: clamp(1.8rem, 3vw, 2.6rem); margin: 0; font-weight: 500; }
.lede { color: var(--muted); font-size: 1.05rem; line-height: 1.6; max-width: 600px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 34px; }
.page-heading .lede { margin: 12px 0 0; }

.variant-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px; }
.variant-card {
  min-height: 390px;
  padding: 0;
  overflow: hidden;
  text-align: left;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  transition: transform .2s ease, box-shadow .2s ease;
}
.variant-card:hover { transform: translateY(-6px); box-shadow: 0 24px 70px rgba(34,31,24,.15); }
.variant-art { height: 230px; background: var(--variant-accent); position: relative; display: grid; place-items: center; overflow: hidden; }
.variant-art::after { content: ""; width: 270px; height: 270px; position: absolute; border: 1px solid rgba(255,255,255,.55); border-radius: 50%; }
.preview-board { width: 170px; aspect-ratio: 1; padding: 9px; background: #202124; display: grid; grid-template-columns: repeat(4, 1fr); transform: rotate(-5deg); box-shadow: 0 16px 26px rgba(0,0,0,.23); z-index: 1; }
.preview-board span { display: grid; place-items: center; font-size: 1.45rem; background: rgba(255,255,255,.65); }
.preview-board span:nth-child(2n), .preview-board span:nth-child(5), .preview-board span:nth-child(7), .preview-board span:nth-child(10), .preview-board span:nth-child(12), .preview-board span:nth-child(13), .preview-board span:nth-child(15) { background: rgba(35,35,35,.18); }
.variant-copy { min-height: 160px; padding: 22px; border-top: 1.5px solid var(--line); }
.variant-copy h3 { margin: 0 0 8px; font-size: 1.35rem; }
.variant-copy p { color: var(--muted); line-height: 1.5; margin: 0; }
.variant-meta { display: flex; justify-content: space-between; margin-top: 18px; text-transform: uppercase; font-size: .7rem; letter-spacing: .1em; font-weight: 700; }

.back-button, .primary-button, .secondary-button {
  border: 1.5px solid var(--line); border-radius: 999px; padding: 11px 18px; background: transparent; font-weight: 700;
}
.primary-button { background: var(--ink); color: white; padding: 14px 24px; }
.primary-button:hover { transform: translateY(-1px); }
.secondary-button:hover, .back-button:hover { background: white; }

.setup-layout { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(280px, .7fr); gap: 24px; }
.panel { border: 1.5px solid var(--line); background: var(--card); border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow); }
.panel-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.versus { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: end; }
.player-select label { display: block; color: var(--muted); text-transform: uppercase; font-weight: 700; font-size: .7rem; letter-spacing: .12em; margin: 0 0 8px 4px; }
.player-select select { width: 100%; appearance: none; border: 1.5px solid var(--line); background: white; padding: 15px 42px 15px 16px; border-radius: 14px; font-weight: 700; background-image: linear-gradient(45deg,transparent 50%,var(--ink) 50%),linear-gradient(135deg,var(--ink) 50%,transparent 50%); background-position: calc(100% - 19px) 21px,calc(100% - 13px) 21px; background-size: 6px 6px; background-repeat: no-repeat; }
.vs { padding-bottom: 15px; font-family: "Fraunces", serif; font-style: italic; color: var(--muted); }
.model-details { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.model-card { height: 100%; padding: 15px; border: 1px solid var(--soft-line); border-radius: 14px; background: #fff; }
.model-card > strong { font-family: "Fraunces", serif; font-size: 1.15rem; }
.model-card > p:last-child { margin: 12px 0 0; color: var(--muted); font-size: .79rem; line-height: 1.5; }
.model-card dl { display: grid; gap: 5px; margin: 12px 0 0; }
.model-card dl div { display: grid; grid-template-columns: 66px 1fr; gap: 8px; font-size: .72rem; }
.model-card dt { color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.model-card dd { margin: 0; }
.start-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 22px; }
.start-row small { color: var(--muted); }
.rules-list { margin: 0; padding-left: 18px; color: var(--muted); line-height: 1.7; }
.recent { margin-top: 24px; }
.recent-list { display: grid; gap: 8px; }
.recent-match { width: 100%; border: 1px solid var(--soft-line); background: white; border-radius: 11px; padding: 11px 13px; display: grid; grid-template-columns: 1fr auto; text-align: left; gap: 12px; }
.recent-match:hover { border-color: var(--line); }
.recent-match small { color: var(--muted); }
.empty { color: var(--muted); padding: 22px 0; }

.leaderboard-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; align-items: start; }
.leaderboard-card { border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--card); overflow: hidden; box-shadow: var(--shadow); }
.leaderboard-card header { padding: 20px 22px; background: var(--board-accent); border-bottom: 1.5px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.leaderboard-card h3 { margin: 0; }
.rating-row { width: 100%; display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; padding: 15px 20px; border: 0; border-bottom: 1px solid var(--soft-line); background: transparent; text-align: left; }
.rating-row:hover, .rating-row:focus-visible { background: rgba(255,255,255,.72); outline: none; box-shadow: inset 4px 0 0 var(--board-accent); }
.rating-row:last-child { border: 0; }
.rank { color: var(--muted); font-weight: 700; }
.bot-line strong { display: block; }
.bot-line small { color: var(--muted); }
.elo { font: 600 1.25rem "Fraunces", serif; text-align: right; }
.elo small { display: block; font: 500 .62rem "DM Sans", sans-serif; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

.model-heading h1 { font-size: clamp(3rem, 7vw, 6rem); }
.model-profile { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 22px; align-items: start; }
.model-about > p:not(.eyebrow) { color: var(--muted); font-size: 1rem; line-height: 1.75; margin: 18px 0 0; }
.model-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 26px; }
.model-facts div { min-height: 96px; padding: 16px; border: 1px solid var(--soft-line); border-radius: 14px; background: white; }
.model-facts small { display: block; margin-bottom: 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: .64rem; font-weight: 700; }
.model-facts strong { line-height: 1.35; }
.model-ratings { display: grid; gap: 14px; }
.model-rating-card { padding: 20px; border: 1.5px solid var(--line); border-top: 10px solid var(--model-accent); border-radius: 18px; background: var(--card); box-shadow: var(--shadow); }
.model-rating-card > div > strong { font: 500 3.3rem "Fraunces", serif; line-height: 1; }
.model-rating-card > div > small { margin-left: 6px; color: var(--muted); }
.model-rating-card > p { color: var(--muted); line-height: 1.55; }

.game-shell { display: grid; grid-template-columns: 280px minmax(320px, 720px) 230px; gap: 22px; align-items: start; justify-content: center; }
.game-title { text-align: center; margin: 0 0 16px; }
.game-title small { display: block; color: var(--muted); font: 600 .72rem "DM Sans", sans-serif; text-transform: uppercase; letter-spacing: .12em; margin-bottom: 3px; }
.board-frame { background: #202124; padding: 14px; border-radius: 8px; box-shadow: 0 24px 60px rgba(30,26,20,.22); }
.board { width: 100%; aspect-ratio: 1; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr)); overflow: hidden; }
.square { width: 100%; height: 100%; min-width: 0; min-height: 0; overflow: hidden; border: 0; padding: 0; display: grid; place-items: center; position: relative; background: var(--light-square); touch-action: none; }
.square.dark { background: var(--dark-square); }
.square img { width: 88%; height: 88%; object-fit: contain; pointer-events: none; filter: drop-shadow(0 3px 2px rgba(0,0,0,.18)); }
.square.target::after { content: ""; position: absolute; width: 26%; aspect-ratio: 1; background: rgba(30,110,65,.6); border-radius: 50%; }
.square.target.occupied::after { width: 82%; border: 5px solid rgba(30,110,65,.65); background: transparent; }
.square.selected { box-shadow: inset 0 0 0 5px rgba(255,225,95,.75); }
.square.last { box-shadow: inset 0 0 0 100px rgba(255,225,95,.24); }
.side-stack { display: grid; gap: 14px; }
.game-panel { background: var(--dark); color: #f6f2e9; border-radius: 18px; padding: 18px; }
.game-panel h3 { margin: 0 0 12px; color: var(--accent); text-transform: uppercase; letter-spacing: .1em; font: 700 .68rem "DM Sans", sans-serif; }
.status { line-height: 1.45; font-weight: 600; }
.status small { display: block; color: #9fa2a4; font-weight: 500; margin-top: 5px; }
.tray { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.tray button { position: relative; border: 1px solid #3c4045; background: #24272b; border-radius: 9px; padding: 4px; touch-action: none; cursor: grab; }
.tray button.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(240,180,95,.25); }
.tray img { width: 100%; display: block; }
.tray span { position: absolute; right: 4px; bottom: 3px; font-size: .64rem; color: #bbb; }
.dragging, .dragging * { cursor: grabbing !important; user-select: none; }
.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  width: clamp(48px, 7vw, 78px);
  height: clamp(48px, 7vw, 78px);
  object-fit: contain;
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  filter: drop-shadow(0 10px 8px rgba(0,0,0,.32));
  will-change: transform;
}
.drag-ghost.visible { opacity: .92; }
.history { max-height: 340px; overflow-y: auto; margin: 0; padding-left: 22px; color: #afb1b2; font-size: .76rem; line-height: 1.65; }
.player-card { border: 1.5px solid var(--line); border-radius: 15px; padding: 14px 16px; background: var(--card); }
.player-card.active { background: #fff6df; }
.player-card small { display: block; color: var(--muted); text-transform: uppercase; font-size: .62rem; letter-spacing: .1em; }
.replay-controls { display: flex; gap: 6px; align-items: center; }
.replay-controls button { border: 1px solid #3c4045; color: white; background: #24272b; border-radius: 7px; width: 32px; height: 32px; }
.replay-controls span { flex: 1; text-align: center; font-size: .75rem; color: #aaa; }

.game-result-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(20, 19, 16, .62);
  backdrop-filter: blur(7px);
  animation: result-fade-in .2s ease-out;
}
.game-result-card {
  width: min(460px, 100%);
  padding: 34px;
  text-align: center;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .28);
  animation: result-card-in .25s ease-out;
}
.game-result-card h2 { margin-bottom: 10px; font-size: clamp(2.2rem, 7vw, 3.5rem); }
.game-result-card > p:not(.eyebrow) { margin: 0; color: var(--muted); }
.game-result-actions { display: flex; justify-content: center; gap: 10px; margin-top: 26px; }
@keyframes result-fade-in { from { opacity: 0; } }
@keyframes result-card-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }

#toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--ink); color: white; padding: 12px 18px; border-radius: 99px; transition: .2s; z-index: 50; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1000px) {
  .variant-grid, .leaderboard-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .game-shell { grid-template-columns: minmax(220px, 1fr) minmax(360px, 2fr); }
  .game-shell > .side-stack:last-child { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .site-header { height: 68px; padding: 0 16px; }
  nav > button:not(.menu-button) { display: none; }
  #view { padding: 24px 16px 60px; }
  .variant-grid, .leaderboard-grid, .setup-layout, .model-profile { grid-template-columns: 1fr; }
  .variant-card { min-height: 340px; }
  .variant-art { height: 190px; }
  .versus { grid-template-columns: 1fr; }
  .model-details { grid-template-columns: 1fr; }
  .game-result-actions { flex-direction: column-reverse; }
  .vs { padding: 0; text-align: center; }
  .game-shell { grid-template-columns: 1fr; }
  .game-shell > .side-stack:first-child { order: 2; }
  .game-shell > section { order: 1; }
  .game-shell > .side-stack:last-child { order: 3; grid-column: auto; grid-template-columns: 1fr; }
  .page-heading { align-items: start; flex-direction: column; }
  .model-facts { grid-template-columns: 1fr; }
}
