/* Minimal, readable styling */
:root{
  --bg:#0f141a;
  --panel:#141b22;
  --card:#18212b;
  --text:#e8eef6;
  --muted:#93a4b8;
  --line:#2a3644;
  --btn:#273546;
  --btn2:#1f2a36;
  --accent:#4aa3ff;
  --danger:#ff5b5b;
  --ok:#38d27a;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius: 16px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  --tab-ui-scale: 1;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --right-sidebar-width: 520px;
}

*{box-sizing:border-box}
html,body{height:100%; min-height:100%; overflow:hidden; overscroll-behavior:none}
body{
  margin:0;
  font-family:var(--sans);
  background: radial-gradient(1200px 900px at 20% 10%, rgba(74,163,255,.12), transparent 55%),
              radial-gradient(900px 700px at 90% 40%, rgba(56,210,122,.10), transparent 55%),
              var(--bg);
  color:var(--text);
  overflow:hidden;
  min-height:0;
}
#app{height:100dvh; min-height:100vh; display:flex; flex-direction:column}
.topbar{
  display:flex; align-items:center; justify-content:space-between;
  padding:18px 22px;
  border-bottom:1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.03), transparent);
}
.brand .title{font-size:20px; font-weight:700; letter-spacing:.3px}
.brand .subtitle{font-size:12px; color:var(--muted); margin-top:2px}
.status{display:flex; align-items:center; gap:10px; color:var(--muted); font-size:13px}
.connInline{display:flex; align-items:center; gap:10px; color:var(--muted); font-size:13px; margin-top:6px}
.connInline .dot{width:9px; height:9px}
.connText{color:var(--muted)}
.dot{width:10px; height:10px; border-radius:999px; background:#4b5563; box-shadow:0 0 0 4px rgba(255,255,255,.04) inset}
.dot.ok{background:var(--ok)}
.dot.bad{background:var(--danger)}
.layout{
  flex:1;
  display:grid;
  grid-template-columns: 360px 1fr;
  gap:16px;
  padding:16px;
  height:100%;
  min-height:0;
  overflow:hidden;
}

/* During gameplay, the HUD overlays move onto the board. */
body.in-game .layout{grid-template-columns: 1fr; padding:0; gap:0; height:100%; min-height:0; flex:1 1 auto;}
body.in-game .panel{display:none;}
.panel{display:flex; flex-direction:column; gap:16px; height:100%; overflow-y:auto; padding-right:6px; padding-bottom:88px}
.card{
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.01));
  border:1px solid var(--line);
  border-radius:var(--radius);
  padding:14px;
  box-shadow:var(--shadow);
}
.card h2{margin:0 0 12px 0; font-size:14px; letter-spacing:.3px; color:var(--text)}

/* Card headers with inline status */
.cardTitleRow{display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:12px}
.cardTitleRow h2{margin:0; font-size:14px; letter-spacing:.3px; color:var(--text)}
.connInline.connTight{margin-top:0; gap:8px; font-size:12px}
.connInline.connTight .dot{width:9px; height:9px}
.label{font-size:12px; color:var(--muted); margin:8px 0 6px}
.labelTiny{font-size:11px; color:var(--muted); margin:8px 0 6px}
.input{
  width:100%;
  padding:10px 10px;
  border-radius:12px;
  border:1px solid var(--line);
  background: rgba(0,0,0,.25);
  color:var(--text);
  outline:none;
}
.input:focus{border-color:rgba(74,163,255,.55); box-shadow:0 0 0 4px rgba(74,163,255,.12)}
.input.code{font-family:var(--mono); text-transform:uppercase; letter-spacing:1.5px}
.row{display:flex; gap:10px; margin-top:10px}
.btn{
  appearance:none;
  border:1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  color:var(--text);
  padding:10px 12px;
  border-radius:12px;
  cursor:pointer;
  font-weight:600;
}
.btn:hover{filter:brightness(1.08)}
.btn:disabled{opacity:.45; cursor:not-allowed}
.btn.primary{
  border-color:rgba(74,163,255,.45);
  background: linear-gradient(180deg, rgba(74,163,255,.25), rgba(74,163,255,.08));
}
.divider{height:1px; background:var(--line); margin:12px 0}
.error{
  margin-top:10px;
  padding:10px;
  border-radius:12px;
  border:1px solid rgba(255,91,91,.45);
  background: rgba(255,91,91,.10);
  color:#ffd4d4;
  font-size:13px;
}
.hidden{display:none !important}
.roomBox{
  border:1px solid var(--line);
  border-radius:12px;
  padding:10px;
  background: rgba(0,0,0,.22);
}
.roomTop{display:flex; align-items:center; justify-content:space-between; gap:10px}
.roomCode{
  font-family:var(--mono);
  font-size:18px;
  letter-spacing:2px;
}
.playersList{display:flex; flex-direction:column; gap:8px; margin-top:10px}
.playerRow{display:flex; align-items:center; justify-content:space-between; gap:10px}
.playerTag{display:flex; align-items:center; gap:10px}
.badge{width:10px; height:10px; border-radius:999px}
.colorPickerRow{margin-top:8px}
.colorPicker{display:flex; flex-wrap:wrap; gap:8px; margin-top:8px}
.colorChip{
  width:26px; height:26px;
  border-radius:999px;
  border:1px solid var(--line);
  cursor:pointer;
  position:relative;
  box-shadow:0 2px 8px rgba(0,0,0,.25);
}
.colorChip.selected{
  box-shadow:0 0 0 3px rgba(255,255,255,.18), 0 2px 8px rgba(0,0,0,.25);
}
.colorChip.disabled{opacity:.35; cursor:not-allowed; filter:grayscale(.25)}
.colorChip .check{
  position:absolute; inset:0;
  display:flex; align-items:center; justify-content:center;
  font-size:14px;
  font-weight:900;
  user-select:none;
}
.turnInfo{font-size:13px; color:var(--text); line-height:1.35}
.actions{display:flex; gap:10px; flex-wrap:wrap; margin-top:10px}
.hint{margin-top:10px; color:var(--muted); font-size:12px; line-height:1.3}
.resourcesBox{display:flex; flex-direction:column; gap:10px; font-size:13px}
.pRes{border:1px solid var(--line); border-radius:12px; padding:10px; background: rgba(0,0,0,.18)}
.pRes.turnActive{border-color:rgba(74,163,255,.55); box-shadow:0 0 0 3px rgba(74,163,255,.12) inset}
.pResHead{display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:8px}
.pResName{display:flex; align-items:center; gap:10px; font-weight:700}
.pResGrid{display:grid; grid-template-columns: repeat(5, 1fr); gap:8px; font-family:var(--mono); font-size:12px}
.resCell{display:flex; align-items:center; justify-content:flex-start; gap:6px; padding:2px 0}
.resIcon{width:18px; height:18px; object-fit:contain; filter:drop-shadow(0 1px 2px rgba(0,0,0,.35))}
.resVal{font-family:var(--mono); font-size:12px; color:rgba(232,238,246,.96)}
.pPieceGrid{display:grid; grid-template-columns: repeat(4, 1fr); gap:8px; font-family:var(--mono); font-size:12px; margin-top:8px; color:rgba(232,238,246,.92)}
.bankRes{border:1px solid var(--line); border-radius:12px; padding:10px; background: rgba(0,0,0,.18)}
.bankResHead{font-weight:800; color:var(--text); margin-bottom:8px; font-size:12px; letter-spacing:.3px}
.smallNote{margin-top:10px; font-size:11px; color:var(--muted)}
.boardWrap{
  border:1px solid var(--line);
  border-radius:var(--radius);
  overflow:hidden;
  background: linear-gradient(180deg, rgba(255,255,255,.02), transparent);
  box-shadow:var(--shadow);
  display:flex; flex-direction:column;
  position:relative;
  height:100%;
  min-height:0;
}
body.in-game .boardWrap{border:none; border-radius:0; box-shadow:none; height:100%; min-height:0; padding-right:var(--right-sidebar-width, 520px);}
body.in-game .boardFooter{display:none;}
#board{
  touch-action:none;
  width:100%;
  flex:1;
  height:auto;
  display:block;
  background: #5f6f7c; /* ocean backdrop (darker muted grey-blue) */
}
.boardFooter{
  display:flex; justify-content:space-between;
  padding:10px 12px;
  border-top:1px solid var(--line);
  color:var(--muted);
  font-size:12px;
}

