:root {
  --bg: #302e2b;
  --panel: #262421;
  --panel-light: #3a3835;
  --text: #e8e6e3;
  --text-dim: #a09d99;
  --accent: #81b64c;
  --accent-dark: #5d8a32;
  --danger: #c0504d;
  --wood: #dcb35c;
  --line: #3b2a14;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 10px 20px;
  background: var(--panel);
}
.logo { display: flex; align-items: center; gap: 8px; font-size: 22px; font-weight: 700; }
.logo-stone {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #666, #000 70%);
  box-shadow: 8px 0 0 -2px #eee;
  margin-right: 10px;
}
nav { display: flex; gap: 18px; }
.nav-item {
  color: var(--text-dim); font-weight: 600; font-size: 16px;
  background: none; border: none; padding: 0; font-family: inherit; cursor: pointer;
}
.nav-item.active { color: var(--text); }
a.nav-item { text-decoration: none; }
a.nav-item:hover, button.nav-item:hover { color: var(--text); }
.nav-item.soon { opacity: 0.5; cursor: default; }
.sound-toggle {
  margin-left: auto; padding: 6px 12px; border: none; border-radius: 6px;
  background: var(--panel-light); color: var(--text); font-weight: 600; font-family: inherit; cursor: pointer;
  white-space: nowrap;
}
.sound-toggle.off { color: var(--text-dim); }
.account-button {
  margin-left: auto; padding: 6px 12px; border: none; border-radius: 6px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 700; font-family: inherit; white-space: nowrap;
  max-width: 45vw; overflow: hidden; text-overflow: ellipsis;
}
.account-button:not([hidden]) + .sound-toggle { margin-left: 0; }

.account-dialog {
  width: min(380px, calc(100vw - 32px)); padding: 18px 20px; border: none; border-radius: 10px;
  background: var(--panel); color: var(--text); font-family: inherit;
}
.account-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.account-dialog h2 { margin: 0 0 12px; font-size: 20px; }
.account-dialog p { color: var(--text-dim); font-size: 14px; line-height: 1.45; }
.account-dialog label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--text-dim); }
.account-dialog input {
  display: block; width: 100%; margin-top: 4px; padding: 10px; border-radius: 6px;
  border: 2px solid var(--panel-light); background: var(--bg); color: var(--text); font-size: 16px; font-family: inherit;
}
.account-dialog input:focus { outline: none; border-color: var(--accent); }
.account-dialog .btn { width: 100%; margin-top: 4px; }
.account-view[hidden] { display: none; }
.dialog-close-row { margin: -8px -10px 0 0; text-align: right; }
.dialog-close { border: none; background: none; color: var(--text-dim); font-size: 18px; cursor: pointer; }
.account-links { text-align: center; margin: 12px 0 0; }
.link-button {
  border: none; background: none; padding: 0; color: var(--accent); cursor: pointer;
  font-family: inherit; font-size: 14px; text-decoration: underline;
}
.link-button.danger { color: var(--danger); }
.account-message { min-height: 1.2em; margin: 12px 0 0; }
.account-message:empty { display: none; }
.account-message.error { color: #ff8a80; }
.account-footer { margin: 12px 0 0; text-align: center; font-size: 12px; }
.account-footer a { color: var(--text-dim); }
.profile-stats { margin-bottom: 14px; }
.account-dialog [data-view="profile"] .btn { margin-bottom: 8px; }
.friend-add { margin-bottom: 4px; }
.friend-add input { margin-top: 0; letter-spacing: normal; text-transform: none; font-weight: 400; }
.friend-note { min-height: 0; margin: 4px 0 8px; }
.friend-note:empty { display: none; }
.friend-note.error { color: #ff8a80; }
.friend-section h3 { margin: 14px 0 6px; font-size: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.friend-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--panel-light);
}
.friend-who { display: flex; flex-direction: column; min-width: 0; }
.friend-who b { overflow: hidden; text-overflow: ellipsis; }
.friend-detail { font-size: 12px; color: var(--text-dim); }
.friend-actions { display: flex; gap: 6px; flex: none; }
.account-dialog .small-btn { width: auto; margin: 0; padding: 6px 10px; font-size: 13px; }
.friend-empty { margin: 4px 0; }
.account-dialog { max-height: calc(100vh - 40px); overflow-y: auto; }
.profile-stats div { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--panel-light); }

.game-layout {
  display: flex;
  gap: 24px;
  justify-content: center;
  align-items: flex-start;
  padding: 20px 16px;
  flex-wrap: wrap;
}

