/* ==============================================
   CSS CUSTOM PROPERTIES (VARIABLES)
   ============================================== */
:root {
  /* Colors */
  --color-primary: #4caf50;
  --color-primary-dark: #3f9a45;
  --color-primary-light: #55b757;
  --color-primary-lighter: #1cfc66;
  --color-accent: #f59e0b;
  --color-accent-alt: #ff6500;
  --color-secondary: #2563eb;
  
  --color-white: #ffffff;
  --color-gray-50: #f9fafb;
  --color-gray-100: #f3f4f6;
  --color-gray-200: #e5e7eb;
  --color-gray-300: #d1d5db;
  --color-gray-400: #9ca3af;
  --color-gray-500: #6b7280;
  --color-gray-600: #4b5563;
  --color-gray-700: #374151;
  --color-gray-800: #1f2937;
  --color-gray-900: #111827;
  
  --color-orange-50: #fff7ed;
  --color-orange-100: #ffedd5;
  --color-orange-border: #fde6c9;
  --color-resident-glow: rgba(249, 115, 22, 0.8);
  
  --color-error: #ef4444;
  --color-success: #15803d;
  --color-success-bg: #f0fdf4;
  
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  
  /* Border radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 12px;
  --radius-2xl: 14px;
  --radius-full: 50%;
  
  /* Shadows */
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.06);
  --shadow-xl: 0 20px 40px rgba(0,0,0,0.18);
  --shadow-2xl: 0 20px 40px rgba(0,0,0,0.25);
  --shadow-primary: 0 3px 10px rgba(76, 175, 80, 0.2);
  --shadow-primary-hover: 0 6px 16px rgba(76, 175, 80, 0.28);
  
  /* Transitions */
  --transition-fast: 0.06s ease;
  --transition-base: 0.12s ease;
  --transition-slow: 0.2s ease;
  --transition-slower: 0.3s ease;
  --transition-slowest: 0.5s ease;
  
  /* Typography */
  --font-system: system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-base: Moderat, sans-serif;
  --line-height-tight: 1.2;
  --line-height-normal: 1.4;
  --line-height-relaxed: 1.55;
}

/* ==============================================
   BASE RESETS & TYPOGRAPHY
   ============================================== */
* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: var(--font-base);
  overflow: hidden;
  color: var(--color-primary);
}

/* ==============================================
   ACCESSIBILITY UTILITIES
   ============================================== */

/* Screen Reader Only Content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Skip to Content Link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-primary);
  color: var(--color-white);
  padding: 8px 16px;
  text-decoration: none;
  z-index: 3000;
  border-radius: 0 0 4px 0;
  font-weight: 600;
  transition: top var(--transition-base);
}

.skip-link:focus {
  top: 0;
  outline: 3px solid var(--color-primary-dark);
  outline-offset: 2px;
}

/* Universal Focus Indicators */
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* ==============================================
   LAYOUT CONTAINERS
   ============================================== */
#mainpage {
  display: flex;
  height: 100vh;
  margin: 0;
  flex-direction: row;
  background: var(--color-white);
}

#content {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 570px;
  background-color: var(--color-white);
  padding: 20px 50px 10px 80px;
  overflow-y: auto;
  font-weight: 100;
}

#map {
  flex: 1;
  height: 100vh;
  transition: filter var(--transition-slowest);
}

#map.sepia {
  filter: sepia(0.6);
}

/* ==============================================
   HEADER & LOGO
   ============================================== */
#head_logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  touch-action: none;
}

#head_logo h1 {
  margin: 0;
  font-size: 2rem;
}

/* ==============================================
   CARDS (INTRO & ABOUT)
   ============================================== */
#intro,
#about-project {
  max-width: 760px;
  padding: 1.25rem 1.25rem 1.5rem;
  border-radius: var(--radius-2xl);
  border: 1px solid rgba(0,0,0,.08);
  background: var(--color-white);
  box-shadow: var(--shadow-lg);
  text-align: justify;
  text-justify: inter-word;
}

#intro h2 {
  font-size: 1.5em;
  margin: var(--space-md) 0 0;
  color: var(--color-primary);
}

#intro p {
  color: var(--color-primary);
  margin: 0.8rem 0;
  line-height: var(--line-height-relaxed);
  font-weight: 400;
}

#intro blockquote,
#intro em {
  color: var(--color-primary);
  font-weight: 400;
}

#intro blockquote {
  background: var(--color-gray-50);
  border-left: 2px solid #ccc;
  margin: 0.5em 0;
  padding: 0.5em 10px;
  font-style: normal;
  position: relative;
}

