/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0D1B2A;
  --bg-card: #152238;
  --bg-nav: #091524;
  --accent: #D4A843;
  --accent-dim: #A07E30;
  --accent-blue: #2B5797;
  --text: #f0ece2;
  --text-dim: #8a8fa0;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 48px;
  --nav-h: 56px;
}

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

/* === Screens === */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  flex-direction: column;
}
.screen.active { display: flex; }

/* === Language Select === */
#screen-lang {
  background: linear-gradient(180deg, #0D1B2A 0%, #091524 100%);
  justify-content: center;
  align-items: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.lang-container {
  text-align: center;
  padding: 1.5rem 1.25rem;
  max-width: 360px;
  width: 100%;
}

.lang-logo {
  margin-bottom: 1rem;
}
.lang-logo img {
  width: 100px;
  height: 100px;
  border-radius: 50%;
}

.lang-container h1 {
  font-size: 1.4rem;
  font-weight: 300;
  letter-spacing: 2px;
  color: var(--accent);
  line-height: 1.3;
  margin-bottom: 0.2rem;
}

.lang-brand {
  font-size: 0.75rem;
  color: var(--accent-blue);
  letter-spacing: 1px;
  margin-bottom: 0.4rem;
  font-weight: 500;
}

.lang-subtitle {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 1.25rem;
}

.lang-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.lang-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.8rem;
  background: var(--bg-card);
  border: 1px solid rgba(43,87,151,0.25);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.lang-btn:active {
  background: rgba(212,168,67,0.1);
  border-color: var(--accent);
}
.lang-flag { font-size: 1.3rem; }

/* Small phones (iPhone SE, etc) */
@media (max-height: 600px) {
  .lang-logo img { width: 72px; height: 72px; }
  .lang-container h1 { font-size: 1.1rem; }
  .lang-subtitle { margin-bottom: 0.75rem; }
  .lang-btn { padding: 0.55rem 0.6rem; font-size: 0.8rem; }
  .lang-grid { gap: 0.4rem; }
  .lang-logo { margin-bottom: 0.5rem; }
}

/* === Top Header === */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.75rem;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--bg-nav);
  border-bottom: 1px solid rgba(43,87,151,0.2);
  z-index: 1002;
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  min-height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  flex-shrink: 0;
  width: 100%;
  position: relative;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text);
  min-width: 0;
  flex: 1;
  overflow: hidden;
}
.header-brand img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
}
.header-brand span {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-menu-btn {
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: auto;
  -webkit-tap-highlight-color: transparent;
}

/* === Slide Menu === */
.slide-menu {
  position: fixed;
  top: 0;
  right: -280px;
  width: 280px;
  max-width: 85vw;
  height: 100%;
  background: var(--bg-card);
  z-index: 3000;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
  box-shadow: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  visibility: hidden;
}
.slide-menu.open {
  right: 0;
  box-shadow: -4px 0 20px rgba(0,0,0,0.5);
  visibility: visible;
}

.slide-menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2999;
  display: none;
}
.slide-menu-overlay.open { display: block; }

.slide-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(43,87,151,0.2);
}
.slide-menu-header span {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
}

.menu-close-btn {
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.2rem;
}

.slide-menu-links {
  flex: 1;
  padding: 0.5rem 0;
}
.slide-menu-links a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.2s;
}
.slide-menu-links a:active {
  background: rgba(212,168,67,0.08);
}
.slide-menu-links a svg {
  width: 20px;
  height: 20px;
  color: var(--accent-blue);
  flex-shrink: 0;
}
.slide-menu-links .menu-divider {
  height: 1px;
  background: rgba(43,87,151,0.15);
  margin: 0.5rem 1.25rem;
}

.slide-menu-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(43,87,151,0.2);
  text-align: center;
}
.slide-menu-footer img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  margin-bottom: 0.5rem;
}
.slide-menu-footer p {
  color: var(--text-dim);
  font-size: 0.7rem;
  line-height: 1.4;
}

/* === Map === */
#map {
  flex: 1;
  z-index: 1;
  min-height: 0;
}

.leaflet-control-zoom { display: none; }

/* Custom marker */
.landmark-marker {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
  transition: transform 0.2s, filter 0.2s;
}
.landmark-marker img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
.landmark-marker.active {
  transform: scale(1.3);
  filter: drop-shadow(0 0 8px rgba(212,168,67,0.7));
}
.landmark-marker.played {
  opacity: 0.6;
  filter: grayscale(0.4) drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

/* Landmark name labels on map */
.landmark-label {
  background: rgba(13, 27, 42, 0.85) !important;
  border: 1px solid rgba(212, 168, 67, 0.4) !important;
  color: #f0ece2 !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  padding: 2px 6px !important;
  border-radius: 4px !important;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4) !important;
  white-space: nowrap !important;
  transition: opacity 0.3s ease !important;
}
.landmark-label::before {
  display: none !important;
}

.user-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #4a9eff;
  border: 3px solid #fff;
  box-shadow: 0 0 10px rgba(74,158,255,0.6);
}

