:root {
  color-scheme: dark;
  --bg: #07131f;
  --panel: rgba(11, 23, 39, 0.92);
  --panel-strong: rgba(7, 15, 27, 0.98);
  --line: rgba(148, 195, 255, 0.24);
  --text: #eef6ff;
  --muted: #9ab5ce;
  --blue: #52b3ff;
  --red: #ff7b7b;
  --gold: #f7ca75;
  --green: #7af0b0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(82, 179, 255, 0.16), transparent 28%),
    radial-gradient(circle at bottom right, rgba(255, 123, 123, 0.14), transparent 24%),
    linear-gradient(180deg, #08111c, #040b13 65%);
  color: var(--text);
}

.shell {
  padding: 14px;
}

body.match-active {
  overflow: hidden;
}

body.match-active .shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 14px;
}

body.match-active .topbar {
  align-items: center;
  margin-bottom: 8px;
  min-height: 40px;
}

body.match-active .topbar h1 {
  margin: 0;
  font-size: 28px;
  line-height: 0.95;
}

body.match-active .eyebrow {
  margin-bottom: 2px;
  font-size: 10px;
  letter-spacing: 0.16em;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 12px;
  color: var(--gold);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.layout {
  display: grid;
  grid-template-columns: 250px minmax(620px, 1fr) 320px;
  gap: 18px;
  min-width: 0;
}

.auth-panel[hidden],
body.auth-required .layout {
  display: none;
}

.auth-panel {
  min-height: calc(100vh - 128px);
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(920px, 96vw);
  border: 1px solid rgba(148, 195, 255, 0.24);
  border-radius: 26px;
  padding: 28px;
  background:
    radial-gradient(circle at 18% 8%, rgba(247, 202, 117, 0.15), transparent 26%),
    linear-gradient(145deg, rgba(10, 24, 40, 0.98), rgba(4, 10, 18, 0.98));
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.44);
}

.auth-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 18px;
}

body.match-active .layout {
  flex: 1;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 12px;
  min-height: 0;
}

body.match-active.right-rail-collapsed .layout {
  grid-template-columns: minmax(0, 1fr);
}

body.match-active #home-panel {
  display: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.32);
  min-height: 220px;
  min-width: 0;
}

body.match-active .panel {
  min-height: 0;
  padding: 10px;
  border-radius: 16px;
}

.panel-canvas {
  padding: 8px;
  background: var(--panel-strong);
}

body.match-active .panel-canvas {
  --context-panel-height: clamp(190px, 24vh, 244px);
  display: grid;
  grid-template-rows: minmax(0, calc(100% - var(--context-panel-height) - 10px)) var(--context-panel-height);
  gap: 10px;
  align-content: stretch;
  align-self: stretch;
  height: 100%;
  overflow: hidden;
}

.panel-canvas #game-root {
  position: relative;
  width: 100%;
  min-width: 0;
  aspect-ratio: 2 / 1;
  min-height: 420px;
  max-height: calc(100vh - 126px);
  overflow: hidden;
  border-radius: 14px;
}

body.match-active .panel-canvas #game-root {
  min-height: 0;
  height: 100%;
  max-height: none;
  aspect-ratio: auto;
  align-self: center;
}

body.match-active[data-phase="world_planning"] .panel-canvas {
  --context-panel-height: clamp(220px, 27vh, 286px);
}

body.match-active[data-phase="battle_planning"] .panel-canvas {
  --context-panel-height: clamp(340px, 34vh, 380px);
}

body.match-active[data-phase="battle_resolving"] .panel-canvas {
  --context-panel-height: clamp(150px, 18vh, 190px);
}

body.match-active[data-phase="match_end"] .panel-canvas {
  --context-panel-height: 92px;
}

.panel-canvas #game-root canvas {
  display: block;
  width: 100%;
  height: 100%;
}

body.match-active .panel-wide {
  overflow: hidden;
  max-height: calc(100vh - 84px);
  align-self: start;
}

body.match-active.right-rail-collapsed .panel-wide {
  display: none;
}

.active-notice {
  display: none;
  max-width: min(460px, 38vw);
  border: 1px solid rgba(148, 195, 255, 0.18);
  border-radius: 12px;
  padding: 8px 12px;
  background: rgba(5, 11, 18, 0.72);
  color: var(--muted);
  line-height: 1.25;
  font-size: 13px;
}