/* Resources panel overlay */
.resourcesOverlay{
  position:absolute;
  left:6px;
  top:56px;
  right:auto;
  bottom:auto;
  z-index:13;
  width:min(360px, 34vw);
  max-width:400px;
  padding:12px;
  background: rgba(14,19,28,.78);
  backdrop-filter: blur(6px);
}
.resourcesOverlay h2{margin:0 0 10px 0}
.resourcesOverlay .resourcesBox{gap:8px; font-size:12px}
.resourcesOverlay .pResGrid,
.resourcesOverlay .pPieceGrid{font-size:11px}
.resourcesOverlay > .smallNote{display:none;}

.resSummaryRow{
  display:flex;
  align-items:center;
  gap:10px;
  padding:8px 10px;
  border:1px solid rgba(255,255,255,.08);
  border-radius:14px;
  background: rgba(0,0,0,.18);
}
.resSummaryRow + .resSummaryRow{margin-top:8px;}
.resSummaryRow.turnActive{border-color:rgba(74,163,255,.5); box-shadow:0 0 0 2px rgba(74,163,255,.16) inset;}
.resSummaryMain{display:flex; align-items:center; gap:8px; min-width:0; width:100%;}
.resSummaryName{font-weight:700; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:116px;}
.resSummaryStats{display:flex; align-items:center; gap:8px; flex:1 1 auto; min-width:0; flex-wrap:wrap;}
.resSummaryStat{font-family:var(--mono); font-size:11px; color:#dbe7f5; white-space:nowrap;}
.resSummaryRoad{display:inline-flex; align-items:center; gap:5px;}
.resSummaryRoadSwatch{width:12px; height:6px; border-radius:999px; box-shadow:0 0 0 1px rgba(255,255,255,.16) inset;}
.resSummaryVp{margin-left:auto; display:inline-flex; align-items:center; gap:6px; justify-content:flex-end;}
.resSummaryBadges{font-size:10px; color:var(--muted); letter-spacing:.02em;}

.rightSidebar{
  position:absolute;
  top:0;
  right:0;
  bottom:0;
  width:var(--right-sidebar-width, 520px);
  z-index:12;
  display:flex;
  border-left:1px solid rgba(255,255,255,.08);
  background: rgba(14,19,28,.76);
  backdrop-filter: blur(8px);
  box-shadow:-18px 0 48px rgba(0,0,0,.24);
}
.rightSidebar.hidden{display:none !important;}
.rightSidebarResize{
  width:8px;
  cursor:ew-resize;
  flex:0 0 8px;
  position:relative;
  touch-action:none;
}
.rightSidebarResize::before{
  content:'';
  position:absolute;
  top:50%;
  left:2px;
  width:3px;
  height:72px;
  border-radius:999px;
  transform:translateY(-50%);
  background:rgba(255,255,255,.12);
}
.rightSidebarInner{
  flex:1 1 auto;
  min-width:0;
  min-height:0;
  display:flex;
  flex-direction:column;
  gap:10px;
  padding:10px 10px 10px 6px;
  overflow:hidden;
}
.rightSidebarInner > .card{margin:0;}
.rightSidebarInner > .card.hidden{display:none !important;}
.rightSidebarInner > #logCard,
.rightSidebarInner > #devCard{flex:1 1 0; min-height:0;}
.rightSidebarResourceDock{
  --tool-ui-scale: 1;
  flex:0 0 auto;
  border-top:1px solid rgba(255,255,255,.08);
  padding-top:10px;
  min-height:0;
}
.rightSidebarResourcesBody{display:flex; flex-direction:column; gap:10px; zoom: var(--tool-ui-scale); transform-origin: top left;}
.rightSidebarBankTitle{font-size:12px; font-weight:800; letter-spacing:.3px; color:var(--text);}
.rightSidebarResStrip,
.rightSidebarPieceStrip{display:grid; gap:10px;}
.rightSidebarResStrip{grid-template-columns:repeat(5, minmax(0, 1fr));}
.rightSidebarPieceStrip{grid-template-columns:repeat(4, minmax(0, 1fr));}
.rightSidebarSeparator{height:1px; background:rgba(255,255,255,.08);}
.rightSidebarMeta{display:flex; flex-wrap:wrap; align-items:center; gap:8px 14px; font-family:var(--mono); font-size:11px; color:#dbe7f5;}
.rightSidebarMetaStrong{font-size:17px; font-weight:900; color:var(--text); letter-spacing:.02em;}
.rightSidebarNote{font-size:11px; color:var(--muted);}
.rightSidebar .logOverlay,
.rightSidebar #devCard.rightSidebarDocked{
  position:relative;
  left:auto;
  right:auto;
  top:auto;
  bottom:auto;
  width:100%;
  max-width:none;
  padding:0;
  background:transparent;
  backdrop-filter:none;
  border:0;
  border-radius:0;
  box-shadow:none;
  overflow:hidden;
  display:flex;
  flex-direction:column;
  min-height:0;
}
.rightSidebar .logOverlay .cardTitleRow,
.rightSidebar #devCard.rightSidebarDocked .devHeaderRow{margin-bottom:8px;}
.rightSidebar .logOverlay .logList{max-height:none; flex:1 1 auto; min-height:0;}
.rightSidebar #devCard.rightSidebarDocked .panelScaleContent{display:flex; flex-direction:column; min-height:0; gap:8px;}
.rightSidebar #devCard.rightSidebarDocked .devHand{flex:1 1 auto; min-height:0; overflow:auto; margin-top:0;}
body.in-game .rightHud{right:calc(var(--right-sidebar-width, 520px) + 8px);}

/* Game log overlay (toggleable + draggable) */
.logOverlay{
  position:absolute;
  left:auto;
  top:56px;
  right:6px;
  bottom:auto;
  z-index:14;
  width:min(520px, 56vw);
  max-width:620px;
  padding:12px;
  background: rgba(14,19,28,.78);
  backdrop-filter: blur(6px);
}
.logOverlay .cardTitleRow{margin-bottom:10px}
.logOverlay h2{margin:0}
.logOverlay{ --tool-ui-scale: 1; }
.logOverlay .logScaleHost{ margin-left:auto; display:flex; align-items:center; }
.logOverlay .logScaleHost .toolScaleControl{ padding:3px 5px; gap:4px; }
.logOverlay .logScaleHost .tabScaleBtn{ width:24px; height:24px; border-radius:8px; }
.logOverlay .logScaleHost .tabScaleLabel{ min-width:52px; }
.logOverlay .logList{max-height:320px; zoom: var(--tool-ui-scale)}
.logOverlay #logHideBtn{padding:6px 10px}

/* Board HUD overlays */
.hudBar{
  position:absolute;
  z-index:26;
  padding:10px 12px;
  background: rgba(14,19,28,.78);
  backdrop-filter: blur(6px);
  border:1px solid var(--line);
  border-radius:18px;
  box-shadow:0 18px 60px rgba(0,0,0,.35);
  max-width:calc(100% - 24px);
}
.hudTopLeft{left:6px; top:6px;}
.hudBottomLeft{left:6px; right:auto; bottom:6px; width:max-content; max-width:calc(100% - 24px);}
.dragGrip{
  width:22px;
  height:26px;
  display:flex;
  align-items:center;
  justify-content:center;
  border:1px solid var(--line);
  border-radius:12px;
  background: rgba(255,255,255,.03);
  color:var(--muted);
  font-family:var(--mono);
  font-size:12px;
  line-height:1;
  cursor:grab;
  user-select:none;
}
.hudBarRow{
  --tool-ui-scale: 1;
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:nowrap;
  white-space:nowrap;
  overflow-x:auto;
  zoom: var(--tool-ui-scale);
  transform-origin: left center;
}
.hudBarScaleHost{display:flex; align-items:center; margin-left:8px; flex:0 0 auto;}
.hudBarScaleHost .toolScaleControl{padding:3px 5px; gap:4px;}
.hudBarScaleHost .tabScaleBtn{width:24px; height:24px; border-radius:8px;}
.hudBarScaleHost .tabScaleLabel{min-width:52px;}
.hudBarRow::-webkit-scrollbar{height:8px}
.hudBarRow::-webkit-scrollbar-thumb{background:rgba(255,255,255,.10); border-radius:999px}
.hudConn{display:flex; align-items:center; gap:8px}
.hudTurnInfo{display:flex; align-items:center; gap:10px; min-width:0; flex:0 1 auto}
.hudTurnInfo .timerInfo{margin-top:0}
.hudBtns{display:flex; align-items:center; gap:8px; flex-wrap:nowrap}
.btnTiny{padding:8px 10px; border-radius:12px; font-size:12px}
.hudDev{display:flex; align-items:center; gap:8px; margin-left:auto}
#devRemaining{font-family:var(--mono); font-size:11px; color:var(--muted); white-space:nowrap}

.hudDevOverlay{
  position:absolute;
  left:6px;
  top:344px;
  bottom:auto;
  z-index:25;
  width:min(480px, 56vw);
  max-height:45vh;
  overflow:auto;
  padding:12px;
  background: rgba(14,19,28,.78);
  backdrop-filter: blur(6px);
  border:1px solid var(--line);
  border-radius:18px;
  box-shadow:0 18px 60px rgba(0,0,0,.35);
}
.hudDevOverlay h2{margin:0}
body.in-game .hudDevOverlay .actions{display:none;}

.panelScalable{ --tool-ui-scale: 1; }
.panelScaleContent{ zoom: var(--tool-ui-scale); transform-origin: top left; }
.panelScaleHost{ margin-left:auto; display:flex; align-items:center; }
.panelScaleHost .toolScaleControl{ padding:3px 5px; gap:4px; }
.panelScaleHost .tabScaleBtn{ width:24px; height:24px; border-radius:8px; }
.panelScaleHost .tabScaleLabel{ min-width:52px; }

.resourcesHeaderRow, .devHeaderRow{
  display:flex;
  align-items:center;
  gap:10px;
  margin-bottom:10px;
}
.resourcesHeaderRow h2, .devHeaderRow h2{ margin:0; }

.devHeaderRight{
  margin-left:auto;
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:nowrap;
}
.devHeaderRight .btnTiny{ padding:6px 10px; }
.devDeckInline{ margin:0 !important; white-space:nowrap; }

#resourcesCard .panelScaleContent .smallNote{ margin-top:10px; }
#devCard .panelScaleContent .smallNote{ margin-top:8px; }
#devCard .panelScaleContent .devHand{ margin-top:8px; }

.pieceCell{display:flex; align-items:center; justify-content:flex-start; gap:6px; padding:2px 0}
.pieceLeft{display:flex; align-items:center; gap:8px; min-width:0}
.pieceIcon{
  width:22px;
  height:22px;
  border-radius:8px;
  background-repeat:no-repeat;
  background-size:200% 200%;
  filter:drop-shadow(0 1px 2px rgba(0,0,0,.35));
}
.pieceVal{font-family:var(--mono); font-size:12px; color:rgba(232,238,246,.96)}

/* The bottom dock is redundant with the HUD bar; keep it hidden in-game. */
body.in-game .hudRollDock{display:none;}

/* Sticky bottom roll dock (shows at start of your turn) */
.rollDock{
  position:sticky;
  bottom:10px;
  z-index:30;
}
.rollDockInner{
  display:flex;
  gap:10px;
  padding:10px;
  border-radius:18px;
  border:1px solid var(--line);
  background: rgba(0,0,0,.28);
  box-shadow:0 18px 60px rgba(0,0,0,.45);
  backdrop-filter: blur(6px);
}

.pill{
  display:inline-block;
  padding:2px 8px;
  border-radius:999px;
  border:1px solid var(--line);
  background: rgba(0,0,0,.18);
  color:var(--text);
  font-family:var(--mono);
  font-size:11px;
}

/* Development cards */
.devHand{display:flex; flex-direction:column; gap:10px; font-size:13px}
.devRow{display:flex; align-items:center; justify-content:space-between; gap:10px; padding:8px 10px; border:1px solid var(--line); border-radius:14px; background: rgba(0,0,0,.12)}
.devLeft{display:flex; align-items:center; gap:10px; min-width:0}
.devThumb{width:44px; height:58px; border-radius:8px; border:1px solid var(--line); object-fit:cover; background: rgba(255,255,255,.03)}
.devName{font-weight:700; color:var(--text); white-space:nowrap; overflow:hidden; text-overflow:ellipsis}
.devMeta{color:var(--muted); font-size:12px}
.devRight{display:flex; align-items:center; gap:8px}
.tag{display:inline-block; padding:2px 8px; border-radius:999px; border:1px solid var(--line); background: rgba(255,255,255,.02); color:var(--muted); font-family:var(--mono); font-size:11px}

/* Modal */
.modal{position:fixed; inset:0; z-index:50; display:flex; align-items:center; justify-content:center}
.modal.hidden{display:none}
.modalBackdrop{position:absolute; inset:0; background: rgba(0,0,0,.55)}
.modalBox{position:relative; width:min(659px, calc(100% - 24px)); border:1px solid var(--line); border-radius:18px; background: linear-gradient(180deg, rgba(14,19,28,.98), rgba(10,14,20,.96)); box-shadow:0 18px 60px rgba(0,0,0,.45); padding:14px}
.modalTitle{font-size:16px; font-weight:800; color:var(--text); margin-bottom:10px}
.modalBody{color:var(--text); font-size:13px; line-height:1.4}
.modalActions{display:flex; justify-content:flex-end; gap:10px; margin-top:12px}
.modalImg{width:100%; max-height:70vh; object-fit:contain; border-radius:14px; border:1px solid var(--line); background: rgba(255,255,255,.02)}
.choiceRow{display:flex; flex-wrap:wrap; gap:8px; margin-top:10px}
.choiceBtn{border:1px solid var(--line); background: rgba(0,0,0,.18); color:var(--text); border-radius:999px; padding:6px 10px; font-size:12px; cursor:pointer}
.choiceBtn:hover{filter:brightness(1.1)}

/* Click-to-build context menu */
.buildPopup{position:fixed; z-index:60; border:1px solid var(--line); border-radius:16px; background: linear-gradient(180deg, rgba(14,19,28,.98), rgba(10,14,20,.96)); box-shadow:0 18px 60px rgba(0,0,0,.45); padding:10px; min-width:160px}
.buildPopup.hidden{display:none}
.buildPopupTitle{font-size:12px; font-weight:800; color:var(--text); margin-bottom:8px}
.buildPopupBtns{display:flex; flex-wrap:wrap; gap:8px}
.audioSfxPanel{
  position:fixed;
  right:10px;
  top:64px;
  width:min(360px, calc(100vw - 20px));
  max-height:min(70vh, 640px);
  z-index:62;
  border:1px solid var(--line);
  border-radius:16px;
  background: linear-gradient(180deg, rgba(14,19,28,.98), rgba(10,14,20,.96));
  box-shadow:0 18px 60px rgba(0,0,0,.45);
  backdrop-filter: blur(8px);
  display:flex;
  flex-direction:column;
  overflow:hidden;
}
.audioSfxPanel.hidden{display:none !important}
.audioSfxPanelHeader{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  padding:10px 12px;
  border-bottom:1px solid rgba(255,255,255,.05);
  cursor:grab;
  user-select:none;
  touch-action:none;
}
.audioSfxPanelTitle{font-size:13px; font-weight:800; letter-spacing:.3px}
.audioSfxPanelActions{display:flex; align-items:center; gap:6px}
.audioSfxPanelBody{padding:10px 12px; overflow:auto; display:flex; flex-direction:column; gap:10px}
.audioSfxRow{border:1px solid rgba(255,255,255,.05); border-radius:12px; padding:8px 10px; background:rgba(255,255,255,.02)}
.audioSfxRowHead{display:flex; align-items:center; justify-content:space-between; gap:8px; margin-bottom:6px}
.audioSfxLabel{font-size:12px; font-weight:700; color:var(--text)}
.audioSfxPct{font-size:11px; color:var(--muted); font-family:var(--mono)}
.audioSfxSlider{width:100%}
.audioSfxPanelFoot{padding:8px 12px 12px; color:var(--muted); font-size:11px; border-top:1px solid rgba(255,255,255,.04)}


.nodeBuildHover{position:fixed; z-index:58; display:flex; align-items:center; gap:8px; pointer-events:none; border:1px solid rgba(255,255,255,.16); background:rgba(8,12,18,.94); color:var(--text); border-radius:999px; padding:6px 10px; box-shadow:0 10px 24px rgba(0,0,0,.35)}
.nodeBuildHover.hidden{display:none !important}
.nodeBuildHoverIcon{width:22px; height:22px; display:grid; place-items:center; border-radius:999px; background:rgba(255,255,255,.08); font-size:14px}
.nodeBuildHoverText{font-size:12px; font-weight:700; letter-spacing:.02em}

.nodeBuildConfirm{position:fixed; z-index:61; display:grid; grid-template-columns:auto 1fr auto auto; align-items:center; gap:8px; border:1px solid rgba(255,255,255,.18); border-radius:14px; background:linear-gradient(180deg, rgba(14,19,28,.98), rgba(10,14,20,.96)); color:var(--text); padding:8px 10px; box-shadow:0 16px 36px rgba(0,0,0,.42)}
.nodeBuildConfirm.hidden{display:none !important}
.nodeBuildConfirmIcon{width:28px; height:28px; display:grid; place-items:center; border-radius:10px; background:rgba(255,255,255,.08); font-size:16px}
.nodeBuildConfirmLabel{font-size:12px; font-weight:800; white-space:nowrap}
.nodeBuildConfirmOk,.nodeBuildConfirmCancel{border:1px solid var(--line); background:rgba(255,255,255,.04); color:var(--text); width:28px; height:28px; border-radius:10px; cursor:pointer; font-weight:900; line-height:1}
.nodeBuildConfirmOk:hover,.nodeBuildConfirmCancel:hover{filter:brightness(1.15)}

/* Trading */
.tradeWrap{display:flex; flex-direction:column; gap:12px}
.tradeBox{border:1px solid var(--line); border-radius:14px; padding:10px; background: rgba(0,0,0,.14)}
.tradeTitle{font-size:12px; font-weight:800; color:var(--text); letter-spacing:.3px; margin-bottom:8px}
.tradeRow{display:flex; align-items:center; gap:8px; flex-wrap:wrap}
.tradeGrids{display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-top:8px}
.tradeGrid{border:1px dashed rgba(255,255,255,.12); border-radius:12px; padding:8px; background: rgba(255,255,255,.02)}
.tradeGridInner{display:grid; grid-template-columns:repeat(2, 1fr); gap:8px; margin-top:6px}
.tradeCell{display:flex; align-items:center; justify-content:space-between; gap:8px}
.tradeCellLab{font-size:11px; color:var(--muted); font-family:var(--mono)}
.tradeDetail{margin-top:10px}
/* Global player trade */
.gTradeRows{display:flex; flex-direction:column; gap:10px; margin-top:6px}
.gTradeRow{display:flex; align-items:center; justify-content:space-between; gap:12px}
.gTradeChips{display:flex; gap:10px; flex-wrap:wrap}
.resChipBtn{display:flex; align-items:center; justify-content:space-between; gap:8px; padding:10px 12px; background: rgba(0,0,0,.18); border:1px solid rgba(255,255,255,.12); border-radius:14px; min-width:92px; color:var(--text); cursor:pointer; box-shadow: inset 0 1px 0 rgba(255,255,255,.04)}
.resChipBtn:hover{border-color: rgba(255,255,255,.22)}
.resChipBtn img{width:32px; height:32px}
.resChipBtn .delta{font-family:var(--mono); font-size:14px; min-width:32px; text-align:right; color:var(--muted)}
.resChipBtn.pos .delta{color: var(--ok)}
.resChipBtn.neg .delta{color: var(--danger)}
.gTradeArrow{font-size:44px; font-weight:900; line-height:1; padding-right:4px; user-select:none}
.gTradeArrow.ok{color: var(--ok)}
.gTradeArrow.bad{color: var(--danger)}

/* Proposed trade */
.ptHead{display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:10px}
.ptProposer{display:flex; align-items:center; gap:10px}
.ptName{font-weight:700}
.ptChips{display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end}
.resChip{display:flex; align-items:center; justify-content:space-between; gap:8px; padding:8px 10px; border-radius:12px; background: rgba(0,0,0,.18); border:1px solid rgba(255,255,255,.10); min-width:74px}
.resChip img{width:26px; height:26px}
.resChip .delta{font-family:var(--mono); font-size:13px; min-width:28px; text-align:right; color:var(--muted)}
.resChip.pos .delta{color: var(--ok)}
.resChip.neg .delta{color: var(--danger)}

.ptGrid{display:grid; grid-template-columns: 1fr 110px 110px; gap:8px; align-items:center; margin-top:8px}
.ptCell{min-height:44px; display:flex; align-items:center; justify-content:center}
.ptHeader{color:var(--muted); font-size:12px; font-weight:800; letter-spacing:.3px}
.ptNameCell{justify-content:flex-start; gap:10px; padding-left:6px}
.ptRowName{font-weight:650}

.voteBtn{width:74px; height:44px; border-radius:12px; border:1px solid rgba(255,255,255,.12); background: rgba(0,0,0,.16); color:var(--text); cursor:pointer; font-size:28px; line-height:1; display:flex; align-items:center; justify-content:center}
.voteBtn:hover{border-color: rgba(255,255,255,.22)}
.voteBtn:disabled{opacity:.6; cursor:default}
.voteBtn.on.ok{background: rgba(56,210,122,.12); border-color: rgba(56,210,122,.25); color: var(--ok)}
.voteBtn.on.bad{background: rgba(255,91,91,.10); border-color: rgba(255,91,91,.25); color: var(--danger)}


/* Turn timer */
.timerInfo{
  margin-top:8px;
  font-family:var(--mono);
  font-size:12px;
  color:var(--muted);
  display:flex;
  align-items:center;
  gap:8px;
}

.timerPill{
  display:inline-block;
  padding:2px 8px;
  border-radius:999px;
  border:1px solid var(--line);
  background: rgba(0,0,0,.18);
  color:var(--text);
}

/* Discard selector */
.discardGrid{
  margin-top:10px;
  display:flex;
  flex-direction:column;
  gap:8px;
}
.discardRow{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:8px 10px;
  border:1px solid var(--line);
  border-radius:12px;
  background: rgba(0,0,0,.12);
}
.discardLabel{
  font-family:var(--mono);
  font-size:12px;
  color:var(--text);
}
.discardControls{
  display:flex;
  align-items:center;
  gap:8px;
}
.stepBtn{
  width:34px;
  height:30px;
  border-radius:10px;
  border:1px solid var(--line);
  background: rgba(255,255,255,.03);
  color:var(--text);
  font-weight:800;
  cursor:pointer;
}
.stepBtn:disabled{opacity:.45; cursor:not-allowed}
.countPill{
  min-width:56px;
  text-align:center;
  font-family:var(--mono);
  font-size:12px;
  padding:4px 10px;
  border-radius:999px;
  border:1px solid var(--line);
  background: rgba(0,0,0,.18);
}

/* Right-side HUD (countdown + pause) */
.rightHud{
  position:absolute;
  top:6px;
  right:6px;
  z-index:12;
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:10px;
  pointer-events:auto;
}
.countdownClock{
  --tool-ui-scale: 1;
  min-width:170px;
  text-align:right;
  padding:8px 10px 10px;
  border-radius:14px;
  border:1px solid var(--line);
  background: rgba(0,0,0,.28);
  box-shadow:0 10px 30px rgba(0,0,0,.35);
}
.clockTopRow{display:flex; align-items:center; gap:8px; margin-bottom:4px;}
.clockTopRow .panelScaleHost{margin-left:auto;}
.clockTopRow .toolScaleControl{padding:2px 4px; gap:3px;}
.clockTopRow .tabScaleBtn{width:22px; height:22px; border-radius:7px;}
.clockTopRow .tabScaleLabel{min-width:48px; font-size:11px;}
.clockDragGrip{width:20px; height:20px; border-radius:999px; font-size:10px; opacity:.95;}
.countdownClock .panelScaleContent{text-align:right;}
.countdownClock .panelScaleContent .clockTime,
.clockTime{
  font-family:var(--mono);
  font-size:22px;
  font-weight:900;
  color:var(--text);
  letter-spacing:1px;
}
.countdownClock .panelScaleContent .clockMeta,
.clockMeta{
  margin-top:4px;
  font-size:11px;
  color:var(--muted);
  line-height:1.2;
}
.pausedOverlay{
  position:absolute;
  inset:0;
  z-index:11;
  display:flex;
  align-items:center;
  justify-content:center;
  background: rgba(0,0,0,.28);
  color: rgba(232,238,246,.92);
  font-size:36px;
  font-weight:900;
  letter-spacing:6px;
  text-shadow:0 18px 60px rgba(0,0,0,.65);
  pointer-events:none;
}


/* --- Setup / Tools --- */
.label{
  display:block;
  margin-top:10px;
  margin-bottom:4px;
  font-size:12px;
  color: var(--muted);
}
select.input{
  background:#0b0c10;
  color: var(--text);
}

/* --- Modal Tools --- */
.toolWrap{ display:flex; flex-direction:column; gap:10px; }
.toolWrapScaled{ --tool-ui-scale: 1; }
.toolScaleRow{ display:flex; justify-content:flex-end; }
.toolScaleControl{
  display:flex;
  align-items:center;
  gap:6px;
  padding:4px 6px;
  border:1px solid rgba(255,255,255,.10);
  border-radius:12px;
  background: rgba(255,255,255,.03);
  align-self:flex-end;
}
.toolScaleContent{
  zoom: var(--tool-ui-scale);
  display:flex;
  flex-direction:column;
  gap:10px;
}
.logList, .chatList{
  max-height:360px;
  overflow:auto;
  border:1px solid var(--line);
  border-radius:12px;
  padding:10px;
  background:#0b0c10;
}
.logRow{
  font-size:12px;
  padding:6px 4px;
  border-bottom:1px solid rgba(255,255,255,.08);
  color: var(--text);
}
.logRow:last-child{ border-bottom:none; }

.logTs{color:var(--muted); font-family:var(--mono); margin-right:6px;}
.logAutoIcon{display:inline-flex; align-items:center; justify-content:center; font-size:12px; line-height:1; margin-right:6px; opacity:.95;}
.logPlayerSeg{display:inline-flex; align-items:center; gap:6px; margin-left:10px; margin-right:6px; flex-wrap:wrap;}
.logDot{width:10px; height:10px; border-radius:999px; display:inline-block; border:1px solid rgba(0,0,0,.35)}
.logRes{display:inline-flex; align-items:center; gap:4px; margin-left:6px;}
.logResIcon{width:18px; height:18px; display:inline-block; vertical-align:middle;}
.logResNum{font-family:var(--mono); font-size:12px; color:#bfe2ff;}

.diceTable{
  width:100%;
  border-collapse:collapse;
  font-size:12px;
}
.diceTable th, .diceTable td{
  padding:6px 8px;
  border-bottom:1px solid rgba(255,255,255,.08);
}
.diceTable th{
  color: var(--muted);
  font-weight:600;
}
.chatRow{ padding:6px 4px; border-bottom:1px solid rgba(255,255,255,.08); }
.chatRow:last-child{ border-bottom:none; }
.chatMeta{ font-size:11px; color: var(--muted); margin-bottom:2px; }
.chatBody{ font-size:13px; color: var(--text); }
.chatInputRow{ display:flex; gap:8px; align-items:center; }
.chatInputRow .input{ flex:1; }



/* Post-game overlay (victory splash + stats) */
.postgameOverlay{
  position:fixed;
  inset:0;
  z-index: 5000;
  display:flex;
  align-items:center;
  justify-content:center;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
}
.postgameSplash{
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:10px;
  text-align:center;
  padding:24px 26px;
  border-radius:18px;
  border:1px solid rgba(255,255,255,.10);
  background: radial-gradient(1200px 900px at 20% 10%, rgba(74,163,255,.16), transparent 60%),
              radial-gradient(900px 700px at 90% 40%, rgba(56,210,122,.12), transparent 60%),
              rgba(10,12,15,.78);
  box-shadow: 0 30px 90px rgba(0,0,0,.55);
  min-width: min(680px, calc(100vw - 36px));
  max-width: min(920px, calc(100vw - 36px));
}
.postgameSplashTitle{
  font-size: 44px;
  font-weight: 900;
  letter-spacing: .5px;
  text-shadow: 0 10px 24px rgba(0,0,0,.55);
}
.postgameSplashSub{
  font-size: 14px;
  color: var(--muted);
  font-family: var(--mono);
}

.postgamePanel{
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  border:0;
  background: rgba(10,12,15,.92);
  box-shadow: none;
  display:flex;
  flex-direction:column;
  overflow:hidden;
}
.postgameTop{
  display:grid;
  grid-template-columns: 1fr auto 1fr;
  align-items:center;
  gap:12px;
  padding:14px 14px 10px 14px;
  border-bottom:1px solid rgba(255,255,255,.08);
}
.postgameTopLeft{display:flex; gap:10px; justify-content:flex-start}
.postgameTopCenter{display:flex; flex-direction:column; align-items:center; gap:2px; min-width:0}
.postgameTopRight{display:flex; gap:10px; justify-content:flex-end}
.postgameWinnerLine{
  font-size: 34px;
  font-weight: 900;
  text-shadow: 0 10px 24px rgba(0,0,0,.55);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  max-width: 520px;
}
.postgameMetaLine{
  font-size: 13px;
  color: var(--muted);
  font-family: var(--mono);
}
.postgameTabs{
  display:flex;
  gap:8px;
  padding:10px 14px;
  border-bottom:1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.02);
  flex-wrap:wrap;
  justify-content:center;
}
.pgTab{
  border:1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.18);
  color: var(--text);
  padding:9px 12px;
  border-radius: 12px;
  cursor:pointer;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .2px;
}
.pgTab.active{
  border-color: rgba(74,163,255,.55);
  background: rgba(74,163,255,.14);
}
.postgameBody{
  flex:1;
  overflow:auto;
  padding:14px;
}