/* === Now Playing Bar === */
.now-playing {
  position: fixed;
  bottom: var(--nav-h);
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--bg-card);
  border-top: 1px solid rgba(43,87,151,0.15);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s;
  max-height: calc(100vh - var(--header-h) - var(--nav-h));
}
.now-playing.hidden { transform: translateY(200%); pointer-events: none; }

.np-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  flex-shrink: 0;
}

.np-info { flex: 1; min-width: 0; }
#np-title {
  font-size: 0.82rem;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.np-progress {
  height: 3px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  margin-top: 0.25rem;
  overflow: hidden;
}
.np-bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s linear;
}

.np-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.np-text-toggle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(43,87,151,0.2);
  border: none;
  color: var(--accent-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
  position: relative;
}
.np-text-toggle.active {
  background: var(--accent-blue);
  color: #fff;
}
.np-text-icon {
  position: relative;
}
.np-chevron {
  position: absolute;
  top: 1px;
  right: 1px;
  transition: transform 0.3s ease;
  color: var(--accent);
  filter: drop-shadow(0 0 1px rgba(0,0,0,0.5));
}
.np-text-toggle.active .np-chevron {
  transform: rotate(180deg);
  color: #fff;
}

/* === Text Panel with Image === */
.np-text-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
}
.np-text-panel.open {
  max-height: 35vh;
  overflow-y: auto;
}
.np-text-content {
  padding: 0;
  border-top: 1px solid rgba(43,87,151,0.15);
}

/* Scrollable text body - scroll defined below in main .np-text-body */
.np-text-body::-webkit-scrollbar {
  width: 8px;
}
.np-text-body::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.05);
  border-radius: 4px;
}
.np-text-body::-webkit-scrollbar-thumb {
  background: var(--accent-dim);
  border-radius: 4px;
  min-height: 30px;
}
.np-text-body::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* Landmark image in text panel */
.np-landmark-image {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
  background: var(--bg);
  flex-shrink: 0;
}
.np-landmark-image-placeholder {
  width: 100%;
  height: 120px;
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg-card) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.np-landmark-image-placeholder svg {
  width: 36px;
  height: 36px;
  color: var(--accent-dim);
  opacity: 0.3;
}

.np-text-body {
  padding: 0.75rem 1rem 1rem;
  padding-right: 0.5rem;
  font-size: 0.95rem;
  line-height: 1.75;
  color: var(--text);
  opacity: 0.92;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  max-height: calc(35vh - 120px);
  scrollbar-width: thin;
  scrollbar-color: var(--accent-dim) rgba(255,255,255,0.05);
}

/* === Bottom Nav === */
.bottom-nav {
  display: flex;
  background: var(--bg-nav);
  border-top: 1px solid rgba(43,87,151,0.15);
  padding-bottom: var(--safe-bottom);
  z-index: 1001;
  height: var(--nav-h);
  min-height: var(--nav-h);
  flex-shrink: 0;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.4rem 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.6rem;
  cursor: pointer;
  transition: color 0.2s;
}
.nav-btn.active { color: var(--accent); }
.nav-btn svg { width: 20px; height: 20px; }

/* === Landmark List === */
.list-header {
  padding: 0.75rem 1rem 0.4rem;
  background: var(--bg);
  flex-shrink: 0;
}
.list-header h2 {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--accent);
}

.landmark-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem 0.75rem;
  padding-bottom: calc(0.75rem + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}

.landmark-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.6rem;
  border-radius: var(--radius);
  margin-bottom: 0.3rem;
  background: var(--bg-card);
  cursor: pointer;
  transition: background 0.2s;
}
.landmark-item:active { background: rgba(212,168,67,0.08); }
.landmark-item.nearby {
  border: 1px solid rgba(212,168,67,0.3);
}

.li-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
}

.li-info { flex: 1; min-width: 0; }
.li-name {
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.li-distance {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 0.1rem;
}

.li-play {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(212,168,67,0.1);
  border: none;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.li-play svg { width: 16px; height: 16px; }

/* === Settings === */
.settings-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}
.settings-container h2 {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 1rem;
}

.setting-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  padding: 0.6rem 0;
  border-bottom: 1px solid rgba(43,87,151,0.12);
}
.setting-group label:first-child {
  font-size: 0.85rem;
  color: var(--text);
}

.setting-select {
  padding: 0.35rem 0.5rem;
  background: var(--bg-card);
  border: 1px solid rgba(43,87,151,0.25);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.82rem;
  max-width: 140px;
}

/* Toggle */
.toggle { position: relative; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: #444;
  border-radius: 24px;
  cursor: pointer;
  transition: 0.3s;
}
.toggle-slider::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.3s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::after { transform: translateX(20px); }

