:root {
  color-scheme: light;
  font-family: "Noto Sans KR", sans-serif;
  font-synthesis: none;
  --surface: #ffffff;
  --surface-muted: #f4f7fb;
  --ink: #172033;
  --muted: #687287;
  --line: #d8dee9;
  --line-strong: #bac4d4;
  --blue: #1459f5;
  --blue-dark: #0e3fb9;
  --blue-soft: #eef4ff;
  --red: #e53b42;
  --green: #13865b;
  --yellow: #ffd84d;
  --danger: #b4232a;
  --shadow: 0 8px 24px rgba(34, 47, 74, 0.13);
  --command-height: 82px;
  --dock-height: 150px;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--surface);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(20, 89, 245, 0.25);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-rows: var(--command-height) minmax(0, 1fr) var(--dock-height);
  width: 100%;
  height: 100dvh;
  min-height: 620px;
}

.command-bar {
  position: relative;
  z-index: 900;
  display: grid;
  grid-template-columns: 205px 326px minmax(280px, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: baseline;
  font-size: 26px;
  line-height: 1;
  white-space: nowrap;
}

.brand strong {
  color: var(--blue);
  font-size: 30px;
  font-weight: 700;
}

.brand span {
  font-weight: 700;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 52px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}

.mode-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  border: 0;
  background: transparent;
  color: #3e4759;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.mode-button + .mode-button {
  border-left: 1px solid var(--line);
}

.mode-button:hover {
  background: var(--surface-muted);
}

.mode-button.is-active {
  background: var(--blue-soft);
  color: var(--blue);
}

.mode-button .material-symbols-outlined {
  font-size: 22px;
}

.command-form {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  height: 52px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.command-form:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(20, 89, 245, 0.12);
}

.command-form.has-error {
  border-color: var(--danger);
}

.command-icon {
  margin-left: 16px;
  color: var(--muted);
  font-size: 23px;
}

.command-form input {
  width: 100%;
  min-width: 0;
  height: 100%;
  padding: 0 12px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
}

.command-form input::placeholder {
  color: #8a94a7;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-muted);
}

.icon-button.compact {
  width: 34px;
  height: 34px;
  border: 0;
}

.submit-button {
  width: 48px;
  height: 100%;
  border-width: 0 0 0 1px;
  border-radius: 0;
  color: var(--blue);
}

.submit-button.is-loading .material-symbols-outlined {
  animation: spin 800ms linear infinite;
}

.command-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.connection-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #a2aabd;
}

.connection-state.is-online {
  color: var(--green);
}

.connection-state.is-online .connection-dot {
  background: var(--green);
}

.connection-state.is-offline {
  color: var(--danger);
}

.connection-state.is-offline .connection-dot {
  background: var(--danger);
}

.settings-panel {
  position: absolute;
  z-index: 1100;
  top: 70px;
  right: 24px;
  width: min(420px, calc(100vw - 32px));
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.settings-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.settings-panel label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

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

.settings-row input,
.settings-row button {
  height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
}

.settings-row input {
  min-width: 0;
  padding: 0 12px;
}

.settings-row button {
  padding: 0 16px;
  background: var(--ink);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.map-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  background: #dbeaf3;
}

.leaflet-tile-pane {
  filter: saturate(0.62) brightness(1.06) contrast(0.91);
}

.leaflet-control-zoom,
.leaflet-control-scale-line,
.map-location-control {
  border: 1px solid rgba(113, 127, 151, 0.5) !important;
  border-radius: 6px !important;
  box-shadow: 0 3px 10px rgba(39, 56, 82, 0.14) !important;
}

.leaflet-control-zoom a {
  color: var(--ink) !important;
}

.leaflet-control-attribution {
  padding: 3px 7px !important;
  background: rgba(255, 255, 255, 0.9) !important;
  color: #58647a !important;
}

.map-location-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: auto;
  height: 42px;
  padding: 0 12px;
  border: 0;
  background: white;
  color: var(--blue);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.map-location-control:hover {
  background: var(--blue-soft);
}

.map-location-control:disabled {
  cursor: wait;
  opacity: 0.72;
}

.map-location-control .material-symbols-outlined {
  font-size: 22px;
}

.map-location-control.is-locating .material-symbols-outlined {
  animation: spin 800ms linear infinite;
}

.selection-card {
  position: absolute;
  z-index: 700;
  top: 18px;
  left: 18px;
  width: 238px;
  padding: 14px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  pointer-events: none;
}

.selection-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 600;
}

.selection-title strong {
  color: var(--red);
  font-weight: 600;
}

.selection-card dl,
.coordinate-result dl {
  margin: 0;
}

.selection-card dl > div,
.coordinate-result dl > div {
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: baseline;
  gap: 10px;
}

.selection-card dt,
.coordinate-result dt {
  color: var(--muted);
  font-size: 13px;
}

