:root{
  --bg:#0b0b0d;
  --panel:#101014;
  --line:#22242a;
  --text:#e7e7ea;
  --muted:#a6a6b0;
  --btn:#14151a;
  --btn2:#1a1c22;
  --focus:#79a7ff;
  --accent:#d8bd7e;
  --combat-h:126px;
  --hud-h:72px;
  --side-w:328px;
  --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);
  --ui-font:'Source Sans 3', 'Segoe UI', Tahoma, sans-serif;
}

*{box-sizing:border-box;}
html,body{
  height:100%;
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:var(--ui-font);
  font-size:15px;
  -webkit-text-size-adjust:100%;
}
body{
  padding:var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

#hud{
  position:relative;
  padding:10px 14px;
  border-bottom:1px solid var(--line);
}
#hudTitle{
  font-family:'Cinzel','Trajan Pro','Times New Roman',serif;
  font-weight:700;
  letter-spacing:0.09em;
  font-size:clamp(34px, 1.8vw + 8px, 56px);
  text-transform:uppercase;
  text-align:center;
  width:calc(100% - var(--side-w));
  margin:0 auto 0 0;
}
#hudMeta{
  position:absolute;
  right:16px;
  top:8px;
  margin-top:0;
  color:#ece5cf;
  font-size:14px;
  line-height:1.3;
  font-weight:700;
  text-align:right;
  white-space:nowrap;
  padding:4px 8px;
  border:1px solid rgba(216,189,126,0.25);
  border-radius:10px;
  background:rgba(11,14,20,0.55);
}
#hudLast{
  margin-top:8px;
  font-size:13px;
  border-top:1px dashed rgba(255,255,255,0.08);
  padding-top:7px;
  display:none;
}

#layout{
  display:grid;
  grid-template-columns: 1fr var(--side-w);
  height: calc(100% - var(--hud-h) - var(--combat-h));
  height: calc(100dvh - var(--hud-h) - var(--combat-h));
  min-height:0;
}

#canvasWrap{
  position:relative;
  display:flex;
  flex-direction:column;
  gap:6px;
  min-height:0;
}
#boardStage{
  position:relative;
  min-height:0;
  flex:1 1 auto;
}
#c{
  display:block;
  width:100%;
  height:100%;
  touch-action:manipulation;
  -webkit-user-select:none;
  user-select:none;
  -webkit-tap-highlight-color:transparent;
}

#cornerDiceHud{
  position:absolute;
  top:8px;
  left:8px;
  z-index:6;
  pointer-events:none;
  display:none;
  padding:4px 6px;
  border-radius:10px;
  border:1px solid rgba(255,255,255,0.18);
  background:rgba(8,10,14,0.5);
  backdrop-filter:blur(2px);
}

#boardDiceDock{
  position:relative;
  z-index:5;
  width:min(92%, 560px);
  margin:0 auto 4px;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:6px;
  pointer-events:none;
}

#boardDiceDock .physicalDiceRow{
  width:100%;
  min-height:64px;
  padding:9px 11px;
  border-color:rgba(216,189,126,0.28);
  background:rgba(8,10,14,0.62);
  backdrop-filter:blur(2px);
}

#boardDiceResult{
  min-height:16px;
  font-size:13px;
  color:#d3d9e4;
  letter-spacing:0.02em;
  text-align:center;
}

#boardDiceDock .physicalDie{
  width:56px;
  height:56px;
}

#cornerDiceHud.combat-active{
  border-color:rgba(216,189,126,0.92);
  box-shadow:0 0 0 1px rgba(216,189,126,0.2), 0 0 20px rgba(216,189,126,0.25);
}

body[data-combat="on"] #hudMeta{
  color:#d8bd7e;
}

#cornerDiceRow{
  min-height:0;
  padding:0;
  gap:5px;
  border:none;
  background:transparent;
}

#cornerDiceRow .cornerDie{
  width:24px;
  height:24px;
  border-radius:6px;
}

