:root {
    --hunter: #4d5e4f;
    --hunter-dark: #3a4840;
    --glass: #d6ded1;
    --sunshine: #c79c45;
    --sunshine-bright: #e8b85a;
    --ink: #1f2a22;
    --muted: #6b7a6f;
    --surface: #f4f6f2;
    --card: #ffffff;
    --danger: #b54a3d;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: radial-gradient(circle at 50% 20%, #5f7364 0%, var(--hunter) 45%, var(--hunter-dark) 100%);
    background-attachment: fixed;
    color: var(--glass);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-tap-highlight-color: transparent;
}

.app {
    min-height: 100%;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: calc(12px + var(--safe-top)) 16px calc(12px + var(--safe-bottom));
}

.topbar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 8px;
}

.topbar-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.brand-logo {
    display: block;
    width: min(40vw, 152px);
    max-width: 100%;
    height: auto;
    justify-self: start;
}

.title {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.1;
    text-align: center;
}

.status-pill {
    justify-self: end;
    width: auto;
    max-width: none;
    flex: none;
    font-size: 0.72rem;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    white-space: nowrap;
}

.status-pill.is-error {
    background: rgba(181, 74, 61, 0.25);
    border-color: rgba(255, 180, 170, 0.35);
}

.compass-stage {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    position: relative;
    gap: 10px;
}

.compass-loading {
    position: absolute;
    inset: 0;
    z-index: 6;
    pointer-events: none;
}

.compass-loading-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0 8%;
    top:25px;
}

.compass-loading-spinner {
    font-size: clamp(1.8rem, 8vw, 2.4rem);
    color: var(--sunshine-bright);
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.25));
    line-height: 1;
    width: 1em;
    height: 1em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.compass-loading-text {
    text-align: center;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.9;
    line-height: 1.3;
}

.compass-wrap {
    width: min(78vw, 340px);
    aspect-ratio: 1;
    position: relative;
    flex: 0 0 auto;
}

.compass-note {
    width: min(78vw, 340px);
    margin: 0;
    padding: 0 8px;
    text-align: center;
    font-size: 0.82rem;
    line-height: 1.4;
    opacity: 0.88;
}

.compass-ring-outer {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background:
        radial-gradient(circle at 50% 50%, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0.02) 55%, rgba(0,0,0,0.18) 100%);
    box-shadow:
        0 18px 50px rgba(0, 0, 0, 0.35),
        inset 0 0 0 2px rgba(255, 255, 255, 0.18),
        inset 0 10px 30px rgba(255, 255, 255, 0.08);
}

.compass-face {
    position: absolute;
    top: 5%;
    left: 5%;
    width: 90%;
    height: 90%;
    display: block;
    overflow: visible;
    z-index: 2;
}

.compass-dial,
.compass-needle-wrap {
    transform-box: view-box;
    transform-origin: 50% 50%;
    transition: transform 0.1s ease-out;
    will-change: transform;
}

.compass-face .compass-ticks {
    stroke: rgba(255, 255, 255, 0.16);
    stroke-width: 1.1;
    stroke-linecap: round;
}

.compass-face .compass-dial-ring {
    fill: none;
    stroke: rgba(255, 255, 255, 0.22);
    stroke-width: 0.9;
}

.compass-face .compass-label {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-weight: 800;
    font-size: 5.5px;
    letter-spacing: 0.08em;
    fill: rgba(255, 255, 255, 0.95);
    user-select: none;
    pointer-events: none;
}

.compass-face .compass-label-n {
    font-size: 6.2px;
    fill: #fff;
}

.compass-face .compass-needle-layer {
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35));
}

.compass-face .needle-tail {
    stroke: rgba(255, 255, 255, 0.38);
    stroke-width: 4;
    stroke-linecap: round;
}

.compass-face .needle-shaft {
    stroke-width: 5.5;
    stroke-linecap: round;
}

.compass-face .needle-head {
    fill: var(--sunshine-bright);
    stroke: #9a7428;
    stroke-width: 1.2;
    stroke-linejoin: round;
}

