:root{
  --text:#2b1b0f;
  --muted:#7e6144;
  --accent:#7b2f18;
  --accent-2:#5b1f0f;
  --ok:#2c7a4b;
  --bad:#9f342f;
  --line:rgba(76,44,18,.14);
  --panel-shadow:0 18px 40px rgba(32,20,10,.22);
  --board-css-size:240px;
}

*{box-sizing:border-box;}
html,body{height:100%;}
body{
  margin:0;
  overflow:hidden;
  font-family:"Avenir Next","PingFang TC","Noto Sans TC","Microsoft JhengHei",sans-serif;
  font-size:14px;
  line-height:1.45;
  color:var(--text);
  background:
    radial-gradient(circle at top left, rgba(255,232,193,.18), transparent 28%),
    linear-gradient(135deg, rgba(255,255,255,.05), transparent 30%),
    linear-gradient(180deg, #5e432b 0%, #3c2919 34%, #22170f 100%);
}

body::before{
  content:"";
  position:fixed;
  inset:0;
  pointer-events:none;
  opacity:.16;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.18) 0 1px, transparent 1px 110px),
    repeating-linear-gradient(0deg, rgba(0,0,0,.12) 0 2px, transparent 2px 64px);
  mix-blend-mode:soft-light;
}

.app{
  position:relative;
  z-index:1;
  height:100dvh;
  padding:10px;
}

.screen{
  display:none;
  height:100%;
  min-height:0;
}

.screen.active{
  display:flex;
}

.screen-lobby{
  flex-direction:column;
  gap:10px;
}

.heroCard,
.panel,
.gameHeader{
  border-radius:20px;
  background:linear-gradient(180deg, rgba(255,249,238,.97), rgba(239,220,189,.96));
  box-shadow:var(--panel-shadow);
  border:1px solid rgba(255,255,255,.34);
}

.heroCard{
  padding:14px 18px;
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:14px;
}

.heroCopy h1,
.panelHead h2,
.gameTitle,
.modalCard h2{
  margin:0;
  font-family:Georgia,"Noto Serif TC","PMingLiU",serif;
}

.heroCopy h1{
  font-size:30px;
  line-height:1;
}

.heroCopy p,
.panelHead p,
.miniStatus{
  margin:4px 0 0;
  color:var(--muted);
}

.heroMeta{
  display:flex;
  align-items:center;
  gap:10px;
  flex-shrink:0;
}

.eyebrow{
  margin-bottom:4px;
  font-size:10px;
  letter-spacing:.18em;
  text-transform:uppercase;
  color:var(--muted);
}

.lobbyGrid{
  flex:1 1 auto;
  min-height:0;
  display:grid;
  grid-template-columns:minmax(320px, 380px) minmax(0, 1fr);
  gap:10px;
}

.panel{
  min-height:0;
  padding:16px;
}

.createPanel{
  display:flex;
  flex-direction:column;
}

.panelHead{
  margin-bottom:10px;
}

.panelHead h2{
  font-size:24px;
  line-height:1.05;
}

.formGrid{
  display:grid;
  gap:10px;
}

.formGrid.compact{
  gap:10px;
}

.field span{
  display:block;
  margin-bottom:4px;
  font-size:11px;
  color:var(--muted);
}

.checkField{
  display:flex;
  align-items:center;
  gap:10px;
  padding:4px 2px 0;
  color:var(--text);
  font-size:13px;
  font-weight:700;
}

.checkField input{
  width:18px;
  height:18px;
  margin:0;
}

input{
  width:100%;
  padding:9px 12px;
  border-radius:12px;
  border:1px solid rgba(104,70,36,.16);
  background:rgba(255,255,255,.72);
  color:var(--text);
  outline:none;
  font-size:14px;
}

input:focus{
  border-color:rgba(123,47,24,.45);
  box-shadow:0 0 0 3px rgba(123,47,24,.12);
}

