:root{
 font-family:Inter,"Segoe UI","Microsoft YaHei",sans-serif;color:#f3f0e8;background:#150c14;font-size:16px;color-scheme:dark;
 --accent:#e08fc4;--muted:rgba(243,240,232,.62);--line:rgba(224,143,196,.16);
 --surface-0:#150c14;--surface-1:#20131e;--surface-2:#2c1a29;--turn-color:#3fe08f;
 --p0:#e0524a;--p1:#e3b23c;--p2:#4caf7d;--p3:#4a90d9;--p4:#a97bd6;--p5:#e8e6df;
 --safe-top:env(safe-area-inset-top,0px);--safe-bottom:env(safe-area-inset-bottom,0px);
}
*{box-sizing:border-box}html,body{height:100%}body{margin:0;background:var(--surface-0);display:flex;flex-direction:column;min-height:100dvh}button,input,select{font:inherit}button,a{-webkit-tap-highlight-color:transparent}
button{cursor:pointer;border:1px solid var(--line);border-radius:8px;padding:10px 16px;background:var(--surface-2);color:#f3f0e8;transition:background .15s,transform .1s}
button:hover:enabled{background:#3c2438}button:active:enabled{transform:scale(.97)}button:disabled{cursor:default;opacity:.5}
button:focus-visible,a:focus-visible,summary:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
button.primary{background:linear-gradient(#eab8d8,#c983b3);border-color:var(--accent);color:#2c1428;font-weight:700}
a{color:inherit;text-decoration:none}a:hover{color:var(--accent)}h1,h2,h3,p{margin-top:0}
input,select{width:100%;padding:12px;margin:8px 0 18px;border:1px solid #56395a;border-radius:8px;background:var(--surface-1);color:#fff}
label{display:block}small{font-size:12px}[hidden]{display:none!important}

/* ---------- header ---------- */
.top-nav{
 flex-shrink:0;width:100%;height:52px;max-width:1400px;margin:auto;padding:0 max(16px,var(--safe-top,0px)) 0 16px;padding-top:var(--safe-top);
 display:grid;grid-template-columns:1fr auto 1fr;align-items:center;gap:14px;border-bottom:1px solid var(--line);
}
.nav-left{display:flex;align-items:center;gap:10px;font-size:12.5px;min-width:0;overflow:hidden}
.lobby-link{color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.nav-divider{width:1px;height:14px;background:var(--line);flex-shrink:0}
#room-label{white-space:nowrap;font-weight:500;letter-spacing:.03em;font-size:12px;color:var(--muted);flex-shrink:0}
.top-nav h1{display:none;font-size:14px;margin:0;letter-spacing:.15em;text-align:center;opacity:.85}
.top-nav h1 span{display:none}
nav{display:flex;justify-content:flex-end;align-items:center;gap:6px;font-size:12.5px;min-width:0}
nav button{background:transparent;border:0;font-size:12.5px;padding:6px 4px;color:var(--muted);white-space:nowrap}
nav button:hover:enabled{color:var(--accent);background:transparent}
nav a{color:var(--muted);font-size:12.5px;white-space:nowrap}
nav a.back-lobby{display:inline-flex}
#message{flex-shrink:0;padding:8px 20px;text-align:center;color:#f0c4e0;background:var(--surface-2);font-size:13px;margin:0}
#message:empty{display:none}
main{flex:1;display:flex;flex-direction:column;min-height:0;width:100%;max-width:1240px;margin:auto;padding:10px 14px calc(10px + var(--safe-bottom)) 14px}
#app{flex:1;display:flex;flex-direction:column;min-height:0;width:100%}

/* ---------- lobby / waiting room (unchanged structure, refreshed surfaces) ---------- */
.lobby{max-width:820px;margin:40px auto}.lobby h2{font-size:26px}.lobby>p{color:var(--muted)}
.forms{display:grid;grid-template-columns:1fr 1fr;gap:20px}
.card{padding:26px;background:var(--surface-1);border:1px solid var(--line);border-radius:14px}
.card p{color:var(--muted);line-height:1.7}
.members{margin:18px 0}
.member{padding:11px 0;border-bottom:1px solid var(--line);display:flex;align-items:center;justify-content:space-between;gap:16px}
.actions{display:flex;gap:12px;flex-wrap:wrap}
.invite{font-size:13px;overflow-wrap:anywhere;margin-top:20px;color:var(--muted)}
@media(max-width:700px){.forms{grid-template-columns:1fr}}

/* ---------- in-game shell: mobile-first single column ---------- */
/* The board row is the flexible 1fr track — it fills whatever vertical space
   is left after the header, turn bar, status chips and chat take their
   natural height, so the board never has to guess a viewport-relative size
   that might overflow on a short phone screen. */
.game-shell{
 flex:1;min-height:0;display:grid;gap:8px;grid-template-columns:1fr;
 grid-template-rows:auto minmax(0,1fr) auto auto auto;
 grid-template-areas:"turn" "board" "status" "chat" "footer";
 padding-bottom:calc(6px + var(--safe-bottom));
}
.turn-row{grid-area:turn;display:flex;gap:8px;align-items:stretch}
.turn-indicator{
 flex:1;min-width:0;text-align:center;padding:10px 14px;border-radius:12px;font-size:13.5px;font-weight:600;
 background:var(--surface-1);color:#d9c6d4;transition:background .2s,color .2s;
}
.turn-indicator.your-turn{
 background:var(--turn-color);color:#0c2417;animation:tiaoqi-pulse 1.8s ease-in-out infinite;
}
@keyframes tiaoqi-pulse{0%,100%{box-shadow:0 0 0 0 #3fe08f66}50%{box-shadow:0 0 0 7px #3fe08f00}}
.hint-toggle{
 flex-shrink:0;padding:0 14px;border-radius:12px;font-size:12.5px;font-weight:600;
 background:var(--surface-1);border:1px solid var(--line);color:var(--muted);
}
.hint-toggle[aria-pressed="true"]{color:var(--accent);border-color:var(--accent)}

/* ---------- board: the visual centerpiece, softened "table" surface ---------- */
.board-stage{grid-area:board;display:flex;align-items:center;justify-content:center;min-width:0;min-height:0}
.board-frame{
 width:100%;height:100%;max-width:640px;max-height:640px;
 background:radial-gradient(ellipse at 50% 36%,#331c3a 0%,#20111f 58%,#170d18 100%);
 border-radius:clamp(18px,5vw,32px);
 box-shadow:0 18px 46px -12px #00000070,inset 0 0 0 1px #ffffff0d,inset 0 0 34px #00000055;
 padding:4%;
}
.board-frame svg{width:100%;height:100%;display:block;overflow:visible}
.cell{fill:url(#holeGrad);stroke:#4a2f4c;stroke-width:.9;transition:stroke .15s,fill .15s}
.cell.home-tint{fill:var(--home-c);fill-opacity:.13}
.cell.home-tint.mine-tint{fill-opacity:.26}
.cell.legal{fill:#4c2745;stroke:var(--accent);stroke-width:1.4;animation:cell-pulse 1.4s ease-in-out infinite}
@keyframes cell-pulse{0%,100%{stroke-opacity:.55}50%{stroke-opacity:1}}
.cell.turn-base{stroke:var(--turn-c);stroke-width:1.5;stroke-opacity:.85}
.cell.turn-base.legal{stroke:var(--accent)}
.hit{cursor:pointer}
.hop-trail{fill:none;stroke:#f3f0e8;stroke-width:1.3;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:2.2 2;opacity:.8;transition:opacity .1s linear;pointer-events:none}
.peg-shadow{fill:#000;opacity:.32;transform:translateY(.5px);transition:opacity .12s}
.peg{stroke:#00000055;stroke-width:.7;filter:url(#pegShadow);transform-box:fill-box;transform-origin:center;transition:transform .15s ease,opacity .12s}
.peg.mine{cursor:pointer}
.peg.mine:hover{transform:scale(1.08)}
.peg.selected{transform:scale(1.24);stroke:#fff;stroke-width:1.4}
.hit:active+.cell,.peg.mine:active{transform:scale(.95)}

/* ---------- compact player status: chips row on mobile ---------- */
.status-strip{grid-area:status;display:flex;flex-direction:row;justify-content:space-around;gap:6px;padding:2px 2px 4px}
.status-row{
 display:flex;flex-direction:column;align-items:center;gap:3px;flex:1;min-width:0;text-align:center;
 padding:7px 6px;border-radius:12px;transition:background .15s;
}
.status-row .dot{width:11px;height:11px;border-radius:50%;flex-shrink:0;box-shadow:0 0 0 2px #00000030 inset}
.status-row .name{font-size:11.5px;color:#f3f0e8;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:100%}
.status-row .name .tag{display:none}
.status-row .state{font-size:10px;color:var(--muted)}
.status-row.active{background:var(--surface-2);box-shadow:0 0 0 1px var(--accent) inset}
.status-row.active .state{color:var(--accent);font-weight:700}
.status-row.done .state{color:#9be3b8}
.status-row .hint-state{font-size:9px;color:var(--muted);opacity:.7}
.status-row .hint-state.on{color:var(--turn-color);opacity:1}

/* ---------- end-of-game / host controls footer ---------- */
.footer{grid-area:footer}
.end-panel{background:var(--surface-1);border:1px solid var(--line);border-radius:14px;padding:16px}
.result-table{border-collapse:collapse;width:100%}
.result-table td,.result-table th{text-align:left;padding:8px 10px;border-bottom:1px solid var(--line)}
.waiting-note{color:var(--muted);font-size:13px}
#rematch{display:block;margin:12px auto 0}
.text-btn{background:transparent;border:1px solid var(--line);color:var(--muted);font-size:12px;padding:7px 12px;width:100%}
#end-confirm button{margin:10px 10px 0 0}

/* ---------- group chat: always on screen, never behind a click ---------- */
/* Open chat replaces the game history in the board layout. */
.chat-panel{
 flex-shrink:0;margin:8px 14px calc(8px + var(--safe-bottom));background:var(--surface-1);border:1px solid var(--line);
 border-radius:14px;height:220px;display:flex;flex-direction:column;overflow:hidden;
}
#chat-slot{grid-area:chat;min-width:0}
#chat-slot .chat-panel{margin:0;width:100%;height:240px}
.chat-head{flex-shrink:0;padding:10px 14px 6px}
.chat-head h2{font-size:13px;margin:0;color:var(--muted);font-weight:600}
.chat-list{flex:1;min-height:0;overflow-y:auto;padding:2px 14px;display:flex;flex-direction:column;gap:8px}
.chat-empty{color:var(--muted);font-size:13px;text-align:center;margin:24px 0}
.chat-msg{max-width:80%;padding:8px 12px;border-radius:14px;background:var(--surface-2);font-size:13.5px;line-height:1.5;word-break:break-word}
.chat-msg .chat-name{display:block;font-size:11px;color:var(--muted);margin-bottom:2px}
.chat-msg.mine{align-self:flex-end;background:linear-gradient(#eab8d8,#c983b3);color:#2c1428}
.chat-msg.mine .chat-name{display:none}
#chat-form{flex-shrink:0;display:flex;gap:8px;padding:8px 14px 12px}
#chat-form input{margin:0;flex:1;min-width:0}
#chat-form button{flex-shrink:0}
/* ---------- dialogs ---------- */
dialog{max-width:620px;width:92%;max-height:88svh;border:1px solid #6b4460;border-radius:14px;background:var(--surface-1);color:#f3f0e8;padding:24px;line-height:1.75}
dialog::backdrop{background:#0a0510cc}
#close-rules{float:right}

/* ---------- tablet ≥600px: a bit more breathing room, still stacked ---------- */
@media(min-width:600px){
 main{padding:18px 18px calc(18px + var(--safe-bottom))}
 .board-frame{width:min(560px,88vw);max-height:min(66vh,560px)}
 .status-strip{gap:10px}
 .status-row{padding:9px 10px}
}

/* ---------- desktop ≥1024px: board + sidebar, board is the star ---------- */
@media(min-width:1024px){
 .top-nav{height:60px}
 .top-nav h1{display:block}
 .top-nav h1 span{display:block;font-size:9px;color:var(--accent);letter-spacing:.28em;margin-top:2px}
 main{padding:22px 24px;margin-inline:auto}
 .game-shell{
  grid-template-columns:1fr 300px;align-items:start;gap:16px 22px;
  grid-template-rows:auto auto auto auto;
  grid-template-areas:"turn status" "board status" "board chat" "board footer";
 }
 .turn-indicator{font-size:15px;padding:13px 18px;text-align:left}
 .board-stage{padding:0}
 .board-frame{width:min(100%,720px);max-height:min(78vh,720px);margin-inline:auto}
 .status-strip{flex-direction:column;justify-content:flex-start;gap:7px;padding:0}
 .status-row{flex-direction:row;text-align:left;justify-content:flex-start;padding:10px 12px;gap:10px}
 .status-row .name{flex:1}
 .status-row .name .tag{display:inline;color:var(--muted);font-weight:400}
 .status-row .state{flex-shrink:0}
 .status-row .hint-state{flex-shrink:0}
}

/* ---------- phone landscape: board left, compact controls right ---------- */
/* Keep chat open beside the board on short landscape screens. */
@media(max-width:1023.98px) and (orientation:landscape) and (max-height:540px){
 .game-shell{
  grid-template-columns:1fr 210px;gap:8px 12px;
  grid-template-rows:auto auto auto auto;
  grid-template-areas:"turn status" "board status" "board chat" "board footer";
 }
 .status-strip{flex-direction:column;gap:5px}
 .status-row{flex-direction:row;text-align:left;padding:6px 8px}
 .status-row .name .tag{display:inline;color:var(--muted);font-weight:400}
}

@media(prefers-reduced-motion:reduce){button,.peg,.cell{transition:none}.turn-indicator.your-turn,.cell.legal{animation:none}}

/* Keep the main lobby reachable from every game header. */
header a.back-lobby{display:inline-flex;align-items:center;justify-content:center;min-height:40px;padding:6px 10px;border:1px solid currentColor;border-radius:8px;text-decoration:none;white-space:nowrap;flex-shrink:0}
header a.back-lobby:focus-visible{outline:2px solid currentColor;outline-offset:3px}
@media(max-width:760px){.top-nav{grid-template-columns:minmax(0,1fr) auto;gap:6px}}
