:root {
  color-scheme: light;
  --ink: #181818;
  --muted: #62666d;
  --line: #d7dadf;
  --panel: #f7f8fa;
  --accent: #245b45;
  --accent-dark: #173d2f;
  --paper: #ffffff;
  --selected: #edf5f1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: #eceff3;
  overflow-x: hidden;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: #f7f8fa;
  color: var(--ink);
  font-family: "Segoe UI Variable Display", "Segoe UI Variable", "Segoe UI", Arial, Helvetica, sans-serif;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.loading-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-panel {
  width: min(360px, calc(100vw - 48px));
  display: grid;
  gap: 10px;
  text-align: center;
}

.loading-panel h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 650;
  letter-spacing: 0;
}

.loading-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.loading-bar {
  height: 3px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe3e8;
}

.loading-bar::before {
  content: "";
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  animation: loading-slide 1.1s ease-in-out infinite;
}

@keyframes loading-slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(260%); }
}

.export-error,
.tutorial-modal {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(24, 24, 24, 0.18);
}

.export-error[hidden],
.tutorial-modal[hidden] {
  display: none;
}

.export-error-panel,
.tutorial-panel {
  position: relative;
  min-width: min(320px, calc(100vw - 48px));
  padding: 22px 24px;
  border: 1px solid #d7dadf;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 48px rgba(24, 24, 24, 0.16);
  text-align: center;
}

.tutorial-modal {
  z-index: 910;
  background: rgba(24, 24, 24, 0.24);
}

.tutorial-panel {
  width: min(560px, calc(100vw - 40px));
  max-height: calc(100vh - 48px);
  padding: 26px;
  overflow: auto;
  text-align: left;
}

.export-error-close,
.tutorial-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
  line-height: 1;
}

.export-error-close:hover,
.tutorial-close:hover {
  border-color: var(--line);
  color: var(--ink);
  background: #f7f8fa;
}

.export-error-panel p {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 16px;
}

.export-error-panel strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
  text-align: center;
}

.tutorial-kicker {
  margin: 0 0 7px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.tutorial-panel h2 {
  margin: 0 32px 18px 0;
  font-size: 24px;
  line-height: 1.15;
}

.tutorial-steps {
  display: grid;
  gap: 12px;
}

.tutorial-steps section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f8fa;
}

.tutorial-steps strong {
  display: block;
  margin-bottom: 7px;
  font-size: 14px;
}

.tutorial-steps p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.tutorial-done {
  width: 100%;
  height: 42px;
  margin-top: 18px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

button,
input {
  font: inherit;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand h1 {
  margin: 0 0 6px;
  font-size: 24px;
  line-height: 1.1;
}

.brand p,
.toolbar span {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.brand .autosave-label {
  margin-top: 7px;
  font-size: 11px;
  color: #7a8088;
}

.field {
  display: grid;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
}

.field input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--paper);
}

.field input:focus {
  outline: 2px solid rgba(36, 91, 69, 0.22);
  border-color: var(--accent);
}

.active-unit-label {
  margin: 0;
  line-height: 1.25;
  color: var(--ink);
  font-size: 13px;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--ink);
}

