/* Shared battle chrome: the same DOM and presentation in both rulesets. */
:root {
  --panel: #091722;
  --line: #254352;
  --muted: #92adbf;
  --shield-healthy: #69e0f1;
  --shield-damaged: #edbb67;
  --shield-critical: #ff8d83;
  --shield-collapsed: #98524f;
}
[hidden] {
  display: none !important;
}
body {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
header {
  min-height: 74px;
  height: auto;
  gap: 14px;
  padding: 12px 18px;
  flex-shrink: 0;
}
.brand {
  font-size: 22px;
  letter-spacing: 1.5px;
  white-space: nowrap;
}
.time-controls {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}
.time-controls button {
  font-size: 10px;
  padding: 9px 10px;
}
.sector-power {
  flex: 1;
  max-width: 380px;
  margin: 0 8px;
}
.sector-power .sector {
  font-size: 9px;
  gap: 7px;
}
.power-balance-label {
  font-size: 9px;
}
main {
  flex: 1;
  min-height: 0;
  height: auto;
  grid-template-columns: clamp(230px, 18vw, 320px) minmax(260px, 1fr) clamp(300px, 23vw, 380px);
  gap: 6px;
  padding: 6px;
}
aside {
  padding: 14px 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  overscroll-behavior: contain;
  scrollbar-color: #365868 transparent;
  scrollbar-gutter: stable;
}
.viewport {
  border: 1px solid var(--line);
  border-radius: 5px;
}
.section-title {
  color: #89d9e7;
  margin: 15px 0 10px;
  font-size: 10px;
  letter-spacing: 1.2px;
}
.section-title span {
  color: #91b2c4;
}
footer {
  height: 48px;
  flex-shrink: 0;
}
#log {
  max-height: 34px;
}
#ship-name {
  font-size: 28px;
  line-height: 1.2;
}
#ship-class {
  line-height: 1.5;
}
#captain-summary {
  color: var(--gold);
  font-size: 11px;
  margin-top: 6px;
}
.status-line {
  margin: 12px 0 6px;
}
.stats {
  margin: 12px 0;
  justify-content: space-between;
}
.stats strong {
  font-size: 20px;
}
.stats small {
  font-size: 9px;
}
.command-identity {
  padding: 0 2px;
}
.hostile .command-identity .section-title {
  color: var(--red);
}
#command-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  position: sticky;
  top: -14px;
  z-index: 2;
  padding: 10px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