body.match-active .active-notice {
  display: block;
}

.world-map-shell {
  position: absolute;
  inset: 0;
  z-index: 3;
}

.map-designer {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  padding: 10px;
  overflow: hidden;
  border-radius: 14px;
  background:
    radial-gradient(ellipse at center, rgba(24, 62, 96, 0.35), transparent 72%),
    linear-gradient(135deg, rgba(6, 16, 27, 0.98), rgba(2, 7, 13, 0.98));
}

.map-designer-topbar,
.map-designer-toolbar,
.map-designer-profile,
.map-designer-notice {
  border: 1px solid rgba(148, 195, 255, 0.18);
  border-radius: 16px;
  padding: 8px;
  background: rgba(4, 10, 18, 0.74);
}

.map-designer-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, auto);
  gap: 10px;
  align-items: start;
  min-width: 0;
}

.map-designer-topbar > div:first-child {
  min-width: 0;
}

.map-designer-topbar .context-actions {
  justify-content: end;
  flex-wrap: wrap;
  max-width: min(100%, 440px);
  min-width: 0;
}

.map-designer-topbar .context-actions button {
  min-width: 0;
  min-height: 36px;
  padding: 8px 10px;
}

.world-designer-create-mode {
  display: grid;
  grid-template-columns: repeat(2, minmax(82px, 1fr));
  gap: 6px;
  min-width: 190px;
}

.world-designer-create-mode button {
  min-height: 36px;
  padding: 8px 9px;
  border-radius: 12px;
  white-space: nowrap;
}

.world-designer-create-mode button.is-active {
  border-color: rgba(247, 202, 117, 0.78);
  box-shadow: inset 0 0 0 1px rgba(247, 202, 117, 0.32);
}

.map-designer-topbar p {
  display: none;
  margin: 2px 0 0;
}

.map-designer-mode-pill {
  margin-left: 8px;
  vertical-align: middle;
  background: rgba(247, 202, 117, 0.14);
  color: #ffe9b3;
}

.map-designer-workspace {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(0, 1fr);
  gap: 10px;
  min-height: 0;
}

