:root {
  --bg: #07080c;
  --panel: rgba(16, 18, 26, .78);
  --line: rgba(255, 255, 255, .08);
  --text: #e9ecf3;
  --muted: #8b93a7;
  --cyan: #4fd2ff;
  --amber: #ff8a2a;
  --gold: #e9c27a;
  --danger: #ff5a6e;
  --radius: 14px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

#app { display: flex; height: 100dvh; }
#stage { position: relative; flex: 1; min-width: 0; }
#canvas { position: absolute; inset: 0; }
#canvas canvas { display: block; touch-action: none; }

/* panel */
#panel {
  width: 340px; display: flex; flex-direction: column; gap: 10px; padding: 14px;
  background: linear-gradient(180deg, rgba(20, 22, 32, .95), rgba(10, 11, 16, .98));
  border-left: 1px solid var(--line);
}
.player-card {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-radius: var(--radius); background: rgba(255, 255, 255, .03);
  border: 1px solid var(--line); transition: box-shadow .3s, border-color .3s;
}
.player-card.active { border-color: rgba(79, 210, 255, .5); box-shadow: 0 0 22px rgba(79, 210, 255, .18), inset 0 0 12px rgba(79, 210, 255, .06); }
.player-card.active.b-side { border-color: rgba(255, 138, 42, .5); box-shadow: 0 0 22px rgba(255, 138, 42, .18), inset 0 0 12px rgba(255, 138, 42, .06); }
.pc-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.dot.w { background: #f2ede2; box-shadow: 0 0 8px rgba(255, 138, 42, .6); }
.dot.b { background: #18181c; border: 1px solid #444; box-shadow: 0 0 10px var(--amber); }
.dot.off { opacity: .35; box-shadow: none; }
.pc-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-caps { font-size: 17px; letter-spacing: -2px; color: var(--muted); min-height: 20px; line-height: 20px; }
.pc-caps b { font-size: 12px; letter-spacing: 0; margin-left: 6px; color: var(--gold); }
.clock {
  font-family: "Consolas", "SF Mono", monospace; font-size: 26px; font-weight: 600; padding: 4px 10px;
  border-radius: 9px; background: rgba(0, 0, 0, .35); min-width: 96px; text-align: center; font-variant-numeric: tabular-nums;
}
.active .clock { background: rgba(79, 210, 255, .14); color: #fff; }
.active.b-side .clock { background: rgba(255, 138, 42, .14); }
.clock.low { color: var(--danger) !important; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .55; } }

.room-line { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); padding: 0 4px; letter-spacing: .04em; text-transform: uppercase; }
#turnLabel.check { color: var(--danger); font-weight: 700; }

.moves {
  flex: 1; min-height: 80px; overflow-y: auto; border-radius: var(--radius); border: 1px solid var(--line);
  background: rgba(0, 0, 0, .25); padding: 6px 0; font-family: "Consolas", "SF Mono", monospace; font-size: 14px;
  display: grid; grid-template-columns: 42px 1fr 1fr; align-content: start;
}
.moves .n { color: var(--muted); padding: 4px 10px; text-align: right; }
.moves .m { padding: 4px 10px; border-radius: 6px; }
.moves .m.last { background: rgba(255, 200, 69, .16); color: #ffe2a0; }
.moves .row:nth-child(even) { background: rgba(255, 255, 255, .02); }

.actions { display: flex; gap: 6px; }
.actions .btn { flex: 1; padding: 9px 6px; font-size: 13px; }

.offer { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-radius: var(--radius); background: rgba(233, 194, 122, .12); border: 1px solid rgba(233, 194, 122, .35); font-size: 14px; }
.offer div { display: flex; gap: 6px; }

.chat { border-radius: var(--radius); border: 1px solid var(--line); background: rgba(0, 0, 0, .2); display: flex; flex-direction: column; }
.chat-log { height: 96px; overflow-y: auto; padding: 8px 10px; font-size: 13px; display: flex; flex-direction: column; gap: 3px; }
.chat-log .who { font-weight: 600; margin-right: 4px; }
.chat-log .who.w { color: var(--cyan); }
.chat-log .who.b { color: var(--amber); }
.chat-log .sys { color: var(--muted); font-style: italic; }
#chatForm { display: flex; border-top: 1px solid var(--line); }
#chatForm input { flex: 1; background: transparent; border: 0; padding: 8px 10px; outline: none; }

/* buttons */
.btn {
  border: 1px solid rgba(255, 255, 255, .14); background: rgba(255, 255, 255, .07); padding: 11px 16px;
  border-radius: 11px; cursor: pointer; font-weight: 600; transition: transform .1s, background .2s, box-shadow .2s;
}
.btn:hover { background: rgba(255, 255, 255, .12); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn.primary { background: linear-gradient(135deg, #2ab7f0, #4fd2ff 50%, #8fe6ff); color: #04121b; border: 0; box-shadow: 0 6px 24px rgba(79, 210, 255, .35); }
.btn.primary:hover { box-shadow: 0 6px 34px rgba(79, 210, 255, .55); }
.btn.ghost { background: transparent; }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.wide { width: 100%; margin-top: 8px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  backdrop-filter: blur(10px); cursor: pointer; font-size: 20px; display: grid; place-items: center;
}
.floating { position: absolute; top: 14px; right: 14px; z-index: 5; }
.floating.second { right: 64px; }

/* overlays */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 30%, rgba(20, 40, 60, .55), rgba(3, 4, 7, .9));
  backdrop-filter: blur(6px); overflow-y: auto;
}
#over, #promo { background: rgba(3, 4, 7, .55); }
.lobby-card {
  width: min(820px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 26px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6), 0 0 0 1px rgba(79, 210, 255, .05), 0 0 60px rgba(79, 210, 255, .07);
  backdrop-filter: blur(16px);
}
.lobby-card.narrow { width: min(420px, 100%); }
.center { text-align: center; }
.brand { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.crown { font-size: 56px; line-height: 1; color: #fff; text-shadow: 0 0 18px var(--cyan), 0 0 40px rgba(79, 210, 255, .5); }
.brand h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 34px; letter-spacing: .02em; }
.brand p { margin: 2px 0 0; color: var(--muted); }
h2 { font-family: Georgia, serif; margin: 6px 0 8px; }
h3 { margin: 0 0 12px; font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: var(--gold); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.box { border: 1px solid var(--line); border-radius: 16px; padding: 16px; background: rgba(0, 0, 0, .2); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.field input, .field select, .join-row input {
  background: rgba(0, 0, 0, .35); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; color: var(--text); outline: none; font-size: 15px;
}
.field input:focus, .join-row input:focus, select:focus { border-color: rgba(79, 210, 255, .5); }
select option { background: #11131a; }
.seg { display: flex; background: rgba(0, 0, 0, .35); border-radius: 10px; padding: 3px; border: 1px solid var(--line); }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 6px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 13px; }
.seg button.on { background: rgba(79, 210, 255, .16); color: #fff; box-shadow: inset 0 0 0 1px rgba(79, 210, 255, .4); }
.join-row { display: flex; gap: 8px; margin-bottom: 14px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: .2em; font-family: monospace; min-width: 0; }
.rooms-head { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.room-list { display: flex; flex-direction: column; gap: 8px; max-height: 230px; overflow-y: auto; }
.room-list .empty { color: var(--muted); font-size: 14px; padding: 14px 0; text-align: center; }
.room { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, .03); }
.room .r-title { font-weight: 600; font-size: 14px; }
.room .r-sub { font-size: 12px; color: var(--muted); }
.lan-info { margin-top: 16px; font-size: 13px; color: var(--muted); text-align: center; line-height: 1.6; }
.lan-info code { color: var(--cyan); background: rgba(79, 210, 255, .08); padding: 2px 8px; border-radius: 6px; }

.code { font-family: monospace; font-size: 44px; letter-spacing: .3em; margin: 14px 0 8px; color: #fff; text-shadow: 0 0 20px var(--cyan); }
.share { font-size: 13px; color: var(--muted); margin-bottom: 18px; word-break: break-all; }
.share code { color: var(--cyan); }
.spinner { width: 46px; height: 46px; border-radius: 50%; margin: 4px auto 10px; border: 3px solid rgba(79, 210, 255, .15); border-top-color: var(--cyan); animation: spin 1s linear infinite; box-shadow: 0 0 20px rgba(79, 210, 255, .25); }
@keyframes spin { to { transform: rotate(360deg); } }

.promo-row { display: flex; gap: 10px; justify-content: center; margin-top: 12px; }
.promo-row button { width: 76px; height: 86px; font-size: 52px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, .05); cursor: pointer; line-height: 1; }
.promo-row button:hover { border-color: var(--cyan); box-shadow: 0 0 20px rgba(79, 210, 255, .35); }

.over-icon { font-size: 64px; text-shadow: 0 0 24px var(--gold); }
.over-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
#overReason { color: var(--muted); margin: 0; }

.popover {
  position: fixed; top: 64px; right: 14px; z-index: 30; width: 290px; padding: 16px; border-radius: 16px;
  background: rgba(16, 18, 26, .96); border: 1px solid var(--line); box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
}
.field input[type=range] { padding: 0; accent-color: var(--cyan); }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); margin-top: 8px; cursor: pointer; }
.check input { accent-color: var(--cyan); }

.banner {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%); z-index: 4; padding: 9px 22px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(10px); font-weight: 600; letter-spacing: .03em;
}
.banner.check { color: #fff; background: rgba(255, 40, 60, .25); border-color: rgba(255, 60, 80, .6); box-shadow: 0 0 30px rgba(255, 40, 60, .35); }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 50; padding: 10px 18px; border-radius: 12px;
  background: rgba(30, 32, 44, .95); border: 1px solid var(--line); font-size: 14px;
}

/* mobile */
@media (max-width: 820px) {
  #app { flex-direction: column; }
  #stage { flex: none; height: 58dvh; }
  #panel { width: 100%; flex: 1; border-left: 0; border-top: 1px solid var(--line); padding: 10px; gap: 8px; overflow-y: auto; }
  .grid2 { grid-template-columns: 1fr; }
  .moves { min-height: 70px; max-height: 120px; }
  .chat-log { height: 64px; }
  .clock { font-size: 22px; min-width: 84px; }
  .lobby-card { padding: 18px; }
  .brand h1 { font-size: 28px; }
}

.hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.popover .seg button { font-size: 12px; }
