:root {
  --bg: #1e2126;
  --bg2: #25292f;
  --card: #2b3037;
  --card2: #333941;
  --ink: #e8eaed;
  --muted: #9aa3ad;
  --line: #3b424b;
  --accent: #4f9cf0;
  --accent2: #3a86db;
  --warn: #f0b74f;
  --danger: #e0604b;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%; }
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* nav */
.nav { display: flex; align-items: center; gap: 14px; height: 48px; padding: 0 16px; background: #16181c; border-bottom: 1px solid #0d0f12; }
.logo { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 18px; letter-spacing: .01em; }
.logostone { width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #666, #000 70%); box-shadow: 9px 5px 0 -1px #eee; margin-right: 12px; margin-top: -5px; }
.navsub { color: var(--muted); font-size: 12px; }
#app { max-width: 1400px; margin: 0 auto; padding: 16px; }

/* generic */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.cardhead { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.cardhead .linkbtn { margin-left: auto; text-transform: none; letter-spacing: 0; }
.btn { cursor: pointer; border-radius: 6px; border: 1px solid var(--line); background: var(--card2); padding: 8px 12px;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: var(--ink); }
.btn:hover { border-color: #56606b; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent); }
.btn.danger { color: #ffb4a6; }
.btn.big { width: 100%; padding: 12px; font-size: 16px; }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-size: 12px; }
.err { color: var(--danger); min-height: 1.2em; margin-top: 8px; }

/* lobby */
.lobby { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 16px; align-items: start; }
.challenge h2 { margin: 2px 0 12px; font-size: 20px; }
.kv { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--line); }
.kv span { color: var(--muted); }
.field { display: block; margin: 14px 0 6px; color: var(--muted); font-size: 12px; }
.field input { display: block; width: 100%; margin-top: 6px; padding: 9px 10px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--ink); font-size: 16px; }
.seg { display: flex; margin: 6px 0 14px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { flex: 1; padding: 9px 6px; background: var(--bg2); border: 0; cursor: pointer; color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 6px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--card2); color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.mini { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.mini.b { background: #000; box-shadow: 0 0 0 1px #555; }
.mini.w { background: #f2f2f2; }
.mini.n { background: linear-gradient(90deg, #000 50%, #f2f2f2 50%); box-shadow: 0 0 0 1px #555; }
.resume { margin-top: 12px; color: var(--muted); }
.serverline { margin-top: 10px; color: var(--muted); font-size: 12px; }
.gamelist table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.gamelist th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.gamelist td { padding: 7px 8px; border-bottom: 1px solid #333940; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.gamelist tbody tr { cursor: pointer; }
.gamelist tbody tr:hover { background: var(--card2); }
.num { text-align: right; }
.live { color: #7fd17f; font-size: 11px; font-weight: 600; }

/* game */
.gameview { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.boardcol { min-width: 0; display: flex; justify-content: center; }
.boardbox { position: relative; }
#board { display: block; border-radius: 3px; touch-action: manipulation; box-shadow: 0 6px 24px rgba(0,0,0,.5); cursor: pointer; }
.confirm { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; gap: 8px;
  background: rgba(22,24,28,.93); padding: 8px; border-radius: 8px; border: 1px solid var(--line); }
.banner { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); background: rgba(22,24,28,.9);
  border: 1px solid var(--line); padding: 14px 22px; border-radius: 10px; font-size: 22px; font-weight: 700; pointer-events: none; text-align: center; }

.panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; position: relative; min-width: 0; }
.pcard.turn { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.pcard .top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pcard .stone { width: 22px; height: 22px; border-radius: 50%; flex: none; }
.pcard .stone.b { background: radial-gradient(circle at 35% 30%, #666, #0a0a0a 65%); }
.pcard .stone.w { background: radial-gradient(circle at 35% 30%, #fff, #d4d0c8 80%); }
.pcard .pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .rank { color: var(--muted); font-size: 12px; }
.pcard .caps { color: var(--muted); font-size: 12px; margin-top: 4px; }
.pcard .clock { margin-top: 8px; padding: 6px 8px; border-radius: 6px; background: var(--bg2); border: 1px solid var(--line);
  font-variant-numeric: tabular-nums; text-align: center; }
.pcard .clock .main { font-size: 24px; font-weight: 700; letter-spacing: .02em; }
.pcard .clock .byo { font-size: 12px; color: var(--muted); }
.pcard .clock.run { border-color: var(--accent); background: #1c2a3a; }
.pcard .clock.inbyo .main { color: var(--warn); }
.pcard .clock.low { border-color: var(--danger); background: #3a1f1c; }
.pcard .clock.low .main { color: #ff8a73; }
.pcard .think { position: absolute; top: 10px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.status { font-weight: 600; margin-bottom: 10px; }
.controls { display: flex; gap: 8px; }
.controls .btn { flex: 1; }
.replaynav { display: flex; gap: 6px; align-items: center; margin-top: 10px; }
.replaynav .btn { padding: 6px 10px; }
.navpos { flex: 1; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); }
#navSlider { width: 100%; margin-top: 8px; }
.resultbig { font-size: 26px; font-weight: 800; letter-spacing: .02em; }
.resultcard .row { display: flex; gap: 8px; margin-top: 10px; }
.resultcard .row > * { flex: 1; }

.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-weight: 600; }
.switch input { display: none; }
.switch span { width: 34px; height: 18px; border-radius: 9px; background: var(--line); position: relative; transition: .2s; }
.switch span::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: #ccc; transition: .2s; }
.switch input:checked + span { background: var(--accent2); }
.switch input:checked + span::after { left: 18px; background: #fff; }
#anaBody { margin-top: 10px; }
.wrbar { position: relative; height: 22px; border-radius: 5px; overflow: hidden; background: #f2f2f2; border: 1px solid var(--line); margin-bottom: 6px; }
.wrfill { position: absolute; left: 0; top: 0; bottom: 0; width: 50%; background: #111; transition: width .4s; }
.wrlab { position: absolute; top: 2px; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.wrlab.l { left: 8px; color: #eee; mix-blend-mode: difference; }
.wrlab.r { right: 8px; color: #222; }

.moves ol { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 10px; max-height: 260px; overflow: auto; font-variant-numeric: tabular-nums; font-size: 13px; }
.moves li { display: flex; gap: 6px; padding: 1px 4px; border-radius: 4px; cursor: pointer; color: var(--muted); }
.moves li:hover { background: var(--card2); }
.moves li.cur { background: #1c2a3a; color: var(--ink); }
.moves li .n { min-width: 2.4em; text-align: right; }
.moves li b { color: var(--ink); font-weight: 500; min-width: 3.2em; }
.foot { color: var(--muted); font-size: 12px; text-align: center; padding: 8px 16px 20px; }

@media (max-width: 960px) {
  #app { padding: 10px 8px; }
  .lobby { grid-template-columns: 1fr; }
  .gameview { grid-template-columns: 1fr; gap: 10px; }
  .gamelist td:nth-child(5), .gamelist th:nth-child(5) { display: none; }
  .pcard .clock .main { font-size: 20px; }
  .moves ol { max-height: 180px; }
}

/* nav tabs */
.tabs { display: flex; gap: 2px; margin-left: 6px; }
.tabs a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 6px; font-weight: 600; }
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--ink); background: var(--card2); }

/* watch (self-play viewer) */
.watchview { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.wboardcol { min-width: 0; display: flex; justify-content: center; }
.wtitle { display: flex; align-items: baseline; gap: 10px; font-weight: 700; font-size: 16px; }
.wres { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--warn); }
.wmove { display: flex; justify-content: space-between; align-items: baseline; margin-top: 8px; font-weight: 600; font-variant-numeric: tabular-nums; }
#wSlider { width: 100%; margin-top: 8px; }
.wspeedrow { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.wspeedrow .seg { flex: 1; margin: 6px 0; }
.wresultline { margin-top: 8px; padding: 8px 10px; background: var(--bg2); border-radius: 6px; }
.wprog { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.wlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; margin-top: 8px; }
.wcard { cursor: pointer; text-align: left; border: 1px solid var(--line); background: var(--bg2); border-radius: 6px; padding: 7px 9px; color: var(--ink); }
.wcard:hover { border-color: #56606b; }
.wcard.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.wcard.big { min-width: 96px; flex: 0 0 auto; }
.wcard .wv { font-weight: 700; }
.wcard .wr { color: var(--warn); font-variant-numeric: tabular-nums; }
.wcard .wm, .wcard .wa { color: var(--muted); font-size: 11px; }
.tag { display: inline-block; font-size: 10px; padding: 0 5px; border-radius: 4px; background: var(--card2); color: var(--muted); }
.tag.cyc { background: #4a2f5e; color: #e3c8f5; }
@media (max-width: 960px) {
  .watchview { grid-template-columns: 1fr; gap: 10px; }
  .navsub { display: none; }
}

/* watch: live feed */
.wboardwrap { display: flex; flex-direction: column; gap: 8px; align-items: center; min-width: 0; width: 100%; }
.wlivebar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; width: 100%; justify-content: space-between;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; font-weight: 600; font-size: 13px; }
.wlivebtns { display: flex; gap: 6px; }
.wlivebtns .btn { padding: 4px 10px; font-size: 12px; }
.livedot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #e0604b; margin-right: 7px; vertical-align: 1px;
  animation: livepulse 1.4s ease-in-out infinite; }
@keyframes livepulse { 50% { opacity: .3; } }
#wGoLive { color: #ff8a78; font-weight: 600; margin-left: auto; }
#wGoLive + #wRefresh { margin-left: 10px; }
.wgens { display: flex; flex-wrap: wrap; gap: 6px; }
.gen { font-size: 12px; background: var(--bg2); border-radius: 5px; padding: 3px 7px; }

/* eval tab */
.evalview { display: flex; flex-direction: column; gap: 12px; }
.egrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; align-items: start; }
.echart { position: relative; margin-top: 8px; }
.echart svg { display: block; max-width: 100%; touch-action: pan-y; }
.echart .grid { stroke: var(--line); stroke-width: 1; }
.echart .ax { fill: var(--muted); font-size: 11px; }
.echart .eline { fill: none; stroke: var(--accent); stroke-width: 2; }
.echart .eband { fill: var(--accent); opacity: .15; }
.echart .edot { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.echart .xhair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.etip { position: absolute; pointer-events: none; background: var(--card2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 12px; min-width: 120px; }
.etab { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.etab th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11px; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.etab td { padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.egrid .card { overflow-x: auto; }
.ealarm { font-size: 12px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.ealarm b { color: var(--warn); }