.compass-face .compass-center-dot {
    fill: #fff;
    stroke: rgba(255, 255, 255, 0.2);
    stroke-width: 0.45;
    filter: drop-shadow(0 0.1px 0.4px rgba(0, 0, 0, 0.35));
}

.compass-face .heading-readout {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 3.4px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    fill: rgba(255, 255, 255, 0.8);
    user-select: none;
    pointer-events: none;
}

.panel {
    flex: 0 0 auto;
    margin-top: 10px;
}

.trail-card {
    display: flex;
    gap: 12px;
    align-items: stretch;
    background: var(--card);
    color: var(--ink);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
    text-decoration: none;
    min-height: 88px;
}

.trail-card.is-static {
    pointer-events: none;
}

.trail-thumb {
    width: 96px;
    flex: 0 0 96px;
    background: linear-gradient(135deg, #c8d4c9, #95a898);
    object-fit: cover;
}

.trail-thumb.placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.85);
    font-size: 1.6rem;
}

.trail-body {
    padding: 12px 14px 12px 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.trail-name {
    margin: 0;
    font-size: 1rem;
    line-height: 1.2;
    font-weight: 700;
    color: var(--hunter);
}

.trail-meta {
    margin: 0;
    font-size: 0.86rem;
    color: var(--muted);
    line-height: 1.35;
}

.trail-distance {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ink);
}

.trail-distance small {
    font-weight: 500;
    color: var(--muted);
}

.trail-nav {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.btn-trail-nav {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 700;
    padding: 10px 12px;
    flex: 1 1 0;
    cursor: pointer;
}

.btn-trail-nav:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.btn-trail-nav:not(:disabled):active {
    transform: scale(0.98);
}

.trail-rank {
    flex: 0 0 auto;
    min-width: 72px;
    text-align: center;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.88;
}

.message-card,
.cta-card {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 16px;
    padding: 16px;
    backdrop-filter: blur(8px);
}

.cta-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.cta-intro {
    width: 100%;
    margin: 0 0 12px;
    line-height: 1.45;
    font-size: 0.95rem;
    text-align: center;
}

.cta-card .btn {
    align-self: stretch;
}

.message-card p {
    margin: 0 0 12px;
    line-height: 1.45;
    font-size: 0.95rem;
}

.btn {
    appearance: none;
    border: none;
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
}

.btn-primary {
    background: var(--sunshine);
    color: #fff;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: rgba(255,255,255,0.14);
    color: #fff;
    margin-top: 8px;
}

.footnote {
    margin: 10px 0 0;
    text-align: center;
    font-size: 0.74rem;
    opacity: 0.72;
    line-height: 1.35;
    a{
        color:#fff;
    }
}

.debug {
    margin-top: 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.68rem;
    line-height: 1.4;
    background: rgba(0,0,0,0.28);
    border-radius: 10px;
    padding: 10px;
    white-space: pre-wrap;
    max-height: 120px;
    overflow: auto;
}

.hidden { display: none !important; }

@media (max-height: 640px) {
    .title { font-size: 1.15rem; }
    .compass-wrap { width: min(70vw, 300px); }
    .trail-thumb { width: 80px; flex-basis: 80px; }
}

@media (max-height: 500px), (orientation: landscape) and (max-height: 520px) {
    .app {
        padding-top: calc(8px + var(--safe-top));
        padding-bottom: calc(8px + var(--safe-bottom));
    }

    .topbar {
        gap: 6px;
        margin-bottom: 4px;
    }

    .title { margin-bottom:30px;}

    .compass-stage {
        flex: 0 1 auto;
        gap: 6px;
        margin-bottom:20px;
    }

    .compass-wrap {
        width: min(42vh, 55vw, 220px);
    }

    .compass-note {
        width: min(42vh, 55vw, 220px);
        font-size: 0.76rem;
    }

    .panel {
        margin-top: 6px;
    }

    .footnote {
        margin-top: 6px;
    }
}

@media (orientation: landscape) and (max-height: 520px) {
    .topbar {
        gap: 0;
        margin-bottom: 0;
    }

    .title {
        margin-top: -40px;
    }
}