#cornerDiceRow .cornerDie .physicalFace{
  inset:3px;
  border-radius:4px;
}

#cornerDiceRow .cornerDie .physicalPip{
  width:4px;
  height:4px;
}

#side{
  position:relative;
  border-left:1px solid var(--line);
  padding:8px;
  display:flex;
  flex-direction:column;
  overflow:auto;
  -webkit-overflow-scrolling:touch;
  overscroll-behavior:contain;
}

body[data-mode="play"] #side{
  overflow:auto;
}

#setupStageBanner{
  order:0;
  border:1px solid rgba(216,189,126,0.35);
  background:linear-gradient(180deg, rgba(216,189,126,0.12), rgba(216,189,126,0.04));
  border-radius:12px;
  padding:9px 10px;
  margin-bottom:8px;
  text-align:center;
}

.setupStageTitle{
  color:var(--accent);
  font-family:'Cinzel','Trajan Pro','Times New Roman',serif;
  text-transform:uppercase;
  letter-spacing:0.08em;
  font-weight:700;
  font-size:14px;
}

.setupStageSub{
  margin-top:3px;
  color:#d9dce5;
  font-size:12px;
  line-height:1.3;
}

.panel{
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:12px;
  padding:8px;
  margin-bottom:8px;
}

.panelTitle{
  font-size:13px;
  letter-spacing:0.08em;
  text-transform:uppercase;
  color:var(--accent);
  font-weight:700;
  margin-bottom:8px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
}

.panelToggleBtn{
  appearance:none;
  border:1px solid var(--line);
  background:rgba(255,255,255,0.02);
  color:var(--muted);
  border-radius:999px;
  padding:2px 8px;
  font-size:10px;
  letter-spacing:0.08em;
  text-transform:uppercase;
  font-weight:700;
  cursor:pointer;
}

.panelToggleBtn:hover{
  background:rgba(255,255,255,0.06);
  color:var(--text);
}

.panel.panel-collapsed{
  padding-bottom:9px;
}

.panel.panel-collapsed > :not(.panelTitle){
  display:none !important;
}

.panel.panel-collapsed .panelTitle{
  margin-bottom:0;
}

.row{display:flex;gap:6px;align-items:center;margin:5px 0;flex-wrap:wrap;}
.label{width:88px;color:var(--muted);font-size:11px;letter-spacing:0.05em;text-transform:uppercase;}
#side{
  font-family:var(--ui-font);
}
#side .label{
  color:var(--text);
  font-size:14px;
  font-weight:700;
  letter-spacing:0.01em;
  text-transform:none;
}
#turnOrdersPanel .label{
  color:var(--text);
  font-size:13px;
  font-weight:700;
  letter-spacing:0.01em;
  text-transform:none;
}

.btn{
  background:var(--btn);
  color:var(--text);
  border:1px solid var(--line);
  border-radius:10px;
  padding:8px 10px;
  font-family:var(--ui-font);
  font-size:13px;
  font-weight:400;
  letter-spacing:0.01em;
  cursor:pointer;
}
.btn,.select,.input{min-height:34px;}
.btn:hover{background:var(--btn2);}
.btn.active{outline:2px solid var(--focus);}
.btn.wide{flex:1;justify-content:center;}

.btnHero{
  min-height:40px;
  font-size:14px;
  font-weight:700;
  letter-spacing:0.02em;
  border-color:rgba(216,189,126,0.45);
  background:linear-gradient(180deg, rgba(216,189,126,0.2), rgba(216,189,126,0.08));
}

.btnHero:hover{
  background:linear-gradient(180deg, rgba(216,189,126,0.3), rgba(216,189,126,0.12));
}

.btn:disabled{
  opacity:0.45;
  cursor:not-allowed;
}
.btn:disabled:hover{background:var(--btn);}