#command-tabs button {
  padding: 9px 1px;
  font-size: 10px;
}
#command-tabs [aria-selected='true'],
#fleet-filters [aria-pressed='true'] {
  color: var(--cyan);
  border-color: var(--cyan);
  background: #15323f;
}
#command-content:focus-visible {
  outline: 1px solid var(--cyan);
}
.command-section {
  padding-bottom: 12px;
  border-bottom: 1px solid #25435288;
}
.command-section .hint {
  margin: 8px 0;
  min-height: 0;
  font-size: 11px;
  line-height: 1.5;
}
.command-section .toggle {
  margin: 10px 0;
  font-size: 11px;
}
.command-section .segmented {
  grid-template-columns: repeat(4, 1fr);
}
.command-section .segmented button {
  font-size: 10px;
  padding: 8px 2px;
}
.order-grid button {
  padding: 9px 3px;
  font-size: 11px;
}
.reactor-telemetry {
  font-size: 11px;
  color: var(--muted);
}
summary {
  cursor: pointer;
  padding: 8px 0;
}
summary:focus-visible {
  outline: 2px solid var(--cyan);
}
#ship-diagram {
  position: relative;
  aspect-ratio: 320/260;
  background:
    radial-gradient(ellipse, #12354866, transparent 70%),
    repeating-linear-gradient(0deg, transparent 0 19px, #1f45502b 20px),
    repeating-linear-gradient(90deg, transparent 0 19px, #1f45502b 20px);
  border: 1px solid var(--line);
  border-radius: 4px;
}
#command-art {
  position: absolute;
  width: 50%;
  height: 61.54%;
  left: 25%;
  top: 19.23%;
  filter: drop-shadow(0 0 8px #57c8e21a);
}
#shield-diagram {
  position: absolute;
  width: 100%;
  height: 100%;
  inset: 0;
  pointer-events: none;
}
#shield-diagram path {
  stroke: var(--shield-healthy);
  stroke-linecap: round;
  transition: stroke 0.2s;
}
#shield-diagram [data-state='damaged'] {
  stroke: var(--shield-damaged);
}
#shield-diagram [data-state='critical'] {
  stroke: var(--shield-critical);
}
#shield-diagram [data-state='collapsed'],
#shield-diagram [data-state='unequipped'] {
  stroke: var(--shield-collapsed);
  stroke-dasharray: 4 8;
}
#shield-sectors {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-top: 8px;
}
#shield-sectors button {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px 2px;
  font-size: 10px;
}
#shield-sectors button strong {
  color: var(--shield-healthy);
}
#shield-sectors [data-state='damaged'] strong {
  color: var(--shield-damaged);
}
#shield-sectors [data-state='critical'] strong,
#shield-sectors [data-state='collapsed'] strong {
  color: var(--shield-critical);
}
#shield-sectors [aria-pressed='true'] {
  border-color: var(--cyan);
}
#shield-inspection {
  font: 10px monospace;
  min-height: 30px;
}
.weapon-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 5px;
  font-size: 11px;
}
.weapon-row small {
  color: var(--muted);
}
.weapon-row span {
  color: var(--gold);
  font-size: 10px;
}
.system {
  font-size: 11px;
}
#fleet-filters {
  display: flex;
  gap: 5px;
  margin: 0 0 12px;
}
#fleet-filters button {
  flex: 1;
  padding: 7px 3px;
  font-size: 10px;
}
.ship-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px;
  margin-bottom: 6px;
  min-height: 100px;
  background: #0d202c;
}
.ship-card canvas {
  width: 66px;
  height: 70px;
  flex: 0 0 66px;
  pointer-events: none;
}
.roster-copy {
  flex: 1;
  min-width: 0;
}
.ship-card strong {
  font-size: 12px;
  font-weight: 600;
  display: block;
}
.ship-card small {
  font-size: 9px;
  margin: 5px 0;
  line-height: 1.35;
}
.ship-card .captain-line {
  color: var(--gold);
  white-space: normal;
}
.roster-health {
  font: 9px monospace;
  color: #adcad7;
}
.ship-card .bar {
  margin-top: 5px;
}
.shield-bar {
  opacity: 0.65;
}
.ship-card.selected {
  box-shadow: inset 3px 0 var(--cyan);
  background: #14303b;
}
.ship-card.destroyed {
  opacity: 0.6;
}
.map-label {
  top: 16px;
  left: 16px;
}
.view-controls {
  top: 55px;
  right: 12px;
}
.map-footer {
  padding: 12px;
}
.map-footer span:last-child {
  font-size: 8px;
}
@media (min-width: 1700px) {
  .view-controls {
    top: 15px;
  }
  .ship-card canvas {
    width: 84px;
    flex-basis: 84px;
  }
  .ship-card strong {
    font-size: 13px;
  }
}
@media (max-width: 1150px) {
  header {
    flex-wrap: wrap;
    gap: 8px;
  }
  .brand {
    font-size: 19px;
  }
  .sector-power {
    max-width: none;
    min-width: 220px;
  }
  .time-controls {
    width: 100%;
    justify-content: flex-end;
  }
  main {
    grid-template-columns: 200px minmax(210px, 1fr) 300px;
  }
  .ship-card {
    gap: 5px;
    padding: 6px;
  }
  .ship-card canvas {
    width: 44px;
    flex-basis: 44px;
  }
  .map-footer span:last-child {
    display: none;
  }
}
@media (max-width: 850px) {
  main {
    grid-template-columns: 170px minmax(180px, 1fr) 280px;
  }
  .ship-card canvas {
    display: none;
  }
  .brand small {
    display: block;
  }
  .view-controls {
    left: 10px;
    right: 10px;
    flex-wrap: wrap;
  }
  .view-controls button {
    font-size: 8px;
    padding: 6px;
  }
  .map-label {
    font-size: 9px;
  }
  .map-label small {
    font-size: 8px;
  }
}
@media (max-width: 760px) {
  body {
    height: auto;
    min-height: 100dvh;
    overflow: auto;
  }
  header {
    min-height: 0;
    padding: 10px;
  }
  .sector-power {
    order: 0;
  }
  .sector-power .sector {
    display: flex;
  }
  .time-controls {
    justify-content: flex-start;
  }
  main {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) minmax(230px, 1.6fr);
    height: auto;
    overflow: visible;
  }
  .viewport {
    grid-column: 1/-1;
    grid-row: 1;
    height: 55vh;
    min-height: 360px;
  }
  .left,
  .right {
    height: 65vh;
    min-height: 400px;
    overflow: auto;
  }
  .ship-card canvas {
    display: none;
  }
  footer {
    min-height: 55px;
  }
  .comms-label {
    display: none;
  }
  #command-tabs {
    top: -14px;
  }
  .stats {
    gap: 12px;
  }
  .brand {
    font-size: 17px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
#shield-diagram text {
  font:
    8px 'IBM Plex Mono',
    monospace;
  fill: #9fbfce;
  letter-spacing: 0.5px;
}
#shield-diagram .inspected {
  stroke-width: 7;
}
.right[data-command-tab='overview'] #ship-diagram {
  max-width: 250px;
  margin: 0 auto;
}
.right[data-command-tab='overview'] #shield-inspection {
  display: none;
}
.right[data-command-tab='overview'] .command-section {
  padding-bottom: 9px;
}
.command-identity .stats {
  margin: 9px 0 2px;
}
.command-identity .stats strong {
  font-size: 18px;
}
.command-identity .section-title {
  margin-top: 0;
}
.right .section-title {
  margin-top: 12px;
}
.right .command-identity .section-title {
  margin-top: 0;
}
.command-identity .status-line {
  margin-top: 9px;
}
.command-section .torpedo {
  padding: 9px 5px;
}
/* Overview favors immediate orders; full explanations and telemetry live in Systems. */
.right[data-command-tab='overview'] #power-hint,
.right[data-command-tab='overview'] .reactor-telemetry {
  display: none;
}
.right[data-command-tab='overview'] #ship-diagram {
  max-width: 230px;
}
.right[data-command-tab='overview'] .command-section .toggle {
  display: inline-flex;
  margin-right: 12px;
}
.command-identity .stats > div {
  display: flex;
  gap: 10px;
  align-items: baseline;
}
.command-identity .stats {
  margin-top: 10px;
  margin-bottom: 4px;
}
header .sector-power {
  display: block;
}
header .sector-power .sector {
  display: flex;
}