.pgTable{
  width:100%;
  border-collapse:collapse;
  font-size: 13px;
}
.pgTable th, .pgTable td{
  padding:10px 10px;
  border-bottom:1px solid rgba(255,255,255,.08);
  text-align:left;
  vertical-align:middle;
}
.pgTable th{
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .3px;
  font-family: var(--mono);
  font-weight: 700;
}
.pgName{
  display:flex;
  align-items:center;
  gap:10px;
  min-width:0;
}
.pgBadge{
  width:12px;
  height:12px;
  border-radius:999px;
  box-shadow: 0 0 0 3px rgba(255,255,255,.06) inset;
  flex:0 0 auto;
}
.pgMono{font-family: var(--mono)}
.pgNote{
  margin-top:10px;
  font-size: 12px;
  color: var(--muted);
}

/* keep the Show Stats button accessible over the board */
.rightHud #pgShowBtn{
  padding:8px 10px;
  font-size: 12px;
  border-radius: 12px;
  align-self:flex-end;
}

/* Postgame stats helpers */
.pgSection{
  margin-bottom: 16px;
}
.pgSectionHead{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:10px;
}
.pgSectionTitle{
  font-weight: 900;
  font-size: 14px;
  letter-spacing: .2px;
}
.pgControls{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
}
.pgControl{
  display:flex;
  gap:8px;
  align-items:center;
}
.pgControlLabel{
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  font-weight: 700;
}
.pgSelect{
  background: rgba(0,0,0,.25);
  border:1px solid rgba(255,255,255,.14);
  color: var(--text);
  padding:8px 10px;
  border-radius: 12px;
  font-weight: 900;
  font-size: 12px;
  cursor:pointer;
}
.pgSelect:focus{
  outline: none;
  border-color: rgba(74,163,255,.55);
}
.pgSubTabs{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  justify-content:center;
}
.pgSubTab{
  border:1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.18);
  color: var(--text);
  padding:8px 10px;
  border-radius: 12px;
  cursor:pointer;
  font-weight: 900;
  font-size: 11px;
  letter-spacing: .2px;
}
.pgSubTab.active{
  border-color: rgba(74,163,255,.55);
  background: rgba(74,163,255,.14);
}

