/* ── Design Tokens ── */
:root {
    --bg-dark: #1E1E1E;
    --bg-surface: #2A2A2A;
    --bg-surface-hover: #333333;
    --bg-page: #141414;
    --yellow: #F5C518;
    --yellow-dim: #B8940F;
    --green: #4ADE80;
    --green-bg: rgba(74, 222, 128, 0.12);
    --amber: #FBBF24;
    --red: #EF4444;
    --text-primary: #FFFFFF;
    --text-secondary: #B0B0B0;
    --text-muted: #888888;
    --border: #3A3A3A;
    --radius: 12px;
    --header-height: 88px;
    --sidebar-width: 72px;
    --footer-height: 68px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

/* ── Body ── */
body {
    font-family: var(--font);
    background: var(--bg-page);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* ── Header ── */
#app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    padding: 0 20px;
    padding-top: env(safe-area-inset-top, 0);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-text {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-primary);
}

.brand-dot {
    color: var(--yellow);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* GPS accuracy icon */
.gps-accuracy-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--text-muted);
    transition: background 0.3s;
}

.gps-accuracy-icon.accurate {
    background: #22c55e;
}

.gps-accuracy-icon.inaccurate {
    background: #ef4444;
}

.gps-accuracy-icon svg {
    width: 20px;
    height: 20px;
}

/* Language cache status indicator */
.lang-cache-status {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.3s;
}

.lang-cache-status.cached {
    background: #22c55e;
}

.lang-cache-status.not-cached {
    background: #ef4444;
}

.lang-cache-status.partial {
    background: #f59e0b;
}

.lang-cache-status svg {
    width: 20px;
    height: 20px;
}

/* Language selector */
.lang-selector {
    display: flex;
    gap: 3px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 3px;
}

.lang-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.2s;
    min-width: 48px;
    min-height: 44px;
}

.lang-btn.active {
    background: var(--yellow);
    color: #000;
}

/* Settings toggle */
#settings-toggle {
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

#settings-toggle:active {
    background: rgba(255, 255, 255, 0.15);
}

/* Header status */
.header-status {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-status.has-location {
    color: var(--green);
    font-weight: 600;
}

/* GPS inaccurate: header status turns red */
.gps-inaccurate .header-status {
    color: var(--red);
    font-weight: 600;
}

/* ── GPS Accuracy Banner ── */
.gps-banner {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    background: var(--amber);
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font);
    z-index: 99;
    transform: translateY(-100%);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    pointer-events: none;
}

.gps-banner.visible {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
    animation: banner-pulse 3s ease-in-out infinite;
}

@keyframes banner-pulse {
    0%, 100% { background: var(--amber); }
    50% { background: #f59e0b; }
}

/* ── Main Layout ── */
#app-main {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
    height: 100dvh;
    padding-top: var(--header-height);
    transition: padding-top 0.3s ease;
}

/* Shift content down when GPS banner is visible */
.gps-inaccurate #app-main {
    padding-top: calc(var(--header-height) + 36px);
}

/* Dim proximity indicators when GPS is inaccurate */
.gps-inaccurate .poi-card.nearest {
    border-left-color: var(--border);
    background: var(--bg-surface);
    box-shadow: none;
    transform: none;
}

.gps-inaccurate .poi-card.nearest .poi-number {
    background: var(--border);
    color: var(--text-secondary);
}

.gps-inaccurate .poi-card.nearest .poi-distance {
    color: var(--text-muted);
    font-weight: 400;
}

.gps-inaccurate .poi-card.nearest .poi-play-btn {
    background: var(--border);
}

.gps-inaccurate .poi-card {
    opacity: 1;
}

.gps-inaccurate .poi-card.far {
    opacity: 1;
}

/* ── Route Progress Sidebar ── */
#route-progress {
    background: var(--bg-dark);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 0 16px;
    position: relative;
}

.progress-track {
    position: relative;
    width: 4px;
    flex: 1;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto;
}

.progress-fill {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    background: var(--yellow);
    border-radius: 2px;
    height: 0%;
    transition: height 0.8s ease-out;
}

.poi-dot {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    border: 2px solid var(--text-muted);
    transition: all 0.3s;
    z-index: 2;
}

.poi-dot.passed {
    background: var(--yellow);
    border-color: var(--yellow);
}

.poi-dot.current {
    background: var(--green);
    border-color: var(--green);
    width: 12px;
    height: 12px;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.5);
}

.ship-indicator {
    position: absolute;
    left: 50%;
    top: 0;
    transform: translateX(-50%) translateY(-50%);
    z-index: 10;
    transition: top 0.8s ease-out;
    filter: drop-shadow(0 2px 6px rgba(245, 197, 24, 0.4));
}

.progress-labels {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: absolute;
    top: 16px;
    bottom: 8px;
    left: 0;
    right: 0;
    pointer-events: none;
}

.progress-labels span {
    font-size: 9px;
    font-weight: 600;
    color: var(--text-muted);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── POI List ── */
#poi-list {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 20px;
    padding-bottom: 100px;
    scroll-behavior: smooth;
}