.btnGrid{display:grid;grid-template-columns:repeat(5, 1fr);gap:6px;flex:1;}
.editorOnly .btnGrid{grid-template-columns:repeat(3, 1fr);}

.select{
  flex:1;
  background:var(--btn);
  color:var(--text);
  border:1px solid var(--line);
  border-radius:10px;
  padding:8px 10px;
  font-size:13px;
  font-family:var(--ui-font);
  font-weight:400;
  letter-spacing:0.01em;
  appearance:none;
  -webkit-appearance:none;
}

.monoVal{
  flex:1;
  min-height:36px;
  display:flex;
  align-items:center;
  padding:6px 10px;
  border:1px solid var(--line);
  border-radius:10px;
  background:#0d0f15;
  color:#c5d4f7;
  font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size:12px;
  word-break:break-all;
}

.roomCode{
  justify-content:center;
  letter-spacing:0.22em;
  font-size:20px;
  font-weight:800;
  color:#e7f0ff;
}

.roomCode.empty{
  letter-spacing:0.08em;
  font-size:13px;
  font-weight:650;
  color:var(--muted);
}

.input{
  flex:1;
  background:var(--btn);
  color:var(--text);
  border:1px solid var(--line);
  border-radius:10px;
  padding:8px 10px;
  font-size:13px;
  font-family:var(--ui-font);
  font-weight:400;
}

.note{
  color:var(--muted);
  font-size:12px;
  line-height:1.35;
  margin-top:8px;
}

.doctrineList{
  display:flex;
  flex-direction:column;
  gap:6px;
  margin-top:6px;
}

.ordersExplainList{
  margin-top:8px;
  border:1px solid var(--line);
  border-radius:10px;
  background:rgba(255,255,255,0.02);
  padding:8px;
  max-height:220px;
  overflow:auto;
}

.ordersExplainEmpty{
  color:var(--muted);
  font-size:12px;
  line-height:1.35;
}

.ordersExplainTier{
  margin:0 0 10px;
}

.ordersExplainTier:last-child{
  margin-bottom:0;
}

.ordersExplainTierTitle{
  color:#f0ddae;
  font-size:11px;
  font-weight:700;
  letter-spacing:0.07em;
  text-transform:uppercase;
  margin:0 0 6px;
}

.ordersExplainItem{
  border:1px solid rgba(255,255,255,0.08);
  border-radius:8px;
  background:rgba(255,255,255,0.02);
  padding:7px 8px;
  margin-bottom:6px;
}

.ordersExplainItem:last-child{
  margin-bottom:0;
}

.ordersExplainHead{
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:8px;
}

.ordersExplainName{
  color:#e9edf9;
  font-size:12px;
  font-weight:700;
  line-height:1.25;
}

.ordersExplainMeta{
  color:#aeb4c5;
  font-size:11px;
  line-height:1.2;
  white-space:nowrap;
}

.ordersExplainBody{
  margin-top:4px;
  color:#d5d9e4;
  font-size:12px;
  line-height:1.35;
}

.ordersExplainLayman{
  margin-top:4px;
  color:#edf1fb;
  font-size:12px;
  line-height:1.35;
}

.doctrineChip{
  border:1px solid var(--line);
  border-radius:8px;
  padding:6px 8px;
  font-size:12px;
  line-height:1.25;
  color:#dde2ef;
  background:rgba(255,255,255,0.02);
}

.doctrineChip .monoVal{
  margin-right:8px;
}

.doctrineChip.spent{
  opacity:0.66;
  text-decoration:line-through;
}

.doctrineChip.hidden{
  color:#a3a8b5;
  background:rgba(255,255,255,0.01);
}

.doctrineCard{
  padding:0;
}

.doctrineBuilderGrid{
  display:grid;
  grid-template-columns:repeat(3, minmax(0, 1fr));
  gap:8px;
  padding:8px 10px;
  overflow:auto;
  flex:1;
}

