:root {
  color-scheme: dark;
  --ink: #edf5f1;
  --muted: #9fb1aa;
  --surface: rgba(8, 20, 17, 0.95);
  --surface-soft: rgba(15, 34, 29, 0.92);
  --line: rgba(169, 211, 195, 0.19);
  --accent: #6cddb0;
  --accent-deep: #18845e;
  --amber: #efbd68;
  --danger: #f29980;
  --shadow: 0 16px 46px rgba(0, 0, 0, 0.34);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #07110f;
  color: var(--ink);
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-rows: 54px minmax(0, 1fr);
  width: 100%;
  height: 100%;
  min-width: 0;
  max-width: 100vw;
  overflow: hidden;
}

.topbar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, #091713, #10231d 55%, #0a1714);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.24);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 29px;
  height: 29px;
  flex: 0 0 auto;
  border: 1px solid rgba(108, 221, 176, 0.56);
  border-radius: 9px 9px 9px 2px;
  background:
    linear-gradient(135deg, rgba(108, 221, 176, 0.94), rgba(24, 132, 94, 0.2)),
    #102b24;
  box-shadow: inset 0 0 0 6px rgba(7, 17, 15, 0.36);
  transform: rotate(-4deg);
}

.brand > span:last-child {
  display: grid;
  line-height: 1.05;
}

.brand strong {
  font-size: 0.91rem;
  letter-spacing: 0.01em;
}

.brand small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.65rem;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.nav-link,
.nav-button,
.map-button,
.scenario-button,
.close-button {
  border: 1px solid transparent;
  color: #d7e4df;
  background: transparent;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease, transform 140ms ease;
}

.nav-link,
.nav-button {
  min-height: 38px;
  padding: 0 11px;
  border-radius: 9px;
  font-size: 0.78rem;
  font-weight: 700;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.nav-link:hover,
.nav-link:focus-visible,
.nav-button:hover,
.nav-button:focus-visible,
.nav-button.is-active {
  border-color: var(--line);
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
  outline: none;
}

.viewer-stage,
#cesiumContainer {
  position: relative;
  width: 100%;
  height: 100%;
}

#cesiumContainer {
  touch-action: none;
}

.viewer-stage {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #07110f;
}

.map-tools,
.scenario-control,
.navigation-hint,
.loading-state,
.runtime-message,
.authority-note,
.identify-card,
.debug-hud {
  position: absolute;
  z-index: 7;
  border: 1px solid var(--line);
  background: rgba(7, 17, 15, 0.86);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.map-tools {
  top: 14px;
  right: 14px;
  display: flex;
  gap: 5px;
  padding: 5px;
  border-radius: 12px;
}

.map-button {
  min-width: 44px;
  min-height: 40px;
  padding: 0 11px;
  border-color: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.75rem;
  font-weight: 800;
}

.map-button-square {
  min-width: 40px;
  padding: 0;
  font-size: 1.05rem;
}

.north-button {
  color: var(--accent);
  font-size: 0.9rem;
}

.map-button:hover,
.map-button:focus-visible,
.scenario-button:hover,
.scenario-button:focus-visible,
.close-button:hover,
.close-button:focus-visible {
  color: #fff;
  background: rgba(108, 221, 176, 0.13);
  outline: 2px solid rgba(108, 221, 176, 0.42);
  outline-offset: 1px;
}

.scenario-control {
  left: 50%;
  bottom: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  min-width: 210px;
  padding: 4px;
  border-radius: 12px;
  transform: translateX(-50%);
}

.scenario-button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  font-size: 0.76rem;
  font-weight: 750;
}

.scenario-button.is-active {
  color: #06120f;
  background: var(--accent);
  box-shadow: 0 7px 20px rgba(40, 164, 118, 0.24);
}

.navigation-hint {
  top: 72px;
  left: 14px;
  padding: 7px 10px;
  border-radius: 9px;
  color: #d7e8e1;
  font-size: 0.66rem;
  pointer-events: none;
  animation: hint-fade 8s forwards;
}

.loading-state {
  top: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.75rem;
}

.loading-state.is-hidden {
  display: none;
}

.loading-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(108, 221, 176, 0.55);
  animation: pulse 1.5s infinite;
}

.runtime-message {
  top: 69px;
  right: 14px;
  max-width: min(420px, calc(100% - 28px));
  padding: 10px 12px;
  border-color: rgba(242, 153, 128, 0.38);
  border-radius: 10px;
  color: #ffd8cd;
  font-size: 0.74rem;
  overflow-wrap: anywhere;
}

.debug-hud {
  top: 118px;
  left: 14px;
  width: min(355px, calc(100% - 28px));
  max-height: calc(100% - 180px);
  overflow: auto;
  padding: 10px 11px;
  border-color: rgba(108, 221, 176, 0.45);
  border-radius: 10px;
  color: #d7f7ea;
  background: rgba(3, 12, 10, 0.92);
  font: 11px/1.35 ui-monospace, SFMono-Regular, Consolas, monospace;
  pointer-events: none;
}

.debug-hud strong {
  color: var(--accent);
}

.debug-hud pre {
  margin: 6px 0 0;
  white-space: pre-wrap;
}

.authority-note {
  right: 14px;
  bottom: 14px;
  max-width: calc(50% - 130px);
  padding: 7px 9px;
  border-radius: 8px;
  color: #cad8d3;
  font-size: 0.62rem;
  pointer-events: none;
}

