/* ===== Chess lounge — dark, warm, editorial ===== */
:root {
  --bg: #14110d;
  --bg-soft: #1c1813;
  --surface: #211c15;
  --surface-2: #2a241b;
  --border: #372f24;
  --border-soft: #2c261d;
  --text: #ece5d6;
  --muted: #a79b86;
  --faint: #7c7260;
  --accent: #e2a63d;
  --accent-hover: #eeb64e;
  --accent-ink: #241a05;
  --danger: #e0654d;
  --danger-hover: #ec7960;
  --ok: #7fbf7f;
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --shadow: 0 18px 50px -18px rgba(0, 0, 0, 0.65);
  --radius: 16px;
  --font-serif: Georgia, 'Times New Roman', serif;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1100px 520px at 18% -8%, rgba(226, 166, 61, 0.09), transparent 60%),
    radial-gradient(900px 480px at 100% 100%, rgba(74, 58, 30, 0.20), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- header ---------- */
.site-header {
  max-width: 1080px;
  margin: 0 auto;
  padding: 22px 24px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 13px; text-decoration: none; color: inherit; }
.brand .mark {
  width: 46px; height: 46px;
  border-radius: 13px;
  background: linear-gradient(145deg, #f2c55c, #c88a2b);
  color: #241a05;
  display: grid; place-items: center;
  font-size: 27px;
  font-family: var(--font-serif);
  box-shadow: 0 8px 18px -8px rgba(226,166,61,.55);
}
.brand .title { font-family: var(--font-serif); font-size: 25px; letter-spacing: 0.2px; font-weight: 700; }
.brand .sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }

.container { max-width: 1080px; margin: 0 auto; padding: 12px 24px 60px; }

/* ---------- cards ---------- */
.card {
  background: linear-gradient(180deg, rgba(255,255,255,.028), rgba(255,255,255,0)) , var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card h2, .card h3 {
  font-family: var(--font-serif);
  font-weight: 700;
  margin: 0 0 12px;
  font-size: 19px;
  color: var(--text);
}
.card .muted { color: var(--muted); font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  font: inherit; font-weight: 650; font-size: 15px;
  padding: 13px 22px; border-radius: 12px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none; color: var(--text);
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease, border-color .14s ease;
}
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none !important; box-shadow: none !important; }
.btn-primary {
  background: linear-gradient(160deg, #f2c55c, #dfa036);
  color: var(--accent-ink);
  box-shadow: 0 10px 26px -10px rgba(226,166,61,.6);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 14px 30px -10px rgba(226,166,61,.7); background: linear-gradient(160deg, #f6cd68, #e8ac45); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: transparent; border-color: rgba(224,101,77,.45); color: #f0977f; }
.btn-danger:hover { background: rgba(224,101,77,.12); border-color: var(--danger); color: #f6ac93; }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 8px 13px; font-size: 13px; border-radius: 10px; }

/* ---------- home grid ---------- */
.home-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 4fr); gap: 18px; margin-top: 14px; align-items: start; }
@media (max-width: 880px) { .home-grid { grid-template-columns: 1fr; } }

.hero-card { text-align: center; padding: 30px 26px; }
.hero-card h1 {
  font-family: var(--font-serif); font-size: clamp(30px, 5.4vw, 44px);
  margin: 0 0 8px; letter-spacing: -.4px; line-height: 1.12;
}
.hero-card p { color: var(--muted); margin: 0 auto 22px; max-width: 460px; font-size: 15px; line-height: 1.55; }
.hero-cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.color-btn { min-width: 168px; }

/* link card */
.link-card { display: none; margin-top: 18px; border: 1px solid rgba(226,166,61,.4); background: linear-gradient(180deg, rgba(226,166,61,.10), rgba(226,166,61,.045)); }
.link-card.show { display: block; }
.link-card h3 { color: var(--accent); }
.link-row { display: flex; gap: 10px; align-items: stretch; margin-top: 12px; }
.link-row input {
  flex: 1; min-width: 0; background: #17130e; color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12.5px; padding: 11px 13px; outline: none;
}
.link-row input:focus { border-color: var(--accent); }

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat { background: var(--bg-soft); border: 1px solid var(--border-soft); border-radius: 13px; padding: 14px 16px; }
.stat .num { font-family: var(--font-serif); font-size: 30px; font-weight: 700; line-height: 1.1; }
.stat .label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .9px; margin-top: 5px; }
.winrate { margin-top: 12px; font-size: 13px; color: var(--muted); text-align: center; }
.winrate b { color: var(--accent); font-size: 15px; }

/* lists */
.list { display: flex; flex-direction: column; gap: 9px; }
.list-item {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--bg-soft); border: 1px solid var(--border-soft);
  border-radius: 12px; padding: 11px 13px; text-decoration: none; color: inherit;
  transition: border-color .14s ease, transform .14s ease;
}
.list-item:hover { border-color: var(--accent); transform: translateY(-1px); }
.list-item .mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; color: var(--muted); font-size: 12px; }
.list-item .grow { flex: 1; min-width: 120px; }
.list-item .grow b { display: block; font-size: 13px; font-weight: 650; }
.list-item .grow small { color: var(--muted); font-size: 12px; }
.empty { color: var(--faint); text-align: center; padding: 18px 10px; font-size: 13.5px; line-height: 1.5; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 650; letter-spacing: .3px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.badge.b-waiting { color: #ebcb7a; border-color: rgba(235,203,122,.4); background: rgba(235,203,122,.08); }
.badge.b-active { color: #8fd18f; border-color: rgba(127,207,140,.35); background: rgba(127,207,140,.08); }
.badge.b-finished { color: var(--text); border-color: var(--border); background: var(--surface-2); }
.badge.b-cancelled { color: var(--faint); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.b-active .dot { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- game page ---------- */
.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 600px) minmax(0, 340px);
  gap: 22px;
  align-items: start;
  margin-top: 14px;
}
@media (max-width: 960px) { .game-layout { grid-template-columns: 1fr; } }

.board-zone { display: flex; flex-direction: column; gap: 10px; }
.board-frame {
  position: relative;
  padding: 11px;
  background: linear-gradient(160deg, #2c2215, #1d1810);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.sq { position: relative; display: grid; place-items: center; border: 0; padding: 0; background: transparent; color: inherit; font-family: inherit; font-size: clamp(1.35rem, 6.4vw, 2.9rem); line-height: 1; cursor: default; }
.sq:focus-visible { outline: 3px solid rgba(226,166,61,.85); outline-offset: -3px; }
@media (min-width: 700px) { .sq { font-size: clamp(1.7rem, 4.4vw, 2.7rem); } }
.sq.light { background: var(--board-light); }
.sq.dark { background: var(--board-dark); }
.sq .piece {
  font-family: 'Segoe UI Symbol', 'Noto Sans Symbols 2', 'DejaVu Sans', 'Apple Symbols', serif;
  pointer-events: none;
  transition: transform .1s ease;
}
.sq.can-move, .sq.selected { cursor: pointer; }
.sq.can-move:hover .piece { transform: scale(1.12); }
.sq.last::after { content: ''; position: absolute; inset: 0; background: rgba(226,166,61,.34); }
.sq.selected::before { content: ''; position: absolute; inset: 0; background: rgba(226,166,61,.48); }
.sq.check::before { content: ''; position: absolute; inset: 0; background: radial-gradient(circle, rgba(224,70,70,.75), rgba(224,70,70,.18) 62%, transparent 70%); }
.sq.target::before { content: ''; position: absolute; inset: 0; background: rgba(50, 42, 24, .20); }
.sq.target::after { content: ''; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 26%; height: 26%; border-radius: 50%; background: rgba(35, 28, 15, .5); box-shadow: 0 0 0 2px rgba(255,255,255,.15); }
.sq.target.cap::after { width: 92%; height: 92%; left: 50%; top: 50%; transform: translate(-50%, -50%); border-radius: 50%; background: transparent; border: 4px solid rgba(224,166,61,.9); box-shadow: none; }
.sq .sq-coord { position: absolute; font-size: 9px; font-weight: 700; opacity: .75; pointer-events: none; }
.sq .sq-coord.file { right: 3px; bottom: 2px; }
.sq .sq-coord.rank { left: 3px; top: 2px; }
.sq.light .sq-coord { color: var(--board-dark); }
.sq.dark .sq-coord { color: var(--board-light); }

.piece-w { color: #26200f; text-shadow: 0 0 2px rgba(255,255,255,.65), 0 2px 3px rgba(0,0,0,.45); }
.piece-b { color: #191410; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.piece-outline { color: #f5ead2; text-shadow: 0 1px 2px rgba(0,0,0,.6), 0 0 6px rgba(0,0,0,.35); }
.piece-filled { color: #171310; text-shadow: 0 1px 2px rgba(255,255,255,.22); }

.game-panel { display: flex; flex-direction: column; gap: 14px; }
.panel-section { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.panel-section h3 { margin: 0 0 10px; font-family: var(--font-serif); font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.1px; font-weight: 700; }
.status-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.turn-dot { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); font-weight: 600; }
.turn-dot .lamp { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px rgba(127,207,140,.8); }
.turn-dot.waiting .lamp { background: #ebcb7a; box-shadow: 0 0 8px rgba(235,203,122,.7); animation: pulse 1.4s infinite; }
.seat-line { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.seat-line b { color: var(--text); }
.moves-scroll { max-height: 224px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding-right: 4px; }
.moves-scroll::-webkit-scrollbar { width: 6px; }
.moves-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.move-row { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 6px; font-size: 13.5px; padding: 3px 6px; border-radius: 6px; align-items: center; }
.move-row:nth-child(odd) { background: rgba(255,255,255,.03); }
.move-row .n { color: var(--faint); font-variant-numeric: tabular-nums; }
.move-row .mv { font-family: ui-monospace, 'SF Mono', Menlo, monospace; }
.move-row .mv.current { color: var(--accent); font-weight: 700; }

.result-banner {
  display: none; text-align: center; padding: 20px;
  border-radius: var(--radius); border: 1px solid rgba(226,166,61,.45);
  background: linear-gradient(180deg, rgba(226,166,61,.14), rgba(226,166,61,.04));
}
.result-banner.show { display: block; }
.result-banner .big { font-family: var(--font-serif); font-size: 26px; font-weight: 700; color: var(--accent); margin: 0 0 6px; }
.result-banner .sub { color: var(--muted); font-size: 13.5px; }

.toolbar-row { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.link-copy-row { display: flex; gap: 7px; align-items: center; }
.link-copy-row input {
  flex: 1; min-width: 0; background: #17130e; color: var(--muted); font-size: 12px;
  border: 1px solid var(--border); border-radius: 9px; padding: 7px 10px; outline: none;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}
.link-copy-row input:focus { border-color: var(--accent); }

.promote-modal {
  position: fixed; inset: 0; background: rgba(10, 8, 5, .72);
  display: none; place-items: center; z-index: 50; padding: 20px;
}
.promote-modal.show { display: grid; }
.promote-box { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 22px; text-align: center; box-shadow: var(--shadow); }
.promote-box h3 { margin: 0 0 12px; font-family: var(--font-serif); }
.promote-options { display: flex; gap: 10px; justify-content: center; }
.promote-options button {
  width: 76px; height: 76px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer;
  font-size: 40px; line-height: 1;
  transition: all .13s ease;
}
.promote-options button:hover { border-color: var(--accent); background: var(--surface); transform: translateY(-2px); }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: #f2ead9; color: #2a2013; font-weight: 600; font-size: 13.5px;
  padding: 12px 20px; border-radius: 12px; box-shadow: 0 14px 34px -8px rgba(0,0,0,.6);
  opacity: 0; pointer-events: none; transition: opacity .22s ease, transform .22s ease; z-index: 60;
  max-width: min(92vw, 480px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.notfound { text-align: center; padding: 50px 20px; }
.notfound h1 { font-family: var(--font-serif); color: var(--text); }
.footnote { margin-top: 26px; text-align: center; color: var(--faint); font-size: 12px; }

/* ---------- mode picker / segmented control ---------- */
.mode-row { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 18px; }
.seg { display: inline-flex; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 12px; padding: 4px; gap: 4px; }
.seg-btn { background: transparent; border: 0; border-radius: 9px; color: var(--muted); font: inherit; font-size: 13.5px; font-weight: 600; padding: 8px 16px; cursor: pointer; transition: background .15s ease, color .15s ease; }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--surface-2); color: var(--accent); box-shadow: 0 4px 14px -6px rgba(0,0,0,.5); }
.difficulty {
  background: #17130e; color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  font: inherit; font-size: 13px; padding: 9px 12px; outline: none; cursor: pointer;
}
.difficulty:focus { border-color: var(--accent); }
.link-in-footnote { color: var(--accent); }

/* ---------- AI badge ---------- */
.badge.b-ai { color: #c9a0ff; border-color: rgba(178,132,255,.35); background: rgba(178,132,255,.08); }

/* ---------- settings page ---------- */
.settings-token-row, .settings-actions { display: flex; gap: 10px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.settings-actions { margin-top: 18px; }
.settings-error { color: #e86c5e; font-size: 13px; margin: 10px 0 0; }
.field { display: block; margin-top: 14px; }
.field > span { display: block; font-size: 12.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .7px; margin-bottom: 6px; }
.input {
  width: 100%; box-sizing: border-box; background: #17130e; color: var(--text);
  border: 1px solid var(--border); border-radius: 11px; padding: 11px 13px;
  font: inherit; font-size: 14px; outline: none; transition: border-color .15s ease;
}
.input:focus { border-color: var(--accent); }
.hint { display: block; color: var(--faint); font-size: 12px; margin-top: 6px; line-height: 1.45; }
.info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.info-grid > div { background: var(--bg-soft); border: 1px solid var(--border-soft); border-radius: 11px; padding: 12px 14px; }
.info-grid .k { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .7px; }
.info-grid .v { font-size: 14px; margin-top: 4px; display: block; }
@media (max-width: 700px) { .info-grid { grid-template-columns: 1fr; } }
.field select.input { cursor: pointer; }