#intro blockquote::before {
  content: open-quote;
  color: #ccc;
  font-size: 3rem;
  line-height: 0;
  margin-right: 0.25em;
  position: absolute;
  left: -0.25em;
  top: -0.25em;
}

#about-project h2 {
  font-size: clamp(1.05rem, 1.2vw + 0.9rem, 1.25rem);
  margin: 0 0 var(--space-sm);
}

#about-project p {
  margin: var(--space-sm) 0 0;
  line-height: var(--line-height-relaxed);
}

#about-project .about-cta {
  margin-top: 0.75rem;
}

#about-project .about-cta a {
  color: var(--color-secondary);
  text-decoration: none;
  border-bottom: 1px dashed rgba(37,99,235,.45);
}

#about-project .about-cta a:hover {
  border-bottom-style: solid;
}

#about-project .about-meta {
  display: block;
  margin-top: 0.75rem;
  color: var(--color-gray-500);
}

/* ==============================================
   BUTTONS (UNIFIED SYSTEM)
   ============================================== */
.btn,
.sf-btn,
.leaflet-bar .residents-toggle-btn,
.share-sheet button,
.tour-progress-nav button,
.retry-btn {
  appearance: none;
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font: 600 14px/var(--line-height-tight) var(--font-system);
  cursor: pointer;
  transition: transform var(--transition-fast), 
              box-shadow var(--transition-base), 
              background var(--transition-base), 
              color var(--transition-base);
  border: 1px solid transparent;
}

.btn:focus-visible,
.sf-btn:focus-visible,
.leaflet-bar .residents-toggle-btn:focus-visible {
  outline: 3px solid rgba(37, 99, 235, .5);
  outline-offset: 2px;
}

/* Primary Button Variant */
.btn-primary,
.sf-btn-primary,
.leaflet-bar .residents-toggle-btn,
.share-sheet button.primary,
.tour-next,
.tour-complete,
.tour-prev,
.retry-btn {
  border-color: rgba(0,0,0,.12);
  color: var(--color-white);
  background: linear-gradient(180deg, var(--color-primary), var(--color-primary-dark));
  box-shadow: var(--shadow-primary);
}

.btn-primary:hover,
.sf-btn-primary:hover,
.leaflet-bar .residents-toggle-btn:hover,
.share-sheet button.primary:hover,
.retry-btn:hover {
  background: linear-gradient(180deg, var(--color-primary-light), var(--color-primary-dark));
  box-shadow: var(--shadow-primary-hover);
}

.btn-primary:active,
.sf-btn-primary:active,
.leaflet-bar .residents-toggle-btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 6px rgba(76, 175, 80, .25);
}

/* Ghost Button Variant */
.btn-ghost,
.sf-btn-ghost,
.share-sheet button.ghost {
  border-color: var(--color-gray-300);
  background: var(--color-white);
  color: var(--color-gray-700);
}

.btn-ghost:hover,
.sf-btn-ghost:hover,
.share-sheet button.ghost:hover {
  background: #f8fafc;
}

/* Special Buttons */
.btn-share {
  margin-top: var(--space-md);
  padding: 0.75em 1.5em;
  background-color: orange;
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: bold;
  cursor: pointer;
}

.leaflet-bar .residents-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 132px;
  padding: 8px 12px;
}

.leaflet-bar.leaflet-control {
  background: transparent;
  border: none;
  box-shadow: none;
}

.modal-share-btn {
  position: absolute;
  right: 8px;
  top: 8px;
  appearance: none;
  border: 1px solid rgba(0,0,0,.12);
  background: var(--color-white);
  color: var(--color-gray-700);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  font: 600 13px/1 var(--font-system);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.modal-share-btn:hover {
  background: var(--color-gray-50);
}

.modal-share-btn svg {
  display: block;
}

/* ==============================================
   THEME/CATEGORY BUTTONS
   ============================================== */
#themes {
  width: 100%;
  margin-top: var(--space-lg);
  margin-bottom: var(--space-md);
}

.themes-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: var(--space-md);
}

.theme {
  display: inline-block;
  padding: 5px 10px;
  background-color: var(--color-primary);
  color: var(--color-white);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: bold;
  user-select: none;
}

.theme.active {
  background-color: var(--color-primary-lighter);
}

/* ==============================================
   DIALOGS (UNIFIED SYSTEM)
   ============================================== */