#preload-status {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    padding: 8px 0;
    min-height: 32px;
}

#preload-status.loaded {
    color: var(--green);
}

/* ── POI Cards ── */
.poi-card {
    display: flex;
    align-items: center;
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: 16px 16px;
    margin-bottom: 10px;
    border-left: 4px solid transparent;
    cursor: pointer;
    transition: all 0.25s ease;
    gap: 14px;
    min-height: 72px;
}

.poi-card:active {
    background: var(--bg-surface-hover);
    transform: scale(0.98);
}

.poi-card.far {
    opacity: 0.5;
}

.poi-card.in-range {
    border-left-color: var(--yellow);
    opacity: 1;
}

.poi-card.nearest {
    border-left-color: var(--green);
    background: var(--green-bg);
    opacity: 1;
    transform: scale(1.01);
    box-shadow: 0 4px 16px rgba(74, 222, 128, 0.12);
}

.poi-card.nearest:active {
    transform: scale(0.99);
}

.poi-card.playing {
    border-left-color: var(--amber);
    background: rgba(251, 191, 36, 0.1);
}

.poi-card.played {
    border-left-color: var(--text-muted);
}

/* POI number circle */
.poi-number {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.poi-card.nearest .poi-number {
    background: var(--green);
    color: #000;
}

.poi-card.playing .poi-number {
    background: var(--amber);
    color: #000;
}

/* POI info */
.poi-info {
    flex: 1;
    min-width: 0;
}

.poi-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}

.poi-distance {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.poi-card.nearest .poi-distance {
    color: var(--green);
    font-weight: 600;
}

/* POI audio progress (visible when playing) */
.poi-audio-progress {
    display: none;
    margin-top: 8px;
    align-items: center;
    gap: 8px;
}

.poi-card.playing .poi-audio-progress {
    display: flex;
}

.poi-progress-bar {
    flex: 1;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.poi-progress-fill {
    height: 100%;
    background: var(--amber);
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s linear;
}

.poi-time {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* Play button */
.poi-play-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.poi-play-btn:active {
    transform: scale(0.9);
}

.poi-card.nearest .poi-play-btn {
    background: var(--green);
}

.poi-card.playing .poi-play-btn {
    background: var(--amber);
}

.poi-play-btn .icon-play {
    display: block;
}

.poi-play-btn .icon-playing {
    display: none;
}

.poi-card.playing .poi-play-btn .icon-play {
    display: none;
}

.poi-card.playing .poi-play-btn .icon-playing {
    display: block;
}

/* Fading state – audio fading out */
.poi-card.fading {
    border-left-color: var(--amber);
    background: rgba(251, 191, 36, 0.06);
}

.poi-card.fading .poi-number {
    background: var(--amber);
    color: #000;
    animation: fade-pulse 0.4s ease-in-out infinite alternate;
}

.poi-card.fading .poi-play-btn {
    background: var(--amber);
    animation: fade-pulse 0.4s ease-in-out infinite alternate;
}

.poi-card.fading .poi-play-btn .icon-play { display: none; }
.poi-card.fading .poi-play-btn .icon-playing { display: block; }

@keyframes fade-pulse {
    from { opacity: 1; }
    to { opacity: 0.25; }
}

#now-playing.fading {
    animation: bar-fade 2s ease-out forwards;
    pointer-events: none;
}

@keyframes bar-fade {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ── Floating Scroll Button ── */
.scroll-btn {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--yellow);
    color: #000;
    border: none;
    border-radius: 24px;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 20px rgba(245, 197, 24, 0.3);
    z-index: 90;
    transition: all 0.3s;
    animation: bounce-subtle 2s ease-in-out infinite;
}

.scroll-btn.hidden {
    display: none;
}

.scroll-btn:active {
    transform: translateX(-50%) scale(0.95);
}

/* Move scroll btn up when now-playing is visible */
body.is-playing .scroll-btn {
    bottom: calc(var(--footer-height) + 16px);
}

@keyframes bounce-subtle {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-4px); }
}

/* ── Now Playing Footer ── */
#now-playing {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--footer-height);
    background: var(--bg-dark);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    z-index: 100;
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

#now-playing.hidden {
    transform: translateY(100%);
    pointer-events: none;
}

.now-playing-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    max-width: 200px;
}

.now-playing-pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--amber);
    animation: pulse 1.5s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

.now-playing-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.now-playing-progress {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}

#audio-progress-bar {
    flex: 1;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    cursor: pointer;
}

#audio-progress-fill {
    height: 100%;
    background: var(--amber);
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s linear;
}

.audio-time {
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#stopButton {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: rgba(239, 68, 68, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

#stopButton:active {
    background: rgba(239, 68, 68, 0.3);
    transform: scale(0.9);
}

/* ── Bottom Sheet ── */
.backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

.bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 50vh;
    background: var(--bg-surface);
    border-radius: 16px 16px 0 0;
    z-index: 200;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    padding: 0 24px 24px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0));
}

.bottom-sheet.visible {
    transform: translateY(0);
}

.sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--text-muted);
    border-radius: 2px;
    margin: 12px auto 16px;
}

