:root {
  --monster-shell-gap: clamp(8px, 1vw, 14px);
  --monster-shell-edge: clamp(8px, 1.25vw, 18px);
  --monster-rail-width: clamp(218px, 18vw, 268px);
  --monster-intel-width: clamp(236px, 20vw, 296px);
  --monster-command-height: clamp(128px, 18vh, 184px);
}

body.monster-master-match-active {
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

body.monster-master-match-active::before {
  opacity: .15;
}

body.monster-master-match-active .monster-master-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
  margin: 0;
  padding: var(--monster-shell-edge);
  gap: var(--monster-shell-gap);
}

body.monster-master-match-active .monster-master-shell > .hero {
  display: flex;
  align-items: center;
  min-height: 48px;
  margin: 0;
  padding: 0 4px;
}

body.monster-master-match-active .monster-master-shell > .hero h1 {
  font-size: clamp(1.18rem, 2vw, 1.7rem);
  line-height: 1;
  letter-spacing: -.025em;
}

body.monster-master-match-active .monster-master-shell > .hero .eyebrow {
  margin-bottom: 3px;
  font-size: .56rem;
}

body.monster-master-match-active .monster-master-shell > .hero .hero-copy {
  display: none;
}

body.monster-master-match-active .combat-nav a {
  min-height: 34px;
  padding: 7px 11px;
  font-size: .72rem;
}

body.monster-master-match-active #monster-master-error {
  position: fixed;
  top: 62px;
  left: 50%;
  z-index: 80;
  width: min(720px, calc(100% - 24px));
  margin: 0;
  transform: translateX(-50%);
  box-shadow: 0 18px 46px rgba(0, 0, 0, .55);
}

#monster-master-match.monster-master-game-shell {
  position: relative;
  min-height: 0;
}

body.monster-master-match-active #monster-master-match.monster-master-game-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(16, 24, 42, .96), rgba(7, 11, 19, .98)),
    var(--panel);
  backdrop-filter: blur(20px);
}

.monster-master-match-topbar {
  display: grid;
  grid-template-columns: minmax(180px, auto) minmax(260px, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 58px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(87, 112, 164, .35);
  background: rgba(7, 12, 23, .82);
}

.monster-master-match-topbar .match-header {
  min-width: 0;
}

.monster-master-match-topbar .section-label {
  margin-bottom: 2px;
  font-size: .56rem;
}

.monster-master-match-topbar h2 {
  font-size: clamp(1rem, 1.6vw, 1.32rem);
}

.monster-master-match-topbar .revision {
  padding: 5px 8px;
  font-size: .66rem;
}

.monster-master-match-topbar .status {
  min-height: 38px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid rgba(101, 145, 216, .22);
  background: rgba(32, 55, 94, .34);
  font-size: .78rem;
}

.monster-master-utility-menu {
  position: relative;
  z-index: 40;
}

.monster-master-utility-menu > summary {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(112, 150, 213, .35);
  border-radius: 11px;
  background: rgba(22, 35, 59, .9);
  color: #dceaff;
  cursor: pointer;
  font-size: 0;
  list-style: none;
}

.monster-master-utility-menu > summary::-webkit-details-marker { display: none; }
.monster-master-utility-menu > summary::before { content: "•••"; font-size: .9rem; letter-spacing: .08em; }
.monster-master-utility-menu[open] > summary,
.monster-master-utility-menu > summary:hover,
.monster-master-utility-menu > summary:focus-visible {
  border-color: var(--cyan);
  background: rgba(36, 66, 98, .96);
  outline: none;
}

.monster-master-utility-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(360px, calc(100vw - 24px));
  max-height: min(72dvh, 620px);
  padding: 12px;
  overflow: auto;
  border: 1px solid rgba(100, 135, 195, .42);
  border-radius: 14px;
  background: rgba(9, 15, 27, .98);
  box-shadow: 0 24px 72px rgba(0, 0, 0, .65);
}