.check-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.line-action {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

.tool-section {
  display: grid;
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.symbol-section {
  padding-top: 18px;
}

.tool-section h2 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.tool-section button {
  height: 38px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 700;
}

.tool-section button:disabled {
  cursor: not-allowed;
  border-color: var(--line);
  background: #eef0f3;
  color: #8a8e95;
}

.general-edits {
  margin-bottom: 28px;
}

.scale-control {
  display: grid;
  gap: 9px;
}

.scale-control input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.suggestions {
  display: grid;
  gap: 8px;
  overflow: auto;
  min-height: 0;
  max-height: 176px;
  padding-right: 4px;
}

.suggestions.compact {
  min-height: 0;
  max-height: 142px;
}

.suggestions:empty {
  display: none;
}

.suggestion {
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 7px;
  padding: 10px 11px;
  text-align: left;
  cursor: pointer;
}

.suggestion:hover {
  border-color: var(--accent);
  background: var(--selected);
}

.suggestion.selected {
  border-color: var(--accent);
  background: var(--selected);
}

.suggestion strong {
  display: block;
  font-size: 15px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: auto;
  padding-top: 12px;
}

.actions button {
  height: 42px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
}

.add-unit {
  height: 42px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent-dark);
  color: white;
  cursor: pointer;
  font-weight: 700;
}

.add-unit:disabled {
  cursor: not-allowed;
  border-color: var(--line);
  background: #d7dadf;
  color: #73777e;
}

.actions .secondary {
  background: transparent;
  color: var(--accent-dark);
}

.actions button:disabled {
  cursor: not-allowed;
  border-color: var(--line);
  background: #eef0f3;
  color: #8a8e95;
}

.workspace {
  padding: 26px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
  width: 100%;
  max-width: 100vw;
  min-width: 0;
  overflow: hidden;
}

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

.toolbar-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.toolbar span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.info-button {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 900;
  line-height: 1;
}

.info-button:hover {
  border-color: var(--accent);
  background: var(--selected);
}

.slide {
  position: relative;
  background: var(--paper);
  border: 1px solid #cfd3d9;
  aspect-ratio: 16 / 9;
  width: 100%;
  max-width: min(100%, calc((100vh - 96px) * 16 / 9));
  justify-self: center;
  box-shadow: 0 16px 38px rgba(26, 31, 38, 0.12);
  padding: 0;
  overflow: hidden;
}

.slide h2 {
  display: none;
}

.board {
  position: absolute;
  inset: 3.2% 4.2%;
  min-height: 0;
  overflow: hidden;
}

.link-layer,
.guide-layer,
.node-layer {
  position: absolute;
  inset: 0;
}

.link-layer {
  z-index: 3;
  pointer-events: none;
}

.node-layer {
  z-index: 2;
}

.guide-layer {
  z-index: 4;
}

.link {
  fill: none;
  stroke: #111;
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.line-hit-target {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  pointer-events: stroke;
  cursor: move;
}

.selected-line {
  stroke: #111;
  filter: drop-shadow(0 0 4px rgba(244, 198, 73, 0.85));
}

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

.guide-line {
  fill: none;
  stroke: #f0b429;
  stroke-width: 1.2;
  stroke-dasharray: 5 5;
  vector-effect: non-scaling-stroke;
}

.placed {
  position: absolute;
  border: 2px solid #111;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  min-width: 0;
  transform: translate(-50%, -50%);
  cursor: pointer;
  padding: 0;
  touch-action: none;
  user-select: none;
}

.placed:active {
  cursor: grabbing;
}

.echelon-mark {
  position: absolute;
  left: 50%;
  top: calc(-15px * var(--symbol-scale, 1));
  width: 42px;
  height: 12px;
  transform: translateX(-50%) scale(var(--symbol-scale, 1));
  transform-origin: top center;
}

.placed[data-size="team_crew"] .echelon-mark::before,
.placed[data-size="squad"] .echelon-mark::before,
.placed[data-size="section"] .echelon-mark::before,
.placed[data-size="platoon_detachment"] .echelon-mark::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #111;
  transform: translateX(-50%);
  box-shadow: var(--dot-shadow, none);
}

.placed[data-size="section"] .echelon-mark {
  --dot-shadow: -10px 0 0 #111;
}

.placed[data-size="platoon_detachment"] .echelon-mark {
  --dot-shadow: -11px 0 0 #111, 11px 0 0 #111;
}

.placed[data-size="company_battery_troop"] .echelon-mark::before,
.placed[data-size="battalion_squadron"] .echelon-mark::before,
.placed[data-size="regiment_group"] .echelon-mark::before {
  content: "";
  position: absolute;
  inset: 1px auto auto 50%;
  width: 3px;
  height: 13px;
  background: #111;
  transform: translateX(-50%);
  box-shadow: var(--bar-shadow, none);
}

.placed[data-size="battalion_squadron"] .echelon-mark {
  --bar-shadow: -7px 0 0 #111;
}

.placed[data-size="regiment_group"] .echelon-mark {
  --bar-shadow: -9px 0 0 #111, 9px 0 0 #111;
}

.placed[data-size="brigade"] .echelon-mark,
.placed[data-size="division"] .echelon-mark,
.placed[data-size="corps"] .echelon-mark {
  top: calc(-18px * var(--symbol-scale, 1));
  width: 48px;
  height: 15px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  font-style: normal;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -1px;
  text-align: center;
  color: #111;
}

.placed[data-size="brigade"] .echelon-mark::before {
  content: "X";
}

.placed[data-size="division"] .echelon-mark::before {
  content: "XX";
}

.placed[data-size="corps"] .echelon-mark::before {
  content: "XXX";
}

.placed.active {
  border-color: #111;
  box-shadow:
    0 0 0 3px rgba(244, 198, 73, 0.34),
    0 0 12px rgba(244, 198, 73, 0.48);
  z-index: 2;
}

.placed span {
  padding: 4px;
  text-align: center;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.symbol-preview {
  width: 100%;
  height: 100%;
  display: block;
}

.symbol-fallback {
  padding: 4px;
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .suggestions {
    max-height: 260px;
  }

  .workspace {
    padding: 16px;
  }
}
