*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2d6a4f;
  --primary-light: #52b788;
  --primary-pale: #d8f3dc;
  --bg: #f0f4f1;
  --card: #ffffff;
  --text: #1b1f1c;
  --muted: #6b7c72;
  --radius: 18px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 18px;
  gap: 8px;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.settings-btn {
  background: transparent;
  border: 1px solid #d2dbd5;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.settings-btn:active { background: #e2ebe5; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20,40,28,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 200;
}
.modal[hidden] { display: none; }
.modal-content {
  background: white;
  border-radius: var(--radius);
  padding: 22px 22px 18px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
.modal-summary { max-width: 420px; }
#summaryMap {
  width: 100%;
  height: 240px;
  border-radius: 12px;
  border: 1px solid #dde5e0;
  margin-bottom: 14px;
  z-index: 1;
}
.modal-content h3 {
  font-size: 1.1rem;
  margin-bottom: 14px;
  color: var(--primary);
}
.setting-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 500;
}
.setting-row input {
  padding: 10px 12px;
  font-size: 1rem;
  border: 1.5px solid #d2dbd5;
  border-radius: 10px;
  font-family: inherit;
}
.setting-row input:focus { outline: none; border-color: var(--primary-light); }
.setting-hint {
  font-size: 0.72rem;
  color: var(--muted);
  margin: 10px 0 16px;
}
.btn-modal {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-modal:active { background: #205038; }

/* Summary stats */
.stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 14px;
  background: var(--primary-pale);
  border-radius: 10px;
}
.stat-row span { color: var(--muted); font-size: 0.8rem; }
.stat-row b { color: var(--primary); font-size: 1.15rem; font-variant-numeric: tabular-nums; }

/* Track polyline marker color is set via Leaflet options */

h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.lang-selector {
  display: flex;
  gap: 3px;
  background: #e2ebe5;
  padding: 4px;
  border-radius: 10px;
}

.lang-btn {
  border: none;
  background: transparent;
  padding: 5px 11px;
  border-radius: 7px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.lang-btn.active {
  background: white;
  color: var(--primary);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

/* Usage bar */
.usage-bar {
  position: relative;
  height: 22px;
  background: #e2ebe5;
  border-radius: 11px;
  overflow: hidden;
  margin-bottom: 12px;
}
.usage-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, var(--primary-light), var(--primary));
  transition: width 0.4s ease;
}
.usage-fill.warning { background: linear-gradient(90deg, #f4a261, #e76f51); }
.usage-fill.critical { background: linear-gradient(90deg, #e76f51, #c1121f); }
.usage-label {
  position: relative;
  z-index: 1;
  display: block;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text);
  line-height: 22px;
  text-shadow: 0 0 4px rgba(255,255,255,0.7);
}

/* Status bar */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 10px;
  padding: 0 2px;
}

.coords { font-variant-numeric: tabular-nums; }

/* Card */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px 20px;
  min-height: 200px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.07);
  flex: 1;
  margin-bottom: 16px;
  position: relative;
  transition: box-shadow 0.3s;
}
.card.loading {
  box-shadow: 0 2px 16px rgba(45,106,79,0.25);
}
.card.loading::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--primary-light), var(--primary), var(--primary-light), transparent);
  background-size: 200% 100%;
  border-radius: var(--radius) var(--radius) 0 0;
  animation: loadingbar 1.4s linear infinite;
}
@keyframes loadingbar {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.placeholder {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.65;
}

.explanation {
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text);
}

/* POIs */
.pois {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #eef2ef;
}

.pois-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

.poi-tag {
  display: inline-block;
  background: var(--primary-pale);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 20px;
  margin: 3px 3px 0 0;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.poi-tag:hover, .poi-tag.active {
  background: var(--primary);
  color: white;
}
.poi-tag:active { transform: scale(0.96); }

/* POI marker dot on map */
.poi-marker-dot {
  width: 22px;
  height: 22px;
  background: #ff8c42;
  color: white;
  border: 2px solid white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* Controls */
.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 28px;
}

.btn-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  padding: 18px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
  box-shadow: 0 4px 18px rgba(45,106,79,0.32);
  -webkit-tap-highlight-color: transparent;
}

.btn-main:active { transform: scale(0.97); }
.btn-main:disabled { opacity: 0.5; cursor: default; transform: none; }

.btn-auto {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  background: white;
  color: var(--primary);
  border: 2px dashed var(--primary-light);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-auto:active { background: var(--primary-pale); }
.btn-auto.running {
  background: #c1121f;
  color: white;
  border: 2px solid #c1121f;
}
.btn-auto.running:active { background: #9c0e19; }

.btn-speak {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  background: white;
  color: var(--primary);
  border: 2px solid var(--primary-light);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-speak:active { background: var(--primary-pale); }
.btn-speak.speaking { background: var(--primary-pale); }

/* Map */
.map-section { margin-bottom: 28px; }
.map-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 6px;
  text-align: center;
}
#map {
  width: 100%;
  height: 320px;
  border-radius: var(--radius);
  border: 1px solid #dde5e0;
  z-index: 1;
}
.selected-marker-pin {
  background: var(--primary);
  width: 18px;
  height: 18px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.current-loc-dot {
  width: 16px;
  height: 16px;
  background: #2196f3;
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* Loading overlay */
.overlay[hidden] { display: none; }
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 28, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: white;
  font-size: 1rem;
  font-weight: 500;
  z-index: 100;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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