/* Table bar-cells */
.pgBarCell{
  position:relative;
  height:22px;
  min-width: 84px;
  border-radius: 10px;
  background: rgba(255,255,255,.04);
  overflow:hidden;
  border:1px solid rgba(255,255,255,.06);
}
.pgBarFill{
  position:absolute;
  inset:0;
  width:0;
  border-radius: 10px;
}
.pgBarLabel{
  position:relative;
  z-index:1;
  display:flex;
  align-items:center;
  height:100%;
  padding:0 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: rgba(255,255,255,.92);
  text-shadow: 0 2px 10px rgba(0,0,0,.55);
}
.pgBarCell.right .pgBarLabel{
  justify-content:flex-end;
}
.pgBarStack{
  position:absolute;
  inset:0;
  display:flex;
}
.pgBarStackSeg{
  height:100%;
}
.pgBarCell.pgStack .pgBarFill{ display:none; }

/* Legend */
.pgLegend{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
  margin-bottom: 10px;
}
.pgLegendItem{
  display:flex;
  gap:6px;
  align-items:center;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  font-weight: 700;
}
.pgLegendDot{
  width:10px;
  height:10px;
  border-radius:999px;
  box-shadow: 0 0 0 3px rgba(255,255,255,.06) inset;
}

/* Postgame: Resources per-turn layout */
.pgThPlayer{
  display:flex;
  align-items:center;
  gap:8px;
  min-width: 0;
}