.selection-card dd,
.coordinate-result dd {
  margin: 0;
  color: var(--blue);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.toast {
  position: absolute;
  z-index: 1000;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
  font-size: 14px;
}

.toast.is-error {
  background: var(--danger);
}

.result-dock {
  position: relative;
  z-index: 800;
  display: grid;
  grid-template-columns: 330px 1px minmax(350px, 1fr) auto;
  align-items: center;
  gap: 36px;
  padding: 22px 34px;
  border-top: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.97);
}

.coordinate-result {
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 18px;
}

.coordinate-symbol {
  color: var(--blue);
  font-size: 38px;
}

.coordinate-result dl > div {
  grid-template-columns: 40px 1fr;
  margin: 3px 0;
}

.coordinate-result dt,
.coordinate-result dd {
  font-size: 16px;
}

.coordinate-axis {
  color: var(--muted);
  font-weight: 400;
}

.result-divider {
  width: 1px;
  height: 76px;
  background: var(--line);
}

.npn-result {
  min-width: 0;
}

.npn-result > span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.npn-result strong {
  display: block;
  overflow: hidden;
  color: #121827;
  font-size: 44px;
  font-weight: 600;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-dock.has-result .code-prefix {
  color: #121827;
}

.result-dock.has-result .code-digits {
  color: var(--red);
}

.dock-actions {
  display: flex;
  gap: 12px;
}

.dock-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 118px;
  height: 50px;
  padding: 0 20px;
  border-radius: 5px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.dock-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.primary-action {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: white;
}

.primary-action:not(:disabled):hover {
  background: var(--blue-dark);
}

.secondary-action {
  border: 1px solid var(--line-strong);
  background: white;
}

.secondary-action:not(:disabled):hover {
  background: var(--surface-muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

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

@media (max-width: 1040px) {
  :root {
    --command-height: 132px;
    --dock-height: 142px;
  }

  .command-bar {
    grid-template-columns: 170px minmax(0, 1fr) auto;
    grid-template-rows: 48px 52px;
    gap: 10px 14px;
    padding: 10px 16px 12px;
  }

  .brand {
    font-size: 22px;
  }

  .brand strong {
    font-size: 26px;
  }

  .command-tools {
    grid-column: 3;
    grid-row: 1;
  }

  .mode-switch {
    grid-column: 1;
    grid-row: 2;
    width: 280px;
  }

  .command-form {
    grid-column: 2 / 4;
    grid-row: 2;
  }

  .result-dock {
    grid-template-columns: 240px 1px minmax(250px, 1fr) auto;
    gap: 20px;
    padding: 18px 20px;
  }

  .coordinate-symbol {
    display: none;
  }

  .coordinate-result {
    grid-template-columns: 1fr;
  }

  .npn-result strong {
    font-size: 34px;
  }

  .dock-actions button {
    min-width: 50px;
    width: 50px;
    padding: 0;
    font-size: 0;
  }

  .dock-actions .material-symbols-outlined {
    font-size: 23px;
  }
}

@media (max-width: 700px) {
  :root {
    --command-height: 150px;
    --dock-height: 192px;
  }

  .app-shell {
    min-height: 540px;
  }

  .command-bar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: 42px 42px 48px;
    gap: 6px 10px;
    padding: 8px 12px 10px;
  }

  .brand {
    grid-column: 1;
    grid-row: 1;
  }

  .command-tools {
    grid-column: 2;
    grid-row: 1;
  }

  .connection-state {
    font-size: 12px;
  }

  .mode-switch {
    grid-column: 1 / 3;
    grid-row: 2;
    width: 100%;
    height: 42px;
  }

  .command-form {
    grid-column: 1 / 3;
    grid-row: 3;
    height: 48px;
  }

  .selection-card {
    top: 12px;
    left: 12px;
    width: 210px;
    padding: 11px 13px;
  }

  .map-location-control {
    width: 42px;
    padding: 0;
  }

  .map-location-label {
    display: none;
  }

  .result-dock {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto 1px auto;
    gap: 10px 14px;
    padding: 14px 16px;
  }

  .coordinate-result {
    grid-column: 1;
    grid-row: 3;
  }

  .coordinate-result dl {
    display: flex;
    gap: 16px;
  }

  .coordinate-result dl > div {
    display: flex;
    gap: 7px;
  }

  .coordinate-result dt,
  .coordinate-result dd {
    font-size: 12px;
  }

  .result-divider {
    grid-column: 1 / 3;
    grid-row: 2;
    width: 100%;
    height: 1px;
  }

  .npn-result {
    grid-column: 1 / 3;
    grid-row: 1;
  }

  .npn-result strong {
    font-size: 29px;
  }

  .dock-actions {
    grid-column: 2;
    grid-row: 3;
  }

  .dock-actions button {
    width: 42px;
    min-width: 42px;
    height: 42px;
  }

  .settings-panel {
    top: 54px;
    right: 12px;
  }

  .leaflet-control-attribution {
    max-width: 240px;
    font-size: 9px !important;
  }
}

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