@font-face {
  font-family: "CatsHandwriting";
  /* Compatible with common structures:
     - index.html at root, font at ./assets/fonts
     - style.css at /css, font at ../assets/fonts */
  src:
    url("/assets/fonts/CatsHandwriting.woff") format("woff"),
    url("./assets/fonts/CatsHandwriting.woff") format("woff"),
    url("../assets/fonts/CatsHandwriting.woff") format("woff");
  font-display: swap;
}

:root {
  --bg-page: #e9ddc7;
  --bg-frame: #f7edd7;
  --border-card: #d6c4a3;
  --accent-brown: #7c5b39;
  --accent-soft: #f2d9b1;
  --accent-green: #9cbf7b;
  --accent-orange: #e7a868;
  --accent-red: #d86e5b;
  --text-main: #4e4030;
  --text-muted: #8a7b65;
  --radius-large: 26px;
  --radius-card: 18px;
  --shadow-soft: 0 4px 12px rgba(124, 91, 57, 0.18);
  --shadow-strong: 0 10px 24px rgba(124, 91, 57, 0.22);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text-main);
  background: var(--bg-page);
  font-family: "CatsHandwriting", "Nunito", system-ui, -apple-system, Segoe UI, sans-serif;
}

.page-bg {
  min-height: 100vh;
  padding: 10px;
}

.app-frame {
  height: calc(100vh - 20px);
  max-width: 1620px;
  margin: 0 auto;
  background: var(--bg-frame);
  border-radius: var(--radius-large);
  border: 2px solid #d1c1a3;
  box-shadow: 0 8px 20px rgba(109, 84, 56, 0.25);
  display: flex;
  flex-direction: column;
  padding: 12px 18px 12px;
  overflow: hidden;
}

/* Top bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 18px;
  background: #f9f0dd;
  border: 1px solid var(--border-card);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-icon {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid var(--border-card);
  background: #f5e3c3;
}

.app-title {
  margin: 0;
  font-family: "Patrick Hand", cursive;
  font-size: 1.35rem;
  color: var(--accent-brown);
}

.app-subtitle {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: "Nunito", system-ui, sans-serif;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.top-icon-button {
  border: 1px solid var(--border-card);
  background: #f5e6c7;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

.primary-chip {
  border-radius: 16px;
  border: 1px solid var(--accent-brown);
  background: var(--accent-brown);
  color: #fffdf5;
  padding: 5px 12px;
  font-size: 0.82rem;
  cursor: pointer;
  font-family: "Nunito", system-ui, sans-serif;
  box-shadow: var(--shadow-soft);
}

/* Sub bar */
.sub-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 16px;
  background: #f8edd6;
  border: 1px solid var(--border-card);
}

.sub-bar-left,
.sub-bar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sub-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: "Nunito", system-ui, sans-serif;
}

.sub-select {
  font-size: 0.78rem;
  border-radius: 12px;
  border: 1px solid var(--border-card);
  padding: 2px 10px;
  background: #fdf6e9;
  font-family: "Nunito", system-ui, sans-serif;
}

.ghost-chip {
  border-radius: 999px;
  padding: 3px 10px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--text-muted);
  font-family: "Nunito", system-ui, sans-serif;
}

.ghost-chip--active {
  background: #fdf6ea;
  border-color: var(--border-card);
  color: var(--accent-brown);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.5);
}

/* Main workspace */
.app-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) 340px;
  gap: 16px;
  padding: 14px 10px 10px;
}

/* Canvas panel */
.map-panel {
  position: relative;
  border-radius: 20px;
  border: 1px solid var(--border-card);
  background: #f3e8cf;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(120, 80, 20, 0.15);
  padding: 12px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#map {
  flex: 1;
  min-height: 0;
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  background:
    linear-gradient(180deg, rgba(140, 190, 220, 0.14), rgba(140, 190, 220, 0.08));
}