.pgResTurnTable{
  border-collapse: separate;
  border-spacing: 0 10px;
}
.pgResTurnTable th, .pgResTurnTable td{
  border-bottom: none;
  vertical-align: top;
  padding: 8px 10px;
}

.pgTurnCell, .pgRollCell{
  font-family: var(--mono);
  font-size: 12px;
  color: rgba(255,255,255,.92);
  white-space: nowrap;
}
.pgRollCell{ color: rgba(255,255,255,.82); }

.pgResTurnCard{
  display:flex;
  gap:14px;
  align-items:flex-end;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(255,255,255,.10);
  box-shadow:
    0 12px 30px rgba(0,0,0,.35),
    inset 0 1px 0 rgba(255,255,255,.06);
  min-width: 280px;
}

.pgResSlot{
  display:flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 46px;
}

.pgResIcon{
  width: 34px;
  height: 34px;
  object-fit: contain;
  filter: drop-shadow(0 10px 14px rgba(0,0,0,.45));
}

.pgResNums{
  margin-top: 6px;
  display:flex;
  gap: 6px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1;
}

.pgResTotal{ color: rgba(255,255,255,.92); }
.pgResDelta{ font-weight: 800; }
.pgResDelta.pos{ color: #57ff9a; }
.pgResDelta.neg{ color: #ff6a6a; }
.pgResDelta.zero{ color: rgba(255,255,255,.58); }




.pgReplayControls{
  display:flex;
  flex-direction:column;
  gap:8px;
  margin-bottom:12px;
  position: fixed;
  top: 88px;
  left: 12px;
  width: min(420px, calc(100vw - 24px));
  max-height: min(74vh, 620px);
  overflow: hidden;
  z-index: 66;
  padding: 10px;
  border-radius: 16px;
  background: rgba(17, 23, 34, 0.92);
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 20px 40px rgba(0,0,0,.45);
}
.pgReplayFloatTop{display:flex; align-items:center; gap:8px;}
.pgReplayFloatTitle{font-weight:900; letter-spacing:.2px;}
.pgReplayControlsBody{display:flex; flex-direction:column; gap:8px; overflow:auto; padding-right:2px;}
.pgReplayNav{display:flex; gap:8px; align-items:center; flex-wrap:wrap;}
.pgReplayMeta{font-family:var(--mono); color:var(--muted); font-size:11px; font-weight:700;}
.pgReplayText{font-size:12px; color:rgba(255,255,255,.9);}
.pgReplayPlayers{display:flex; gap:8px; flex-wrap:wrap;}
.pgReplayPlayerChip{
  border:1px solid rgba(255,255,255,.2);
  background:rgba(0,0,0,.18);
  color:var(--text);
  border-radius:999px;
  padding:6px 10px;
  font-size:11px;
  font-weight:800;
  cursor:pointer;
}
.pgReplayPlayerChip.active{background:rgba(74,163,255,.2);}
.pgCurrentPlayerBadge{
  margin:8px 0 0 auto;
  width:fit-content;
  border:1px solid rgba(255,255,255,.25);
  border-radius:999px;
  padding:6px 10px;
  font-size:11px;
  font-family:var(--mono);
  font-weight:800;
}

.pgReplayStepState{display:grid; grid-template-columns:1fr; gap:8px;}
.pgReplayResCard{border:1px solid rgba(255,255,255,.12); border-radius:12px; padding:8px; background:rgba(0,0,0,.2);}
.pgReplayResTitle{font-size:11px; font-family:var(--mono); color:var(--muted); margin-bottom:6px; font-weight:800;}
.pgReplayResGrid{display:flex; flex-wrap:wrap; gap:6px;}
.pgReplayResItem{font-size:11px; border:1px solid rgba(255,255,255,.12); border-radius:999px; padding:4px 8px; background:rgba(255,255,255,.04);}
.pgReplayResPlayerBtn{border:1px solid rgba(255,255,255,.2); background:rgba(0,0,0,.18); color:var(--text); border-radius:999px; padding:5px 9px; font-size:11px; font-weight:800; cursor:pointer;}
.pgReplayResPlayerBtn.active{background:rgba(74,163,255,.2);}
.pgReplayLog{border:1px solid rgba(255,255,255,.12); border-radius:12px; padding:8px; background:rgba(0,0,0,.2); display:flex; flex-direction:column; gap:6px; max-height:220px; overflow:auto;}
.pgReplayLogRow{text-align:left; border:1px solid rgba(255,255,255,.12); background:rgba(255,255,255,.03); color:var(--text); border-radius:10px; padding:6px 8px; font-size:11px; cursor:pointer;}
.pgReplayLogRow.active{border-color:rgba(74,163,255,.55); background:rgba(74,163,255,.16);}

/* User-adjustable scaling for tabbed overlays (Postgame + History) */
.postgameTabs,
.postgameBody,
.historyTabs,
.historyBody{
  zoom: var(--tab-ui-scale);
}

.tabScaleControl{
  display:flex;
  align-items:center;
  gap:6px;
  padding:4px 6px;
  border:1px solid rgba(255,255,255,.10);
  border-radius:12px;
  background: rgba(255,255,255,.03);
}
.tabScaleBtn{
  appearance:none;
  border:1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.18);
  color: var(--text);
  width:26px;
  height:26px;
  border-radius:10px;
  cursor:pointer;
  font-weight:900;
  line-height:1;
  padding:0;
}
.tabScaleBtn:hover{ filter:brightness(1.12); }
.tabScaleBtn:disabled{ opacity:.5; cursor:not-allowed; }
.tabScaleLabel{
  min-width:58px;
  text-align:center;
  font-family: var(--mono);
  font-size:11px;
  color: var(--muted);
  user-select:none;
}

/* History + Player Stats overlay */
.historyOverlay{
  position:fixed;
  inset:0;
  z-index: 4800;
  display:flex;
  align-items:center;
  justify-content:center;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
}
.historyOverlay.hidden{ display:none; }

.historyPanel{
  width: min(1100px, calc(100vw - 24px));
  height: min(760px, calc(100vh - 24px));
  border:1px solid rgba(255,255,255,.10);
  border-radius:18px;
  background: rgba(10,12,15,.92);
  box-shadow: 0 30px 90px rgba(0,0,0,.55);
  display:flex;
  flex-direction:column;
  overflow:hidden;
}

.historyTop{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:12px 14px;
  border-bottom:1px solid rgba(255,255,255,.08);
}

.historyTopCenter{ display:flex; flex-direction:column; align-items:center; gap:2px; min-width:0; flex:1; }
.historyTitle{ font-size:16px; font-weight:900; letter-spacing:.2px; }
.historySub{ font-size:12px; color: var(--muted); font-family: var(--mono); }

.historyTabs{
  display:flex;
  gap:8px;
  padding:10px 12px;
  border-bottom:1px solid rgba(255,255,255,.08);
  background: rgba(0,0,0,.12);
}

.hTab{
  padding:8px 10px;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.04);
  color: var(--text);
  cursor:pointer;
  font-weight:800;
  font-size:12px;
}
.hTab.active{
  background: rgba(74,163,255,.18);
  border-color: rgba(74,163,255,.32);
}

