:root {
  color-scheme: light;
  --bg: #eef3f5;
  --surface: #ffffff;
  --surface-strong: #f7fafb;
  --ink: #142026;
  --muted: #65747c;
  --line: #d9e2e6;
  --river: #2d8ccf;
  --teal: #0f766e;
  --green: #1f8a4c;
  --amber: #b7791f;
  --red: #c24132;
  --blue: #1d4ed8;
  --shadow: 0 16px 42px rgba(20, 32, 38, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter,
    "Pretendard",
    "Segoe UI",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  grid-template-rows: auto minmax(240px, 1fr);
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
}

.workspace {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 14px;
  min-width: 0;
}

.topbar,
.status-panel,
.control-rail,
.event-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 92px;
  padding: 18px 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 2.8vw, 3rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
  line-height: 1.3;
  letter-spacing: 0;
}

.top-actions,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.top-actions {
  min-width: 0;
}

.primary-button,
.ghost-button,
.icon-button,
.quick-filters button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease,
    background-color 0.15s ease;
}

.primary-button {
  gap: 8px;
  min-width: 0;
  padding: 0 14px;
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
  white-space: nowrap;
}

.ghost-button {
  gap: 8px;
  padding: 0 12px;
  background: var(--surface-strong);
}

.icon-button {
  width: 40px;
  padding: 0;
}

.primary-button:hover,
.ghost-button:hover,
.icon-button:hover,
.quick-filters button:hover {
  transform: translateY(-1px);
}

button svg,
.search-box svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.4;
}

.icon {
  flex: 0 0 auto;
}

.status-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 18px 20px;
}

.status-copy p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.status-copy {
  min-width: 0;
}

.risk-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  margin-bottom: 10px;
  padding: 0 10px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--blue);
  font-size: 0.82rem;
  font-weight: 900;
}

.risk-pill.low {
  background: var(--green);
}

.risk-pill.medium {
  background: var(--amber);
}

.risk-pill.high {
  background: var(--red);
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, 92px);
  gap: 8px;
}