/* Grid overlay in design mode */
#map::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.32) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.32) 1px, transparent 1px);
  background-size: 26px 26px;
}

#map[data-mode="design"]::before { opacity: 1; }

/* Gentle view filters */
#map[data-mode="design"] .leaflet-tile { filter: saturate(0.88) brightness(0.93); }
#map[data-mode="habitat"] .leaflet-tile { filter: saturate(1.05) hue-rotate(35deg) brightness(0.95); }
#map[data-mode="traffic"] .leaflet-tile { filter: saturate(1.1) hue-rotate(-20deg) contrast(1.08) brightness(0.96); }

.leaflet-container { background: transparent; }

.map-status {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid rgba(214, 196, 163, 0.9);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-soft);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 0.88rem;
  color: rgba(78, 64, 48, 0.88);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.map-status.is-error { color: rgba(216, 110, 91, 0.95); }
.map-status.is-ok { color: rgba(100, 140, 80, 0.95); }

.canvas-attrib {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(214, 196, 163, 0.9);
  background: rgba(255, 255, 255, 0.68);
  backdrop-filter: blur(8px);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 0.72rem;
  color: rgba(78, 64, 48, 0.85);
  pointer-events: none;
}

.map-overlay-badge {
  margin-top: 10px;
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(251, 244, 231, 0.95);
  border: 1px solid var(--border-card);
  font-size: 0.78rem;
  font-family: "Nunito", system-ui, sans-serif;
}

/* HUD */
.hud {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 10px;
  z-index: 600;
}

.gauge {
  width: 140px;
  padding: 10px 10px 8px;
  border-radius: 18px;
  border: 1px solid rgba(214, 196, 163, 0.9);
  background: rgba(255, 255, 255, 0.68);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-soft);
  font-family: "Nunito", system-ui, sans-serif;
}

.gauge-title {
  font-size: 0.72rem;
  color: rgba(78, 64, 48, 0.8);
  margin-bottom: 4px;
}

.gauge-svg {
  display: grid;
  place-items: center;
  margin-top: 4px;
}

.gauge-track {
  fill: none;
  stroke: rgba(214, 196, 163, 0.55);
  stroke-width: 10;
  stroke-linecap: round;
}

.gauge-progress {
  fill: none;
  stroke: rgba(124, 91, 57, 0.92);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 157;
  stroke-dashoffset: 157;
  transition: stroke-dashoffset 240ms ease;
}

.gauge[data-gauge="eco"] .gauge-progress { stroke: rgba(120, 170, 110, 0.95); }
.gauge[data-gauge="joy"] .gauge-progress { stroke: rgba(231, 168, 104, 0.95); }

.gauge-value {
  text-align: center;
  margin-top: -2px;
  font-size: 1.1rem;
  font-weight: 700;
  color: rgba(78, 64, 48, 0.9);
}

.gauge-unit {
  font-size: 0.82rem;
  font-weight: 600;
  color: rgba(78, 64, 48, 0.7);
  margin-left: 2px;
}

@keyframes hudShake {
  0% { transform: translateY(0); }
  20% { transform: translateY(-1px) rotate(-0.6deg); }
  40% { transform: translateY(1px) rotate(0.6deg); }
  60% { transform: translateY(-1px) rotate(-0.4deg); }
  80% { transform: translateY(1px) rotate(0.4deg); }
  100% { transform: translateY(0); }
}

.gauge.is-ping { animation: hudShake 320ms ease; }

/* Floating dock */
.dock {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 18px;
  border: 1px solid rgba(214, 196, 163, 0.9);
  background: rgba(255, 255, 255, 0.66);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-strong);
  z-index: 650;
}

.dock-split {
  width: 1px;
  height: 26px;
  background: rgba(214, 196, 163, 0.8);
  margin: 0 2px;
}

.tool-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(214, 196, 163, 0.9);
  background: rgba(253, 243, 222, 0.92);
  font-size: 0.82rem;
  cursor: pointer;
  font-family: "Nunito", system-ui, sans-serif;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
  user-select: none;
}