.monster-master-utility-popover .tactical-actions {
  margin: 0 0 10px;
}

.monster-master-utility-popover .secondary-button {
  width: 100%;
}

.monster-master-utility-popover .invite-panel,
.monster-master-utility-popover .diagnostics {
  margin-top: 9px;
}

.monster-master-game-grid {
  position: relative;
  display: grid;
  grid-template-columns: var(--monster-rail-width) minmax(360px, 1fr) var(--monster-intel-width);
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  gap: var(--monster-shell-gap);
  padding: var(--monster-shell-gap);
  align-items: stretch;
}

.monster-master-rail {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(107, 145, 206, .45) transparent;
  border: 1px solid rgba(69, 91, 132, .42);
  border-radius: 16px;
  background: rgba(8, 14, 25, .8);
  box-shadow: inset 0 1px rgba(255, 255, 255, .025);
}

.monster-master-roster-rail {
  grid-column: 1;
  grid-row: 1 / span 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
}

.monster-master-roster-rail .tactical-player-grid {
  grid-template-columns: 1fr;
}

.monster-master-roster-rail .player-card {
  padding: 9px;
}

.monster-master-roster-rail .mark-badge {
  width: 32px;
  height: 32px;
  border-radius: 9px;
}

.monster-master-roster-rail .combat-roster {
  min-height: 0;
  padding: 10px;
  overflow: auto;
}

.monster-master-roster-rail .combat-roster-unit {
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 6px 8px;
  padding: 8px;
}

.monster-master-roster-rail .combat-roster-health {
  grid-column: 2;
}

.monster-master-battlefield-stage {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  gap: 6px;
}

.monster-master-battlefield-stage .combat-canvas-frame {
  min-height: 0;
  height: 100%;
  border-radius: 16px;
}

body.monster-master-match-active #monster-master-canvas,
body.monster-master-match-active #monster-master-motion-canvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  aspect-ratio: auto;
}

