:root {
  --bg: #0f1419;
  --bg-card: #1a2332;
  --bg-hover: #243044;
  --text: #e8eaed;
  --text-dim: #8b95a5;
  --accent: #2d6a4f;
  --accent-light: #40916c;
  --danger: #d32f2f;
  --danger-light: #ef5350;
  --border: #2d3748;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
}

[data-theme="light"] {
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --bg-hover: #e8eaed;
  --text: #1a1a2e;
  --text-dim: #6b7280;
  --accent: #2d6a4f;
  --accent-light: #40916c;
  --border: #e0e0e0;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 8px; }
.logo { font-size: 24px; }
header h1 { font-size: 18px; font-weight: 700; }

.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s;
}
.icon-btn:hover { background: var(--bg-hover); }

main { padding-bottom: 80px; }

.page { display: none; }
.page.active { display: block; }

.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.page-header h2 { font-size: 18px; }

.back-btn {
  background: var(--bg-hover);
  border: none;
  color: var(--text);
  font-size: 18px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.back-btn:hover { background: var(--accent); color: #fff; }

.content { padding: 16px; }

.hero {
  text-align: center;
  padding: 48px 16px 32px;
}
.hero-icon { font-size: 64px; margin-bottom: 12px; }
.hero h2 { font-size: 28px; font-weight: 800; margin-bottom: 8px; }
.hero-sub { color: var(--text-dim); font-size: 15px; }

.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 16px 16px;
}

.home-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}
.home-card:hover { background: var(--bg-hover); transform: translateY(-2px); }
.card-icon { font-size: 36px; }
.card-label { font-size: 15px; font-weight: 700; }
.card-desc { font-size: 12px; color: var(--text-dim); }

.status-bar {
  margin: 0 16px;
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.status-item { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); }
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s infinite;
}
.status-dot.error { background: var(--danger); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.section { margin-bottom: 24px; }
.section h3 { font-size: 16px; margin-bottom: 12px; color: var(--text-dim); }
.section-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 12px; }

.emergency-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.emergency-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  color: #fff;
  font-weight: 700;
  transition: transform 0.2s;
}
.emergency-card:hover { transform: scale(1.03); }
.emergency-card:active { transform: scale(0.97); }
.emergency-card.police { background: #1565c0; }
.emergency-card.fire { background: var(--danger); }
.emergency-card.disaster { background: #e65100; }
.emergency-card.coast { background: #00695c; }
.emergency-icon { font-size: 32px; }
.emergency-num { font-size: 28px; }
.emergency-label { font-size: 12px; opacity: 0.9; }

.info-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.info-card h4 { font-size: 14px; margin-bottom: 8px; }
.info-card ol, .info-card ul { padding-left: 20px; font-size: 13px; color: var(--text-dim); line-height: 1.8; }

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-full { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-light); }
.btn-secondary { background: var(--bg-hover); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--accent); color: #fff; }
.btn:active { transform: scale(0.97); }

.map-container {
  width: 100%;
  height: 300px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.map-full { height: 50vh; }

.map-legend {
  display: flex;
  gap: 16px;
  padding: 12px 0;
  flex-wrap: wrap;
}
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.legend-dot.park { background: #4caf50; }
.legend-dot.station { background: #2196f3; }
.legend-dot.convenience { background: #ff9800; }
.legend-dot.rest { background: #9c27b0; }

.map-controls {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-row { display: flex; gap: 8px; }
.form-row input { flex: 1; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 15px; }
.form-row input:focus { outline: none; border-color: var(--accent); }

.share-result {
  margin-top: 8px;
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  display: none;
  word-break: break-all;
}
.share-result.show { display: block; background: var(--bg-hover); color: var(--accent-light); }

.checklist-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.check-count { font-size: 14px; color: var(--accent-light); font-weight: 700; }

.checklist { display: flex; flex-direction: column; gap: 4px; }

.check-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}
.check-item:hover { background: var(--bg-hover); }
.check-item.checked { opacity: 0.6; }
.check-item.checked .check-text { text-decoration: line-through; }
.check-item.custom { border-style: dashed; }

.check-box {
  width: 22px; height: 22px;
  border: 2px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
.check-item.checked .check-box {
  background: var(--accent);
  border-color: var(--accent);
}
.check-box::after {
  content: '✓';
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s;
}
.check-item.checked .check-box::after { opacity: 1; }

.check-text { flex: 1; font-size: 15px; }
.check-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}
.check-item:hover .check-delete { opacity: 1; }
.check-delete:hover { color: var(--danger); }

.template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.template-btn {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.template-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.spot-list { display: flex; flex-direction: column; gap: 8px; }
.spot-card {
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.spot-info h4 { font-size: 14px; margin-bottom: 4px; }
.spot-info p { font-size: 12px; color: var(--text-dim); }
.spot-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
}
.spot-delete:hover { color: var(--danger); }

.empty-text { font-size: 13px; color: var(--text-dim); text-align: center; padding: 20px; }

.nearby-list { display: flex; flex-direction: column; gap: 8px; }
.nearby-item {
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.nearby-item-info { font-size: 14px; }
.nearby-item-dist { font-size: 12px; color: var(--text-dim); }
.nearby-item a { color: var(--accent-light); text-decoration: none; font-size: 13px; }

#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding: 4px 0 env(safe-area-inset-bottom, 0);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.2s;
  font-size: 10px;
}
.nav-btn.active { color: var(--accent-light); }
.nav-icon { font-size: 20px; }
.nav-label { font-size: 10px; }

.sos-overlay {
  position: fixed;
  inset: 0;
  background: rgba(211, 47, 47, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: sos-flash 0.5s infinite;
}
@keyframes sos-flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}
.sos-overlay .sos-icon { font-size: 120px; margin-bottom: 24px; }
.sos-overlay .sos-text { font-size: 48px; font-weight: 900; color: #fff; margin-bottom: 16px; }
.sos-overlay .sos-sub { font-size: 18px; color: rgba(255,255,255,0.8); margin-bottom: 32px; }
.sos-overlay .sos-close {
  background: rgba(255,255,255,0.2);
  border: 2px solid #fff;
  color: #fff;
  padding: 16px 48px;
  border-radius: 50px;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
}

@media (min-width: 600px) {
  .home-grid { max-width: 480px; margin: 0 auto; }
  .emergency-grid { max-width: 480px; }
  .content { max-width: 600px; margin: 0 auto; }
}