.tool-button.is-active {
  border-color: rgba(124, 91, 57, 0.92);
  box-shadow: 0 10px 20px rgba(124, 91, 57, 0.22);
  transform: translateY(-1px);
}

.tool-button:hover { transform: translateY(-1px); }

.tool-icon { font-size: 1rem; }

/* Tooltip */
.tool-button[data-tooltip]::after,
.dock-mini[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  top: -10px;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  padding: 4px 8px;
  border-radius: 10px;
  border: 1px solid rgba(214, 196, 163, 0.9);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-soft);
  font-size: 0.72rem;
  color: rgba(78, 64, 48, 0.9);
}

.tool-button[data-tooltip]:hover::after,
.dock-mini[data-tooltip]:hover::after { opacity: 1; }

.dock-mini {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid rgba(214, 196, 163, 0.9);
  background: rgba(253, 243, 222, 0.92);
  cursor: pointer;
  font-size: 1rem;
  display: grid;
  place-items: center;
}

@keyframes duang {
  0% { transform: translateY(0) scale(1); }
  60% { transform: translateY(-2px) scale(1.06); }
  100% { transform: translateY(0) scale(1); }
}

.dock.is-duang { animation: duang 220ms ease; }

/* AI critic */
.ai-critic {
  position: absolute;
  right: 12px;
  bottom: 78px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  z-index: 640;
  max-width: min(330px, calc(100% - 24px));
}

.ai-avatar {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  border: 1px solid rgba(214, 196, 163, 0.9);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-soft);
  font-size: 1.25rem;
}

.ai-bubble {
  border-radius: 18px;
  border: 1px solid rgba(214, 196, 163, 0.9);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-soft);
  padding: 10px 12px;
  font-family: "Nunito", system-ui, sans-serif;
}

.ai-name {
  font-weight: 700;
  font-size: 0.78rem;
  color: rgba(78, 64, 48, 0.86);
}

.ai-text {
  margin-top: 4px;
  font-size: 0.78rem;
  color: rgba(78, 64, 48, 0.82);
  line-height: 1.35;
}

/* Right side panels */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.card {
  border-radius: var(--radius-card);
  border: 1px solid var(--border-card);
  background: #fdf4e0;
  box-shadow: var(--shadow-soft);
  padding: 10px 12px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.card-header h2 {
  margin: 0;
  font-size: 0.92rem;
  color: var(--accent-brown);
  font-family: "Nunito", system-ui, sans-serif;
}

.card-close-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-muted);
}

.scenario-text {
  font-size: 0.8rem;
  margin: 5px 0;
  line-height: 1.45;
  font-family: "Nunito", system-ui, sans-serif;
  color: rgba(78, 64, 48, 0.86);
}

.score-tabs {
  display: flex;
  gap: 6px;
}

.score-tab {
  border-radius: 14px;
  padding: 2px 8px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 0.74rem;
  cursor: pointer;
  color: var(--text-muted);
  font-family: "Nunito", system-ui, sans-serif;
}

.score-tab--active {
  background: #fbeedb;
  border-color: var(--border-card);
  color: var(--accent-brown);
}

.scores-body {
  margin-top: 4px;
  font-size: 0.78rem;
  font-family: "Nunito", system-ui, sans-serif;
}

.is-hidden { display: none !important; }

.score-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.score-block-title {
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.meter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.76rem;
  margin-top: 8px;
}

.meter-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #f0e1c7;
  overflow: hidden;
  margin-top: 3px;
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-green);
  border-radius: 999px;
  transition: width 240ms ease;
}

.meter-fill--orange { background: var(--accent-orange); }
.meter-fill--red { background: var(--accent-red); }

.primary-button {
  border-radius: 999px;
  border: 1px solid var(--accent-brown);
  background: var(--accent-brown);
  color: #fffdf6;
  padding: 8px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  font-family: "Nunito", system-ui, sans-serif;
}