.monster-master-battlefield-stage .board-help {
  min-height: 24px;
  margin: 0;
  padding: 4px 8px;
  overflow: hidden;
  color: #93a8c8;
  font-size: .69rem;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.monster-master-intel-rail {
  grid-column: 3;
  grid-row: 1;
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 10px;
}

.monster-master-unit-hud {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  padding: 11px;
  border: 1px solid rgba(101, 139, 201, .38);
  border-radius: 14px;
  background:
    radial-gradient(circle at 15% 15%, rgba(83, 151, 217, .2), transparent 52%),
    rgba(18, 29, 49, .86);
}

.monster-master-unit-portrait {
  display: grid;
  place-items: center;
  width: 54px;
  height: 62px;
  border: 1px solid rgba(120, 173, 228, .52);
  border-radius: 14px 14px 10px 10px;
  background: linear-gradient(165deg, rgba(54, 105, 151, .72), rgba(17, 32, 56, .95));
  color: #e7f6ff;
  font-size: 1.45rem;
  font-weight: 950;
  box-shadow: inset 0 1px rgba(255,255,255,.08), 0 8px 20px rgba(0,0,0,.28);
}

.monster-master-unit-hud[data-role="bulwark"] .monster-master-unit-portrait {
  border-radius: 50% 50% 16px 16px;
  background: linear-gradient(165deg, rgba(86, 113, 135, .8), rgba(23, 35, 47, .96));
}

.monster-master-unit-hud[data-role="emberling"] .monster-master-unit-portrait {
  border-color: rgba(255, 145, 100, .58);
  background: linear-gradient(165deg, rgba(164, 69, 45, .78), rgba(60, 25, 29, .96));
  color: #ffe0cf;
}

.monster-master-unit-copy { min-width: 0; }
.monster-master-unit-copy .section-label { margin-bottom: 3px; font-size: .54rem; }
.monster-master-unit-copy h3 {
  margin: 0;
  overflow: hidden;
  font-size: .94rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.monster-master-unit-statline {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}

.monster-master-unit-statline span {
  padding: 3px 6px;
  border: 1px solid rgba(116, 145, 193, .28);
  border-radius: 999px;
  background: rgba(6, 12, 22, .55);
  color: #b9c9e5;
  font-size: .61rem;
  font-variant-numeric: tabular-nums;
}

.monster-master-health-meter {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  margin-top: 1px;
  color: #9fb0cf;
  font-size: .58rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.monster-master-health-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(4, 8, 14, .9);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}

#monster-master-hud-health-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4dbf83, #8aedb6);
  transition: width .22s ease;
}

.monster-master-resource-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.monster-master-resource {
  min-width: 0;
  padding: 8px;
  border: 1px solid rgba(83, 108, 154, .32);
  border-radius: 11px;
  background: rgba(14, 23, 40, .72);
}

.monster-master-resource small,
.monster-master-resource strong { display: block; }
.monster-master-resource small { color: #8498bd; font-size: .54rem; letter-spacing: .08em; text-transform: uppercase; }
.monster-master-resource strong { margin-top: 3px; overflow: hidden; font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }

.monster-master-intel-rail .monster-master-meta {
  grid-template-columns: 1fr 1fr;
  grid-column: auto;
  grid-row: auto;
  gap: 7px;
  padding: 9px;
}

.monster-master-intel-rail .monster-master-meta div {
  min-width: 0;
  padding: 6px;
  border-radius: 8px;
  background: rgba(22, 34, 56, .56);
}

.monster-master-intel-rail .monster-master-meta dt { font-size: .56rem; }
.monster-master-intel-rail .monster-master-meta dd {
  margin-top: 2px;
  font-size: .67rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.monster-master-intel-rail .tactical-controls {
  grid-column: auto;
  grid-row: auto;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.monster-master-intel-rail .tactical-controls button {
  min-height: 32px;
  padding: 5px;
  font-size: .68rem;
}

.monster-master-intel-rail .monster-master-rotation-controls {
  margin-top: 0;
}

.monster-master-intel-rail .combat-effects {
  align-content: flex-start;
  min-height: 48px;
  max-height: 118px;
  margin-top: 0;
  padding: 7px;
  overflow: auto;
  border: 1px solid rgba(74, 96, 137, .3);
  border-radius: 11px;
  background: rgba(7, 12, 22, .46);
}

.monster-master-intel-rail .combat-effect {
  width: 100%;
  padding: 5px 7px;
  border-radius: 8px;
  font-size: .64rem;
}

.monster-master-command-deck {
  grid-column: 2 / 4;
  grid-row: 2;
  display: grid;
  grid-template-columns: minmax(420px, 1.1fr) minmax(280px, .9fr);
  min-height: 0;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(75, 101, 151, .42);
  border-radius: 15px;
  background: rgba(7, 12, 22, .92);
  box-shadow: 0 -14px 38px rgba(0, 0, 0, .26);
}

.monster-master-command-deck .monster-master-action-bar {
  grid-template-columns: repeat(5, minmax(78px, 1fr));
  gap: 7px;
  margin: 0;
}

.monster-master-command-deck .combat-action-button {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 1px 7px;
  min-height: 58px;
  padding: 7px 8px;
  text-align: left;
  border-radius: 11px;
}

.monster-master-command-deck .combat-action-button::before {
  content: attr(data-action-icon);
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: rgba(112, 216, 255, .1);
  color: #bfeeff;
  font-size: .95rem;
}

.monster-master-command-deck .combat-action-button::after {
  content: attr(data-hotkey);
  grid-column: 3;
  grid-row: 1 / span 2;
  padding: 2px 5px;
  border: 1px solid rgba(151, 175, 214, .28);
  border-radius: 5px;
  color: #8fa2c1;
  font-size: .55rem;
  font-weight: 800;
}

.monster-master-action-label { grid-column: 2; font-size: .72rem; font-weight: 850; }
.monster-master-action-caption { grid-column: 2; color: #8fa3c4; font-size: .54rem; font-weight: 650; }

.monster-master-command-deck .combat-action-button[aria-pressed="true"]::before {
  background: rgba(112, 216, 255, .2);
  box-shadow: 0 0 16px rgba(64, 184, 225, .22);
}

.monster-master-command-deck .monster-master-mend-button::before {
  background: rgba(92, 226, 167, .12);
  color: #a7f3cf;
}

.monster-master-command-deck .combat-end-button::before {
  background: rgba(255, 201, 104, .12);
  color: #ffe0a1;
}

.monster-master-command-deck .monster-master-options {
  display: flex;
  align-content: flex-start;
  min-height: 58px;
  max-height: 96px;
  margin: 0;
  padding: 2px 4px;
}

.monster-master-command-deck .monster-master-options::before {
  content: "TARGETS";
  flex: 0 0 auto;
  align-self: center;
  margin-right: 2px;
  color: #6f84a8;
  font-size: .52rem;
  font-weight: 850;
  letter-spacing: .12em;
}

.monster-master-command-deck .monster-master-options:empty::after {
  content: "Choose an action to reveal legal targets";
  align-self: center;
  color: #7183a2;
  font-size: .67rem;
}

.monster-master-mobile-rail-controls,
.monster-master-rail-close,
.monster-master-drawer-backdrop {
  display: none;
}

@media (max-width: 1180px) {
  :root {
    --monster-rail-width: 210px;
    --monster-intel-width: 238px;
  }

  .monster-master-game-grid {
    grid-template-columns: var(--monster-rail-width) minmax(320px, 1fr) var(--monster-intel-width);
  }

  .monster-master-command-deck {
    grid-template-columns: 1fr;
  }

  .monster-master-command-deck .monster-master-options {
    max-height: 62px;
  }
}

@media (max-width: 900px) {
  :root { --monster-command-height: 174px; }

  body.monster-master-match-active .monster-master-shell {
    padding: 6px;
    gap: 6px;
  }

  body.monster-master-match-active .monster-master-shell > .hero {
    min-height: 42px;
  }

  body.monster-master-match-active .combat-nav a:first-child { display: none; }

  .monster-master-match-topbar {
    grid-template-columns: minmax(150px, auto) minmax(0, 1fr) auto;
    gap: 8px;
    min-height: 50px;
    padding: 6px 8px;
  }

  .monster-master-match-topbar .revision { display: none; }
  .monster-master-match-topbar .status { min-height: 34px; padding: 6px 8px; font-size: .68rem; }

  .monster-master-game-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    padding: 6px;
    gap: 6px;
  }

  .monster-master-battlefield-stage {
    grid-column: 1;
    grid-row: 1;
  }

  .monster-master-command-deck {
    grid-column: 1;
    grid-row: 2;
    padding: 6px;
  }

  .monster-master-command-deck .monster-master-action-bar {
    grid-template-columns: repeat(5, minmax(62px, 1fr));
  }

  .monster-master-command-deck .combat-action-button {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    place-items: center;
    min-height: 54px;
    padding: 5px;
    text-align: center;
  }

  .monster-master-command-deck .combat-action-button::before {
    grid-column: 1;
    grid-row: 1;
    width: 26px;
    height: 24px;
  }

  .monster-master-command-deck .combat-action-button::after { display: none; }
  .monster-master-action-label { grid-column: 1; grid-row: 2; font-size: .61rem; }
  .monster-master-action-caption { display: none; }

  .monster-master-mobile-rail-controls {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 12;
    display: flex;
    gap: 6px;
  }

  .monster-master-mobile-rail-controls button,
  .monster-master-rail-close {
    min-height: 34px;
    padding: 6px 9px;
    border: 1px solid rgba(117, 157, 216, .42);
    border-radius: 9px;
    background: rgba(7, 14, 26, .86);
    color: #d8edff;
    cursor: pointer;
    font-size: .65rem;
    font-weight: 800;
    backdrop-filter: blur(8px);
  }

  .monster-master-rail-close {
    display: inline-grid;
    place-items: center;
    justify-self: end;
    width: 32px;
    min-height: 32px;
    padding: 0;
    font-size: .9rem;
  }

  .monster-master-rail {
    position: absolute;
    top: 6px;
    bottom: 6px;
    z-index: 30;
    width: min(320px, calc(100% - 26px));
    max-height: none;
    transition: transform .18s ease, opacity .18s ease;
  }

  .monster-master-roster-rail {
    left: 6px;
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-column: auto;
    grid-row: auto;
    transform: translateX(calc(-100% - 16px));
    opacity: 0;
  }

  .monster-master-intel-rail {
    right: 6px;
    grid-column: auto;
    grid-row: auto;
    transform: translateX(calc(100% + 16px));
    opacity: 0;
  }

  body.monster-master-roster-open .monster-master-roster-rail,
  body.monster-master-intel-open .monster-master-intel-rail {
    transform: translateX(0);
    opacity: 1;
  }

  .monster-master-drawer-backdrop {
    position: absolute;
    inset: 0;
    z-index: 20;
    border: 0;
    background: rgba(2, 5, 10, .62);
    cursor: pointer;
    backdrop-filter: blur(2px);
  }

  body.monster-master-roster-open .monster-master-drawer-backdrop,
  body.monster-master-intel-open .monster-master-drawer-backdrop {
    display: block;
  }
}

@media (max-width: 650px) {
  body.monster-master-match-active .monster-master-shell > .hero {
    flex-direction: row;
    align-items: center;
  }

  body.monster-master-match-active .monster-master-shell > .hero .eyebrow,
  body.monster-master-match-active .combat-nav a {
    display: none;
  }

  body.monster-master-match-active .monster-master-shell > .hero h1 {
    font-size: 1rem;
  }

  .monster-master-match-topbar {
    grid-template-columns: minmax(108px, auto) minmax(0, 1fr) 36px;
  }

  .monster-master-match-topbar .section-label { display: none; }
  .monster-master-match-topbar h2 { font-size: .88rem; }
  .monster-master-match-topbar .status { font-size: .62rem; }

  .monster-master-battlefield-stage .board-help { display: none; }
  .monster-master-battlefield-stage { grid-template-rows: minmax(0, 1fr); }

  .monster-master-command-deck .monster-master-action-bar {
    grid-template-columns: repeat(5, minmax(48px, 1fr));
  }

  .monster-master-command-deck .monster-master-options {
    max-height: 54px;
  }

  .monster-master-command-deck .monster-master-options::before { display: none; }
  .monster-master-command-deck .monster-master-options button {
    padding: 6px 8px;
    font-size: .66rem;
  }

  .combat-canvas-frame[data-projection-ready="true"]::before {
    max-width: calc(100% - 138px);
  }
}

@media (max-width: 440px) {
  body.monster-master-match-active .monster-master-shell {
    padding: 4px;
    gap: 4px;
  }

  body.monster-master-match-active .monster-master-shell > .hero {
    min-height: 30px;
  }

  .monster-master-match-topbar {
    min-height: 44px;
    padding: 4px 6px;
  }

  .monster-master-game-grid { padding: 4px; gap: 4px; }
  .monster-master-command-deck { padding: 4px; gap: 4px; }
  .monster-master-command-deck .monster-master-action-bar { gap: 4px; }
  .monster-master-command-deck .combat-action-button { min-height: 48px; }
  .monster-master-command-deck .combat-action-button::before { width: 23px; height: 21px; font-size: .8rem; }
  .monster-master-command-deck .monster-master-options { min-height: 42px; max-height: 46px; }
  .monster-master-mobile-rail-controls { top: 6px; right: 6px; gap: 4px; }
  .monster-master-mobile-rail-controls button { min-height: 30px; padding: 4px 7px; font-size: .58rem; }
}

@media (prefers-reduced-motion: reduce) {
  #monster-master-hud-health-fill,
  .monster-master-rail { transition: none; }
}
