:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #3a3a3a;
  color: #eef4f6;
}

* { box-sizing: border-box; }

html, body, #viewer {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body { background: #3a3a3a; }

#viewer {
  position: relative;
  background:
    linear-gradient(180deg, #858585 0%, #666666 28%, #303030 70%, #101112 100%);
}

#canvas-container,
#canvas-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.label-renderer {
  position: absolute;
  z-index: 6;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.map-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.64);
  border-radius: 6px;
  background: rgba(8, 13, 17, 0.86);
  color: #ffffff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  font-size: 11px;
  letter-spacing: 0.025em;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.map-label-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #70bee4;
  box-shadow: 0 0 8px rgba(112, 190, 228, 0.55);
}

.map-label strong { font-weight: 650; }

.topbar {
  position: absolute;
  z-index: 10;
  top: 0;
  left: 0;
  right: 0;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(8, 13, 17, 0.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-symbol {
  display: block;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  overflow: hidden;
}

.brand-symbol img {
  display: block;
  width: auto;
  max-width: none;
  height: 38px;
}

.brand-mark {
  width: 8px;
  height: 36px;
  border-radius: 3px;
  background: linear-gradient(180deg, #1780b5, #063457);
  box-shadow: 0 0 18px rgba(23, 128, 181, 0.24);
}

h1 { margin: 0; font-size: clamp(17px, 2vw, 21px); letter-spacing: 0.02em; }
.brand p { margin: 3px 0 0; color: #8fa0a8; font-size: 12px; }
.controls { display: flex; gap: 9px; }

button {
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #e8eef0;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

button:hover { background: rgba(255, 255, 255, 0.11); border-color: rgba(255, 255, 255, 0.25); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid #1780b5; outline-offset: 2px; }
button[aria-pressed="true"] { color: #ffffff; background: #0d6895; border-color: #1780b5; }

.layers-panel {
  position: absolute;
  z-index: 9;
  top: 92px;
  right: 22px;
  width: min(250px, calc(100vw - 32px));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(8, 13, 17, 0.84);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.24);
  overflow: hidden;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.layers-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 16px 13px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.eyebrow { color: #6f8792; font-size: 9px; font-weight: 700; letter-spacing: 0.15em; }
.layers-heading h2 { margin: 2px 0 0; font-size: 16px; }
.layers-count {
  min-width: 24px;
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(23, 128, 181, 0.18);
  color: #70bee4;
  font-size: 10px;
  text-align: center;
}

.layer-list { padding: 7px; }
.layer-item {
  position: relative;
  display: grid;
  grid-template-columns: 10px 1fr 34px;
  align-items: center;
  gap: 11px;
  min-height: 56px;
  padding: 8px 9px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 160ms ease;
}
.layer-item:hover { background: rgba(255, 255, 255, 0.055); }
.layer-item.error { background: rgba(175, 62, 45, 0.12); }
.layer-swatch { width: 8px; height: 28px; border-radius: 3px; }
.layer-swatch.terrain { background: #b66d28; }
.layer-swatch.wrd-north { background: #9a8774; }
.layer-swatch.wrd-central { background: #6f7c82; }
.layer-swatch.wrd-south { background: #8b865e; }
.layer-copy { min-width: 0; }
.layer-copy strong, .layer-copy small { display: block; }
.layer-copy strong { color: #e4eaed; font-size: 12px; font-weight: 600; }
.layer-copy small { margin-top: 3px; color: #768890; font-size: 10px; }
.layer-item.error small { color: #e39a8d; }
.layer-item input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  position: relative;
  width: 34px;
  height: 19px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  transition: background 180ms ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #c3cdd1;
  transition: transform 180ms ease, background 180ms ease;
}
.layer-item input:checked + .switch { background: #0d6895; }
.layer-item input:checked + .switch::after { transform: translateX(15px); background: #ffffff; }
.layer-item input:focus-visible + .switch { outline: 2px solid #70bee4; outline-offset: 2px; }
.layer-item input:disabled + .switch { opacity: 0.5; }

.status {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: min(360px, calc(100vw - 32px));
  padding: 18px 20px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(9, 14, 18, 0.9);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  transition: opacity 250ms ease, visibility 250ms ease;
}

.status.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.status.error { border-color: rgba(221, 111, 91, 0.55); }
.status.error .spinner { display: none; }
.status strong, .status span { display: block; }
.status strong { margin-bottom: 4px; font-size: 14px; }
.status span { color: #93a4ab; font-size: 12px; line-height: 1.45; }

.spinner {
  flex: 0 0 auto;
  width: 25px;
  height: 25px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: #1780b5;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.help {
  position: absolute;
  z-index: 7;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  gap: 18px;
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(8, 13, 17, 0.67);
  color: #899aa2;
  font-size: 11px;
  white-space: nowrap;
  backdrop-filter: blur(10px);
}

.help b { color: #cbd5d9; font-weight: 600; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 680px) {
  .topbar { align-items: flex-start; min-height: 118px; }
  .brand { gap: 8px; }
  .brand-symbol { flex-basis: 30px; width: 30px; height: 30px; }
  .brand-symbol img { height: 30px; }
  .brand-mark { width: 6px; height: 30px; }
  .controls { flex-direction: column; }
  button { min-height: 36px; padding: 0 11px; font-size: 12px; }
  .layers-panel { top: 130px; right: 12px; width: 210px; }
  .help { bottom: 12px; gap: 10px; max-width: calc(100vw - 24px); overflow-x: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; }
}