.historyBody{
  flex:1;
  overflow:auto;
  padding:12px;
}

.historyList{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.historyCard{
  border:1px solid rgba(255,255,255,.10);
  border-radius:14px;
  padding:10px 12px;
  background: rgba(0,0,0,.18);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}
.historyMeta{ display:flex; flex-direction:column; gap:4px; min-width:0; }
.historyLine1{ font-weight:900; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.historyLine2{ font-family: var(--mono); font-size:11px; color: var(--muted); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.historyActions{ display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end; }

.standingsTable{
  width:100%;
  border-collapse:separate;
  border-spacing:0;
}
.standingsTable th, .standingsTable td{
  padding:8px 10px;
  border-bottom:1px solid rgba(255,255,255,.08);
  font-size:12px;
  white-space:nowrap;
}
.standingsTable th{
  position:sticky;
  top:0;
  background: rgba(10,12,15,.96);
  z-index:2;
  text-align:left;
  cursor:pointer;
  user-select:none;
}
.standingsTable th.sortAsc::after{ content:" ▲"; font-size:10px; color: var(--muted); }
.standingsTable th.sortDesc::after{ content:" ▼"; font-size:10px; color: var(--muted); }

.standName{
  display:flex;
  align-items:center;
  gap:8px;
  min-width:0;
}
.standDot{
  width:10px; height:10px; border-radius:50%;
  flex:0 0 auto;
  background: #777;
  box-shadow:0 0 0 2px rgba(255,255,255,.10);
}
.standNameText{ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

.resourcesOverlay .panelScaleContent{ display:flex; flex-direction:column; gap:8px; }
.hudDevOverlay .panelScaleContent{ display:flex; flex-direction:column; gap:8px; }


/* Mobile / tablet playability (no desktop view needed) */
@media (hover:none) and (pointer:coarse), (max-width: 980px) {
  .layout{
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(300px, 44vh);
    gap:10px;
    padding:10px;
  }
  .panel{
    height:auto;
    max-height:56vh;
    padding-right:0;
    padding-bottom:8px;
  }
  .boardWrap{min-height:34vh;}
  .topbar{padding:10px 12px; flex-wrap:wrap; gap:8px;}
  .brand .title{font-size:17px;}
  .brand .subtitle, .status{font-size:12px;}
  .row{flex-wrap:wrap;}
  .btn, .input, select, button{font-size:16px;}
  .btn{padding:12px 14px;}
  .input{padding:12px 12px;}
  .hudTopLeft, .hudBottomLeft{left:4px;}
  .rightHud{top:4px; right:4px; gap:6px;}
  .resourcesOverlay{left:4px; top:48px; width:min(92vw, 360px); max-width:none;}
  .logOverlay{right:4px; top:48px; width:min(96vw, 560px); max-width:none;}
  .hudBar{padding:8px 10px; border-radius:14px; max-width:calc(100% - 8px);}
  .nodeBuildConfirm{max-width:calc(100vw - 12px);}
  .buildPopup{max-width:min(92vw, 320px);}
  .audioSfxPanel{right:4px; top:48px; width:min(96vw, 380px);}
  #cartographerDraftPanel{max-width:min(96vw, 380px) !important;}
}

@media (max-width: 640px) {
  .layout{grid-template-rows:auto minmax(260px, 38vh); padding:8px; gap:8px;}
  .card{padding:10px;}
  .roomCode{font-size:16px; letter-spacing:1px;}
  .resourcesOverlay, .logOverlay{top:auto; bottom:4px; width:min(96vw, 420px);}
  .logOverlay .logList{max-height:180px;}
  .rightHud .countdownClock{min-width:132px;}
  .clockTime{font-size:18px;}
}


/* S24 Ultra / tall portrait phone pass */
@media (hover:none) and (pointer:coarse) and (orientation: portrait) and (max-width: 460px) {
  body{overflow:hidden;}
  #app{height:100dvh;}
  .topbar{
    padding:calc(8px + var(--safe-top)) calc(10px + var(--safe-right)) 8px calc(10px + var(--safe-left));
    gap:6px;
  }
  .brand .title{font-size:16px;}
  .brand .subtitle{display:none;}
  .status{font-size:11px; gap:6px; flex-wrap:wrap;}
  .layout{
    padding:6px;
    gap:6px;
    grid-template-rows:auto minmax(240px, 40dvh);
  }
  .card{padding:10px;}
  .panel{max-height:52dvh; padding-bottom:6px;}
  .boardWrap{border-radius:12px;}

  body.in-game .layout{padding:0; gap:0;}
  body.in-game .boardWrap{border-radius:0;}
  body.in-game .topbar,
  body.in-game .topbar *{max-width:100%;}

  .hudBar{
    padding:6px 8px;
    border-radius:12px;
    max-width:calc(100% - 8px - var(--safe-left) - var(--safe-right));
  }
  .hudTopLeft{left:calc(4px + var(--safe-left)); top:4px;}
  .hudBottomLeft{left:calc(4px + var(--safe-left)); bottom:calc(4px + var(--safe-bottom));}
  .hudBarRow{gap:6px;}
  .hudBtns{gap:6px;}
  .btnTiny{padding:7px 9px; font-size:11px; border-radius:10px;}
  .hudTurnInfo{gap:8px;}
  .hudTurnInfo .turnInfo,
  .hudTurnInfo .timerInfo{font-size:11px; line-height:1.2;}

  .rightHud{right:calc(4px + var(--safe-right)); top:4px; gap:6px;}
  .countdownClock{min-width:124px; padding:6px 8px 8px; border-radius:12px;}
  .clockTime{font-size:17px; letter-spacing:.5px;}
  .clockMeta{font-size:10px;}
  .clockTopRow{gap:6px; margin-bottom:2px;}

  .resourcesOverlay{
    left:calc(4px + var(--safe-left));
    top:44px;
    width:min(calc(100vw - 8px - var(--safe-left) - var(--safe-right)), 360px);
    padding:10px;
  }
  .logOverlay{
    right:calc(4px + var(--safe-right));
    left:auto;
    top:auto;
    bottom:calc(4px + var(--safe-bottom));
    width:min(calc(100vw - 8px - var(--safe-left) - var(--safe-right)), 388px);
    padding:10px;
  }
  .logOverlay .logList{max-height:28dvh;}
  .hudDevOverlay{
    left:calc(4px + var(--safe-left));
    width:min(calc(100vw - 8px - var(--safe-left) - var(--safe-right)), 388px);
    max-height:42dvh;
    top:104px;
    padding:10px;
  }
  .audioSfxPanel{
    right:calc(4px + var(--safe-right));
    top:44px;
    width:min(calc(100vw - 8px - var(--safe-left) - var(--safe-right)), 388px);
  }
  #cartographerDraftPanel{
    left:calc(4px + var(--safe-left)) !important;
    right:auto !important;
    bottom:calc(4px + var(--safe-bottom)) !important;
    width:min(calc(100vw - 8px - var(--safe-left) - var(--safe-right)), 388px) !important;
    max-width:min(calc(100vw - 8px - var(--safe-left) - var(--safe-right)), 388px) !important;
  }

  /* tighter modal controls while keeping touch targets usable */
  .btn, .input, select, button{font-size:15px;}
  .btn{padding:11px 12px;}
  .input{padding:11px 11px;}
}

@media (hover:none) and (pointer:coarse) and (orientation: portrait) and (max-width: 430px) {
  .resourcesOverlay .pResGrid,
  .resourcesOverlay .pPieceGrid{font-size:10px;}
  .resourcesOverlay .resIcon{width:16px; height:16px;}
  .resourcesOverlay .resVal{font-size:11px;}
  .hudBarScaleHost .tabScaleLabel,
  .panelScaleHost .tabScaleLabel{min-width:46px;}
}

@media (max-width: 1180px){
  :root{--right-sidebar-width: min(420px, 40vw);}
  body.in-game .boardWrap{padding-right:var(--right-sidebar-width, 420px);}
}

@media (max-width: 900px){
  :root{--right-sidebar-width: min(340px, 44vw);}
  .rightSidebarResize{flex-basis:6px; width:6px;}
  body.in-game .rightHud{right:calc(var(--right-sidebar-width, 340px) + 6px);}
}
