/* ==========================================================================
   renjuonline.top — Lichess (lila) Swiss & Tournament Theme
   ========================================================================== */

:root {
  --c-bg: #ffffff;
  --c-bg-page: #edebe9;
  --c-bg-low: #e3e3e3;
  --c-bg-zebra: #f7f6f5;
  --c-bg-zebra2: #eae8e6;
  --c-font: #4d4d4d;
  --c-font-dim: #787878;
  --c-font-clear: #1f1f1f;
  --c-primary: #1b78d0;
  --c-link: #1b78d0;
  --c-brag: #d59020;
  --c-good: #629924;
  --c-bad: #cc3333;
  --c-border: #d9d9d9;
  --c-metal-top: #f5f5f5;
  --c-metal-bottom: #ededed;
  --box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
  --font-sans: "Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--c-bg-page);
  background-image: linear-gradient(to bottom, #d6d3d0 0, var(--c-bg-page) 116px);
  background-repeat: no-repeat;
  color: var(--c-font);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  min-height: 100vh;
}

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

a:hover {
  text-decoration: underline;
}

/* ---------- Lichess Top Header ---------- */

#top {
  height: 52px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.site-title-nav {
  display: flex;
  align-items: center;
  gap: 20px;
}

.site-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 19px;
  font-weight: 400;
  color: var(--c-font-clear);
  letter-spacing: -0.02em;
  text-decoration: none;
}

.site-name:hover {
  text-decoration: none;
  color: var(--c-primary);
}

.site-name strong {
  font-weight: 700;
}

#topnav {
  display: flex;
  align-items: center;
  gap: 4px;
}

#topnav a {
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--c-font);
  text-transform: uppercase;
  border-radius: 3px;
  text-decoration: none;
  transition: color 0.12s ease, background-color 0.12s ease;
}

#topnav a:hover {
  color: var(--c-primary);
  background: rgba(0, 0, 0, 0.04);
}

#topnav a.active {
  color: var(--c-primary);
  box-shadow: inset 0 -2px 0 var(--c-primary);
  border-radius: 3px 3px 0 0;
}

/* ---------- Main Page Wrapper ---------- */

#main-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 6px 14px 36px;
}

#main-wrap.is-narrow {
  max-width: 940px;
}

/* ---------- Lichess .box ---------- */

.box {
  position: relative;
  background: var(--c-bg);
  box-shadow: var(--box-shadow);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 16px;
}

.box-pad {
  padding: 16px 20px;
}

/* ---------- Lichess Swiss 2-Column Layout (.swiss) ---------- */

.swiss-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}

@media (min-width: 860px) {
  .swiss-layout {
    grid-template-columns: 260px minmax(0, 1fr);
  }
}

.swiss__side {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.swiss__stats {
  padding: 16px 18px;
}

.swiss__stats h2 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--c-font-clear);
  border-bottom: 1px solid var(--c-border);
  padding-bottom: 8px;
}

.swiss__meta-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--c-font);
}

.swiss__meta-list p {
  margin: 0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.swiss__meta-list b {
  color: var(--c-font-dim);
  font-weight: 500;
}

/* ---------- Lichess %tour-header (.swiss__main__header) ---------- */

.swiss__main__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 76px;
  padding: 14px 20px;
}

.swiss__header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.swiss__trophy {
  flex: none;
  width: 36px;
  height: 36px;
  color: var(--c-brag);
}

.swiss__main__header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  color: var(--c-font-clear);
  line-height: 1.25;
}

.swiss__round-badge {
  flex: none;
  text-align: right;
  font-family: var(--font-mono);
  color: var(--c-brag);
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
}

.swiss__round-badge span {
  display: block;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--c-font-dim);
}

/* ---------- Lichess %tour-controls (.swiss__controls) ---------- */

.swiss__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: linear-gradient(to bottom, var(--c-metal-top) 0%, var(--c-metal-bottom) 100%);
  border-top: 1px solid var(--c-border);
  border-bottom: 1px solid var(--c-border);
  padding: 4px 10px;
}

.round-pick {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swiss__controls .round-nav,
.box-controls .round-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  min-width: 30px;
  padding: 0 9px;
  border: 1px solid var(--c-border);
  border-radius: 3px;
  background: var(--c-bg);
  color: var(--c-font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.swiss__controls .round-nav:hover:not(:disabled),
.box-controls .round-nav:hover:not(:disabled) {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #ffffff;
}

.swiss__controls .round-nav:disabled,
.box-controls .round-nav:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.swiss__controls select,
.box-controls select {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--c-border);
  border-radius: 3px;
  background: var(--c-bg);
  color: var(--c-font-clear);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.round-total {
  font-size: 12px;
  color: var(--c-font-dim);
  font-variant-numeric: tabular-nums;
}

/* Lichess .fbt flat tab buttons inside %tour-controls */
.fbt-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.fbt {
  border: none;
  background: transparent;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--c-font);
  cursor: pointer;
  border-radius: 2px;
}

.fbt:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--c-primary);
}

.fbt.active {
  background: var(--c-primary);
  color: #ffffff;
}