.status-indicators {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  margin-top: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-dim);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.green { background: #4caf50; }
.status-dot.red { background: #f44336; }
.status-dot.yellow { background: #ff9800; }

/* === Buttons === */
.btn-primary {
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary {
  width: 100%;
  padding: 0.6rem;
  background: none;
  color: var(--text-dim);
  border: none;
  font-size: 0.82rem;
  cursor: pointer;
  margin-top: 0.5rem;
}

/* === Overlay === */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}
.overlay.hidden { display: none; }
.overlay-content {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 1.5rem 1.25rem;
  text-align: center;
  max-width: 320px;
  width: 100%;
}
.overlay-content h3 {
  color: var(--accent);
  margin: 0.75rem 0 0.4rem;
  font-size: 1rem;
}
.overlay-content p {
  color: var(--text-dim);
  font-size: 0.82rem;
  margin-bottom: 1.25rem;
  line-height: 1.4;
}

.credits {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.72rem;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Leaflet popup custom */
.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  color: var(--text) !important;
  border-radius: 10px !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4) !important;
}
.leaflet-popup-tip { background: var(--bg-card) !important; }
.leaflet-popup-content { font-size: 0.82rem !important; margin: 8px 12px !important; }
.popup-play-btn {
  display: inline-block;
  margin-top: 0.4rem;
  padding: 0.3rem 0.8rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

/* === RTL support === */
[dir="rtl"] .header-brand { direction: rtl; }
[dir="rtl"] .header-menu-btn { margin-left: 0; margin-right: auto; }
[dir="rtl"] .slide-menu { right: auto; left: -280px; box-shadow: 4px 0 20px rgba(0,0,0,0.5); }
[dir="rtl"] .slide-menu.open { left: 0; right: auto; }
[dir="rtl"] .slide-menu-links a { direction: rtl; }
[dir="rtl"] .np-text-body { direction: rtl; text-align: right; }
[dir="rtl"] .li-name { direction: rtl; text-align: right; }
[dir="rtl"] .np-controls { flex-direction: row-reverse; }

/* === Very small screens (< 360px width) === */
@media (max-width: 359px) {
  .header-brand img { width: 24px; height: 24px; }
  .header-brand span { font-size: 0.72rem; }
  .header-brand { gap: 0.35rem; }
  .lang-btn { padding: 0.5rem; font-size: 0.75rem; gap: 0.3rem; }
  .lang-flag { font-size: 1.1rem; }
  .np-controls { padding: 0.4rem 0.5rem; gap: 0.4rem; }
  .np-btn { width: 34px; height: 34px; }
  .np-text-toggle { width: 30px; height: 30px; }
  .landmark-item { padding: 0.5rem 0.4rem; gap: 0.4rem; }
  .li-icon { width: 30px; height: 30px; }
  .li-play { width: 30px; height: 30px; }
}

/* === Medium phones (360-390px) === */
@media (max-width: 390px) {
  .header-brand span { font-size: 0.75rem; }
  .top-header { padding: 0 0.5rem; }
}

/* === Notch phones (safe area) === */
@supports (padding: env(safe-area-inset-bottom)) {
  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
  }
  .now-playing {
    bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  }
}

/* === Desktop — center content with 30% side margins === */
@media (min-width: 768px) {
  .screen {
    padding-left: 15%;
    padding-right: 15%;
  }
  #screen-lang {
    padding-left: 0;
    padding-right: 0;
  }
  .top-header {
    padding-left: calc(15% + 0.75rem);
    padding-right: calc(15% + 0.75rem);
  }
  .bottom-nav {
    padding-left: 15%;
    padding-right: 15%;
  }
  .now-playing {
    left: 15%;
    right: 15%;
  }
  .slide-menu {
    width: 320px;
  }
}

/* === Landscape mode on mobile === */
@media (max-height: 450px) and (orientation: landscape) {
  :root { --header-h: 40px; --nav-h: 44px; }
  .np-text-panel.open { max-height: 28vh; }
  .np-landmark-image { height: 80px; }
  .np-landmark-image-placeholder { height: 80px; }
  .lang-logo img { width: 48px; height: 48px; }
  .lang-container h1 { font-size: 1rem; margin-bottom: 0.1rem; }
  .lang-subtitle { margin-bottom: 0.5rem; font-size: 0.75rem; }
  .lang-grid { gap: 0.3rem; }
  .lang-btn { padding: 0.4rem 0.5rem; font-size: 0.75rem; }
}


/* === Audio Loading Spinner === */
.np-btn .spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid rgba(212,168,67,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Usage Tips on Language Screen === */
.lang-tips {
  margin-top: 1.5rem;
  padding: 0 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.tip-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-dim);
  font-size: 0.78rem;
  line-height: 1.3;
  text-align: left;
}
.tip-item svg {
  flex-shrink: 0;
  stroke: var(--accent);
  opacity: 0.7;
}
@media (max-height: 600px) {
  .lang-tips { margin-top: 0.75rem; gap: 0.35rem; }
  .tip-item { font-size: 0.7rem; }
  .tip-item svg { width: 14px; height: 14px; }
}
@media (max-height: 450px) and (orientation: landscape) {
  .lang-tips { display: none; }
}
