:root {
  --tram-red: #E8102D;
  --cream: #F5E6C8;
  --dark-green: #1A3C34;
  --gold: #D4A847;
  --charcoal: #2D2D2D;
  --light-gray: #F0EDE6;
  --font-cn: 'Noto Sans TC', 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font-cn);
  background: var(--cream);
  color: var(--charcoal);
  overflow: hidden;
}

/* ─── Language Picker ─── */
#lang-picker {
  position: fixed; inset: 0; z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--charcoal) 0%, #1a1a1a 100%);
  padding-top: 60px;
}
#lang-picker.hidden { display: none; }

#picker-box {
  text-align: center;
  padding: 40px 24px;
  max-width: 340px;
  width: 90%;
}

#picker-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--cream);
  margin-bottom: 4px;
}
#picker-title span {
  font-size: .8rem;
  font-weight: 400;
  color: rgba(255,255,255,.5);
}

#picker-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 28px;
}

.picker-btn {
  padding: 16px;
  font-size: 1.2rem;
  font-family: var(--font-cn);
  font-weight: 700;
  border: 2px solid var(--gold);
  border-radius: 12px;
  background: transparent;
  color: var(--cream);
  cursor: pointer;
  transition: all .2s;
  letter-spacing: 2px;
}
.picker-btn:hover {
  background: var(--gold);
  color: var(--charcoal);
}
.picker-btn:active {
  transform: scale(.97);
}

/* ─── Header ─── */
#header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, var(--charcoal) 0%, #1a1a1a 100%);
  padding: 8px 12px;
  border-bottom: 2px solid var(--gold);
  min-height: 48px;
}
#header.hidden { display: none; }

#header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

#brand-icon { font-size: 1.2rem; flex-shrink: 0; }

#brand-text {
  font-size: .85rem;
  font-weight: 700;
  color: var(--cream);
  text-shadow: 0 0 6px rgba(212,168,71,.3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

#ui-lang-bar {
  display: flex;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 4px;
  overflow: hidden;
}

.ui-lang-btn {
  padding: 2px 8px;
  font-size: .75rem;
  font-family: var(--font-cn);
  background: transparent;
  color: rgba(255,255,255,.5);
  border: none;
  cursor: pointer;
  transition: all .2s;
  font-weight: 400;
}
.ui-lang-btn.active {
  background: var(--gold);
  color: var(--charcoal);
  font-weight: 700;
}
.ui-lang-btn:hover:not(.active) { color: var(--gold); }

#help-btn {
  padding: 2px 10px;
  font-size: .75rem;
  font-family: var(--font-cn);
  background: transparent;
  color: var(--gold);
  border: 1px solid var(--gold);
  border-radius: 4px;
  cursor: pointer;
  transition: all .2s;
}
#help-btn:hover { background: var(--gold); color: var(--charcoal); }

/* ─── Map ─── */
#map {
  position: fixed;
  top: 48px; left: 0; right: 0; bottom: 0;
  z-index: 0;
}

.district-marker {
  width: 28px; height: 28px;
  background: var(--tram-red);
  border: 3px solid var(--gold);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  cursor: pointer;
  transition: transform .2s;
}
.district-marker:hover { transform: scale(1.2); }

.landmark-marker {
  width: 18px; height: 18px;
  background: var(--gold);
  border: 2px solid var(--cream);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
  cursor: pointer;
  transition: all .3s;
}
.landmark-marker.flash {
  width: 28px; height: 28px;
  background: #fff;
  border-color: var(--tram-red);
  box-shadow: 0 0 20px rgba(232,16,45,.6);
  animation: pulse-landmark .8s ease-in-out 3;
}
@keyframes pulse-landmark {
  0%, 100% { transform: scale(1); box-shadow: 0 0 20px rgba(232,16,45,.6); }
  50% { transform: scale(1.3); box-shadow: 0 0 40px rgba(232,16,45,.8); }
}

/* ─── Bottom Panel ─── */
#panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 1000;
  background: linear-gradient(180deg, rgba(245,230,200,0) 0%, rgba(245,230,200,.95) 20%);
  padding: 36px 12px 12px;
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  pointer-events: none;
  max-height: 55vh;
  overflow-y: auto;
}
#panel.active { pointer-events: auto; }

#panel-inner {
  background: var(--charcoal);
  border-radius: 16px 16px 0 0;
  padding: 16px;
  color: #fff;
  box-shadow: 0 -4px 20px rgba(0,0,0,.3);
  border-top: 3px solid var(--gold);
}

#district-name {
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
#district-name .label {
  color: var(--gold);
  font-size: .7rem;
  font-weight: 400;
  letter-spacing: 1px;
  text-transform: uppercase;
}

#distance-info {
  font-size: .75rem;
  color: rgba(255,255,255,.5);
  margin-top: 2px;
}

/* ─── Subtitle ─── */
#subtitle-box {
  margin: 10px 0 8px;
  padding: 10px 12px;
  background: rgba(0,0,0,.3);
  border-radius: 8px;
  border-left: 3px solid var(--gold);
  min-height: 48px;
  max-height: 96px;
  overflow-y: auto;
}
#subtitle-text {
  font-size: .9rem;
  line-height: 1.5;
  color: rgba(255,255,255,.9);
  word-break: break-word;
}
#subtitle-text .hl {
  background: var(--gold);
  color: var(--charcoal);
  border-radius: 2px;
  padding: 0 2px;
}

