/* ─── Variables ─────────────────────────────────────────────────────────────── */
:root {
    --bg:         #ffffff;
    --text:       #121212;
    --input-bg:   #f2f2f2;
    --accent:     #1a1a1a;
    --accent2:    #3a3a3a;
    --border:     #d1d1d1;
    --card-bg:    #ffffff;
    --shadow:     0 8px 24px rgba(0,0,0,0.10);
}

.dark-theme {
    --bg:       #121212;
    --text:     #ffffff;
    --input-bg: #1e1e1e;
    --border:   #333333;
    --card-bg:  #1e1e1e;
    --shadow:   0 8px 24px rgba(0,0,0,0.40);
    --accent:   #e0e0e0;
    --accent2:  #bbbbbb;
}

/* ─── Reset & Base ───────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background 0.3s, color 0.3s;
    line-height: 1.6;
    overscroll-behavior-x: none;
}

.hidden { display: none !important; }

/* ─── Header ─────────────────────────────────────────────────────────────────── */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
}

.app-logo {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--text);
}

.app-logo span { color: var(--accent); }

/* Dark mode toggle */
.theme-switch { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #ccc; transition: .4s; border-radius: 34px;
}
.slider::before {
    position: absolute; content: "";
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background: white; transition: .4s; border-radius: 50%;
}
input:checked + .slider                { background: var(--accent); }
input:checked + .slider::before       { transform: translateX(20px); }

/* ─── Container ──────────────────────────────────────────────────────────────── */
.container {
    padding: 24px 20px 80px;
    max-width: 480px;
    margin: 0 auto;
}

/* ─── Start Screen ───────────────────────────────────────────────────────────── */
#start-screen {
    padding-top: 20px;
}

.title {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin: 20px 0 24px;
}

/* Route input visualizer (dot – line – square) */
.route-inputs {
    display: flex;
    gap: 15px;
    margin-bottom: 28px;
}

.visualizer {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 15px;
    flex-shrink: 0;
}

.vis-circle {
    width: 10px; height: 10px;
    border: 2px solid var(--accent);
    border-radius: 50%;
}

.vis-line {
    width: 2px;
    flex-grow: 1;
    background: var(--border);
    margin: 5px 0;
}

.vis-square {
    width: 10px; height: 10px;
    background: var(--accent);
    border-radius: 2px;
}

.fields { flex-grow: 1; }

.input-group { margin-bottom: 12px; }

.input-group input {
    width: 100%;
    padding: 12px 15px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.input-group input:focus { border-color: var(--accent); }

/* Preferences */
.preferences {
    text-align: center;
    margin-bottom: 24px;
    font-size: 0.95rem;
}

.options {
    display: flex;
    justify-content: center;
    gap: 25px;
    margin-top: 10px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.95rem;
}

.radio-label input[type="radio"] { display: none; }

.custom-radio {
    width: 18px; height: 18px;
    border: 2px solid var(--border);
    border-radius: 50%;
    display: inline-block;
    position: relative;
    transition: border-color 0.2s;
}

.radio-label input[type="radio"]:checked + .custom-radio {
    border-color: var(--accent);
}

.radio-label input[type="radio"]:checked + .custom-radio::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 8px; height: 8px;
    background: var(--accent);
    border-radius: 50%;
}

