/* ==========================================================================
   Design tokens
   ========================================================================== */

:root {
    --color-text: #ffffff;
    --color-accent: #d32f2f;
    --color-altitude-start: #ff5252;
    --color-altitude-end: #d32f2f;
    --color-surface: rgb(255 255 255 / 20%);
    --color-control: rgb(0 0 0 / 16%);
    --color-control-border: rgb(255 255 255 / 70%);
    --page-background: linear-gradient(180deg, #20b2aa 0%, #ffa500 100%);
    --altitude-gradient: linear-gradient(
        135deg,
        var(--color-altitude-start) 0%,
        var(--color-altitude-end) 100%
    );
    --shadow-dial: 0 0 10px rgb(0 0 0 / 10%);
    --shadow-altitude: 0 5px 15px rgb(0 0 0 / 20%);
    --font-system: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
    --header-control-size: 44px;
    --dial-size: 300px;
    --altitude-size: 240px;
}

/* ==========================================================================
   Base
   ========================================================================== */

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

html,
body {
    width: 100%;
    height: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--page-background);
    color: var(--color-text);
    font-family: var(--font-system);
}

button {
    font: inherit;
}

[hidden] {
    display: none !important;
}

/* ==========================================================================
   Header
   ========================================================================== */

.app-header {
    width: 100%;
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: var(--header-control-size) 1fr var(--header-control-size);
    gap: 8px;
    align-items: center;
    padding: calc(12px + env(safe-area-inset-top, 0px))
        calc(16px + env(safe-area-inset-right, 0px)) 10px
        calc(16px + env(safe-area-inset-left, 0px));
}

.app-title {
    margin: 0;
    overflow: hidden;
    font-size: 18px;
    font-weight: 500;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-button {
    width: var(--header-control-size);
    height: var(--header-control-size);
    padding: 10px;
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    touch-action: manipulation;
}

.icon-button:focus-visible,
.compass-permission:focus-visible {
    outline: 3px solid rgb(255 255 255 / 85%);
    outline-offset: 2px;
}

.icon {
    display: block;
    width: 100%;
    height: 100%;
    fill: currentColor;
}

:fullscreen .app-header,
:-webkit-full-screen .app-header {
    padding-top: calc(52px + env(safe-area-inset-top, 0px));
}

/* ==========================================================================
   Main content and status
   ========================================================================== */

.app-main {
    width: 100%;
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.status-panel {
    margin-top: 20px;
    margin-bottom: 28px;
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
}

.location-info {
    opacity: 0.8;
}

.compass-readout {
    margin-top: 8px;
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: baseline;
    font-variant-numeric: tabular-nums;
}

.heading-value {
    font-size: 22px;
    font-weight: 650;
}

.heading-direction {
    font-size: 14px;
    font-weight: 500;
}

.compass-status {
    max-width: min(82vw, 360px);
    margin: 3px auto 0;
    font-size: 12px;
    opacity: 0.82;
}

.compass-permission {
    margin-top: 8px;
    padding: 7px 14px;
    border: 1px solid var(--color-control-border);
    border-radius: 999px;
    background: var(--color-control);
    color: inherit;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
}

.compass-permission:disabled {
    cursor: wait;
    opacity: 0.6;
}

/* ==========================================================================
   Compass and altitude dial
   ========================================================================== */

.dial-container {
    position: relative;
    width: var(--dial-size);
    height: var(--dial-size);
    flex: 0 0 auto;
    margin-bottom: auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

.compass-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--color-surface);
    box-shadow: var(--shadow-dial);
    transition: transform 100ms ease-out;
    will-change: transform;
}

.north-marker,
.south-marker {
    position: absolute;
    left: 50%;
    width: 0;
    height: 0;
    transform: translateX(-50%);
}

.north-marker {
    top: -10px;
    border-right: 10px solid transparent;
    border-bottom: 20px solid var(--color-accent);
    border-left: 10px solid transparent;
}

.south-marker {
    bottom: -5px;
    border-right: 8px solid transparent;
    border-bottom: 16px solid var(--color-text);
    border-left: 8px solid transparent;
    transform: translateX(-50%) rotate(180deg);
}

.north-label,
.south-label {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    font-weight: 700;
}

.north-label {
    top: 15px;
    color: var(--color-accent);
}

.south-label {
    bottom: 15px;
    color: var(--color-text);
}

.altitude-circle {
    position: relative;
    z-index: 1;
    width: var(--altitude-size);
    height: var(--altitude-size);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: var(--altitude-gradient);
    box-shadow: var(--shadow-altitude);
}

.altitude-label {
    margin-bottom: 5px;
    font-size: 16px;
    opacity: 0.9;
}

.altitude-value {
    font-size: 64px;
    font-weight: 700;
    line-height: 1;
}

.altitude-unit {
    font-size: 24px;
    vertical-align: super;
}

.altitude-zone {
    margin-top: 8px;
    font-size: 16px;
    font-weight: 500;
    opacity: 0.9;
    text-shadow: 0 1px 3px rgb(0 0 0 / 30%);
}

/* ==========================================================================
   Coordinates
   ========================================================================== */

.coordinates {
    margin-bottom: 100px;
    font-size: 20px;
    font-weight: 300;
    line-height: 1.4;
    text-align: center;
}

/* ==========================================================================
   Responsive behavior
   ========================================================================== */

@media (orientation: landscape) {
    .app-header {
        position: absolute;
        top: 0;
        right: 0;
        left: 0;
        z-index: 2;
    }

    .app-main {
        justify-content: center;
    }

    .status-panel,
    .coordinates {
        display: none;
    }

    .dial-container {
        width: min(60vmin, 350px);
        height: min(60vmin, 350px);
        margin: auto;
    }

    .altitude-circle {
        width: 80%;
        height: 80%;
    }
}

@media (orientation: portrait) and (max-height: 700px) {
    .status-panel {
        margin-top: 8px;
        margin-bottom: 12px;
    }

    .dial-container {
        width: min(75vw, 42vh);
        height: min(75vw, 42vh);
    }

    .altitude-circle {
        width: 80%;
        height: 80%;
    }

    .coordinates {
        margin-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
        font-size: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .compass-ring {
        transition: none;
    }
}