/* ─── Audio Controls ─── */
#audio-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

#play-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: transparent;
  color: var(--gold);
  font-size: 1.3rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
}
#play-btn .ico {
  display: inline-block;
  width: 1em;
  text-align: center;
  line-height: 1;
}
#play-btn:hover { background: var(--gold); color: var(--charcoal); }
#play-btn.playing { background: var(--tram-red); border-color: var(--tram-red); color: #fff; }

#progress-wrap {
  flex: 1;
  position: relative;
}
#progress-bar {
  width: 100%; height: 4px;
  appearance: none;
  background: rgba(255,255,255,.2);
  border-radius: 2px;
  outline: none;
  cursor: default;
  pointer-events: none;
}
#progress-bar::-webkit-slider-thumb {
  appearance: none;
  width: 10px; height: 10px;
  background: var(--gold);
  border-radius: 50%;
  border: none;
  opacity: .6;
  pointer-events: none;
}
#progress-bar::-moz-range-thumb {
  width: 10px; height: 10px;
  background: var(--gold);
  border-radius: 50%;
  border: none;
  opacity: .6;
  pointer-events: none;
}
#time-display {
  font-size: .7rem;
  color: rgba(255,255,255,.5);
  text-align: right;
  margin-top: 2px;
}

/* ─── Voice Language Selector ─── */
#lang-bar {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.lang-btn {
  flex: 1;
  padding: 5px 0;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 6px;
  background: transparent;
  color: rgba(255,255,255,.6);
  font-size: .78rem;
  font-family: var(--font-cn);
  cursor: pointer;
  transition: all .2s;
}
.lang-btn.active {
  background: rgba(255,255,255,.1);
  color: rgba(255,255,255,.3);
  border-color: rgba(255,255,255,.1);
  cursor: default;
  font-weight: 400;
}
.lang-btn:hover:not(.active) {
  border-color: var(--gold);
  color: var(--gold);
}

/* ─── Status Dot ─── */
#gps-dot {
  position: fixed;
  top: 54px; right: 10px;
  z-index: 1000;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #888;
  border: 2px solid rgba(0,0,0,.3);
  transition: background .3s;
}
#gps-dot.active { background: #4CAF50; }
#gps-dot.error { background: var(--tram-red); }
#gps-dot.hidden { display: none; }

/* ─── Help Overlay ─── */
#help-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .3s;
}
#help-overlay.hidden { display: none; }

#help-box {
  background: var(--cream);
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 340px;
  width: 90%;
  border-top: 4px solid var(--gold);
}
#help-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--tram-red);
  margin-bottom: 12px;
}
#help-body {
  font-size: .9rem;
  line-height: 1.7;
  color: var(--charcoal);
  margin-bottom: 20px;
}
#help-close {
  display: block;
  width: 100%;
  padding: 10px;
  background: var(--tram-red);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: .95rem;
  font-family: var(--font-cn);
  font-weight: 700;
  cursor: pointer;
}

/* ─── GPS Confirm Dialog ─── */
#gps-confirm {
  position: fixed; inset: 0; z-index: 10001;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .3s;
}
#gps-confirm.hidden { display: none; }

#gps-confirm-box {
  background: var(--cream);
  border-radius: 16px;
  padding: 32px 24px 24px;
  max-width: 320px;
  width: 88%;
  text-align: center;
  border-top: 4px solid var(--gold);
}
#gps-confirm-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}
#gps-confirm-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--charcoal);
  margin-bottom: 8px;
}
#gps-confirm-body {
  font-size: .85rem;
  line-height: 1.6;
  color: #666;
  margin-bottom: 20px;
}
#gps-confirm-buttons {
  display: flex;
  gap: 10px;
}
#gps-confirm-yes, #gps-confirm-no {
  flex: 1;
  padding: 12px 0;
  border-radius: 8px;
  font-size: .95rem;
  font-family: var(--font-cn);
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  border: none;
}
#gps-confirm-yes {
  background: var(--tram-red);
  color: #fff;
}
#gps-confirm-yes:hover { background: #c00e26; }
#gps-confirm-no {
  background: transparent;
  color: #999;
  border: 1px solid #ccc;
}
#gps-confirm-no:hover { background: #f0f0f0; color: #666; }

/* ─── Leaflet Overrides ─── */
.leaflet-control-zoom a { background: var(--charcoal) !important; color: var(--cream) !important; }
.leaflet-popup-content-wrapper { background: var(--charcoal); color: #fff; border-radius: 12px; }
.leaflet-popup-tip { background: var(--charcoal); }

/* ─── Loading ─── */
#loading {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: var(--cream);
  flex-direction: column; gap: 16px;
}
#loading.hidden { display: none; }
#loading.hidden { display: none; }

.loader-text {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--tram-red);
  animation: pulse 1.5s ease-in-out infinite;
}
#loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--gold);
  border-top-color: var(--tram-red);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }

/* ─── Responsive ─── */
@media (min-width: 768px) {
  #panel { max-width: 420px; left: 50%; transform: translateX(-50%); padding: 36px 0 12px; }
  #panel.active { transform: translateX(-50%); }
  #header { padding: 8px 20px; }
}