dialog#story-form-dialog,
dialog#share-dialog,
dialog#tours-dialog {
  border: none;
  border-radius: var(--radius-xl);
  padding: 0;
  width: min(760px, 92vw);
  max-width: 760px;
  box-shadow: var(--shadow-2xl);
}

dialog#story-form-dialog::backdrop,
dialog#share-dialog::backdrop,
dialog#tours-dialog::backdrop {
  background: rgba(0,0,0,.45);
}

dialog#tours-dialog {
  max-width: 800px;
}

/* Dialog Headers (Unified) */
.sf-header,
.share-sheet header,
.tours-gallery header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: var(--color-primary);
  color: var(--color-white);
}

.tours-gallery header {
  padding: 16px 20px;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.sf-header h3,
.tours-gallery header h2 {
  margin: 0;
  font-size: clamp(1.05rem, 1.1vw + 0.9rem, 1.25rem);
  font-weight: 600;
}

.tours-gallery header h2 {
  font-size: 1.5rem;
}

.tours-gallery .close-btn {
  background: none;
  border: none;
  color: var(--color-white);
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
}

/* Dialog Bodies */
.sf-card {
  margin: 0;
  padding: 0;
  background: transparent;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.sf-body,
.share-sheet .body {
  padding: 1.25rem 1.25rem 1rem;
}

.share-sheet .body {
  padding: 18px;
  background: var(--color-white);
  max-height: 70vh;
  overflow: auto;
}

.sf-blurb {
  margin-bottom: 0.75rem;
  color: var(--color-primary);
  text-align: justify;
  line-height: var(--line-height-relaxed);
}

.sf-blurb p {
  margin: 0.6rem 0;
}

/* Dialog Forms */
.sf-form label {
  display: block;
  margin-top: var(--space-md);
  color: var(--color-primary);
  font-weight: 600;
}

.sf-form input,
.sf-form textarea {
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.65rem 0.7rem;
  border: 1px solid #aaa;
  border-radius: var(--radius-md);
  font: 400 0.95rem/1.3 inherit;
  color: var(--color-gray-900);
  background: var(--color-white);
}

.sf-form textarea {
  min-height: 140px;
  resize: vertical;
}

/* Dialog Footers */
.sf-footer,
.share-sheet footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--color-gray-200);
  background: var(--color-white);
}

.share-sheet footer {
  border-bottom-left-radius: var(--radius-xl);
  border-bottom-right-radius: var(--radius-xl);
}

/* ==============================================
   ARTICLE LISTING & CARDS
   ============================================== */
#article-list {
  width: 100%;
  max-width: 570px;
  padding-top: 10px;
  padding-bottom: 10px;
}

#article-list ul.grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.card {
  position: relative;
  border: 1px solid #ddd;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-slow);
  background: var(--color-white);
}

.card:hover {
  transform: scale(1.05);
}

.card img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
}

.overlay,
.inactiveoverlay {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 5px;
  font-size: 0.8rem;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.overlay {
  background: var(--color-primary);
  color: var(--color-white);
}

.inactiveoverlay {
  background: red;
  color: var(--color-white);
}

/* ==============================================
   ARTICLE SEARCH
   ============================================== */
.article-search-container {
  width: 100%;
  margin-bottom: var(--space-lg);
}

.article-search-box {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 100%;
  background: white;
  border: 2px solid var(--color-gray-200);
  border-radius: var(--radius-lg);
  padding: 0 12px;
  transition: border-color var(--transition-slow);
}

.article-search-box:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

.search-icon {
  color: var(--color-gray-400);
  flex-shrink: 0;
  margin-right: 8px;
}

#article-search-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 12px 8px;
  font-size: 15px;
  background: transparent;
  color: var(--color-gray-800);
}

#article-search-input::placeholder {
  color: var(--color-gray-400);
}

.search-clear-btn {
  appearance: none;
  background: var(--color-gray-100);
  border: none;
  color: var(--color-gray-500);
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition-slow);
}

.search-clear-btn:hover {
  background: var(--color-gray-200);
  color: var(--color-gray-700);
}

.search-results-count {
  margin-top: 8px;
  font-size: 0.9rem;
  color: var(--color-gray-500);
  text-align: center;
  display: none;
}

