:root{
  --bg:#0d0a07;
  --panel:#1c1510;
  --panel-2:#271d16;
  --border:#3b2c20;
  --accent:#e0b04a;
  --accent2:#f0c96a;
  --p1:#ef5b5b;
  --p2:#5b93f0;
  --text:#f3ece2;
  --muted:#a8998a;
  --wood:#8a5a34;
  --wood-dark:#6b4423;
}
*{box-sizing:border-box;}
html, body{height:100%;}
body{
  margin:0;
  height:100dvh;
  overflow:hidden;
  background:radial-gradient(ellipse at 50% 30%, #2b1d12 0%, #140e09 50%, var(--bg) 100%);
  color:var(--text);
  font-family:'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  display:flex;
  flex-direction:column;
}
a{color:var(--accent);}
.topbar{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:10px 22px;
  border-bottom:1px solid var(--border);
}
.topbar .back{
  color:var(--muted);
  text-decoration:none;
  font-size:0.9rem;
}
.topbar h1{
  font-size:1.15rem;
  margin:0;
}
.layout{
  flex:1 1 auto;
  min-height:0;
  display:flex;
  flex-wrap:nowrap;
  gap:20px;
  padding:14px 22px;
  max-width:1180px;
  width:100%;
  margin:0 auto;
  align-items:stretch;
  justify-content:center;
}
.board-wrap{
  flex:1 1 auto;
  min-width:0;
  min-height:0;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:6px;
}
.canvas-frame{
  flex:1 1 auto;
  min-height:0;
  width:100%;
  display:flex;
  align-items:center;
  justify-content:center;
}
#tableCanvas{
  background:#2a160a;
  border-radius:8px;
  box-shadow:0 22px 60px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,220,170,0.08);
  width:auto;
  height:auto;
  max-width:100%;
  max-height:100%;
  aspect-ratio:2 / 3;
  touch-action:none;
  cursor:crosshair;
}
.hint{
  flex:0 0 auto;
  color:var(--muted);
  font-size:0.8rem;
  text-align:center;
  max-width:520px;
}
.panel{
  flex:0 0 300px;
  align-self:center;
  min-height:0;
  max-height:100%;
  overflow-y:auto;
  background:linear-gradient(180deg, #241a13, var(--panel));
  border:1px solid var(--border);
  border-radius:14px;
  box-shadow:0 14px 40px rgba(0,0,0,0.5);
  padding:18px;
  width:300px;
  display:flex;
  flex-direction:column;
  gap:14px;
}
@media (max-width: 780px), (max-aspect-ratio: 4/5){
  .layout{
    flex-direction:column;
    padding:8px 12px;
    gap:8px;
  }
  .board-wrap{
    flex:1 1 auto;
    min-height:0;
    max-height:44%;
    gap:4px;
  }
  .hint{
    font-size:0.7rem;
  }
  .panel{
    flex:1 1 0;
    min-height:0;
    width:100%;
    padding:12px;
    gap:8px;
  }
  .panel h2{
    font-size:0.95rem;
  }
  .scoreboard{
    gap:8px;
  }
  .score-card{
    padding:8px;
  }
  .score-card .score{
    font-size:1.3rem;
  }
  .score-card .name{
    font-size:0.72rem;
  }
  #turnStatus{
    padding:7px;
    font-size:0.85rem;
    min-height:0;
  }
  .aim-controls button{
    width:38px;
    height:38px;
    font-size:1rem;
  }
  .zone-legend{
    font-size:0.68rem;
  }
  #log{
    height:56px;
    font-size:0.7rem;
  }
  .secondary-btn{
    padding:7px;
    font-size:0.8rem;
  }
}
.panel h2{
  margin:0;
  font-size:1.05rem;
}
.setup-tabs{
  display:flex;
  gap:8px;
}
.tab-btn{
  flex:1;
  padding:8px;
  border-radius:8px;
  border:1px solid var(--border);
  background:var(--panel-2);
  color:var(--text);
  cursor:pointer;
  font-size:0.9rem;
}
.tab-btn.active{
  border-color:var(--accent);
  color:var(--accent);
}
.setup-panel label{
  display:block;
  font-size:0.8rem;
  color:var(--muted);
  margin-bottom:4px;
  margin-top:10px;
}
input[type="text"]{
  width:100%;
  padding:9px 10px;
  border-radius:8px;
  border:1px solid var(--border);
  background:var(--panel-2);
  color:var(--text);
  font-size:0.95rem;
}
button{
  cursor:pointer;
  font-family:inherit;
}
.primary-btn{
  width:100%;
  padding:11px;
  margin-top:14px;
  border-radius:8px;
  border:none;
  background:linear-gradient(#f2c35a, #c98a1b);
  box-shadow:inset 0 1px 0 rgba(255,255,255,0.3), 0 3px 8px rgba(0,0,0,0.4);
  color:#2a1a05;
  font-weight:700;
  font-size:0.95rem;
}
.primary-btn:hover{filter:brightness(1.08);}
.secondary-btn{
  width:100%;
  padding:9px;
  border-radius:8px;
  border:1px solid var(--border);
  background:transparent;
  color:var(--text);
  font-size:0.85rem;
}
#hostPanel[hidden], #joinPanel[hidden]{display:none;}
.room-code-box{
  margin-top:14px;
  padding:12px;
  background:var(--panel-2);
  border-radius:8px;
  text-align:center;
}
.room-code-box .code{
  font-size:1.6rem;
  letter-spacing:4px;
  font-weight:700;
  color:var(--accent);
}
.room-code-box .sub{
  font-size:0.75rem;
  color:var(--muted);
  margin-top:4px;
}
.link-row{
  display:flex;
  gap:6px;
  margin-top:8px;
}
.link-row input{
  flex:1;
  font-size:0.75rem;
}
.link-row button{
  padding:0 12px;
  border-radius:8px;
  border:1px solid var(--border);
  background:var(--panel-2);
  color:var(--accent);
}

/* In-game HUD */
.scoreboard{
  display:flex;
  gap:12px;
}
.score-card{
  flex:1;
  padding:12px;
  border-radius:10px;
  background:linear-gradient(180deg, #14100c, #0a0806);
  border:2px solid #3b2c20;
  box-shadow:inset 0 2px 8px rgba(0,0,0,0.6);
  text-align:center;
  transition:border-color 0.2s, box-shadow 0.2s;
}
.score-card.turn.p1{border-color:var(--p1); box-shadow:inset 0 2px 8px rgba(0,0,0,0.6), 0 0 14px rgba(239,91,91,0.35);}
.score-card.turn.p2{border-color:var(--p2); box-shadow:inset 0 2px 8px rgba(0,0,0,0.6), 0 0 14px rgba(91,147,240,0.35);}
.score-card .name{
  font-size:0.85rem;
  color:var(--muted);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.score-card.p1 .name{color:var(--p1);}
.score-card.p2 .name{color:var(--p2);}
.score-card .score{
  font-size:2rem;
  font-weight:700;
  margin-top:2px;
  font-family:"DS-Digital", "Courier New", ui-monospace, monospace;
  color:#ffd66b;
  text-shadow:0 0 10px rgba(255,200,80,0.5);
  letter-spacing:2px;
}
.meta-row{
  display:flex;
  justify-content:space-between;
  font-size:0.8rem;
  color:var(--muted);
}
#turnStatus{
  text-align:center;
  padding:10px;
  border-radius:8px;
  background:var(--panel-2);
  font-size:0.95rem;
  min-height:20px;
}
.aim-controls{
  display:flex;
  gap:8px;
  justify-content:center;
}
.aim-controls button{
  width:44px;
  height:44px;
  border-radius:8px;
  border:1px solid var(--border);
  background:var(--panel-2);
  color:var(--text);
  font-size:1.1rem;
}
#log{
  height:120px;
  overflow-y:auto;
  background:var(--panel-2);
  border-radius:8px;
  padding:8px 10px;
  font-size:0.78rem;
  color:var(--muted);
  display:flex;
  flex-direction:column;
  gap:3px;
}
#gamePanel[hidden], #setupPanel[hidden]{display:none;}
.zone-legend{
  display:flex;
  justify-content:space-around;
  font-size:0.72rem;
  color:var(--muted);
  gap:4px;
}
.zone-legend span{display:flex;align-items:center;gap:4px;}
.dot{width:9px;height:9px;border-radius:50%;display:inline-block;}

/* computer difficulty picker */
.difficulty{display:flex; gap:6px;}
.diff-btn{
  flex:1;
  padding:8px;
  border-radius:8px;
  border:1px solid var(--border);
  background:var(--panel-2);
  color:var(--text);
  font-size:0.85rem;
}
.diff-btn.active{border-color:var(--accent); color:var(--accent); box-shadow:0 0 0 1px var(--accent) inset;}

.log-toggle{display:none;}
/* ---------- phones, portrait: the tall table gets the height, panel shrinks ---------- */
@media (max-width: 780px) and (orientation: portrait), (max-aspect-ratio: 4/5) and (orientation: portrait){
  body.in-game .board-wrap{max-height:none; flex:1 1 auto;}
  body.in-game .hint{display:none;}
  body.in-game .panel{flex:0 0 auto; gap:6px;}
  body.in-game #gamePanel h2, body.in-game .zone-legend{display:none;}
  body.in-game .meta-row{font-size:0.72rem;}
  body.in-game .aim-controls{position:static;}
  body.in-game .aim-controls button{width:34px; height:30px;}
  body.in-game .scoreboard .score-card{padding:5px 8px;}
  body.in-game .score-card .score{font-size:1.15rem;}
  body:not(.in-game) .board-wrap{max-height:38%;}
}
/* game log collapses on phones and short screens */
@media (max-width: 780px), (max-height: 600px){
  .log-toggle{display:block; width:100%; padding:6px; border-radius:8px; border:1px solid var(--border); background:var(--panel-2); color:var(--accent); font-size:0.78rem; font-weight:600;}
  #log{display:none; height:auto; max-height:20dvh;}
  body.log-open #log{display:flex;}
}
/* ---------- phones, landscape: table full height, compact panel ---------- */
@media (orientation: landscape) and (max-height: 600px){
  .topbar{padding:4px 12px;}
  .topbar h1{font-size:0.95rem;}
  .layout{flex-direction:row; padding:6px 10px; gap:10px;}
  .board-wrap{max-height:none;}
  .hint{display:none;}
  .panel{flex:0 0 min(290px, 42vw); width:min(290px, 42vw); max-height:100%; align-self:stretch; padding:8px 10px; gap:6px;}
  #gamePanel h2, .zone-legend{display:none;}
  .score-card{padding:5px;} .score-card .score{font-size:1.15rem;}
  #turnStatus{padding:6px; font-size:0.8rem;}
}