.board-column {
  width: min(720px, 100%, calc(100vh - 170px));
  min-width: 280px;
  display: flex;
  flex-direction: column;
}
/* You sit at the bottom of the board, like on chess.com. */
.board-column .top-seat { order: 0; }
.board-column .board { order: 1; }
.board-column .bottom-seat { order: 2; }

.player-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  font-weight: 600;
  border-left: 4px solid transparent;
}
.player-card.to-move { border-left-color: var(--accent); padding-left: 10px; }
.player-info { margin-left: auto; color: var(--text-dim); font-weight: 400; }
.clock {
  min-width: 70px; padding: 4px 10px; border-radius: 6px; text-align: right;
  background: var(--panel); color: var(--text-dim); font-size: 18px; font-variant-numeric: tabular-nums;
}
.to-move .clock { background: var(--text); color: var(--bg); }
.to-move .clock.low { background: var(--danger); color: #fff; }
.choice-row.wrap { flex-wrap: wrap; }
.choice-row.wrap button { flex: 1 0 40px; }

.stone-icon { width: 20px; height: 20px; border-radius: 50%; display: inline-block; }
.stone-icon.black { background: radial-gradient(circle at 35% 35%, #666, #000 70%); }
.stone-icon.white { background: radial-gradient(circle at 35% 35%, #fff, #ccc 80%); }

.board svg { display: block; width: 100%; height: auto; border-radius: 4px; box-shadow: 0 6px 18px rgba(0,0,0,.45); }

.spot { cursor: pointer; }
.spot .ghost { opacity: 0; pointer-events: none; }
.spot:hover .ghost { opacity: 0.45; }
.board.no-ghost .spot .ghost { display: none; }

.side-panel {
  width: 300px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel-block { background: var(--panel); border-radius: 8px; padding: 14px; }
.panel-block h2 { margin: 0 0 10px; font-size: 16px; }
.panel-block.small p { margin: 0; font-size: 14px; color: var(--text-dim); line-height: 1.45; }

.label { margin: 10px 0 6px; font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.label:first-of-type { margin-top: 0; }
#bot-options[hidden] { display: none; }

.choice-row { display: flex; gap: 6px; margin-bottom: 10px; }
.choice-row button, .bot-list button {
  flex: 1; padding: 8px 4px; border: none; border-radius: 6px;
  background: var(--panel-light); color: var(--text); font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.choice-row button.selected, .bot-list button.selected { outline: 2px solid var(--accent); }

.bot-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.bot-list button { display: flex; align-items: center; gap: 10px; text-align: left; padding: 8px 10px; }
.bot-level {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: var(--bg); font-size: 13px;
}
.bot-name { display: block; }
.bot-blurb { display: block; font-weight: 400; font-size: 12px; color: var(--text-dim); }

.label.spaced { margin-top: 14px; }
.rated-hint { margin: -4px 0 10px; font-size: 13px; color: var(--text-dim); }
.rated-hint:empty { display: none; }
.rated-note { margin: -6px 0 12px; color: var(--accent); font-weight: 600; }
.rated-note:empty { display: none; }
.join-row { display: flex; gap: 8px; }
.join-row input {
  flex: 1; min-width: 0; padding: 10px; border-radius: 6px; border: 2px solid var(--panel-light);
  background: var(--bg); color: var(--text); font-size: 16px; font-weight: 700;
  letter-spacing: .15em; text-transform: uppercase; font-family: inherit;
}
.join-row input:focus { outline: none; border-color: var(--accent); }
.join-row .btn { flex: none; padding: 10px 18px; }

.invite-box { display: flex; flex-direction: column; gap: 8px; text-align: center; }
.invite-box p { margin: 0; color: var(--text-dim); font-size: 14px; }
.invite-code {
  font-size: 30px; font-weight: 800; letter-spacing: .2em;
  background: var(--bg); border-radius: 8px; padding: 10px; user-select: all;
}
.online-status { margin: 10px 0 0; }
.online-status:empty { display: none; }

.chat-messages {
  height: 150px; overflow-y: auto; margin-bottom: 8px; padding: 8px;
  background: var(--bg); border-radius: 6px; font-size: 14px; line-height: 1.4;
  overflow-wrap: anywhere;
}
.chat-line { margin-bottom: 4px; }
.chat-line.mine b { color: var(--accent); }
.chat-line.note { color: var(--text-dim); font-style: italic; }
.chat-block .join-row input { letter-spacing: normal; text-transform: none; font-weight: 400; font-size: 15px; }

.move-list {
  position: relative; /* so the current move can be scrolled into view inside the list */
  max-height: 160px; overflow-y: auto; margin-bottom: 8px; padding: 4px;
  background: var(--bg); border-radius: 6px; font-size: 14px;
}
.move-row { display: grid; grid-template-columns: 40px 1fr 1fr; align-items: center; }
.move-number { color: var(--text-dim); text-align: right; padding-right: 6px; }
.move {
  border: none; background: none; color: var(--text); text-align: left; padding: 3px 8px;
  border-radius: 4px; cursor: pointer; font-family: inherit; font-size: 14px;
}
.move:hover { background: var(--panel-light); }
.move.current { background: var(--accent); color: #fff; font-weight: 700; }
.move-empty { margin: 6px; color: var(--text-dim); }
.replay-row .btn { font-size: 20px; padding: 6px; }
.view-note { margin: 8px 0 0; }
.view-note:empty { display: none; }

.puzzle-prompt { margin: 0 0 12px; font-size: 16px; line-height: 1.45; }
.puzzle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; }
.puzzle-chip {
  height: 40px; border: none; border-radius: 6px; cursor: pointer; font-family: inherit;
  background: var(--panel-light); color: var(--text); font-weight: 700; font-size: 15px;
}
.puzzle-chip.solved { background: var(--accent-dark); color: #fff; }
.puzzle-chip.current { outline: 2px solid var(--accent); }
.puzzle-progress { margin: 10px 0 0; }

.text-page { max-width: 720px; margin: 0 auto; padding: 20px 16px 40px; line-height: 1.6; }
.text-page h1 { font-size: 28px; }
.text-page h2 { font-size: 19px; margin-top: 28px; }
.text-page a { color: var(--accent); }
.text-page .back-link { display: inline-block; width: auto; margin-top: 16px; color: #fff; text-decoration: none; }

/* Position editor */
.setup-button { width: 100%; margin-top: 14px; }
.editor-row { margin-top: 14px; }
#editor-message.error { color: #ff8a80; }

/* Leaderboard page */
.list-page { max-width: 860px; margin: 0 auto; padding: 20px 16px 40px; display: flex; flex-direction: column; gap: 14px; }
.list-page h1 { margin: 6px 0 8px; font-size: 26px; overflow-wrap: anywhere; }
.list-page .message { margin-bottom: 8px; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.data-table th { text-align: left; font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; }
.data-table td { padding: 8px; border-top: 1px solid var(--panel-light); white-space: nowrap; }
.data-table a { color: var(--text); font-weight: 600; }
.data-table tr.me td { background: rgba(129, 182, 76, 0.15); }
.data-table tr.won td:nth-child(5) { color: var(--accent); font-weight: 600; }
.data-table tr.lost td:nth-child(5) { color: #ff8a80; }
.data-table .message { margin: 0; }
.data-table .small-link { display: inline-block; padding: 4px 10px; font-size: 13px; color: var(--text); text-decoration: none; }
.spaced-link { display: inline-block; margin-top: 12px; }
a.link-button { display: inline-block; }
.stat-row { display: flex; flex-wrap: wrap; gap: 10px; }
.stat { flex: 1 0 110px; background: var(--bg); border-radius: 6px; padding: 10px; display: flex; flex-direction: column; }
.stat b { font-size: 20px; }
.stat span { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.account-dialog a.btn { display: block; text-align: center; text-decoration: none; margin-bottom: 8px; }

/* Phones and small windows: the panel drops under the board, so put the game
   buttons first instead of below the whole "New game" box. */
@media (max-width: 1000px) {
  .top-bar { gap: 14px; padding: 10px 12px; flex-wrap: wrap; row-gap: 8px; }
  /* The menu gets its own line on small screens so the account and sound buttons fit. */
  .top-bar nav { order: 3; width: 100%; gap: 16px; }
  .game-layout { gap: 12px; padding-top: 10px; }
  .side-panel { width: min(720px, 100%); }
  .editor-block, .controls-block, .chat-block, .moves-block { order: -1; }
}

.thinking::after { content: ""; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.btn {
  flex: 1; padding: 10px; border: none; border-radius: 6px;
  background: var(--panel-light); color: var(--text);
  font-size: 15px; font-weight: 700; cursor: pointer;
}
.btn:hover:not(:disabled) { filter: brightness(1.15); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { background: var(--accent); box-shadow: 0 4px 0 var(--accent-dark); width: 100%; }
.btn-danger { background: var(--danger); }
.btn-hint { background: #2f6e8a; }
.button-row { display: flex; gap: 8px; }
.button-row[hidden] { display: none; }
.rematch-row { margin-top: 10px; }

.status { margin: 0 0 6px; font-size: 18px; font-weight: 700; }
.message { margin: 0 0 12px; min-height: 1.3em; color: var(--text-dim); font-size: 14px; }