.wide-button { width: 100%; margin-top: 8px; }

.design-score-text {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: "Nunito", system-ui, sans-serif;
}

.selected-desc {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 12px;
  background: #fdf6ea;
  border: 1px solid #e7d5b6;
  color: var(--text-muted);
  line-height: 1.35;
  font-size: 0.75rem;
}

.facility-list {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}

.facility-prompt {
  margin: 6px 0 2px 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: "Nunito", system-ui, sans-serif;
}

.facility-card {
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid #e3d3b3;
  background: #fef8ed;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45);
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.facility-card:hover {
  border-color: #d9c6a4;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.65), 0 2px 4px rgba(0, 0, 0, 0.04);
}

.facility-card--active {
  border-color: var(--accent-brown);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.75), 0 2px 6px rgba(0, 0, 0, 0.08);
  background: #fff9f1;
}

.facility-card-title {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--accent-brown);
  margin: 0 0 2px 0;
}

.facility-card-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0 0 4px 0;
}

.facility-card-text {
  font-size: 0.75rem;
  color: var(--text-main);
  line-height: 1.35;
  margin: 0;
}

.selected-desc {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 12px;
  background: #fdf6ea;
  border: 1px solid #e7d5b6;
  color: var(--text-muted);
  line-height: 1.35;
  font-size: 0.75rem;
}

/* Leaflet control styling */
.leaflet-control-zoom a {
  background: rgba(253, 243, 222, 0.95);
  border: 1px solid rgba(193, 165, 128, 0.8);
  color: var(--accent-brown);
  border-radius: 999px;
  width: 26px;
  height: 26px;
  line-height: 24px;
  font-weight: 700;
  box-shadow: var(--shadow-soft);
}

.leaflet-top.leaflet-left .leaflet-control-zoom {
  margin-top: 14px;
  margin-left: 14px;
}

/* Facility marker (divIcon) */
.facility-marker {
  width: 30px;
  height: 30px;
  border-radius: 12px;
  border: 2px solid rgba(124, 91, 57, 0.75);
  background: rgba(253, 243, 222, 0.92);
  box-shadow: 0 10px 20px rgba(124, 91, 57, 0.18);
  display: grid;
  place-items: center;
  font-size: 16px;
  transform-origin: 50% 100%;
}

.facility-marker.is-bounce { animation: duang 240ms ease; }

.facility-marker--danger {
  border-color: rgba(216, 110, 91, 0.95);
  box-shadow: 0 12px 22px rgba(216, 110, 91, 0.22);
}

/* Save brief dialog */
.brief-modal {
  border: none;
  padding: 0;
  background: transparent;
}

.brief-modal::backdrop {
  background: rgba(34, 25, 16, 0.28);
  backdrop-filter: blur(2px);
}

.brief-card {
  width: min(720px, calc(100vw - 26px));
  border-radius: 22px;
  border: 1px solid rgba(214, 196, 163, 0.9);
  background: rgba(253, 244, 224, 0.98);
  box-shadow: 0 22px 44px rgba(124, 91, 57, 0.22);
  padding: 14px 14px 12px;
}

.brief-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brief-title {
  margin: 0;
  font-family: "Patrick Hand", cursive;
  color: var(--accent-brown);
}

.brief-content {
  margin-top: 10px;
  font-family: "Nunito", system-ui, sans-serif;
  color: rgba(78, 64, 48, 0.9);
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.brief-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Footer */
.bottom-footer {
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 18px;
  border: 1px solid var(--border-card);
  background: #f8edd8;
  display: flex;
  justify-content: flex-end;
}

.toolbar-text {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: "Nunito", system-ui, sans-serif;
}

/* Responsive */
@media (max-width: 980px) {
  .app-frame { height: auto; }
  .app-main { grid-template-columns: 1fr; }
  .side-panel { max-height: none; }
  .ai-critic { bottom: 86px; }
}