/* ==============================================
   MODALS (UNIFIED SYSTEM)
   ============================================== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.modal.show {
  opacity: 1;
}

.modal-content {
  background-color: var(--color-white);
  width: 90%;
  max-width: 500px;
  overflow-y: auto;
  border-radius: var(--radius-lg);
  position: relative;
  text-align: center;
  animation: modalFadeIn 0.4s ease forwards;
}

@keyframes modalFadeIn {
  from {
    transform: translateY(-30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-content.swap-fade {
  transition: opacity 0.16s ease;
}

.modal-content.swap-fade.fade-out {
  opacity: 0;
}

.modal-content header {
  padding: 0.5rem;
  background: var(--color-primary);
  color: var(--color-white);
}

.modal-content header h2 {
  margin: 0;
  font-size: 1.4rem;
}

.modal-content header h3 {
  margin: 0.3rem 0;
  font-size: 1rem;
}

.modal .modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--color-gray-200);
  background: var(--color-white);
}

/* Modal Navigation */
.modal-nav {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  z-index: 2;
}

.modal-nav .nav-btn {
  pointer-events: auto;
  appearance: none;
  border: none;
  background: rgba(0,0,0,0.45);
  color: var(--color-white);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  font-size: 20px;
  font-weight: 700;
  margin: 0 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.modal-nav .nav-btn:hover {
  background: rgba(0,0,0,0.6);
}

/* Modal Content Areas */
.imgWrapper {
  width: 100%;
  height: 300px;
  overflow: hidden;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--color-gray-50);
  position: relative;
}

.imgWrapper img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform var(--transition-slowest);
  border-radius: var(--radius-md);
}

.imgWrapper:hover img {
  transform: scale(1.1);
}

.descriptionWrapper {
  background-color: var(--color-white);
  overflow-y: auto;
  margin-top: 10px;
  text-align: justify;
  scrollbar-width: none;
  padding: 25px;
  max-height: 200px;
}

.descriptionWrapper::-webkit-scrollbar {
  display: none;
}

.progress-bar {
  height: 4px;
  width: 0%;
  background-color: var(--color-primary);
  position: sticky;
  top: 0;
  left: 0;
  z-index: 1;
  transition: width 0.25s ease;
}

/* ==============================================
   REACTIONS
   ============================================== */
.reactions-section {
  margin: var(--space-xl) 0 var(--space-md);
  padding: var(--space-md);
  background: var(--color-gray-50);
  border-radius: var(--radius-md);
}

.reactions-section h4 {
  margin: 0 0 var(--space-md);
  font-size: 1.1rem;
  color: var(--color-primary);
}

.reaction-counts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: var(--space-md);
}

.reaction-badge {
  padding: 4px 12px;
  background: white;
  border: 1px solid var(--color-gray-200);
  border-radius: 20px;
  font-size: 0.9rem;
}

.reaction-comments {
  display: grid;
  gap: 12px;
}

.reaction-comment {
  display: flex;
  gap: 10px;
  padding: 10px;
  background: white;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-gray-200);
}

.reaction-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.reaction-content p {
  margin: 0 0 4px;
  color: var(--color-gray-700);
}

.reaction-content small {
  color: var(--color-gray-500);
  font-size: 0.85rem;
}

.reaction-form {
  margin: var(--space-xl) 0;
  padding: var(--space-lg);
  background: var(--color-gray-50);
  border-radius: var(--radius-md);
}

.reaction-form h4 {
  margin: 0 0 var(--space-md);
  color: var(--color-primary);
}

.reaction-types {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: var(--space-md);
}

.reaction-type-btn {
  cursor: pointer;
}

.reaction-type-btn input {
  display: none;
}

.reaction-type-btn span {
  display: block;
  padding: 8px 16px;
  background: white;
  border: 2px solid var(--color-gray-200);
  border-radius: var(--radius-md);
  transition: all var(--transition-slow);
}

.reaction-type-btn input:checked + span {
  border-color: var(--color-primary);
  background: var(--color-success-bg);
}

.reaction-field {
  display: block;
  margin: var(--space-md) 0;
}

.reaction-field span {
  display: block;
  margin-bottom: 4px;
  font-weight: 600;
  color: var(--color-primary);
  font-size: 0.9rem;
}

.reaction-field input,
.reaction-field textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--color-gray-300);
  border-radius: var(--radius-sm);
  font-family: inherit;
}

.reaction-note {
  margin: var(--space-sm) 0 0;
  font-size: 0.85rem;
  color: var(--color-gray-500);
}

.reaction-success {
  padding: var(--space-md);
  background: var(--color-success-bg);
  color: var(--color-success);
  border-radius: var(--radius-md);
  text-align: center;
  font-weight: 600;
}

/* ==============================================
   TOURS
   ============================================== */