.metric-strip div {
  min-width: 0;
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.metric-strip span {
  display: block;
  margin-bottom: 4px;
  font-size: 1.45rem;
  font-weight: 900;
}

.metric-strip small {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.map-section {
  position: relative;
  overflow: hidden;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

#map {
  position: relative;
  width: 100%;
  height: clamp(420px, 56vh, 620px);
  min-height: 420px;
  background: #dbe8ec;
}

.local-map {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

#map.is-dragging .local-map {
  cursor: grabbing;
}

.map-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.map-land {
  fill: #e3eee8;
}

.map-image {
  pointer-events: none;
}

.map-tile-backdrop {
  fill: #dce8df;
}

.map-tile {
  pointer-events: none;
}

.event-route {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.district-labels text {
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: calc(5px * var(--map-ui-scale, 1));
  fill: rgba(20, 32, 38, 0.46);
  font-size: calc(18px * var(--map-ui-scale, 1));
  font-weight: 900;
}

.park-labels text {
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: calc(4px * var(--map-ui-scale, 1));
  fill: #29444d;
  font-size: calc(13px * var(--map-ui-scale, 1));
  font-weight: 900;
}

.tile-map-svg .district-labels {
  display: none;
}

.tile-map-svg .park-labels text {
  stroke: rgba(255, 255, 255, 0.82);
  stroke-width: calc(3px * var(--map-ui-scale, 1));
  fill: rgba(20, 32, 38, 0.72);
  font-size: calc(10px * var(--map-ui-scale, 1));
}

.event-route {
  stroke: var(--event-color);
  stroke-width: var(--route-width, 16);
  opacity: 0.88;
}

.event-route.medium,
.event-route.low {
  stroke-width: var(--route-width, 12);
}

.event-route.selected {
  opacity: 1;
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.98));
}

.event-route.approximate {
  stroke-dasharray: calc(18px * var(--map-ui-scale, 1)) calc(9px * var(--map-ui-scale, 1));
}

.event-marker circle:first-of-type {
  fill: #ffffff;
  stroke: var(--event-color);
  stroke-width: calc(4px * var(--map-ui-scale, 1));
}

.event-marker circle:last-of-type {
  fill: var(--event-color);
  stroke: none;
}

.event-marker.selected circle:first-of-type {
  stroke-width: calc(6px * var(--map-ui-scale, 1));
}

.map-event-label rect {
  fill: rgba(255, 255, 255, 0.9);
  stroke: rgba(217, 226, 230, 0.92);
  stroke-width: 3;
  filter: drop-shadow(0 8px 16px rgba(20, 32, 38, 0.12));
}

.map-event-title {
  fill: var(--ink);
  font-weight: 900;
}

.map-event-time {
  fill: var(--teal);
  font-weight: 900;
}

.map-controls {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 4;
  display: grid;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 22px rgba(20, 32, 38, 0.13);
}

.map-controls button {
  width: 36px;
  height: 34px;
  border: 0;
  background: #ffffff;
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 900;
}

.map-controls button + button {
  border-top: 1px solid var(--line);
}

.map-source {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  padding: 5px 8px;
  border: 1px solid rgba(217, 226, 230, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.map-provider-note {
  position: absolute;
  left: 64px;
  bottom: 14px;
  z-index: 4;
  max-width: min(520px, calc(100% - 176px));
  padding: 9px 11px;
  border: 1px solid rgba(183, 121, 31, 0.24);
  border-radius: 8px;
  background: rgba(255, 250, 235, 0.94);
  color: #7c4a12;
  font-size: 0.78rem;
  font-weight: 850;
  line-height: 1.4;
}

.map-empty-note {
  position: absolute;
  inset: auto 18px 18px 64px;
  z-index: 5;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-weight: 800;
}

.map-event-detail {
  position: absolute;
  left: 64px;
  top: 14px;
  z-index: 6;
  display: grid;
  gap: 4px;
  width: min(360px, calc(100% - 84px));
  padding: 11px 34px 11px 12px;
  border: 1px solid rgba(217, 226, 230, 0.94);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 22px rgba(20, 32, 38, 0.14);
}

.map-event-detail strong {
  font-size: 0.88rem;
  line-height: 1.3;
}

.map-event-detail span,
.map-event-detail p,
.map-detail-link {
  font-size: 0.72rem;
  line-height: 1.35;
}

.map-event-detail span,
.map-event-detail p {
  color: var(--muted);
}

.map-event-detail p {
  margin: 2px 0 0;
}

.map-detail-link {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.map-detail-close {
  position: absolute;
  top: 5px;
  right: 7px;
  width: 26px;
  height: 26px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
}

.map-legend {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 700;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-width: min(420px, calc(100% - 28px));
  padding: 9px;
  border: 1px solid rgba(217, 226, 230, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-dot.high {
  background: var(--red);
}

.legend-dot.medium {
  background: var(--amber);
}

.legend-dot.low {
  background: var(--green);
}

.control-rail {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  position: sticky;
  top: 16px;
}

.control-group {
  display: grid;
  gap: 8px;
}

.control-group > label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 96px;
  padding-top: 10px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.quick-filters {
  display: grid;
  gap: 6px;
}

.quick-filters {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.quick-filters button {
  min-width: 0;
  padding: 0 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.quick-filters button.active {
  border-color: var(--teal);
  background: rgba(15, 118, 110, 0.1);
  color: var(--teal);
}

.search-box {
  position: relative;
}

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

.api-key-group.is-hidden {
  display: none;
}

.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  color: var(--muted);
  transform: translateY(-50%);
}

.search-box input {
  padding-left: 40px;
}

.source-note {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.source-note strong {
  font-size: 0.86rem;
}

.source-note p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.event-panel {
  grid-column: 1;
  padding: 16px;
}

.panel-heading {
  margin-bottom: 12px;
}

.event-list {
  display: grid;
  gap: 14px;
}

.event-date-group {
  display: grid;
  gap: 8px;
}

.event-date-heading {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 6px 9px;
  border-left: 4px solid var(--teal);
  border-bottom: 1px solid var(--line);
  background: rgba(15, 118, 110, 0.06);
}

.event-date-heading h3 {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 900;
}

.event-date-heading h3.is-weekday {
  color: #111827;
}

.event-date-heading h3.is-saturday {
  color: #2563eb;
}

.event-date-heading h3.is-sunday {
  color: #dc2626;
}

.event-date-heading span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.event-date-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
}

.event-card {
  display: grid;
  gap: 6px;
  min-height: 158px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  cursor: pointer;
}

.event-card.is-selected {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.16);
}

.event-card:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.28);
  outline-offset: 2px;
}

.event-card.high {
  border-left: 4px solid var(--red);
}

.event-card.medium {
  border-left: 4px solid var(--amber);
}

.event-card.low {
  border-left: 4px solid var(--green);
}

.event-card header {
  display: grid;
  gap: 6px;
}

.event-card h3 {
  margin: 0;
  font-size: 0.79rem;
  line-height: 1.25;
  letter-spacing: 0;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.61rem;
  font-weight: 900;
}

.tag.high {
  background: rgba(194, 65, 50, 0.12);
  color: var(--red);
}

.tag.medium {
  background: rgba(183, 121, 31, 0.14);
  color: #8a5a18;
}

.tag.low {
  background: rgba(31, 138, 76, 0.13);
  color: var(--green);
}

.event-meta {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.35;
}

.event-meta span {
  display: inline-flex;
  align-items: flex-start;
  gap: 6px;
}

.event-meta .course-meta {
  color: #374151;
  font-weight: 750;
}

.event-meta svg {
  flex: 0 0 14px;
  width: 14px;
  height: 14px;
  margin-top: 1px;
}

.event-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.35;
}

.event-card .impact-note {
  display: -webkit-box;
  overflow: hidden;
  padding: 6px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  border: 1px solid rgba(194, 65, 50, 0.22);
  border-radius: 8px;
  background: rgba(194, 65, 50, 0.08);
  color: #8f2f25;
  font-weight: 800;
}

.event-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
}

.text-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--blue);
  font-size: 0.64rem;
  font-weight: 800;
  text-decoration: none;
}