.doctrineCostCol{
  border:1px solid var(--line);
  border-radius:10px;
  background:rgba(255,255,255,0.02);
  padding:8px;
  min-height:0;
  display:flex;
  flex-direction:column;
}

.doctrineCostCol.is-complete{
  border-color:rgba(88,176,108,0.92);
  box-shadow:inset 0 0 0 1px rgba(88,176,108,0.28);
}

.doctrineCostCol.is-complete h3{
  color:#9de0ae;
}

.doctrineCostCol.is-incomplete{
  border-color:var(--line);
}

#doctrineOverlay input[type="checkbox"]{
  accent-color:#59b06c;
}

.doctrineCostCol h3{
  margin:0 0 8px;
  color:#f0ddae;
  font-size:12px;
  letter-spacing:0.04em;
  text-transform:uppercase;
}

.doctrineBuilderList{
  display:flex;
  flex-direction:column;
  gap:6px;
  overflow:auto;
}

.doctrinePick{
  display:flex;
  align-items:flex-start;
  gap:6px;
  border:1px solid var(--line);
  border-radius:8px;
  padding:7px;
  background:rgba(255,255,255,0.02);
}

.doctrinePickActive{
  border-color:rgba(121,167,255,0.65);
  box-shadow:0 0 0 1px rgba(121,167,255,0.26) inset;
  background:rgba(121,167,255,0.08);
}

.doctrinePick input{
  margin-top:2px;
}

.doctrinePickName{
  display:block;
  color:#e9edf9;
  font-size:12px;
  font-weight:700;
  line-height:1.2;
}

.doctrinePickMeta{
  display:block;
  color:#aeb4c5;
  font-size:11.5px;
  line-height:1.2;
  margin-top:2px;
}

.doctrinePickExplain{
  display:block;
  color:#dde1eb;
  font-size:11.5px;
  line-height:1.34;
  margin-top:5px;
}

.doctrinePickGroup{
  margin:6px 0 4px;
  color:#f0ddae;
  font-size:11px;
  letter-spacing:0.06em;
  text-transform:uppercase;
  font-weight:700;
}

.doctrineExplain{
  margin:8px 10px 2px;
  padding:9px 10px;
  border:1px solid var(--line);
  border-radius:10px;
  background:rgba(255,255,255,0.03);
  color:#d8dbe6;
  font-size:12px;
  line-height:1.36;
}

.doctrineExplainTitle{
  color:#edf1fb;
  font-size:12px;
  font-weight:700;
  margin-bottom:4px;
}

.doctrineExplainTarget{
  color:#aeb4c5;
  font-size:11px;
  margin-top:5px;
}

#statusPanel{display:none;}

.statusMeta{
  color:var(--muted);
  font-size:12px;
  line-height:1.4;
  white-space:pre-line;
  word-break:break-word;
}

.statusLast{
  margin-top:8px;
  padding-top:8px;
  border-top:1px dashed rgba(255,255,255,0.08);
  font-size:12px;
  line-height:1.35;
}

.draftStatus{
  display:none;
  color:var(--muted);
  font-size:12px;
  line-height:1.35;
  margin-top:8px;
  border-top:1px dashed rgba(255,255,255,0.08);
  padding-top:8px;
}

.details{
  border:1px solid var(--line);
  border-radius:10px;
  padding:8px;
  margin-top:8px;
  background:rgba(255,255,255,0.02);
}

.details > summary{
  cursor:pointer;
  color:var(--text);
  font-size:12px;
  font-weight:650;
}

.details[open] > summary{
  margin-bottom:8px;
}

.rulesSideOverlay{
  position:absolute;
  inset:0;
  z-index:50;
  display:none;
  padding:8px;
  background:rgba(8, 9, 12, 0.70);
  backdrop-filter:blur(1.5px);
}

.rulesSideOverlay.open{
  display:block;
}