#tours-list {
  padding: 20px;
  max-height: 60vh;
  overflow-y: auto;
}

.tour-card {
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
  transition: box-shadow var(--transition-slow);
}

.tour-card:hover {
  box-shadow: var(--shadow-md);
}

.tour-card img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}

.tour-card h3 {
  margin: 0 0 8px;
  color: var(--color-primary);
}

.tour-card p {
  margin: 0 0 12px;
  color: var(--color-gray-500);
}

.tour-meta {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--color-gray-500);
}

.no-tours {
  text-align: center;
  padding: 40px;
  color: var(--color-gray-500);
}

.tour-modal .modal-content {
  max-width: 570px;
  max-height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: 0;
  animation: slideInLeft 0.5s ease forwards;
  overflow-y: auto;
}

@keyframes slideInLeft {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

.tour-modal {
  background: rgba(0,0,0,0.3);
}

.tour-modal .descriptionWrapper {
  max-height: none;
}

.tour-progress {
  background: var(--color-gray-50);
  border-bottom: 1px solid var(--color-gray-200);
}

.tour-progress-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
}

.progress-bar-container {
  height: 4px;
  background: var(--color-gray-200);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--color-primary);
  transition: width var(--transition-slower);
}

.tour-progress-nav {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
}

.tour-progress-nav button {
  padding: 8px 16px;
  border: 1px solid var(--color-gray-300);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

/* Tour markers */
.tour-stop-marker {
  background: transparent;
  border: none;
}

.tour-number {
  width: 30px;
  height: 30px;
  background: var(--color-secondary);
  color: var(--color-white);
  border: 3px solid var(--color-white);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

@keyframes tour-pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.7);
  }
  50% {
    transform: scale(1.15);
    box-shadow: 0 0 0 10px rgba(37, 99, 235, 0);
  }
}

.tour-number.active {
  animation: tour-pulse 2s ease-in-out infinite;
  background: var(--color-accent);
}

/* ==============================================
   LEAFLET CUSTOMIZATION
   ============================================== */
.leaflet-popup.resident-popup-wrap .leaflet-popup-content-wrapper {
  padding: 0;
  border-radius: var(--radius-2xl);
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
  overflow: hidden;
  border: 1px solid rgba(0,0,0,.08);
}

.resident-popup {
  font: 14px/var(--line-height-normal) var(--font-system);
  color: var(--color-gray-800);
}

.rp-header {
  padding: 12px 14px;
  background: linear-gradient(0deg, var(--color-orange-50) 0%, var(--color-orange-100) 100%);
  border-bottom: 1px solid var(--color-orange-border);
}

.rp-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--color-gray-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rp-subtitle {
  font-size: 12px;
  color: var(--color-gray-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rp-body {
  padding: 12px 14px;
  display: grid;
  gap: 8px;
}

.rp-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 8px;
  align-items: start;
}

.rp-label {
  color: var(--color-gray-500);
  font-size: 12px;
}

.rp-value {
  color: var(--color-gray-800);
}

.resident-glow {
  filter: drop-shadow(0 0 6px var(--color-resident-glow))
          drop-shadow(0 0 12px rgba(249, 115, 22, 0.5));
}

.marker-cluster-small div {
  background-color: rgba(255, 165, 0, 0.6) !important;
}

.marker-cluster-small {
  background-color: rgba(255, 165, 0, 0.2) !important;
}

/* ==============================================
   LOADING & ERROR STATES
   ============================================== */
.loading-state,
.error-state,
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.loading-state p,
.error-state p {
  margin-top: 16px;
  color: var(--color-gray-500);
  font-size: 0.95rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-gray-200);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

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

.error-icon {
  margin-bottom: 16px;
}

.error-state h3 {
  margin: 0 0 8px;
  color: var(--color-error);
  font-size: 1.1rem;
}

.error-state p {
  margin: 0 0 20px;
  max-width: 400px;
}

.empty-state {
  color: var(--color-gray-400);
  font-size: 0.95rem;
}

.map-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.map-loading-overlay p {
  margin-top: 16px;
  color: var(--color-gray-500);
  font-weight: 500;
}

.map-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: var(--color-gray-50);
  color: var(--color-gray-500);
}

.map-error p {
  margin-bottom: 16px;
  font-size: 1.1rem;
}

/* ==============================================
   FOOTER
   ============================================== */