.btn-submit {
    width: 100%;
    padding: 16px;
    border-radius: 30px;
    border: none;
    background: var(--accent);
    color: white;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

.btn-submit:active { transform: scale(0.97); }

.dark-theme .btn-submit { box-shadow: 0 4px 16px rgba(255,255,255,0.10); color: #111; }

/* ─── Map Screen — fullscreen overlay ───────────────────────────────────────── */
#map-screen {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Floor tabs */
.floor-tabs {
    display: flex;
    gap: 8px;
    justify-content: center;
    padding: 10px 16px 8px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
}

.floor-tab {
    padding: 8px 24px;
    border-radius: 20px;
    border: 2px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}

.floor-tab.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.dark-theme .floor-tab.active { color: #111; }

/* Map viewport — fills all remaining space between tabs and bottom bar */
.map-viewport {
    flex: 1;
    overflow: hidden;
    position: relative;
    touch-action: none;
    cursor: grab;
    user-select: none;
    min-height: 0; /* important for flex child to shrink */
}

.map-viewport:active { cursor: grabbing; }

/* map-stage wraps image + SVG and is what we translate/scale */
.map-stage {
    width: 100%;
    height: auto;
    transform-origin: 0 0;
    position: relative;
    will-change: transform;
    touch-action: none;
}

.map-stage > * {
    display: block;
}

#floor-map {
    width: 100%;
    height: auto;
    display: block;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}

/* SVG route overlay — positioned over image, dimensions set by JS */
.route-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    overflow: visible;
}

/* ─── Bottom bar — instruction + nav ─────────────────────────────────────────── */
.map-bottom-bar {
    flex-shrink: 0;
    background: var(--bg);
    border-top: 1px solid var(--border);
    padding: 10px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ─── Instruction card ───────────────────────────────────────────────────────── */
.instruction-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--input-bg);
    border-left: 4px solid var(--accent);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.9rem;
}

.instruction-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
}

/* ─── Nav buttons ────────────────────────────────────────────────────────────── */
.nav-buttons {
    display: flex;
    gap: 8px;
}

.nav-btn {
    flex: 1;
    padding: 13px 8px;
    border-radius: 12px;
    border: 2px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: 0.2s;
}

.nav-btn:hover:not(:disabled) {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.dark-theme .nav-btn:hover:not(:disabled) { color: #111; }

.nav-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.nav-btn-secondary {
    background: transparent;
    color: #e74c3c;
    border-color: #e74c3c;
    flex: 0 0 auto;
    padding: 13px 16px;
}

.nav-btn-secondary:hover:not(:disabled) {
    background: #e74c3c;
    color: white;
    border-color: #e74c3c;
}

/* Debug button inside bottom bar */
.debug-row {
    text-align: center;
}

/* ─── Route line & markers ────────────────────────────────────────────────────── */
.route-line {
    fill:             none;
    stroke:           #e63030;
    stroke-linecap:   round;
    stroke-linejoin:  round;
    stroke-dasharray: 12 8;
    stroke-dashoffset: 2000;
}

@keyframes dash-flow {
    from { stroke-dashoffset: 2000; opacity: 0; }
    10%  { opacity: 1; }
    to   { stroke-dashoffset: 0; }
}

.marker { fill: white; stroke-width: 0.5; }
.marker-start { stroke: #27ae60; fill: #27ae60; }
.marker-end   { stroke: #e63030; fill: #e63030; }

.marker-you {
    fill: #27ae60;
    opacity: 0.9;
    transform-box: fill-box;
    transform-origin: center;
    animation: pulse-you 1.8s ease-in-out infinite;
}

@keyframes pulse-you {
    0%, 100% { opacity: 0.9; }
    50%       { opacity: 0.35; }
}

/* ─── Debug coord mode ───────────────────────────────────────────────────────── */
.btn-debug {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px dashed var(--border);
    background: transparent;
    color: #888;
    font-size: 0.8rem;
    cursor: pointer;
}

.btn-debug.active {
    background: #e63030;
    color: white;
    border-color: #e63030;
}

.coord-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.85);
    color: #7CFC00;
    font-family: monospace;
    font-size: 0.9rem;
    padding: 10px 16px;
    border-radius: 10px;
    z-index: 300;
    white-space: nowrap;
    cursor: pointer;
    user-select: all;
    -webkit-user-select: all;
}
.calib-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.82);
    color: white;
    padding: 12px 18px;
    border-radius: 12px;
    font-size: 0.85rem;
    text-align: center;
    max-width: 280px;
    z-index: 200;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    animation: toast-in 0.3s ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(12px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── Compass widget ─────────────────────────────────────────────────────────── */
.compass-widget {
    position: fixed;
    top: 12px;
    right: 15px;
    z-index: 200;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    box-shadow: 0 4px 14px rgba(0,0,0,0.20);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#compass-canvas {
    display: block;
    border-radius: 50%;
}

.compass-permission {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.6);
    border-radius: 50%;
}

.compass-permission button {
    font-size: 0.6rem;
    padding: 4px 6px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    text-align: center;
    line-height: 1.3;
}