:root {
    --bg: #0f1e1b;
    --bg-2: #182825;
    --grid: rgba(255, 255, 255, 0.06);
    --card: rgba(18, 34, 30, 0.9);
    --accent: #f4c27a;
    --accent-2: #f2a653;
    --text: #f6f1e8;
    --muted: #ffffff;
    --danger: #f26b4f;
    --shadow: rgba(0, 0, 0, 0.35);
    --font: "Avenir Next", "Futura", "Gill Sans", "Trebuchet MS", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font);
    color: var(--text);
    background: radial-gradient(circle at top, #233631 0%, var(--bg) 45%, #0a1412 100%);
    min-height: 100vh;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px 8px;
}

.top-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.top-btn {
    padding: 8px 10px;
    font-size: 12px;
}

.brand-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-home {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
}

.brand-toggle {
    background: transparent;
    border: none;
    padding: 0;
    color: var(--muted);
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.brand-mark {
    width: auto;
    height: 35px;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    display: block;
}

.brand-name {
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 12px;
    color: var(--muted);
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    text-align: left;
    appearance: none;
}

.brand-caret {
    font-size: 22px;
    color: var(--muted);
    margin-left: 2px;
    transform: translateY(-1px);
}

.brand-menu {
    position: absolute;
    top: 120%;
    left: 0;
    background: rgba(12, 16, 16, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 6px;
    min-width: 180px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.4);
    z-index: 6;
}

.brand-menu[hidden] {
    display: none;
}

.brand-menu-item {
    border: 0;
    background: transparent;
    color: var(--text);
    text-decoration: none;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    padding: 8px 10px;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
}

.brand-menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.stage {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 16px 10px;
}

.viewport {
    position: relative;
    flex: 1;
    min-height: 44vh;
    border-radius: 24px;
    background: linear-gradient(140deg, var(--bg-2), #10211c);
    overflow: hidden;
    box-shadow: 0 20px 40px var(--shadow);
    touch-action: none;
}

.map-layer {
    position: absolute;
    inset: 0;
}

.trail-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.route-layer {
    position: absolute;
    inset: 0;
    z-index: 2;
}

.viewport-grid {
    position: absolute;
    inset: 0;
    background-image: linear-gradient(var(--grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid) 1px, transparent 1px);
    background-size: 48px 48px;
    opacity: 0.8;
}

.dot {
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 3;
}

.dot.user {
    background: #78d6c6;
    box-shadow: 0 0 14px rgba(120, 214, 198, 0.8);
}

.dot.user .user-arrow {
    position: absolute;
    top: -14px;
    left: 50%;
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-bottom: 14px solid #78d6c6;
    transform: translateX(-50%);
    filter: drop-shadow(0 0 6px rgba(120, 214, 198, 0.8));
}

.dot.user.no-heading .user-arrow {
    display: none;
}

.dot.user .user-accuracy {
    position: absolute;
    top: 50%;
    left: 50%;
    border-radius: 50%;
    border: 1px dashed rgba(120, 214, 198, 0.45);
    background: rgba(120, 214, 198, 0.08);
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0;
}

.dot.target {
    background: var(--accent);
    box-shadow: 0 0 18px rgba(244, 194, 122, 0.8);
}

.dot.target .target-ring {
    position: absolute;
    inset: -10px;
    border-radius: 50%;
    border: 2px solid rgba(244, 194, 122, 0.8);
    box-shadow: 0 0 12px rgba(244, 194, 122, 0.6);
    animation: pulse-ring 1.8s ease-in-out infinite;
}

.dot.target .target-letter {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: #1c1209;
    text-transform: uppercase;
}

.hints-layer {
    position: absolute;
    inset: 0;
    z-index: 4;
}

.legend {
    position: absolute;
    right: 16px;
    bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    z-index: 4;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-item::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.legend-item.user::before {
    background: #78d6c6;
    box-shadow: 0 0 6px rgba(120, 214, 198, 0.7);
}

.legend-item.target::before {
    background: var(--accent);
    box-shadow: 0 0 6px rgba(244, 194, 122, 0.7);
}

.hint-dot {
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(88, 184, 255, 0.9);
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px rgba(88, 184, 255, 0.6);
    color: #0b1d2b;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.route-point {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(120, 214, 198, 0.4);
    transform: translate(-50%, -50%);
    box-shadow: 0 0 8px rgba(120, 214, 198, 0.4);
}

.route-point.done {
    background: rgba(120, 214, 198, 0.85);
    box-shadow: 0 0 10px rgba(120, 214, 198, 0.8);
}

.route-point.pending {
    background: rgba(244, 194, 122, 0.9);
    box-shadow: 0 0 10px rgba(244, 194, 122, 0.7);
}

.blink {
    animation: blink 0.8s ease-in-out infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 0.25;
    }

    50% {
        opacity: 1;
    }
}

@keyframes pulse-ring {

    0%,
    100% {
        transform: scale(0.85);
        opacity: 0.4;
    }

    50% {
        transform: scale(1.05);
        opacity: 0.9;
    }
}

.scale {
    position: absolute;
    left: 16px;
    bottom: 16px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
    z-index: 4;
}

.scale-meta {
    display: flex;
    align-items: center;
    gap: 10px;
}

.scale-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.keep-awake {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.zoom-toggle {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    background: transparent;
    border: 1px solid white;
    padding: 2px 5px;
    cursor: pointer;
    border-radius: 5px;
}

.zoom-toggle.is-off {
    text-decoration: line-through;
    opacity: 0.7;
}

.scale-bar {
    height: 4px;
    width: 80px;
    border-radius: 999px;
    background: var(--muted);
}

.scale-bar.near {
    background: #baf2c6;
}

.scale-bar.close {
    background: #6ce6a0;
}

.hud {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.card-hito {
    grid-column: span 2;
}

.card-distance {
    grid-column: span 1;
}

.hud-actions {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.hud-btn {
    width: 100%;
}

.card {
    background: var(--card);
    border-radius: 14px;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    box-shadow: 0 10px 24px var(--shadow);
}

.label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.value {
    font-size: 14px;
    font-weight: 600;
}

.status {
    font-size: 10px;
    color: var(--muted);
    min-height: 14px;
}

.value.good {
    color: #8ff0b4;
}

.value.warn {
    color: #f6c36b;
}

.value.poor {
    color: #f26b4f;
}

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

.bearing-arrow {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    position: relative;
}

.bearing-arrow::after {
    content: "";
    position: absolute;
    top: 4px;
    left: 50%;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 16px solid var(--accent);
    transform: translateX(-50%);
}

.bearing-value {
    font-size: 14px;
    color: var(--muted);
}

.btn {
    flex: 1;
    background: var(--accent);
    border: none;
    color: #1b1209;
    padding: 14px 16px;
    border-radius: 16px;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    text-decoration: none;
}

.btn.ghost {
    background: white;
    border: 1px solid rgba(244, 194, 122, 0.5);
    color: black;
}

.btn.primary {
    background: var(--accent-2);
    color: #1c1209;
}

.btn-help {
    background: #f4c27a;
    color: #1b1209;
}

.btn.btn-info {
    background: #78d6c6;
    border: none;
    color: #0c1a16;
}

.btn.btn-export {
    background: #f2a653;
    border: none;
    color: #1b1209;
    font-size: 20px;
    line-height: 1;
}

.btn.btn-manifest {
    background: #9c8cff;
    border: none;
    color: #1b1209;
}

.btn.btn-silberius {
    background: #f29fa0;
    border: none;
    color: #2a0c0c;
}

.btn.btn-danger {
    background: #f26b4f;
    border: none;
    color: #2a0c0c;
}

.btn:disabled {
    opacity: 0.5;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(6, 10, 9, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 10;
}

.modal[hidden] {
    display: none;
}

.modal-card {
    background: var(--card);
    border-radius: 20px;
    padding: 24px;
    width: min(420px, 100%);
    max-height: 80vh;
    box-shadow: 0 18px 40px var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow: hidden;
}

.modal-icon {
    width: 56px;
    height: auto;
    margin: 0 auto;
}

.intro-card {
    background: var(--intro-gradient, linear-gradient(160deg, rgba(184, 55, 121, 0.95), rgba(14, 28, 24, 0.98)));
}

.modal-card .modal-text {
    overflow-y: auto;
    padding-right: 6px;
}

.intro-card .modal-text {
    max-height: 40vh;
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
}

.modal-subtitle {
    color: var(--muted);
    font-size: 15px;
}

.modal-footnote {
    font-size: 11px;
    color: var(--muted);
    text-align: left;
    display: flex;
    align-items: center;
    gap: 12px;
}

.footnote-icon {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    flex: 0 0 auto;
}

.modal-text {
    font-size: 15px;
    line-height: 1.45;
    color: var(--text);
    white-space: pre-line;
}

.modal-note {
    font-size: 11px;
    color: var(--muted);
    text-align: center;
    letter-spacing: 0.06em;
}

.modal-label {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.modal-input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(10, 18, 18, 0.55);
    color: var(--text);
    font-size: 14px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.final-track {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.final-track canvas {
    width: 100%;
    height: 140px;
    border-radius: 14px;
    background: rgba(20, 32, 30, 0.6);
    border: 1px solid rgba(120, 214, 198, 0.3);
}

.final-track.large canvas {
    height: 260px;
}

.feedback-input {
    width: 100%;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(14, 20, 20, 0.6);
    color: var(--text);
    padding: 12px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    resize: vertical;
}

.route-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.route-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    cursor: pointer;
}

.route-item:hover {
    border-color: rgba(244, 194, 122, 0.7);
}

.route-item-title {
    font-weight: 600;
}

.route-item-meta {
    color: var(--muted);
    font-size: 12px;
}

.manifesto .modal-text {
    font-size: 14px;
    line-height: 1.6;
    white-space: normal;
}

.manifesto .modal-text p {
    margin: 0 0 10px;
}

.manifesto .pull {
    font-size: 16px;
    margin: 12px 0;
}

.manifesto .lines {
    margin: 12px 0;
    padding: 10px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.error {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: var(--danger);
    color: #1c0a06;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    z-index: 12;
}

.noscript {
    padding: 20px;
    text-align: center;
    color: var(--text);
}

@media (max-width: 520px) {
    .topbar {
        padding: 12px 14px 6px;
    }

    .stage {
        padding: 0 14px 12px;
    }

    .actions {
        padding: 12px 14px 18px;
    }
}