#doctrineOverlay.rulesSideOverlay{
  position:fixed;
  inset:0;
  z-index:240;
  display:none;
  align-items:center;
  justify-content:center;
  padding:clamp(14px, 2.4vw, 34px);
  background:rgba(6,8,12,0.42);
  backdrop-filter:blur(8px) saturate(112%);
  -webkit-backdrop-filter:blur(8px) saturate(112%);
}

#doctrineOverlay.rulesSideOverlay.open{
  display:flex;
}

#doctrineOverlay .rulesSideCard.doctrineCard{
  width:min(82vw, 1420px);
  height:min(88vh, 980px);
  max-height:calc(100dvh - 26px);
  border-radius:14px;
  box-shadow:0 24px 64px rgba(0,0,0,0.58);
}

#doctrineOverlay .rulesSideHead{
  padding:12px 12px 10px;
}

#doctrineOverlay .rulesSideHead h2{
  font-size:16px;
}

#doctrineOverlay .doctrineBuilderGrid{
  gap:12px;
  padding:10px 14px;
}

#doctrineOverlay .doctrineCostCol{
  padding:11px;
}

.rulesSideCard{
  height:100%;
  background:linear-gradient(180deg, rgba(15, 16, 22, 0.98), rgba(10, 11, 17, 0.98));
  border:1px solid var(--line);
  border-radius:12px;
  display:flex;
  flex-direction:column;
  overflow:hidden;
}

.rulesSideHead{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  padding:10px 10px 8px;
  border-bottom:1px solid var(--line);
}

.rulesSideHead h2{
  margin:0;
  color:var(--accent);
  font-size:14px;
  letter-spacing:0.05em;
  text-transform:uppercase;
}

.rulesSideTabs{
  display:grid;
  grid-template-columns:repeat(3, minmax(0, 1fr));
  gap:6px;
  padding:8px 10px;
  border-bottom:1px solid var(--line);
}

.rulesSideTabs .btn{
  min-height:34px;
  padding:6px 8px;
  font-size:12px;
}

.rulesSideTabs .btn.active{
  outline:2px solid var(--focus);
}

.rulesSideBody{
  overflow:auto;
  padding:12px 10px 12px;
}

.rulesDoc{
  display:none;
}

.rulesDoc.active{
  display:block;
}

.rulesDoc h3{
  margin:0 0 8px;
  color:#f0ddae;
  font-size:13px;
  letter-spacing:0.04em;
  text-transform:uppercase;
}

.rulesDoc p,
.rulesDoc li{
  color:#d7d9e0;
  font-size:13px;
  line-height:1.46;
}

.rulesDoc ul{
  margin:0 0 12px;
  padding-left:18px;
}

.rulesDoc p{
  margin:0 0 12px;
}

.rulesCommandTier{
  margin-bottom:14px;
  padding-bottom:10px;
  border-bottom:1px dashed rgba(255,255,255,0.1);
}

.rulesCommandTier:last-child{
  border-bottom:none;
  margin-bottom:0;
  padding-bottom:0;
}

.rulesCommandColumns{
  display:grid;
  grid-template-columns:1fr;
  gap:10px;
}

.rulesCommandColumns h4{
  margin:0 0 6px;
  font-size:12px;
  color:#e7d39f;
  letter-spacing:0.04em;
  text-transform:uppercase;
}

.rulesCommandList{
  margin:0;
  padding-left:16px;
}

.rulesCommandList li{
  margin:0 0 8px;
}

.rulesCommandTag{
  color:#9fc1ff;
  font-size:11px;
  letter-spacing:0.02em;
}

.rulesCommandScopeRow{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px;
  margin:8px 0 6px;
}