/* ---------- Lichess .slist Tables ---------- */

.slist-wrapper,
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.slist,
table[data-feed],
table.tour-games,
table.tour-standings,
table.player-games {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

.slist thead th,
table[data-feed] th,
table.tour-games th,
table.tour-standings th,
table.player-games th {
  padding: 8px 12px;
  background: linear-gradient(to bottom, var(--c-metal-top) 0%, var(--c-metal-bottom) 100%);
  border-top: 1px solid var(--c-border);
  border-bottom: 1px solid var(--c-border);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--c-font-dim);
  text-align: left;
  white-space: nowrap;
}

.slist tbody tr:nth-child(even),
table[data-feed] tbody tr:nth-child(even),
table.tour-games tbody tr:nth-child(even),
table.tour-standings tbody tr:nth-child(even),
table.player-games tbody tr:nth-child(even) {
  background: var(--c-bg-zebra);
}

.slist tbody tr:hover:not(:first-child),
table[data-feed] tbody tr:hover:not(:first-child),
table.tour-games tbody tr:hover:not(:first-child),
table.tour-standings tbody tr:hover:not(:first-child),
table.player-games tbody tr:hover {
  background: color-mix(in oklab, var(--c-primary) 12%, var(--c-bg));
}

.slist td,
table[data-feed] td,
table.tour-games td,
table.tour-standings td,
table.player-games td {
  padding: 9px 12px;
  vertical-align: middle;
  color: var(--c-font-clear);
  border-bottom: 1px solid var(--c-border);
}

.slist tbody tr:last-child td,
table[data-feed] tbody tr:last-child td,
table.tour-games tbody tr:last-child td,
table.tour-standings tbody tr:last-child td,
table.player-games tbody tr:last-child td {
  border-bottom: none;
}

table[data-feed] td a,
table.tour-games td a,
table.tour-standings td a,
table.player-games td a,
table.player-games th a {
  color: var(--c-font-clear);
  font-weight: 600;
}

table[data-feed] td a:hover,
table.tour-games td a:hover,
table.tour-standings td a:hover,
table.player-games td a:hover,
table.player-games th a:hover {
  color: var(--c-primary);
  text-decoration: underline;
}

td.period,
td.date,
td.rnd,
td.rule,
td.cnum {
  color: var(--c-font-dim);
  font-size: 12.5px;
  white-space: nowrap;
}

td.num,
td.prob {
  text-align: right;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 13px;
}

table.tour-standings td.points,
table.tour-standings td:nth-child(3) {
  font-weight: 700;
}

table[data-feed="tournaments"] th:nth-child(n+3),
table[data-feed="players"] th:nth-child(1),
table[data-feed="players"] th:nth-child(n+3),
table.tour-standings th:nth-child(1),
table.tour-standings th:nth-child(n+3),
table.tour-games th:nth-child(n+7) {
  text-align: right;
}

table.tour-games th:nth-child(5),
table.tour-games td.score {
  text-align: center;
  font-weight: 700;
  white-space: nowrap;
}

table.tour-games td.score a.score-link,
table.player-games td a.score-link {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  background: var(--c-bg-zebra2);
  color: var(--c-font-clear);
  font-weight: 700;
}

table.tour-games td.score a.score-link:hover,
table.player-games td a.score-link:hover {
  background: var(--c-primary);
  color: #ffffff;
  text-decoration: none;
}

.player-no {
  display: inline-block;
  margin-right: 5px;
  padding: 0 5px;
  border-radius: 2px;
  background: var(--c-bg-low);
  color: var(--c-font-dim);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
}

.player-pts {
  display: inline-block;
  margin-left: 4px;
  font-size: 11.5px;
  color: var(--c-font-dim);
  font-family: var(--font-mono);
}

td.skip {
  color: var(--c-font-dim);
  font-style: italic;
}

/* ---------- Probability Pills (>=50% green, <50% gray, highest only) ---------- */

.prob-pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
}

.prob-pill.is-green {
  background-color: #16a34a;
  color: #ffffff;
}

.prob-pill.is-slate {
  background-color: #6b7280;
  color: #ffffff;
}

/* ---------- Lichess Section Title inside .box ---------- */

.swiss__section-title {
  margin: 0;
  padding: 10px 14px;
  background: linear-gradient(to bottom, var(--c-metal-top) 0%, var(--c-metal-bottom) 100%);
  border-top: 1px solid var(--c-border);
  border-bottom: 1px solid var(--c-border);
  font-size: 13px;
  font-weight: 700;
  color: var(--c-font-clear);
}

/* ---------- Player Page ---------- */

.nowrap {
  white-space: nowrap;
}

#chart {
  position: relative;
  padding: 14px;
  background: var(--c-bg);
}

#chart svg {
  display: block;
  width: 100%;
  height: auto;
}

#chart .chart-tip {
  position: absolute;
  z-index: 20;
  padding: 6px 10px;
  border-radius: 3px;
  background: #2b2b2b;
  color: #ffffff;
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
}

#chart .chart-tip b,
#chart .chart-tip span {
  display: block;
}