.drawer-backdrop {
  position: absolute;
  z-index: 18;
  inset: 0;
  background: rgba(2, 8, 7, 0.36);
}

.drawer {
  position: absolute;
  z-index: 20;
  top: 12px;
  right: 12px;
  width: min(370px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow-y: auto;
  padding: 21px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    linear-gradient(rgba(8, 20, 17, 0.97), rgba(8, 20, 17, 0.97)),
    radial-gradient(circle at top left, rgba(108, 221, 176, 0.2), transparent 46%);
  box-shadow: var(--shadow);
  transform: translateX(calc(100% + 24px));
  visibility: hidden;
  transition: transform 180ms ease, visibility 180ms ease;
}

.drawer.is-open {
  transform: translateX(0);
  visibility: visible;
}

.drawer h2,
.identify-card h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.drawer > p:not(.panel-kicker),
.helper-text {
  color: var(--muted);
  font-size: 0.79rem;
  line-height: 1.55;
}

.panel-kicker {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.close-button {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
}

.drawer-close,
.identify-card > .close-button {
  position: absolute;
  top: 11px;
  right: 11px;
}

.status-grid {
  display: grid;
  gap: 8px;
  margin-top: 17px;
}

.status-grid > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
  font-size: 0.77rem;
}

.status-grid span,
.layer-row small,
.endpoint-note {
  color: var(--muted);
}

.status-grid strong {
  font-size: 0.71rem;
}

.status-ready {
  color: var(--accent);
}

.status-blocked {
  color: var(--amber);
}

.status-test {
  color: #ffd18a;
}

.endpoint-note {
  display: grid;
  gap: 5px;
  margin-top: 22px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.69rem;
}

.endpoint-note code {
  color: #d6e3de;
  overflow-wrap: anywhere;
}

.endpoint-note strong {
  color: var(--amber);
  font-size: 0.66rem;
}

.layer-list {
  margin-top: 12px;
}

.layer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.layer-row:last-child {
  border-bottom: 0;
}

.layer-row span {
  display: grid;
  gap: 3px;
}

.layer-row strong {
  font-size: 0.79rem;
  font-weight: 670;
}

.layer-row small {
  font-size: 0.67rem;
}

.layer-row input {
  width: 35px;
  height: 19px;
  flex: 0 0 auto;
  accent-color: var(--accent-deep);
  cursor: pointer;
}

.layer-row.is-disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.help-list {
  display: grid;
  gap: 10px;
  margin: 18px 0;
  padding-left: 19px;
  color: #c6d5d0;
  font-size: 0.79rem;
  line-height: 1.45;
}

.identify-card {
  left: 14px;
  bottom: 14px;
  width: min(355px, calc(100% - 28px));
  max-height: min(480px, calc(100% - 28px));
  overflow-y: auto;
  padding: 18px;
  border-radius: 15px;
}

.identify-card .helper-text {
  margin-bottom: 0;
  padding-right: 22px;
}

.attribute-list {
  display: grid;
  grid-template-columns: minmax(100px, 0.8fr) 1.2fr;
  margin: 13px 0 0;
  font-size: 0.72rem;
}

.attribute-list dt,
.attribute-list dd {
  margin: 0;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  overflow-wrap: anywhere;
}

.attribute-list dt {
  padding-right: 10px;
  color: var(--muted);
}

.attribute-list dd {
  color: var(--ink);
}

.cesium-viewer-bottom,
.cesium-viewer-toolbar {
  z-index: 3;
}

.cesium-widget-credits {
  margin-right: 210px;
}

@keyframes pulse {
  70% {
    box-shadow: 0 0 0 8px rgba(108, 221, 176, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(108, 221, 176, 0);
  }
}

@keyframes hint-fade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}

@media (max-width: 720px) {
  .app-shell {
    grid-template-rows: 52px minmax(0, 1fr);
  }

  .topbar {
    gap: 7px;
    padding: 0 8px 0 10px;
  }

  .brand-mark {
    width: 26px;
    height: 26px;
  }

  .brand small {
    display: none;
  }

  .brand strong {
    font-size: 0.78rem;
  }

  .topnav {
    gap: 1px;
  }


  .nav-link,
  .nav-button {
    min-height: 40px;
    padding: 0 8px;
    font-size: 0.69rem;
  }

  .map-tools {
    top: 9px;
    right: 9px;
  }

  .navigation-hint {
    top: 64px;
    left: 9px;
  }

  .map-button {
    min-height: 42px;
  }

  .scenario-control {
    bottom: max(27px, env(safe-area-inset-bottom));
    min-width: 194px;
  }

  .scenario-button {
    min-height: 42px;
  }

  .authority-note {
    right: 8px;
    bottom: 8px;
    max-width: 155px;
    font-size: 0.56rem;
  }

  .identify-card {
    left: 8px;
    bottom: 80px;
    width: calc(100% - 16px);
    max-height: 42%;
  }

  .drawer {
    top: auto;
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
    max-height: min(78%, 620px);
    padding: 19px;
    transform: translateY(calc(100% + 16px));
  }

  .drawer.is-open {
    transform: translateY(0);
  }

  .cesium-widget-credits {
    max-width: calc(100% - 12px);
    margin-right: 0;
    font-size: 8px;
  }
}

@media (max-width: 410px) {
  .nav-link,
  .nav-button {
    padding: 0 6px;
  }

  .brand-mark {
    display: none;
  }

  .brand strong {
    font-size: 0.73rem;
  }

  .map-button {
    min-width: 42px;
    padding: 0 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