#turnOrdersPanel{
  order:2;
  padding:8px 9px;
}
#turnOrdersPanel .panelTitle{
  margin-bottom:5px;
}
#turnOrdersPanel .row{
  margin:4px 0;
  gap:6px;
  flex-wrap:nowrap;
}
#turnOrdersPanel .label{
  width:58px;
  font-size:12px;
}
#turnOrdersPanel .btn,
#turnOrdersPanel .select{
  min-height:32px;
  padding:5px 8px;
  font-size:12px;
}
#turnOrdersPanel .btn.wide{
  min-height:33px;
}
#defensePanel{
  order:99;
  padding:8px 9px;
  display:none !important;
}
#defensePanel .combatMeta{
  font-size:11px;
  line-height:1.2;
}
#rulesPanel{order:1;}
#scenarioPanel{order:3;}
#setupPanel{order:4;}
#ordersPanel{order:5;}
#statusPanel{order:6;}
#editorPanel{order:7;}
#doctrineIntelPanel{
  order:8;
  display:none !important;
}
#dicePanel{
  display:none !important;
}

.inspectorTitle{
  flex:1;
  font-size:14px;
  font-weight:650;
}

.inspectorMeta{
  color:var(--muted);
  font-size:12px;
  line-height:1.3;
  margin-top:2px;
  margin-bottom:4px;
}

.inspectorGrid{
  display:grid;
  grid-template-columns:auto 1fr;
  column-gap:10px;
  row-gap:6px;
}

.inspectorKey{
  color:var(--muted);
  font-size:11px;
  letter-spacing:0.04em;
  text-transform:uppercase;
}

.inspectorVal{
  font-size:12px;
  font-weight:600;
  word-break:break-word;
}

.diceSummary{
  flex:1;
  color:var(--muted);
  font-size:12px;
  line-height:1.35;
  min-height:2.7em;
}

.diceTray{
  display:grid;
  grid-template-columns:repeat(auto-fill, minmax(40px, 1fr));
  gap:8px;
  margin-top:6px;
}

.physicalDiceRow{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  min-height:58px;
  align-items:center;
  justify-content:center;
  padding:8px 10px;
  border:1px solid rgba(255,255,255,0.14);
  border-radius:10px;
  background:rgba(255,255,255,0.025);
}

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

.physicalDie{
  --dice-rot: 0deg;
  width:52px;
  height:52px;
  border-radius:11px;
  border:1px solid #9ca5b6;
  background:#edf1f7;
  box-shadow:
    0 2px 6px rgba(0,0,0,0.24),
    inset 0 1px 0 rgba(255,255,255,0.72);
  transform:rotate(var(--dice-rot));
  position:relative;
  overflow:hidden;
}

.physicalDie::after{
  display:none;
}