.text-link svg {
  width: 13px;
  height: 13px;
}

.empty-state {
  grid-column: 1 / -1;
  min-height: 180px;
  display: grid;
  place-items: center;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  text-align: center;
}

.static-event-summary {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.static-event-summary h3 {
  margin: 0;
  color: var(--ink);
  font-size: 0.9rem;
}

.static-event-summary p {
  margin: 0;
}

.site-footer {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  padding: 0 4px 4px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.site-footer strong {
  color: var(--ink);
}

.popup-title {
  margin-bottom: 4px;
  font-weight: 900;
}

.popup-detail {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .control-rail {
    position: static;
    grid-column: 1;
    grid-row: auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .source-note {
    grid-column: 1 / -1;
  }

  .event-date-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    width: auto;
    max-width: calc(100% - 20px);
    margin: 10px;
    padding: 0;
    overflow: hidden;
  }

  .workspace,
  .control-rail,
  .event-panel,
  .map-section {
    width: calc(100vw - 36px);
    max-width: calc(100vw - 36px);
  }

  .topbar,
  .status-panel {
    width: calc(100vw - 36px);
    max-width: calc(100vw - 36px);
  }

  .topbar,
  .status-panel,
  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions .primary-button {
    flex: 1;
  }

  .status-panel {
    grid-template-columns: 1fr;
  }

  .metric-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .metric-strip div {
    padding: 10px;
  }

  .metric-strip span {
    font-size: 1.3rem;
  }

  .metric-strip small {
    font-size: 0.7rem;
  }

  .control-rail {
    grid-template-columns: 1fr;
  }

  #map {
    height: 420px;
    min-height: 420px;
  }

  .map-legend {
    left: auto;
    right: 10px;
    bottom: 10px;
    max-width: calc(100% - 76px);
    justify-content: flex-end;
    padding: 6px 7px;
  }

  .map-provider-note {
    left: 58px;
    right: 12px;
    bottom: 12px;
    max-width: none;
  }

  .map-event-detail {
    left: 10px;
    right: 10px;
    top: auto;
    bottom: 12px;
    width: auto;
    max-height: 22%;
    overflow: auto;
    gap: 2px;
    padding: 9px 34px 9px 10px;
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(20, 32, 38, 0.16);
  }

  .map-event-detail strong {
    font-size: 0.78rem;
  }

  .map-event-detail span,
  .map-event-detail p,
  .map-detail-link {
    font-size: 0.64rem;
    line-height: 1.22;
  }

  .map-event-detail p {
    display: -webkit-box;
    overflow: hidden;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
  }

  .map-detail-close {
    top: 3px;
    right: 5px;
  }

  .map-legend span {
    font-size: 0.72rem;
  }

  .event-date-grid {
    grid-template-columns: 1fr;
  }
}