table.player-games tr:has(> th[colspan="7"]) th {
  padding: 11px 12px 8px;
  background: var(--c-bg);
  font-size: 14px;
  font-weight: 700;
  color: var(--c-font-clear);
  border-top: 1px solid var(--c-border);
  border-bottom: 1px solid var(--c-border);
}

table.player-games th.second {
  background: var(--c-bg-zebra);
  color: var(--c-font-dim);
}

table.player-games tr:has(> th.second) td {
  background: var(--c-bg-zebra);
  color: var(--c-font-dim);
}

/* ---------- Game Page ---------- */

.game-meta {
  padding: 14px 20px;
  border-bottom: 1px solid var(--c-border);
  font-size: 13.5px;
  color: var(--c-font);
}

.game-meta .meta-line {
  margin: 4px 0;
}

.board-wrap {
  display: flex;
  justify-content: center;
  padding: 18px;
  background: var(--c-bg);
}

#renjuBoard {
  display: block;
  max-width: 100%;
}

.board-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  background: linear-gradient(to bottom, var(--c-metal-top) 0%, var(--c-metal-bottom) 100%);
  border-top: 1px solid var(--c-border);
}

.board-controls button {
  min-width: 40px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--c-border);
  border-radius: 3px;
  background: var(--c-bg);
  color: var(--c-font-clear);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.board-controls button:hover:not(:disabled) {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #ffffff;
}

.board-controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.board-controls .step-info {
  min-width: 64px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
}

/* ---------- Model Page ---------- */

.model-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--c-border);
}

.model-section:last-child {
  border-bottom: none;
}

.model-section h2 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--c-font-clear);
}

.model-desc {
  margin: 0 0 6px;
  font-size: 13.5px;
  line-height: 1.6;
}

.model-list {
  margin: 6px 0 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.65;
}

.model-section code {
  padding: 1px 5px;
  border-radius: 2px;
  background: var(--c-bg-zebra2);
  font-family: var(--font-mono);
  font-size: 12px;
}

.model-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 10px 0 14px;
}

@media (min-width: 640px) {
  .model-metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.model-metric-card {
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: 3px;
  background: var(--c-bg-zebra);
}

.model-metric-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-font-dim);
}

.model-metric-value {
  margin-top: 3px;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--c-font-clear);
}

.model-metric-sub {
  margin-top: 3px;
  font-size: 11px;
  color: var(--c-font-dim);
}

.model-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--c-font-dim);
}

.model-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.model-legend-line {
  width: 12px;
  height: 3px;
  border-radius: 1px;
}

.model-legend-dash {
  width: 12px;
  height: 0;
  border-top: 2px dashed #9aa5b1;
}

.model-chart-wrap {
  position: relative;
  width: 100%;
}

.model-svg {
  display: block;
  width: 100%;
  height: auto;
}

.model-tooltip {
  position: absolute;
  z-index: 25;
  padding: 6px 10px;
  border-radius: 3px;
  background: #2b2b2b;
  color: #ffffff;
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
}

.model-tt-date {
  font-weight: 700;
  margin-bottom: 2px;
}

.model-tt-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.model-tt-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* ---------- Admin Page ---------- */

.admin-panel,
.admin-editor-wrap,
.admin-preview,
.admin-status {
  margin-bottom: 12px;
  padding: 12px 16px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 3px;
}

.admin-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.admin-row label {
  font-size: 13px;
  font-weight: 600;
}

.admin-row input,
.admin-row select {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--c-border);
  border-radius: 3px;
  background: var(--c-bg);
  color: var(--c-font-clear);
  font-size: 13px;
}

.admin-row input {
  min-width: 220px;
  flex: 1 1 200px;
}

.admin-row button,
.admin-actions button {
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--c-border);
  border-radius: 3px;
  background: linear-gradient(to bottom, var(--c-metal-top) 0%, var(--c-metal-bottom) 100%);
  color: var(--c-font-clear);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.admin-actions .admin-btn-primary {
  background: var(--c-primary);
  color: #ffffff;
  border-color: var(--c-primary);
}

.admin-actions .admin-btn-success {
  background: var(--c-good);
  color: #ffffff;
  border-color: var(--c-good);
}

.admin-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--c-font-dim);
}

#txtEditor {
  width: 100%;
  min-height: 320px;
  padding: 10px;
  border: 1px solid var(--c-border);
  border-radius: 3px;
  background: var(--c-bg);
  color: var(--c-font-clear);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
  resize: vertical;
}

.admin-muted {
  font-size: 12px;
  color: var(--c-font-dim);
}

@media (max-width: 600px) {
  #main-wrap {
    padding: 4px 6px 24px;
  }

  .swiss__main__header {
    padding: 12px 14px;
  }

  .swiss__main__header h1 {
    font-size: 18px;
  }

  .slist td,
  table[data-feed] th,
  table[data-feed] td,
  table.tour-games th,
  table.tour-games td,
  table.tour-standings th,
  table.tour-standings td,
  table.player-games th,
  table.player-games td {
    padding: 7px 6px;
    font-size: 12px;
  }
}