.physicalDie.hit{border-color:#2b8f52;}
.physicalDie.retreat{border-color:#b98018;}
.physicalDie.disarray{border-color:#b046d6;}
.physicalDie.miss{border-color:#555963;}

.physicalDie.rolling{
  animation:physicalDiceRoll 180ms ease-in-out infinite alternate;
}

.physicalFace{
  position:absolute;
  inset:6px;
  border-radius:8px;
  background:#f6f8fc;
  box-shadow:inset 0 1px 0 rgba(255,255,255,0.8);
  display:grid;
  grid-template-columns:repeat(3, 1fr);
  grid-template-rows:repeat(3, 1fr);
}

.physicalPip{
  width:7px;
  height:7px;
  border-radius:50%;
  margin:auto;
  background:#1a1e26;
  opacity:0;
  box-shadow:none;
}

.physicalPip.on{opacity:1;}

.die{
  aspect-ratio:1 / 1;
  border:1px solid var(--line);
  border-radius:9px;
  background:linear-gradient(165deg, #ffffff 0%, #ededf1 62%, #dfe1e8 100%);
  box-shadow:inset 0 1px 0 rgba(255,255,255,0.9), 0 2px 5px rgba(0,0,0,0.35);
  position:relative;
  overflow:hidden;
  transform:translateZ(0);
  transition:border-color 120ms ease, box-shadow 120ms ease;
}

.die.hit{border-color:#2b8f52;}
.die.retreat{border-color:#b98018;}
.die.disarray{border-color:#b046d6;}
.die.miss{border-color:#555963;}

.die.rolling{
  border-color:#757986;
  animation:dieRoll 210ms ease-in-out infinite alternate;
}

.dieFace{
  width:100%;
  height:100%;
  padding:5px;
  display:grid;
  grid-template-columns:repeat(3, 1fr);
  grid-template-rows:repeat(3, 1fr);
  transition:opacity 100ms ease;
}

.pip{
  width:7px;
  height:7px;
  border-radius:50%;
  margin:auto;
  background:#111317;
  opacity:0;
}

.pip.on{opacity:1;}

.dieBadge{
  position:absolute;
  right:4px;
  bottom:3px;
  font-size:9px;
  font-weight:700;
  color:#1b1c22;
  text-shadow:0 1px 0 rgba(255,255,255,0.55);
  letter-spacing:0.02em;
}

@keyframes dieRoll{
  0%{transform:translateY(0) rotate(0deg);}
  50%{transform:translateY(-2px) rotate(7deg);}
  100%{transform:translateY(1px) rotate(-7deg);}
}

@keyframes physicalDiceRoll{
  0%{transform:translateY(0) rotate(calc(var(--dice-rot) - 5deg));}
  100%{transform:translateY(1px) rotate(calc(var(--dice-rot) + 5deg));}
}

#combatRail{
  min-height:0;
  height:var(--combat-h);
  max-height:var(--combat-h);
  border-top:1px solid var(--line);
  background:#0f1116;
  padding:7px 10px 8px;
  display:grid;
  grid-template-columns:
    minmax(0, 1.15fr)
    minmax(0, 0.9fr)
    minmax(0, 0.95fr)
    minmax(0, 1fr)
    minmax(0, 0.85fr)
    minmax(0, 1.05fr);
  gap:8px;
  align-items:stretch;
  overflow:hidden;
}

.combatCol{
  border:1px solid rgba(255,255,255,0.12);
  border-radius:10px;
  background:#12151d;
  padding:6px 8px;
  display:flex;
  flex-direction:column;
  gap:4px;
  min-width:0;
  overflow:hidden;
}

.combatColBreakdown,
#selectedUnitPanel{
  overflow:auto;
}

.combatColOutcome,
.combatColOnline{
  overflow:auto;
}

.combatColTitle{
  font-size:11px;
  letter-spacing:0.08em;
  text-transform:uppercase;
  color:var(--accent);
  font-weight:700;
}

.combatSummary{
  font-size:12px;
  font-weight:650;
  line-height:1.3;
}

.combatMeta{
  font-size:12px;
  color:#cfd3de;
  line-height:1.3;
}

.combatHint{
  display:none;
}

.combatColDice .physicalDiceRow{
  width:100%;
  min-height:54px;
  padding:8px;
  gap:8px;
}

.combatColDice .physicalDie{
  width:38px;
  height:38px;
}

.combatColInspector .inspectorMeta{
  margin-bottom:4px;
}

.combatColInspector .inspectorGrid{
  row-gap:2px;
}

.combatColOnline .btn,
.combatColOnline .input,
.combatColOnline .select{
  min-height:24px;
  padding:3px 6px;
  font-size:11px;
}

.combatColOnline .btn{
  min-width:64px;
}

.combatColModifiers .combatMeta{
  font-size:12px;
  line-height:1.35;
}

.combatColOnline .roomCode{
  font-size:11px;
  letter-spacing:0.14em;
  min-height:24px;
  padding:2px 6px;
}

.combatColOnline .rowCode{
  justify-content:flex-start;
}

.onlineRow{
  display:grid;
  grid-template-columns:40px minmax(0, 1fr) auto;
  align-items:center;
  gap:6px;
}

.onlineRow .monoVal{
  min-width:0;
}

.onlineLabel{
  color:var(--muted);
  font-size:10px;
  letter-spacing:0.04em;
  text-transform:uppercase;
}

.onlineDraftBtns{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:4px;
}

.onlineStatusLine{
  color:var(--muted);
  font-size:11px;
  line-height:1.2;
  min-height:1.2em;
}

#onlineStatus,
.onlineStatusLine{
  display:none !important;
}

#selectedUnitPanel #inspectorMeta{
  display:none !important;
}

.combatColBreakdown{max-width:none;}

#combatRail.no-online{
  grid-template-columns:
    minmax(0, 1.2fr)
    minmax(0, 0.95fr)
    minmax(0, 1fr)
    minmax(0, 1fr)
    minmax(0, 0.9fr);
}

#combatRail.no-online .combatColOnline{
  display:none;
}

@media (max-width: 1200px){
  :root{ --side-w:306px; }
}

@media (max-width: 980px){
  :root{
    --combat-h:auto;
    --side-w:0px;
  }
  #layout{
    grid-template-columns:1fr;
    grid-template-rows:minmax(320px, 58dvh) auto;
    height:auto;
    min-height:0;
  }
  .rulesCommandColumns{
    grid-template-columns:1fr;
  }
  #canvasWrap{
    min-height:320px;
    height:min(58dvh, 620px);
  }
  #side{
    border-left:none;
    border-top:1px solid var(--line);
    max-height:min(48dvh, 420px);
  }
  .doctrineBuilderGrid{
    grid-template-columns:1fr;
  }
  #doctrineOverlay .rulesSideCard.doctrineCard{
    width:min(96vw, 740px);
    height:min(92vh, 980px);
  }
  .label{width:80px;}
  #combatRail{
    height:auto;
    max-height:min(38dvh, 340px);
    grid-template-columns:1fr;
    gap:8px;
  }
}