footer {
  background: var(--color-primary);
  color: var(--color-white);
  font-size: 0.9rem;
  padding: 0.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==============================================
   KEYBOARD SHORTCUTS HELP
   ============================================== */

/* Floating Help Button */
.keyboard-help-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-white);
  border: none;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
  z-index: 1000;
  transition: transform var(--transition-slow), box-shadow var(--transition-slow);
}

.keyboard-help-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(76, 175, 80, 0.5);
}

.keyboard-help-btn:focus-visible {
  outline: 3px solid rgba(76, 175, 80, 0.5);
  outline-offset: 2px;
}

/* Keyboard Help Overlay */
.keyboard-help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  transition: opacity var(--transition-slow);
}

.keyboard-help-overlay.show {
  opacity: 1;
}

/* Keyboard Help Content */
.keyboard-help-content {
  background: var(--color-white);
  border-radius: var(--radius-xl);
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-2xl);
}

.keyboard-help-content header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid var(--color-gray-200);
}

.keyboard-help-content h2 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--color-gray-800);
}

.keyboard-help-content .close-btn {
  background: none;
  border: none;
  color: var(--color-gray-600);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
  transition: color var(--transition-base);
}

.keyboard-help-content .close-btn:hover {
  color: var(--color-gray-800);
}

/* Shortcuts List */
.shortcuts-list {
  padding: 20px;
}

.shortcut-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-gray-100);
}

.shortcut-item:last-child {
  border-bottom: none;
}

.shortcut-item kbd {
  display: inline-block;
  padding: 4px 8px;
  background: var(--color-gray-100);
  border: 1px solid var(--color-gray-300);
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9rem;
  box-shadow: 0 2px 0 var(--color-gray-300);
  min-width: 32px;
  text-align: center;
  color: var(--color-gray-700);
}

.shortcut-item span {
  flex: 1;
  color: var(--color-gray-500);
}

/* ==============================================
   RESPONSIVE: MOBILE (<= 500px)
   ============================================== */
@media (max-width: 500px) {
  #mainpage {
    display: grid;
  }

  #content {
    order: 1;
    width: 100%;
    padding: 20px;
    background: white;
    position: absolute;
    top: 50%;
    bottom: 0;
    left: 0;
    right: 0;
    border-top-left-radius: var(--radius-xl);
    border-top-right-radius: var(--radius-xl);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    z-index: 2;
    transition: top var(--transition-slower);
    will-change: transform;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overflow-y: auto;
    padding-bottom: 80px;
  }

  #content::before {
    display: none;
  }

  #content-handle {
    width: 40px;
    height: 5px;
    background: #ccc;
    border-radius: 3px;
    margin: 10px auto 5px auto;
    cursor: grab;
  }

  #map {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    z-index: 1;
  }

  /* Heavier font weights for mobile readability */
  #themes .theme,
  .card .overlay,
  #article-list p {
    font-weight: bold;
  }

  #intro p,
  #about-project p {
    font-weight: 500;
  }

  /* Full-screen dialog on mobile */
  dialog#story-form-dialog {
    max-width: none;
    max-height: none;
    border-radius: 0;
  }

  .sf-header {
    padding: 14px;
  }

  .sf-body {
    padding: 16px;
    height: calc(100vh - 130px);
    overflow-y: auto;
  }

  .sf-footer {
    justify-content: center;
    padding: 14px;
  }

  .sf-form label {
    font-weight: 700;
  }

  .sf-btn {
    width: 100%;
    font-size: 15px;
  }

  /* Prevent iOS zoom on input focus */
  #article-search-input {
    font-size: 16px;
  }

  #article-search-input::placeholder {
    font-size: 14px;
  }

  /* Resident popup mobile adjustments */
  .rp-row {
    grid-template-columns: 1fr;
  }

  /* Tour modal mobile behavior */
  .tour-modal .modal-content {
    left: auto;
    max-width: 100%;
    max-height: 70vh;
    position: fixed;
    bottom: 0;
    top: auto;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: slideInUp 1.0s ease forwards;
  }

  @keyframes slideInUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
}

/* ==============================================
   RESPONSIVE: SMALL MOBILE (<= 420px)
   ============================================== */
@media (max-width: 420px) {
  .rp-row {
    grid-template-columns: 1fr;
  }
}

/* ==============================================
   RESPONSIVE: TABLET (501px - 768px)
   ============================================== */
@media (max-width: 768px) {
  .tour-modal .modal-content {
    left: auto;
    max-width: 100%;
    max-height: 70vh;
    position: fixed;
    bottom: 0;
    top: auto;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: slideInUp 1.0s ease forwards;
  }
}