.btn{
  min-height:36px;
  padding:8px 12px;
  border-radius:12px;
  border:1px solid rgba(98,57,24,.16);
  background:linear-gradient(180deg, rgba(255,255,255,.82), rgba(229,207,175,.95));
  color:var(--text);
  font-size:13px;
  font-weight:700;
  cursor:pointer;
  transition:transform .14s ease, box-shadow .14s ease, background .14s ease;
}

.btn:hover{
  transform:translateY(-1px);
  box-shadow:0 8px 16px rgba(72,43,20,.10);
}

.btn:disabled{
  opacity:.5;
  cursor:not-allowed;
  transform:none;
  box-shadow:none;
}

.btn.primary{
  color:#fff7ef;
  border-color:rgba(91,31,15,.25);
  background:linear-gradient(180deg, var(--accent), var(--accent-2));
}

.btn.ghost{
  background:rgba(255,255,255,.4);
}

.btn.mini{
  min-height:30px;
  padding:6px 10px;
  border-radius:999px;
  font-size:12px;
}

.btn.large{
  width:100%;
  min-height:42px;
  margin-top:auto;
}

.pill{
  padding:5px 10px;
  border-radius:999px;
  border:1px solid rgba(92,58,24,.14);
  background:rgba(255,255,255,.48);
  font-weight:700;
  font-size:12px;
  color:var(--muted);
}

.pill.ok{background:rgba(44,122,75,.16); color:var(--ok); border-color:rgba(44,122,75,.25);}
.pill.bad{background:rgba(159,52,47,.13); color:var(--bad); border-color:rgba(159,52,47,.22);}

.inlineError{
  min-height:18px;
  margin-top:8px;
  color:var(--bad);
  font-size:12px;
  opacity:0;
}

.inlineError.visible{
  opacity:1;
}

.roomTableWrap{
  overflow:auto;
  max-height:100%;
  border:1px solid var(--line);
  border-radius:16px;
  background:rgba(255,255,255,.3);
}

.roomTable{
  width:100%;
  border-collapse:collapse;
}

.roomTable th,
.roomTable td{
  padding:10px 10px;
  border-bottom:1px solid rgba(76,44,18,.08);
  text-align:left;
  white-space:nowrap;
}

.roomTable th{
  position:sticky;
  top:0;
  background:rgba(245,231,208,.95);
  backdrop-filter:blur(6px);
  font-size:12px;
  color:var(--muted);
}

.tableBadge{
  display:inline-flex;
  align-items:center;
  padding:4px 8px;
  border-radius:999px;
  background:rgba(44,122,75,.12);
  color:var(--ok);
  font-size:12px;
  font-weight:700;
}

.tableBadge.hot{
  background:rgba(159,52,47,.12);
  color:var(--bad);
}

.emptyState{
  margin-top:12px;
  color:var(--muted);
  font-size:13px;
}

.screen-room{
  flex-direction:column;
  gap:10px;
}

.gameHeader{
  flex:0 0 auto;
  min-height:60px;
  padding:10px 14px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}

.gameTitleWrap{
  display:flex;
  align-items:baseline;
  gap:10px;
  min-width:0;
}

.gameTitle{
  font-size:22px;
  font-weight:700;
  line-height:1;
}

.statusBar{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:8px;
  flex-wrap:wrap;
}

.statusText{
  font-size:12px;
  color:var(--muted);
}

.statusText strong{
  color:var(--text);
}

.roomLayout{
  flex:1 1 auto;
  min-height:0;
  display:grid;
  grid-template-columns:260px minmax(0, 1fr) 320px;
  gap:10px;
  align-items:stretch;
}

.sidePanel,
.boardPanel{
  min-height:0;
  display:flex;
  flex-direction:column;
}

.boardPanel{
  padding:12px;
  overflow:hidden;
}

.boardViewport{
  width:100%;
  height:100%;
  min-height:0;
  display:grid;
  place-items:center;
  overflow:hidden;
}

