:root {
  color-scheme: light;
  --paper: #ffffff;
  --ink: #171717;
  --muted: #666666;
  --line: #d9d9d9;
  --panel: #f7f7f5;
  --panel-strong: #ededeb;
  --accent: #286451;
  --accent-dark: #1d473a;
  --focus: #b8892e;
  --danger: #8f2f2f;
  --shadow: 0 18px 44px rgba(20, 20, 20, 0.12);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: #e7e8e5;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="text"],
input[type="number"] {
  border: 1px solid #bdbdb9;
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
}

button {
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #777772;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px;
  border-bottom: 1px solid #c8c9c5;
  background: #f8f8f6;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 1.6rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.mode-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid #bfc0bc;
  border-radius: 8px;
  background: var(--panel-strong);
}

.mode-switch label {
  min-width: 118px;
  min-height: 36px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  color: #343434;
  cursor: pointer;
  font-weight: 650;
  font-size: 0.9rem;
}

.mode-switch input {
  position: absolute;
  opacity: 0;
}

.mode-switch label:has(input:checked) {
  background: var(--paper);
  color: var(--accent-dark);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.09);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
}

.sidebar {
  min-height: 0;
  overflow: auto;
  padding: 14px;
  border-right: 1px solid #c6c7c2;
  background: var(--panel);
}

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

.sidebar section:first-child {
  padding-top: 0;
}

.sidebar section:last-child {
  border-bottom: 0;
}

.sidebar h2 {
  margin: 0 0 10px;
  font-size: 0.78rem;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #3d3d3a;
}

.field {
  display: grid;
  gap: 5px;
  margin-bottom: 10px;
}

.field span,
.bbox-grid span {
  color: #4e4e4a;
  font-size: 0.83rem;
  font-weight: 650;
}

.field select,
.field input {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
}

.bbox-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.bbox-grid label {
  display: grid;
  gap: 5px;
}

.bbox-grid input {
  width: 100%;
  min-height: 36px;
  padding: 0 8px;
}

.map-nav {
  display: grid;
  grid-template-columns: 42px 42px 1fr;
  gap: 8px;
  margin: 8px 0 10px;
}

.map-nav button {
  min-width: 0;
  min-height: 38px;
  padding: 0 10px;
  font-weight: 750;
}

.map-nav button:first-child,
.map-nav button:nth-child(2) {
  padding: 0;
  font-size: 1.2rem;
}

.advanced-bbox {
  border-top: 1px solid var(--line);
  padding-top: 9px;
}

.advanced-bbox summary {
  min-height: 30px;
  display: flex;
  align-items: center;
  color: #3d3d3a;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 700;
}

.advanced-bbox .bbox-grid {
  margin-top: 8px;
}

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

.check-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  color: #282826;
}

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

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin: 8px 0 10px;
}

.tool-button {
  min-width: 0;
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  background: var(--paper);
}

.tool-icon {
  width: 20px;
  flex: 0 0 20px;
  display: inline-grid;
  place-items: center;
  font-size: 1.2rem;
  line-height: 1;
  font-weight: 750;
}

.tool-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.86rem;
  font-weight: 700;
}

.label-tool {
  border-color: #9ea7a1;
}

.erase-tool {
  border-color: #b8a5a0;
}

.tool-button.active {
  border-color: var(--accent-dark);
  background: #e8f0ec;
  color: var(--accent-dark);
  box-shadow: inset 0 0 0 1px var(--accent-dark);
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

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

.primary {
  border-color: var(--accent-dark);
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.primary:hover {
  border-color: #12352b;
  background: var(--accent-dark);
}

.stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  background: #d6d8d3;
}

.stage-toolbar {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid #c1c2bd;
  background: #efefec;
  color: #343431;
  font-size: 0.9rem;
}

.page-wrap {
  min-height: 0;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 24px;
}

#mapSvg {
  display: block;
  width: min(100%, 1120px);
  height: auto;
  background: var(--paper);
  box-shadow: var(--shadow);
  touch-action: manipulation;
  user-select: none;
  cursor: grab;
}

#mapSvg.portrait {
  width: min(100%, 794px);
}

.country-hit {
  cursor: pointer;
}

.drawing-cursor {
  cursor: crosshair;
}

.erase-cursor {
  cursor: not-allowed;
}

#mapSvg.panning {
  cursor: grabbing;
}

.map-label {
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 3px;
  stroke-linejoin: round;
}

@media (max-width: 880px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-switch {
    width: 100%;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: 45vh;
    border-right: 0;
    border-bottom: 1px solid #c6c7c2;
  }

  .page-wrap {
    padding: 14px;
    place-items: start center;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .topbar,
  .sidebar,
  .stage-toolbar {
    display: none;
  }

  .workspace,
  .stage,
  .app-shell {
    display: block;
  }

  .page-wrap {
    padding: 0;
    overflow: visible;
  }

  #mapSvg {
    width: 100%;
    box-shadow: none;
  }
}