.sheet-content {
    padding-bottom: 20px;
}

.sheet-content h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* Offline rows in bottom sheet */
.offline-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.offline-row:last-child {
    border-bottom: none;
}

.offline-label {
    flex: 1;
    font-size: 15px;
    color: var(--text-primary);
}

.offline-progress {
    width: 100px;
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
}

.offline-ready {
    color: var(--green);
    font-weight: 600;
}

.download-btn {
    background: var(--yellow);
    color: #000;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    transition: opacity 0.2s;
    min-height: 44px;
}

.download-btn:active {
    opacity: 0.8;
}

.download-btn.small {
    padding: 6px 12px;
    font-size: 13px;
    min-height: 36px;
}

#downloadAllBtn {
    width: 100%;
    margin-top: 12px;
    padding: 12px;
}

#storage-info {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

.sim-link {
    display: block;
    text-align: center;
    margin-top: 12px;
    padding: 10px;
    background: var(--border);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    transition: background 0.2s;
}

.sim-link:active {
    background: var(--bg-surface-hover);
}

.gps-debug {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-muted);
    font-family: monospace;
}

/* ── Audio container (hidden) ── */
#audio-container {
    display: none;
}

/* ── Utility ── */
.hidden {
    display: none !important;
}

/* ── iPhone / Small screens (< 600px) ── */
@media (max-width: 600px) {
    :root {
        --header-height: 80px;
        --sidebar-width: 44px;
        --footer-height: 60px;
    }

    /* Header: smaller brand, compact controls */
    .brand-icon {
        width: 22px;
        height: 22px;
    }

    .brand-text {
        display: none;
    }

    .lang-selector {
        gap: 2px;
        padding: 2px;
    }

    .lang-btn {
        padding: 6px 10px;
        font-size: 12px;
        min-width: 38px;
        min-height: 38px;
    }

    #settings-toggle {
        width: 38px;
        height: 38px;
    }

    #settings-toggle svg {
        width: 20px;
        height: 20px;
    }

    .header-controls {
        gap: 6px;
    }

    .gps-accuracy-icon {
        width: 28px;
        height: 28px;
    }

    .gps-accuracy-icon svg {
        width: 16px;
        height: 16px;
    }

    .lang-cache-status {
        width: 28px;
        height: 28px;
    }

    .lang-cache-status svg {
        width: 16px;
        height: 16px;
    }

    .header-status {
        font-size: 12px;
    }

    /* Sidebar: thinner */
    #route-progress {
        padding: 20px 0 12px;
    }

    .poi-dot {
        width: 6px;
        height: 6px;
    }

    .poi-dot.current {
        width: 10px;
        height: 10px;
    }

    .ship-indicator svg {
        width: 22px;
        height: 22px;
    }

    .progress-labels span {
        font-size: 7px;
    }

    /* POI cards: more compact */
    #poi-list {
        padding: 10px 12px;
        padding-bottom: 80px;
    }

    .poi-card {
        padding: 12px;
        margin-bottom: 8px;
        gap: 10px;
        min-height: 60px;
        border-radius: 10px;
    }

    .poi-number {
        width: 30px;
        height: 30px;
        font-size: 12px;
    }

    .poi-name {
        font-size: 14px;
    }

    .poi-distance {
        font-size: 12px;
    }

    .poi-play-btn {
        width: 38px;
        height: 38px;
    }

    .poi-play-btn svg {
        width: 16px;
        height: 16px;
    }

    /* Now playing: compact */
    #now-playing {
        padding: 0 12px;
        gap: 10px;
    }

    .now-playing-name {
        font-size: 13px;
        max-width: 100px;
    }

    .audio-time {
        font-size: 11px;
    }

    #stopButton {
        width: 40px;
        height: 40px;
    }

    /* Scroll button: smaller */
    .scroll-btn {
        padding: 10px 18px;
        font-size: 13px;
    }

    /* GPS banner */
    .gps-banner {
        font-size: 12px;
        padding: 6px 12px;
    }

    /* Bottom sheet */
    .bottom-sheet {
        padding: 0 16px 16px;
    }
}

/* ── Start Tour Overlay ── */
#start-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: var(--bg-page, #141414);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s ease;
}

#start-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.start-overlay-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.start-overlay-content h2 {
    font-family: var(--font, 'Inter', sans-serif);
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary, #fff);
    letter-spacing: 1px;
}

#start-tour-btn {
    background: var(--yellow, #F5C518);
    color: #000;
    border: none;
    padding: 18px 48px;
    font-size: 20px;
    font-weight: 700;
    font-family: var(--font, 'Inter', sans-serif);
    border-radius: 14px;
    cursor: pointer;
    min-width: 220px;
    min-height: 60px;
    box-shadow: 0 4px 20px rgba(245, 197, 24, 0.3);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#start-tour-btn:active {
    transform: scale(0.96);
    box-shadow: 0 2px 10px rgba(245, 197, 24, 0.2);
}

.start-overlay-content p {
    font-size: 14px;
    color: var(--text-muted, #888);
}