.map-designer-inspector {
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: start;
  gap: 8px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.map-designer-toolbar,
.map-designer-profile {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
  gap: 7px;
}

.map-designer-profile {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.map-designer-toolbar .context-kicker,
.map-designer-profile .context-kicker {
  grid-column: 1 / -1;
}

.map-designer-toolbar label,
.map-designer-profile label {
  min-width: 0;
}

.map-designer-toolbar label:first-of-type,
.map-designer-toolbar label:nth-of-type(2),
.map-designer-toolbar label:last-of-type,
.map-designer-profile label:first-of-type {
  grid-column: 1 / -1;
}

.map-designer-profile button {
  min-height: 36px;
  padding: 8px 10px;
}

.side-profile-preferences {
  grid-template-columns: 1fr;
  padding: 0;
  border: 0;
  background: transparent;
}

.side-profile-preferences label:first-of-type,
.side-profile-preferences button {
  grid-column: 1 / -1;
}

.map-designer-board {
  display: grid;
  place-items: stretch;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  border: 1px solid rgba(148, 195, 255, 0.18);
  border-radius: 16px;
  background:
    radial-gradient(ellipse at center, rgba(47, 111, 155, 0.12), transparent 70%),
    rgba(2, 8, 15, 0.55);
}

.map-designer-hex-svg {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: block;
  filter: drop-shadow(0 18px 24px rgba(0, 0, 0, 0.24));
}

.map-hex-group {
  cursor: pointer;
  outline: none;
  pointer-events: bounding-box;
}

.map-hex-shape {
  stroke: rgba(148, 195, 255, 0.22);
  stroke-width: 1.4;
  transition:
    filter 110ms ease,
    stroke 110ms ease,
    stroke-width 110ms ease;
}

.map-hex-group:hover .map-hex-shape,
.map-hex-group:focus-visible .map-hex-shape {
  filter: brightness(1.18);
  stroke: rgba(247, 202, 117, 0.88);
  stroke-width: 3;
}

.map-hex-marker {
  pointer-events: none;
  fill: rgba(238, 246, 255, 0.94);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-anchor: middle;
  dominant-baseline: middle;
  paint-order: stroke;
  stroke: rgba(2, 8, 15, 0.92);
  stroke-width: 3px;
}

.map-hex-marker-chip {
  pointer-events: none;
  opacity: 0.88;
  stroke: rgba(238, 246, 255, 0.62);
  stroke-width: 1px;
}

.map-hex-bridge-deck {
  pointer-events: none;
  stroke: #c6a16a;
  stroke-width: 8;
  stroke-linecap: round;
}

.map-hex-bridge-rail {
  pointer-events: none;
  stroke: rgba(255, 238, 190, 0.76);
  stroke-width: 2;
  stroke-linecap: round;
}

.map-hex-open {
  background: #17324c;
  fill: #17324c;
}

.map-hex-cover {
  background: #367347;
  fill: #367347;
}

.map-hex-rough {
  background: #8a6b2c;
  fill: #8a6b2c;
}

.map-hex-high_ground {
  background: #587493;
  fill: #587493;
}

.map-hex-mountain,
.map-hex-blocker {
  background: #26303e;
  fill: #26303e;
}

.map-hex-river {
  background: #1b6f91;
  fill: #1b6f91;
}

.map-hex-water {
  background: #155f83;
  fill: #155f83;
}

.map-hex-coast {
  background: linear-gradient(135deg, #155f83 0 42%, #6e7244 42% 100%);
  fill: #2d6370;
}

.map-hex-bridge {
  background: linear-gradient(90deg, #1b6f91 0 35%, #8b7346 35% 65%, #1b6f91 65%);
  fill: #1b6f91;
}

.map-designer-notice {
  min-height: 0;
}

.world-designer .map-designer-workspace {
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
}

.world-designer .map-designer-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.world-designer .context-actions {
  flex-wrap: wrap;
  justify-content: start;
}

.world-designer .context-actions > button {
  min-width: 0;
}

.world-designer-inspector {
  grid-template-rows: auto auto auto minmax(0, 1fr);
  overflow: hidden;
}

.world-designer-toolbar,
.world-designer-profile,
.world-designer-units {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.world-designer-toolbar .context-kicker,
.world-designer-units .context-kicker {
  grid-column: 1 / -1;
}

.world-designer-toolbar label:first-of-type,
.world-designer-toolbar label:nth-of-type(2),
.world-designer-toolbar label:nth-of-type(3) {
  grid-column: auto;
}

.world-designer-toolbar label.world-designer-capital-toggle,
.world-designer-infrastructure label:first-of-type {
  grid-column: auto;
}

.world-designer-toolbar label.world-designer-capital-toggle {
  align-self: end;
}

.world-designer-units {
  max-height: min(230px, 32vh);
  overflow: auto;
}

.world-designer-units input[type="number"] {
  min-width: 0;
}

@media (max-height: 760px) {
  .world-designer-units {
    max-height: 168px;
  }
}

.world-designer-svg {
  width: 100%;
  height: 100%;
  display: block;
  background: #071522;
}

.world-designer-svg .province-shape {
  cursor: pointer;
}

.world-designer-svg .province-shape.readonly-preview {
  cursor: default;
  opacity: 0.7;
  stroke-dasharray: 6 5;
  pointer-events: none;
}

.world-designer-svg .province-shape.has-error {
  filter: saturate(1.18);
}

.world-designer-svg .province-shape:hover,
.world-designer-svg .province-shape.selected {
  filter: brightness(1.16);
}

.world-designer-validation {
  border-color: rgba(255, 123, 123, 0.38);
  color: #ffc7c7;
}

.world-designer-selected-errors {
  grid-column: 1 / -1;
  display: grid;
  gap: 4px;
  color: #ffc7c7;
  font-size: 12px;
  line-height: 1.25;
}

.world-designer-error-badge circle {
  fill: rgba(123, 31, 31, 0.92);
  stroke: rgba(255, 210, 210, 0.9);
  stroke-width: 1.5;
}

.world-designer-error-badge text {
  fill: #fff4f4;
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
}

.province-map-icon.terrain {
  fill: rgba(196, 221, 238, 0.72);
}

.province-map-icon.units {
  fill: rgba(132, 225, 183, 0.88);
}

.world-map-stage {
  position: relative;
  width: 100%;
  height: 100%;
}

.world-map-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.world-water-hex {
  fill: rgba(24, 107, 143, 0.46);
  stroke: rgba(126, 190, 217, 0.28);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.province-shape {
  vector-effect: non-scaling-stroke;
  transition:
    transform 0.12s ease,
    filter 0.12s ease,
    stroke-width 0.12s ease;
}

.province-shape.adjacent-target {
  filter: brightness(1.06);
  cursor: crosshair;
}

.province-shape.planning-selectable {
  cursor: pointer;
}

.province-shape.province-hovered {
  filter: brightness(1.06);
  stroke-width: 4;
}

.province-label-name,
.province-label-sub,
.country-label,
.army-token-count,
.army-token-badge,
.army-token-sub,
.order-arrow-label {
  font-family: "Segoe UI", sans-serif;
  pointer-events: none;
}

.province-label-name {
  fill: #f6f0da;
  font-size: 11px;
  font-weight: 700;
  paint-order: stroke;
  stroke: rgba(7, 19, 31, 0.68);
  stroke-width: 3px;
}

.capital-marker {
  stroke: rgba(7, 19, 31, 0.82);
  stroke-width: 2px;
  paint-order: stroke;
}

.province-icon-strip {
  pointer-events: none;
}

.province-map-icon {
  fill: rgba(246, 240, 218, 0.78);
  stroke: rgba(7, 19, 31, 0.76);
  stroke-width: 2px;
  stroke-linecap: round;
  stroke-linejoin: round;
  paint-order: stroke;
}

.province-map-icon.infrastructure {
  fill: rgba(247, 202, 117, 0.84);
}

.province-map-icon.construction {
  fill: rgba(154, 181, 206, 0.68);
  stroke-dasharray: 2 2;
}

.province-icon-build-dot {
  fill: #7af0b0;
  stroke: rgba(7, 19, 31, 0.9);
  stroke-dasharray: none;
}

.province-label-sub {
  fill: rgba(255, 246, 221, 0.82);
  font-size: 9px;
}

.country-label {
  fill: rgba(255, 246, 221, 0.16);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 46px;
  font-weight: 700;
  pointer-events: none;
}

.army-layer {
  pointer-events: none;
}

.army-token {
  cursor: default;
  pointer-events: none;
}

.army-token.army-token-interactive {
  cursor: pointer;
}

.army-token.selected {
  filter: drop-shadow(0 0 10px rgba(255, 216, 111, 0.65));
}

.army-token-count {
  fill: #f4f1de;
  font-size: 12px;
  font-weight: 800;
}

.army-token-badge {
  fill: #08111c;
  font-size: 9px;
  font-weight: 800;
}

.army-token-sub {
  fill: rgba(244, 241, 222, 0.8);
  font-size: 9px;
}

.order-arrow-label {
  fill: #eef6ff;
  font-size: 12px;
  font-weight: 700;
}

.context-panel[hidden] {
  display: none;
}

.context-panel {
  min-height: 150px;
  max-height: 232px;
  overflow: hidden;
}

body.match-active .context-panel {
  height: 100%;
  min-height: 0;
  max-height: none;
}

.context-shell,
.context-empty {
  height: 100%;
  border: 1px solid rgba(148, 195, 255, 0.2);
  border-radius: 14px;
  padding: 10px;
  background: rgba(5, 11, 18, 0.9);
}

.context-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

.context-empty {
  display: grid;
  align-content: center;
  gap: 6px;
}

.context-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.context-actions,
.mini-button-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.battle-toolbar-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.context-actions button,
.context-toolbar > button {
  width: auto;
  min-width: 136px;
  padding: 9px 12px;
}

.context-actions .world-designer-create-mode button {
  width: 100%;
  min-width: 0;
}

.battle-camera-controls {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 3px;
  border: 1px solid rgba(148, 195, 255, 0.14);
  border-radius: 12px;
  background: rgba(5, 11, 18, 0.7);
}

.battle-camera-controls button {
  width: auto;
  min-width: 34px;
  padding: 6px 8px;
  font-size: 12px;
}

.battle-camera-controls button:last-child {
  min-width: 84px;
}

.context-kicker {
  display: block;
  color: var(--gold);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.selection-panel {
  display: grid;
  grid-template-columns: minmax(210px, 0.82fr) minmax(330px, 1.08fr) minmax(360px, 1.2fr);
  gap: 10px;
  align-items: start;
  height: 100%;
  min-height: 0;
}

.selection-panel section {
  min-width: 0;
}

.selection-summary h2 {
  margin: 2px 0 0;
  font-size: 17px;
}

.compact-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px 8px;
  font-size: 12px;
  line-height: 1.25;
}

.compact-meta-grid span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-meta-grid strong {
  color: var(--text);
}

.context-row-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.mini-button-row button {
  width: auto;
  min-width: 72px;
  padding: 7px 9px;
  font-size: 12px;
}

.compact-unit-list {
  grid-template-columns: repeat(auto-fit, minmax(138px, 1fr));
  gap: 6px;
  align-content: start;
  max-height: 104px;
  overflow: hidden;
}

.stack-unit.compact {
  grid-template-columns: 16px 1fr;
  gap: 8px;
  padding: 7px 8px;
  font-size: 12px;
}

.stack-unit.compact input {
  width: auto;
}

.selection-orders,
.selection-actions {
  display: grid;
  gap: 6px;
  align-content: start;
  min-height: 0;
}

.compact-queued {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 48px;
  overflow: hidden;
}

.world-queued-strip {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid rgba(148, 195, 255, 0.12);
}

.order-action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 6px;
  align-items: stretch;
}

.order-action-grid .compact-queued {
  grid-column: auto;
}

.province-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.province-action-card {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 6px;
  border: 1px solid rgba(148, 195, 255, 0.14);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
}

.province-action-card > strong {
  font-size: 12px;
  color: var(--text);
}

.action-chip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(52px, 1fr));
  gap: 4px;
}

.world-action-chip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0 6px;
  align-items: center;
  min-width: 0;
  padding: 6px 7px;
  text-align: left;
  background: rgba(18, 36, 56, 0.9);
}

body.match-active .world-action-chip {
  padding: 4px 5px;
  border-radius: 9px;
}

.world-action-chip span,
.world-action-chip em {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.world-action-chip span {
  font-size: 10px;
}

.world-action-chip strong {
  color: var(--gold);
  font-size: 10px;
}

.world-action-chip em {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.1;
  font-style: normal;
}

.world-action-chip.queued {
  border-color: rgba(247, 202, 117, 0.62);
  background: rgba(247, 202, 117, 0.12);
}

.province-action button,
.recruit-row button {
  width: auto;
  min-width: 86px;
}

.compact-recruit {
  gap: 4px;
}

.compact-recruit select {
  min-width: 0;
}

.battle-program-strip {
  display: grid;
  grid-auto-columns: minmax(300px, 1fr);
  grid-auto-flow: column;
  gap: 10px;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.battle-program-strip::-webkit-scrollbar {
  display: none;
}

.battle-program-strip .province-card {
  min-width: 0;
}

.battle-unit-card {
  transition:
    border-color 120ms ease,
    background 120ms ease,
    box-shadow 120ms ease;
}

.battle-unit-card.selected {
  border-color: rgba(247, 202, 117, 0.62);
  background: rgba(247, 202, 117, 0.08);
  box-shadow: inset 0 0 0 1px rgba(247, 202, 117, 0.18);
}

.battle-planning-layout {
  display: grid;
  grid-template-columns: minmax(230px, 0.64fr) minmax(390px, 1.36fr);
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}

.battle-command-shell {
  gap: 6px;
  padding: 8px;
  background:
    linear-gradient(90deg, rgba(247, 202, 117, 0.065), transparent 42%),
    rgba(5, 11, 18, 0.9);
}

body.match-active[data-phase="battle_planning"] .battle-toolbar-actions {
  gap: 6px;
}

body.match-active[data-phase="battle_planning"] .battle-toolbar-actions > button {
  padding: 7px 9px;
}

body.match-active[data-phase="battle_planning"] .battle-camera-controls {
  gap: 3px;
  padding: 2px;
}

body.match-active[data-phase="battle_planning"] .battle-camera-controls button {
  padding: 5px 7px;
}

.battle-watch-shell {
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  background:
    linear-gradient(90deg, rgba(82, 179, 255, 0.045), transparent 48%),
    rgba(5, 11, 18, 0.88);
}

.battle-watch-toolbar {
  align-items: center;
}

.auto-advance-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid rgba(82, 179, 255, 0.22);
  border-radius: 999px;
  color: #9fd0ff;
  background: rgba(82, 179, 255, 0.08);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.battle-unit-ribbon {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 6px;
  align-content: start;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
}

.battle-unit-chip {
  display: grid;
  gap: 2px;
  width: 100%;
  min-width: 0;
  min-height: 132px;
  padding: 7px 8px;
  text-align: left;
  border-color: rgba(148, 195, 255, 0.18);
  background: rgba(18, 36, 56, 0.8);
}

.battle-unit-chip.selected {
  border-color: rgba(247, 202, 117, 0.62);
  background: rgba(247, 202, 117, 0.12);
}

.battle-unit-chip span,
.battle-unit-chip em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unit-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px 8px;
  margin-top: 6px;
  font-size: 12px;
}

.unit-stats-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px 6px;
  margin-top: 3px;
  font-size: 10.5px;
}

.unit-stats-grid span {
  display: grid;
  gap: 1px;
  min-width: 0;
  padding: 4px 5px;
  border: 1px solid rgba(148, 195, 255, 0.12);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
}

.unit-stats-grid strong {
  color: rgba(226, 238, 255, 0.76);
  font-size: 10px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-stats-grid b {
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-stats-popover {
  position: fixed;
  z-index: 90;
  width: min(340px, calc(100vw - 16px));
  padding: 10px;
  border: 1px solid rgba(148, 195, 255, 0.28);
  border-radius: 8px;
  background: rgba(6, 14, 24, 0.98);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.36);
}

.unit-stats-popover > strong {
  display: block;
  margin-bottom: 6px;
}

.battle-detail-card {
  display: grid;
  align-content: start;
  gap: 5px;
  min-height: 0;
  overflow: hidden;
  padding: 8px;
}

.battle-detail-card .province-header {
  margin-bottom: 0;
}

.battle-detail-card .unit-stats-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px 6px;
  margin-top: 0;
}

.battle-detail-card .unit-stats-grid.compact span {
  padding: 3px 5px;
}

.battle-command-row {
  display: grid;
  grid-template-columns: minmax(108px, 0.75fr) minmax(108px, 0.8fr) minmax(180px, 1.35fr) auto;
  gap: 6px;
  align-items: end;
}

.battle-command-row label {
  gap: 4px;
}

.battle-command-row select,
.battle-command-row button {
  padding: 7px 8px;
}

.battle-command-row button {
  min-width: 124px;
}

.battle-stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 4px 0;
}

.battle-stat-row span {
  padding: 4px 7px;
  border: 1px solid rgba(148, 195, 255, 0.13);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 11px;
}

.compact-battle-hint {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battle-no-selection {
  display: grid;
  align-content: center;
  gap: 4px;
}

.battle-legend-note {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  gap: 6px 12px;
  padding: 7px 9px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

.battle-legend-note strong {
  color: var(--text);
}

.playback-event-log {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 6px;
  min-height: 0;
  overflow: hidden;
}

.playback-event {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-size: 12px;
}

.playback-event.impact {
  background: rgba(247, 202, 117, 0.09);
  border: 1px solid rgba(247, 202, 117, 0.16);
  color: #fff1b8;
}

.playback-event.damage {
  color: #ffe3aa;
}

.playback-event.shot,
.playback-event.artillery_impact,
.playback-event.drone_released {
  color: #fff1b8;
}

.playback-event.move {
  color: #9fd7f5;
  opacity: 0.82;
}

.playback-event.miss {
  color: #adb8c5;
}

.stack-composer {
  position: absolute;
  width: min(260px, 23vw);
  min-width: 220px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid rgba(247, 202, 117, 0.38);
  background: rgba(5, 11, 18, 0.95);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(10px);
  z-index: 4;
}

.stack-composer.empty {
  border-color: rgba(148, 195, 255, 0.22);
}

.stack-composer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stack-unit-list,
.composer-queued {
  display: grid;
  gap: 8px;
}

.stack-unit {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(148, 195, 255, 0.14);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
}

.stack-unit.selected {
  border-color: rgba(247, 202, 117, 0.46);
  background: rgba(247, 202, 117, 0.08);
}

.command-chip {
  text-align: left;
  background: rgba(18, 36, 56, 0.94);
  padding: 8px 10px;
  font-size: 12px;
}

.stack {
  display: grid;
  gap: 12px;
}

.button-row {
  display: grid;
  gap: 10px;
}

.lobby-slots {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.lobby-slot {
  flex: 1 1 0;
  min-width: 140px;
  border: 2px solid rgba(148, 195, 255, 0.24);
  border-radius: 8px;
  padding: 12px;
  background: rgba(5, 11, 18, 0.9);
  text-align: center;
}

.lobby-slot.side-a {
  border-color: var(--blue);
}

.lobby-slot.side-b {
  border-color: var(--red);
}

.lobby-slot.side-c {
  border-color: #a8b7d4;
}

.lobby-slot-viewer {
  box-shadow: 0 0 0 2px var(--gold) inset;
}

.lobby-slot-side {
  font-weight: bold;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.7;
}

.lobby-slot-name {
  font-size: 1.1rem;
  margin: 4px 0;
  overflow-wrap: anywhere;
}

.lobby-slot-state {
  font-size: 0.85rem;
  opacity: 0.85;
}

.lobby-message {
  margin: 6px 0 12px;
  font-style: italic;
  opacity: 0.85;
}

.lobby-claim-row,
.pending-join-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.lobby-claim-button {
  width: auto;
  border: 2px solid rgba(148, 195, 255, 0.24);
  background: transparent;
  color: inherit;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
}

.lobby-claim-button.side-b {
  border-color: var(--red);
}

.lobby-claim-button.side-c {
  border-color: #a8b7d4;
}

.pending-join-panel {
  padding: 12px;
  border: 1px solid rgba(148, 195, 255, 0.18);
  border-radius: 8px;
  margin: 8px 0;
  background: rgba(5, 11, 18, 0.9);
}

.stack.compact {
  gap: 8px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

input,
select,
button {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(148, 195, 255, 0.2);
  background: rgba(5, 11, 18, 0.95);
  color: var(--text);
  padding: 11px 12px;
  font: inherit;
}

body.match-active input,
body.match-active select,
body.match-active button {
  padding: 9px 10px;
}

button {
  background: linear-gradient(135deg, rgba(82, 179, 255, 0.3), rgba(23, 76, 142, 0.95));
  cursor: pointer;
  font-weight: 600;
}

button.secondary {
  background: rgba(18, 36, 56, 0.94);
}

button.full-width {
  width: 100%;
}

button.warning {
  background: linear-gradient(135deg, rgba(255, 123, 123, 0.25), rgba(123, 31, 31, 0.95));
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.notice,
.card,
.pill-row {
  border: 1px solid rgba(148, 195, 255, 0.18);
  border-radius: 14px;
  padding: 12px;
  background: rgba(5, 11, 18, 0.9);
}

body.match-active #status-panel,
body.match-active #controls-panel {
  gap: 10px;
}

.compact-card {
  padding: 10px;
}

.compact-card h3,
.status-card h3 {
  margin-bottom: 8px;
  font-size: 17px;
}

.status-card {
  padding: 10px;
}

.status-card p {
  margin-bottom: 0;
  font-size: 13px;
  line-height: 1.35;
}

.status-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.player-list {
  display: grid;
  gap: 8px;
}

.player-strip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(82, 179, 255, 0.08);
}

.player-strip.side-b {
  background: rgba(255, 123, 123, 0.08);
}

.player-strip strong,
.player-strip .muted {
  display: block;
}

.player-strip .muted {
  font-size: 12px;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rail-toggle {
  width: auto;
  min-width: 0;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(18, 36, 56, 0.94);
  color: var(--muted);
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(82, 179, 255, 0.14);
  color: var(--text);
  font-size: 12px;
}

.pill.side-a {
  background: rgba(82, 179, 255, 0.14);
}

.pill.red,
.pill.side-b {
  background: rgba(255, 123, 123, 0.16);
}

.pill.side-c {
  background: rgba(168, 183, 212, 0.18);
  color: #eef3ff;
}

.pill.gold {
  background: rgba(247, 202, 117, 0.18);
  color: #ffe9b3;
}

.pill.warning-pill {
  background: rgba(247, 202, 117, 0.14);
  color: #ffe9b3;
}

.session-meta {
  display: flex;
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
}

.session-summary {
  max-width: 100%;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.session-summary .pill,
.session-summary .rail-toggle {
  min-height: 28px;
  padding: 5px 8px;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
}

.session-summary .warning-pill {
  max-width: min(360px, 32vw);
  line-height: 1.25;
  white-space: normal;
}

.session-phase {
  max-width: min(360px, 28vw);
  overflow: hidden;
  text-overflow: ellipsis;
  background: rgba(18, 36, 56, 0.78);
}

.session-player {
  max-width: 210px;
  background: rgba(18, 36, 56, 0.78);
}

.session-player.side-a {
  background: rgba(18, 36, 56, 0.78);
}

.session-player.red,
.session-player.side-b {
  background: rgba(255, 123, 123, 0.12);
}

.session-player.side-c {
  background: rgba(168, 183, 212, 0.14);
}

.session-player strong {
  max-width: 88px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-player small {
  color: var(--muted);
  font-size: 10px;
}

.session-lock {
  background: rgba(18, 36, 56, 0.78);
}

@media (max-width: 1450px) {
  .session-summary .session-code {
    display: none;
  }

  .session-phase {
    max-width: 300px;
  }
}

.province-card {
  border: 1px solid rgba(148, 195, 255, 0.16);
  border-radius: 14px;
  padding: 12px;
  background: rgba(5, 11, 18, 0.82);
}

.province-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.province-header h2,
.province-header h3 {
  margin-bottom: 0;
}

.province-header button {
  width: auto;
  min-width: 116px;
}

.province-units,
.meta-list,
.battle-grid {
  display: grid;
  gap: 6px;
}

.battle-grid {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.reference-grid {
  display: grid;
  gap: 8px;
}

.reference-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.terrain-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

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

.battle-target-line {
  min-width: 0;
  padding: 8px 9px;
  border-radius: 10px;
  background: rgba(247, 202, 117, 0.07);
  color: #ffe9b3;
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 13px;
}

.unit-row strong {
  color: var(--text);
}

.muted {
  color: var(--muted);
}

.error {
  color: #ffb0b0;
}

.success {
  color: var(--green);
}

.phase-banner {
  font-size: 15px;
  font-weight: 700;
}

.unit-legend {
  display: block;
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(148, 195, 255, 0.16);
}

@media (max-width: 1220px) {
  .layout {
    grid-template-columns: 1fr;
  }

  body.match-active .layout {
    grid-template-columns: 1fr;
  }

  .panel-canvas #game-root {
    min-height: 420px;
  }

  body.match-active .panel-wide {
    max-height: none;
  }

  .selection-panel {
    grid-template-columns: 1fr;
  }

  .order-action-grid {
    grid-template-columns: 1fr;
  }

  .battle-planning-layout {
    grid-template-columns: 1fr;
  }

  .battle-detail-card .unit-stats-grid.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .battle-command-row {
    grid-template-columns: 1fr;
  }

  .context-panel {
    max-height: none;
  }
}

@media (max-width: 700px) {
  .shell {
    padding: 10px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .topbar > div:first-child {
    min-width: 0;
  }

  .eyebrow {
    font-size: 10px;
    letter-spacing: 0.12em;
    overflow-wrap: anywhere;
  }

  .session-meta {
    width: 100%;
    justify-content: flex-start;
  }

  .session-summary {
    justify-content: flex-start;
    align-items: flex-start;
  }

  .session-summary .pill,
  .session-summary .rail-toggle {
    min-width: 0;
    min-height: 32px;
    max-width: 100%;
    white-space: normal;
  }

  .session-summary .account-pill {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .auth-panel {
    min-height: calc(100vh - 116px);
    place-items: start stretch;
  }

  .auth-card {
    width: 100%;
    padding: 20px;
    border-radius: 18px;
  }

  .auth-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .layout {
    gap: 12px;
  }

  .panel {
    min-height: 0;
    padding: 14px;
    border-radius: 16px;
  }

  .panel-canvas {
    padding: 8px;
  }

  .panel-canvas #game-root {
    aspect-ratio: auto;
    min-height: 260px;
    max-height: none;
  }

  input,
  select,
  button,
  .notice,
  .card,
  .pill-row,
  .pending-join-panel {
    min-width: 0;
  }

  .notice,
  .card,
  .pending-join-panel {
    overflow-wrap: anywhere;
  }

  .button-row {
    gap: 9px;
  }

  .lobby-slot {
    flex: 1 1 140px;
    min-width: 0;
    padding: 10px;
  }

  .pending-join-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  }

  .lobby-claim-button {
    width: 100%;
    min-height: 40px;
  }
}