@media (max-width: 760px){
  #hud{padding:12px;}
  #hudMeta,#hudLast{font-size:12px;}
  #hudMeta{
    position:static;
    margin-top:6px;
    text-align:left;
    white-space:normal;
  }
  #layout{grid-template-rows:minmax(280px, 52dvh) auto;}
  #canvasWrap{
    min-height:280px;
    height:min(52dvh, 520px);
  }
  #side{
    padding:10px;
    max-height:none;
  }
  .row{gap:6px;}
  .label{
    width:100%;
    margin-bottom:2px;
  }
  #turnOrdersPanel .row{
    flex-wrap:wrap;
    margin:6px 0;
  }
  #turnOrdersPanel .label{
    width:100%;
  }
  .btnGrid{grid-template-columns:repeat(2, 1fr);}
  .editorOnly .btnGrid{grid-template-columns:repeat(2, 1fr);}
  .roomCode{font-size:18px;}
  .combatColDice .physicalDie{
    width:48px;
    height:48px;
  }
  .rulesSideOverlay{
    padding:6px;
  }
}

@media (hover: none) and (pointer: coarse){
  :root{ --hud-h:56px; }
  #hud{
    padding:10px 14px 8px;
  }
  #hudMeta,
  #hudLast{
    display:none;
  }
  #statusPanel{
    display:block;
  }
}

@media (orientation: landscape) and (max-width: 1400px){
  #cornerDiceHud.has-roll{
    display:flex;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: portrait){
  :root{ --hud-h:48px; }
  #hud{
    padding:8px 12px 6px;
  }
  #hudTitle{
    font-size:18px;
    letter-spacing:0.1em;
  }
}

body[data-mode="play"] .editorOnly{
  display:none;
}

body[data-mode="play"] #setupPanel{
  display:none;
}

body[data-mode="play"] #scenarioPanel{
  display:none;
}

body[data-mode="play"] #setupStageBanner{
  display:none;
}

body[data-mode="edit"] .playOnlyRow{
  display:none !important;
}

body[data-mode="edit"] #commandPhaseNote{
  display:none;
}