.boardSizer{
  width:var(--board-css-size);
  height:var(--board-css-size);
  max-width:100%;
  max-height:100%;
  aspect-ratio:1/1;
  display:grid;
  place-items:center;
}

canvas{
  width:100%;
  height:100%;
  display:block;
  border-radius:18px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.28),
    0 14px 28px rgba(50,30,13,.20);
}

.playerSlot{
  padding:12px 14px;
  border:1px solid var(--line);
  border-radius:16px;
  background:rgba(255,255,255,.34);
}

.playerSlot + .playerSlot{
  margin-top:10px;
}

.slotTitle{
  font-size:11px;
  color:var(--muted);
  margin-bottom:6px;
}

.slotValue{
  font-size:16px;
  font-weight:700;
}

.spectatorsSlot{
  flex:1 1 auto;
  min-height:0;
}

.spectatorList{
  margin:0;
  padding-left:18px;
  max-height:100%;
  overflow:auto;
}

.spectatorList li + li{
  margin-top:6px;
}

.emptyLine{
  color:var(--muted);
}

.chatPanel{
  gap:10px;
}

.chatList{
  flex:1 1 auto;
  min-height:0;
  overflow:auto;
  padding:12px;
  border-radius:16px;
  border:1px solid var(--line);
  background:rgba(255,255,255,.34);
}

.chatItem{
  padding:10px 12px;
  border-radius:14px;
  background:rgba(255,250,240,.9);
  border:1px solid rgba(76,44,18,.08);
}

.chatItem + .chatItem{
  margin-top:8px;
}

.chatItem.system{
  background:rgba(123,47,24,.08);
}

.chatMeta{
  display:flex;
  justify-content:space-between;
  gap:10px;
  margin-bottom:4px;
  font-size:11px;
  color:var(--muted);
}

.chatBody{
  white-space:pre-wrap;
  word-break:break-word;
}

.chatComposer{
  display:grid;
  grid-template-columns:minmax(0,1fr) auto;
  gap:8px;
}

.modalOverlay{
  position:fixed;
  inset:0;
  z-index:20;
  display:grid;
  place-items:center;
  padding:20px;
  background:rgba(25,15,8,.42);
  backdrop-filter:blur(6px);
}

.modalCard{
  width:min(100%, 360px);
  padding:24px 22px 20px;
  border-radius:20px;
  background:linear-gradient(180deg, rgba(255,249,238,.98), rgba(235,214,182,.98));
  box-shadow:0 24px 44px rgba(29,18,9,.28);
  border:1px solid rgba(255,255,255,.4);
}

.modalCard h2{
  margin:4px 0 8px;
  font-size:28px;
  line-height:1.1;
}

.modalCard p{
  margin:0 0 14px;
  color:var(--muted);
}

.modalActions{
  display:flex;
  justify-content:flex-end;
  gap:8px;
  margin-top:10px;
}

[hidden]{display:none !important;}

@media (max-width: 1180px){
  body{overflow:auto;}
  .app{height:auto; min-height:100dvh;}
  .roomLayout{
    grid-template-columns:1fr;
  }
  .boardPanel{
    min-height:min(72vw, 680px);
    order:-1;
  }
}

@media (max-width: 960px){
  .lobbyGrid{
    grid-template-columns:1fr;
  }
  .heroCard,
  .gameHeader{
    flex-direction:column;
    align-items:flex-start;
  }
  .statusBar{
    justify-content:flex-start;
  }
}

@media (max-width: 560px){
  .app{padding:10px;}
  .heroCard,
  .panel,
  .gameHeader,
  .modalCard{
    border-radius:16px;
  }
  .heroCopy h1{font-size:28px;}
  .panelHead h2{font-size:20px;}
  .gameTitle{font-size:18px;}
  .chatComposer{grid-template-columns:1fr;}
  .roomTable th,
  .roomTable td{padding:10px 8px;}
}
