:root {
  --bg: #14100c;
  --panel: #1f1812;
  --cell: #2a2118;
  --cell-own: #3a2a1c;
  --line: #4a3a28;
  --red: #d94b41;
  --blue: #3f7fd6;
  --gold: #d8b46a;
  --text: #e8ddc8;
  --muted: #9a8b73;
  --ok: #6bbf59;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(circle at 50% 0%, #241a12, var(--bg));
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(20,16,12,.92); backdrop-filter: blur(6px); z-index: 5;
}
.brand { font-weight: 700; color: var(--gold); }
.who { margin-left: auto; color: var(--muted); font-size: 14px; }
main { max-width: 560px; margin: 0 auto; padding: 16px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px; margin-bottom: 16px; box-shadow: 0 8px 30px rgba(0,0,0,.35);
}
h2 { margin: 0 0 10px; font-size: 18px; }
h3 { margin: 12px 0 6px; font-size: 15px; color: var(--gold); }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
button {
  border: 1px solid var(--line); background: #2c2318; color: var(--text);
  padding: 10px 16px; border-radius: 10px; font-size: 15px; cursor: pointer;
  transition: filter .15s;
}
button:hover { filter: brightness(1.15); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: linear-gradient(180deg,#b5893f,#8a6329); border-color:#6e4f22; color:#1a1206; font-weight:700; }
button.ghost { background: transparent; }
button.sm { padding: 6px 10px; font-size: 13px; }
input {
  background: #120d09; border: 1px solid var(--line); color: var(--text);
  padding: 10px 12px; border-radius: 10px; font-size: 15px; flex: 1; min-width: 0;
}
form { display: flex; flex-direction: column; gap: 10px; }
.msg { margin-top: 10px; min-height: 18px; font-size: 14px; }
.msg.err { color: var(--red); }
.msg.ok { color: var(--ok); }

.board {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px;
  margin: 12px auto; max-width: 420px; aspect-ratio: 1/1;
}
.cell {
  position: relative; border: 1px solid var(--line); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(14px, 4.4vw, 24px); cursor: default; user-select: none;
  background: var(--cell);
}
.cell.own-half { background: var(--cell-own); }
.cell.halffront::after {
  content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 1px; background: rgba(216,180,106,.15);
}
.cell.back { color: transparent; }
.cell.back .face { visibility: hidden; }
.piece { width: 82%; height: 82%; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.piece.red { background: radial-gradient(circle at 35% 30%, #f2836f, var(--red)); color: #2a0d0a; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.piece.blue { background: radial-gradient(circle at 35% 30%, #7fb0f0, var(--blue)); color: #08182f; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.piece.back { background: repeating-linear-gradient(45deg, #3a2f20, #3a2f20 4px, #4a3a28 4px, #4a3a28 8px); }
.cell.sel { outline: 3px solid var(--gold); outline-offset: -3px; }
.cell.can-move { box-shadow: inset 0 0 0 2px var(--ok); }
.cell.can-attack { box-shadow: inset 0 0 0 2px var(--red); }
.cell.can-flip { box-shadow: inset 0 0 0 2px #c9a24a; }
.cell.flash { animation: flash .5s; }
@keyframes flash { 0%{background:#5a4a28} 100%{} }

.tray { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; min-height: 44px; margin-top: 6px; }
.tray .piece { width: 38px; height: 38px; font-size: 15px; cursor: pointer; }
.tray .piece.sel { outline: 3px solid var(--gold); }
.tray .piece.used { opacity: .25; pointer-events: none; }

.phead { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--gold); }
.timer.low { color: var(--red); }
.sideinfo { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.red { background: var(--red); }
.dot.blue { background: var(--blue); }
.dot.off { opacity: .3; }
.turnhint { text-align: center; margin: 6px 0; font-size: 14px; color: var(--muted); }
.turnhint.me { color: var(--ok); font-weight: 700; }
.oppstatus { margin-top: 8px; font-size: 13px; color: var(--muted); }

.log { max-height: 120px; overflow-y: auto; font-size: 13px; color: var(--muted); margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.log div { padding: 1px 0; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; z-index: 20; }
.card { background: var(--panel); border: 1px solid var(--gold); border-radius: 16px; padding: 28px 32px; text-align: center; max-width: 90%; }
.card h2 { font-size: 26px; }

.roomlist { margin-top: 14px; }
.rlhead { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 14px; }
#roomList { list-style: none; padding: 0; margin: 6px 0; }
#roomList li { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 14px; }
#roomList li button { padding: 4px 12px; }

.conn { position: fixed; left: 0; right: 0; bottom: 0; background: var(--red); color: #fff; text-align: center; padding: 8px; font-size: 14px; z-index: 30; }
[hidden] { display: none !important; }