/* Console materials: raised controls, recessed instruments and edged panel glass.
   Shared by campaign and custom battle; static lighting never animates with combat. */
:root {
  --console-face: linear-gradient(180deg, #1b3040, #122331);
  --console-hover: linear-gradient(180deg, #254252, #18303f);
  --console-active: linear-gradient(180deg, #205063, #153847);
  --console-bevel: inset 0 1px 0 #c1eeff12, inset 0 -1px 0 #0005, 0 1px 2px #0004;
  --console-edge: #365a6d;
}
body {
  background: radial-gradient(ellipse at 50% 0, #142937, #050b12 70%);
}
header,
footer {
  background:
    linear-gradient(115deg, #15303f55, transparent 35%), linear-gradient(180deg, #122331, #07131e 55%, #0b1b28);
  box-shadow:
    inset 0 1px 0 #a5e7ff1c,
    inset 0 -1px 0 #000c,
    0 3px 12px #0006;
  border-color: #315166;
}
.brand b {
  text-shadow: 0 0 14px #53d9ec30;
}
.insignia {
  filter: drop-shadow(0 0 6px #4ac9e549);
}
main > aside {
  background:
    linear-gradient(120deg, #20415435, transparent 24%), linear-gradient(180deg, #0c1d29, #07131d 68%, #0a1b27);
  border-color: #305065;
  box-shadow:
    inset 0 0 0 3px #050d15,
    inset 0 0 0 4px #29445255,
    inset 0 8px 16px -12px #a0ecff30,
    0 3px 10px #0007;
}
.viewport {
  border-color: #345568;
  box-shadow:
    0 0 0 1px #02080d,
    0 3px 12px #0008;
}
/* An inset rim stays above the canvas but never intercepts map input. */
.viewport::after {
  content: '';
  position: absolute;
  inset: 3px;
  pointer-events: none;
  border: 1px solid #4b8da32b;
  border-radius: 2px;
  background:
    linear-gradient(#7ddff1, #7ddff1) left top/24px 1px no-repeat,
    linear-gradient(#7ddff1, #7ddff1) left top/1px 24px no-repeat,
    linear-gradient(#7ddff180, #7ddff180) right bottom/24px 1px no-repeat,
    linear-gradient(#7ddff180, #7ddff180) right bottom/1px 24px no-repeat;
  box-shadow: inset 0 0 22px #0006;
}
/* Scope the finish to battle chrome; setup and inventory keep their own layout. */
:is(header, main, footer) button:not(.ship-card),
.right select {
  background: var(--console-face);
  border-color: var(--console-edge);
  box-shadow: var(--console-bevel);
  text-shadow: 0 1px 2px #000b;
  transition:
    background-color 0.12s,
    border-color 0.12s,
    box-shadow 0.12s;
}
:is(header, main, footer) button:not(.ship-card):hover:not(:disabled),
.right select:hover:not(:disabled) {
  background: var(--console-hover);
  border-color: #6babbe;
  box-shadow:
    var(--console-bevel),
    0 0 9px #47caea16;
}
/* Override the legacy flat .active rule with a shared illuminated pressed state. */
:is(header, main, footer) button.active,
#command-tabs [aria-selected='true'],
#fleet-filters [aria-pressed='true'],
#shield-sectors [aria-pressed='true'],
.view-controls [aria-pressed='true'] {
  background: var(--console-active) !important;
  border-color: #54cee7 !important;
  color: #b5f5ff;
  box-shadow:
    inset 0 1px 0 #b3f9ff20,
    inset 0 -1px 0 #0005,
    0 1px 2px #0004;
  text-shadow: none;
}
:is(header, main, footer) button:not(.ship-card):active:not(:disabled) {
  background: linear-gradient(180deg, #071822, #14384a);
  box-shadow:
    inset 0 2px 5px #000a,
    inset 0 -1px 0 #9eeaff33;
}
:is(header, main, footer) button:disabled {
  background: linear-gradient(#13222c, #0c1720);
  box-shadow: inset 0 1px 0 #91c8de0d;
  border-color: #29404c;
  text-shadow: none;
}
header #pause:not(:disabled),
#torpedo:not(:disabled) {
  border-color: #37bcd7;
  box-shadow: var(--console-bevel);
}
#engage,
#result > button {
  background: linear-gradient(180deg, #83dce9, #61bed0) !important;
  color: #062531;
  text-shadow: 0 1px 0 #d3faff80 !important;
  border: 1px solid #7de5f6 !important;
  box-shadow:
    inset 0 1px 0 #ffffff33,
    inset 0 -1px 0 #16627a,
    0 2px 4px #0005 !important;
}
#engage:hover,
#result > button:hover:not(:disabled) {
  filter: brightness(1.08);
}
#command-tabs {
  background: linear-gradient(180deg, #0d202d 75%, #07131e);
  border-bottom-color: #375b6d;
  box-shadow:
    0 4px 8px #0004,
    inset 0 -1px 0 #061019;
}
.command-section {
  background: linear-gradient(110deg, #24475817, transparent 55%);
  border-bottom: 1px solid #36546970;
  box-shadow: 0 1px 0 #020a10;
}
.command-section > .section-title,
.left > .section-title {
  padding: 5px 0 5px 9px;
  border-left: 2px solid #6bd6e9;
  background: linear-gradient(90deg, #24536555, transparent 85%);
  box-shadow:
    inset 0 1px 0 #7addef12,
    inset 0 -1px 0 #0005;
  text-shadow: 0 0 8px #53d7f033;
}
.left > .hostile-title {
  border-left-color: var(--red);
  background: linear-gradient(90deg, #64373240, transparent 85%);
}
.command-identity {
  background: radial-gradient(ellipse at top right, #2d667326, transparent 65%);
}
.command-identity .stats > div {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid #294657;
  border-radius: 3px;
  background: linear-gradient(180deg, #030d16, #112b38);
  box-shadow:
    inset 0 2px 4px #0008,
    0 1px 0 #7ddcf014;
}
.command-identity .stats {
  gap: 6px;
}
.ship-card {
  border-color: #2f5364;
  background:
    linear-gradient(115deg, #25435335, transparent 55%), linear-gradient(180deg, #152b39, #0a1924 55%, #102330);
  box-shadow:
    inset 0 1px 0 #b0e9ff1c,
    inset 0 -1px 0 #0009,
    0 2px 5px #0005;
}
.ship-card:hover {
  background: linear-gradient(120deg, #224657, #102b3b);
  border-color: #6797aa;
}
.ship-card canvas {
  background:
    radial-gradient(ellipse at 50% 75%, #1b4c6055, transparent 72%), linear-gradient(150deg, #112b39, #040c14);
  border: 1px solid #2f5467;
  border-radius: 3px;
  box-shadow:
    inset 0 2px 5px #0009,
    0 1px 0 #7cdbf019;
}
.ship-card.selected {
  border-color: #64d9ed;
  background:
    linear-gradient(115deg, #1e5264aa, transparent 60%), linear-gradient(180deg, #163a49, #092330 52%, #153543);
  box-shadow:
    inset 2px 0 #78e7f6,
    inset 0 1px 0 #a6f3ff20,
    0 1px 3px #0005;
}
.ship-card.target {
  border-color: #cf8c7c;
  box-shadow:
    inset 3px 0 #df8b7c,
    inset 0 1px 0 #f8bbaa30,
    0 0 8px #e98c6c22;
}
.ship-card .bar,
.meter,
.power-balance-track {
  border-radius: 3px;
  background-color: #030c14;
  box-shadow:
    inset 0 1px 3px #000c,
    0 1px 0 #82d3ed1f;
}
.ship-card .bar i,
.meter > div,
.power-balance-track i {
  border-radius: 3px;
  background-image: linear-gradient(180deg, #e1ffff22, #007c9911);
  box-shadow: inset 0 1px 0 #d7ffff22;
}
.power-balance-track {
  background-color: var(--red);
  background-image: linear-gradient(#ffffff44, transparent 55%, #6b1b2422);
}
#ship-diagram {
  border-color: #365d70;
  background:
    linear-gradient(135deg, #83cbe10d, transparent 36%, #2c536310 65%, transparent 66%),
    radial-gradient(ellipse at 50% 65%, #153d50aa, #030e1880 75%),
    repeating-linear-gradient(0deg, transparent 0 19px, #36627233 20px),
    repeating-linear-gradient(90deg, transparent 0 19px, #36627233 20px);
  box-shadow:
    inset 0 0 0 2px #030c14,
    inset 0 3px 10px #0009,
    inset 0 -1px 0 #71d9f02b,
    0 1px 0 #82d5ed19;
}
#shield-diagram path {
  filter: drop-shadow(0 0 1px #48daed33);
}
#shield-diagram [data-state='collapsed'],
#shield-diagram [data-state='unequipped'] {
  filter: none;
}
.map-label {
  border-left: 2px solid #5dccdf;
  padding: 7px 12px;
  background: linear-gradient(90deg, #0e2433e8, #0b1b2880 75%, transparent);
  box-shadow: inset 0 1px 0 #81d9ef1a;
  text-shadow: 0 1px 3px #000;
}
.map-footer {
  background: linear-gradient(180deg, #102735e8, #05111def);
  border-top-color: #3c6577;
  box-shadow:
    inset 0 1px 0 #8de4fb1c,
    0 -3px 10px #0004;
}
#banner,
#result {
  background:
    linear-gradient(130deg, #335d7140, transparent 48%), linear-gradient(180deg, #132b3af5, #081824fa 55%, #102735fa);
  border-color: #456e82;
  box-shadow:
    inset 0 0 0 3px #04101a,
    inset 0 0 0 4px #54869955,
    inset 0 1px 0 #bcf5ff33,
    0 20px 65px #000b;
}
@media (prefers-reduced-motion: reduce) {
  :is(header, main, footer) button {
    transition: none;
  }
}

/* Compact sidebars: retain type sizes and full controls, reduce spare space. */
main > aside {
  padding: 10px;
}
.ship-card {
  min-height: 82px;
  padding: 6px;
  gap: 7px;
  margin-bottom: 5px;
}
.ship-card canvas {
  width: 60px;
  height: 60px;
  flex-basis: 60px;
}
.ship-card small {
  margin: 3px 0;
  line-height: 1.3;
}
.ship-card .bar {
  margin-top: 4px;
}
#fleet-filters {
  margin-bottom: 8px;
}
#fleet-filters button {
  padding: 6px 3px;
}
.left > .section-title {
  margin: 10px 0 8px;
}
.command-section > .section-title,
.left > .section-title {
  padding-top: 3px;
  padding-bottom: 3px;
}
#ship-name {
  font-size: 25px;
}
#ship-class,
#captain-summary {
  margin-top: 4px;
}
.command-identity .status-line {
  margin-top: 7px;
}
.command-identity .stats {
  margin: 7px 0 2px;
}
.command-identity .stats > div {
  padding: 4px 6px;
}
#command-tabs {
  top: -10px;
  padding: 7px 0;
}
#command-tabs button {
  padding: 7px 1px;
}
.right .section-title {
  margin-top: 9px;
  margin-bottom: 7px;
}
.right .command-identity .section-title {
  margin-top: 0;
}
.command-section,
.right[data-command-tab='overview'] .command-section {
  padding-bottom: 7px;
}
.command-section .hint {
  margin: 6px 0;
}
.right[data-command-tab='overview'] #ship-diagram {
  max-width: 210px;
}
#shield-sectors {
  margin-top: 6px;
  margin-bottom: 8px;
}
#shield-sectors button {
  gap: 4px;
  padding: 5px 2px;
}
.order-grid button {
  padding: 7px 3px;
}
.command-section .toggle {
  margin-top: 7px;
  margin-bottom: 7px;
}
.weapon-row {
  padding: 7px 0;
  gap: 4px;
}
@media (max-width: 1150px) {
  .ship-card canvas {
    width: 44px;
    height: 56px;
    flex-basis: 44px;
  }
}
