/* ============================================
   Design Tokens
   ============================================ */

:root {
    --c-bg: #0a0e1a;
    --c-bg-raised: #111827;
    --c-bg-card: #131c2e;
    --c-bg-input: #0d1220;
    --c-border: #1e293b;
    --c-border-focus: #3b82f6;
    --c-text: #e2e8f0;
    --c-text-secondary: #94a3b8;
    --c-text-muted: #4b5563;
    --c-accent: #3b82f6;
    --c-accent-hover: #60a5fa;
    --c-success: #22c55e;
    --c-error: #ef4444;

    --c-dd: #60a5fa;
    --c-dms: #c084fc;
    --c-utm: #4ade80;
    --c-mgrs: #fb923c;
    --c-plus: #f472b6;
    --c-unlocode: #fbbf24;

    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    --font-mono: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Consolas', 'Courier New', monospace;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --max-width: 760px;
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ============================================
   Reset & Base
   ============================================ */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    background: var(--c-bg);
    color: var(--c-text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ============================================
   Layout
   ============================================ */

.page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.header {
    border-bottom: 1px solid var(--c-border);
    padding: 0.875rem 1.5rem;
}

.header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    font-family: var(--font-mono);
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--c-text-secondary);
    text-decoration: none;
    letter-spacing: -0.02em;
}

.brand:hover {
    color: var(--c-text);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav {
    display: flex;
    gap: 1.25rem;
}

.nav-link {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--c-text-secondary);
    text-decoration: none;
    transition: color 0.15s ease;
}

.nav-link:hover {
    color: var(--c-text);
}

.shortcut-hint {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: var(--c-text-muted);
    background: var(--c-bg-card);
    border: 1px solid var(--c-border);
    border-radius: 4px;
    padding: 0.15rem 0.4rem;
    pointer-events: none;
    user-select: none;
    opacity: 1;
    transition: opacity 0.15s ease;
}

#coord-input:focus ~ .shortcut-hint {
    opacity: 0;
}

.page.has-input .shortcut-hint {
    display: none;
}

.main {
    flex: 1;
    max-width: var(--max-width);
    width: 100%;
    margin: 0 auto;
    padding: 0 1.5rem 4rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.footer {
    border-top: 1px solid var(--c-border);
    padding: 0.875rem 1.5rem;
    text-align: center;
    font-size: 0.75rem;
    color: var(--c-text-secondary);
}

/* ============================================
   Input Section — Centering & Transitions
   ============================================ */

.input-section {
    padding-top: 22vh;
    transition: padding-top 0.5s var(--ease-out);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.page.has-input .input-section {
    padding-top: 2rem;
}

/* ============================================
   Hero
   ============================================ */

.hero {
    text-align: center;
    margin-bottom: 0.75rem;
    max-height: 200px;
    overflow: hidden;
    opacity: 1;
    transition:
        opacity 0.2s ease,
        max-height 0.35s var(--ease-out),
        margin-bottom 0.35s var(--ease-out);
}

.page.has-input .hero {
    opacity: 0;
    max-height: 0;
    margin-bottom: 0;
}

.hero-title {
    font-family: var(--font-mono);
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--c-text);
    line-height: 1.2;
}

.hero-sub {
    margin-top: 0.5rem;
    font-size: 1.0625rem;
    color: var(--c-text-secondary);
    letter-spacing: 0.01em;
}

/* ============================================
   Input
   ============================================ */

.input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

#coord-input {
    width: 100%;
    font-family: var(--font-mono);
    font-size: 1.375rem;
    padding: 1rem 5.5rem 1rem 1.25rem;
    background: var(--c-bg-input);
    border: 1.5px solid var(--c-border);
    border-radius: var(--radius-md);
    color: var(--c-text);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#coord-input::placeholder {
    color: var(--c-text-muted);
    font-weight: 400;
}

#coord-input:focus {
    border-color: var(--c-border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

/* ============================================
   Input Meta (badge + error)
   ============================================ */

.input-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.format-badge {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 0.2rem 0.55rem;
    border-radius: 4px;
    border: 1px solid;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.format-badge[data-format="DecimalDegrees"] {
    background: rgba(96, 165, 250, 0.1);
    color: var(--c-dd);
    border-color: rgba(96, 165, 250, 0.2);
}

.format-badge[data-format="DegreesMinutesSeconds"] {
    background: rgba(192, 132, 252, 0.1);
    color: var(--c-dms);
    border-color: rgba(192, 132, 252, 0.2);
}

.format-badge[data-format="Utm"] {
    background: rgba(74, 222, 128, 0.1);
    color: var(--c-utm);
    border-color: rgba(74, 222, 128, 0.2);
}

.format-badge[data-format="Mgrs"] {
    background: rgba(251, 146, 60, 0.1);
    color: var(--c-mgrs);
    border-color: rgba(251, 146, 60, 0.2);
}

.format-badge[data-format="PlusCode"] {
    background: rgba(244, 114, 182, 0.1);
    color: var(--c-plus);
    border-color: rgba(244, 114, 182, 0.2);
}

.format-badge[data-format="UnLocode"] {
    background: rgba(251, 191, 36, 0.1);
    color: var(--c-unlocode);
    border-color: rgba(251, 191, 36, 0.2);
}

.error-msg {
    font-size: 0.9375rem;
    color: var(--c-error);
}

.error-msg.rate-limit-error {
    color: var(--c-unlocode);
}

.rate-limit-cta {
    color: var(--c-accent);
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 500;
    white-space: nowrap;
}

.rate-limit-cta:hover {
    color: var(--c-accent-hover);
}

/* ============================================
   Example Chips
   ============================================ */

.examples {
    display: flex;
    align-items: center;
    gap: 0.4rem 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
    max-height: 140px;
    overflow: hidden;
    opacity: 1;
    transition:
        opacity 0.2s ease,
        max-height 0.35s var(--ease-out),
        margin 0.35s var(--ease-out);
}

.page.has-input .examples {
    opacity: 0;
    max-height: 0;
    margin: 0;
    pointer-events: none;
}

.example-chip {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--c-text-secondary);
    background: var(--c-bg-card);
    border: 1px solid var(--c-border);
    border-radius: 100px;
    padding: 0.25rem 0.65rem;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.example-chip:hover {
    border-color: var(--c-text-muted);
    color: var(--c-text);
}

/* ============================================
   Results
   ============================================ */

.results {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    animation: fadeUp 0.3s var(--ease-out) both;
}

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
}

.results-title {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--c-text-muted);
}

.results-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* ============================================
   Precision (inside results header)
   ============================================ */

.precision-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.precision-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--c-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#precision-slider {
    width: 80px;
    height: 3px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--c-border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

#precision-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--c-accent);
    border: 2px solid var(--c-bg);
    cursor: pointer;
    transition: background 0.15s ease;
}

#precision-slider::-webkit-slider-thumb:hover {
    background: var(--c-accent-hover);
}

#precision-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--c-accent);
    border: 2px solid var(--c-bg);
    cursor: pointer;
}

.precision-value {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--c-accent);
    min-width: 1rem;
    text-align: center;
}

/* ============================================
   Copy All
   ============================================ */

.btn-copy-all {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--c-accent);
    background: transparent;
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.7rem;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.btn-copy-all:hover {
    background: var(--c-accent);
    color: var(--c-bg);
}

.btn-copy-all.copied {
    border-color: var(--c-success);
    color: var(--c-success);
}

.btn-share {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    color: #0a0e1a;
    background: var(--c-success);
    border: 1px solid var(--c-success);
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.7rem;
    min-width: 5.2rem;
    text-align: center;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-share:hover {
    background: #16a34a;
    border-color: #16a34a;
}

.btn-share.copied {
    background: transparent;
    color: var(--c-success);
}

/* ============================================
   Output Cards
   ============================================ */

.output-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.output-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--c-bg-card);
    border: 1px solid var(--c-border);
    border-left: 3px solid var(--c-border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    cursor: pointer;
    user-select: none;
    transition: border-color 0.15s ease, background 0.15s ease;

    opacity: 0;
    transform: translateY(6px);
    animation: cardIn 0.3s var(--ease-out) forwards;
}

.output-card:hover {
    border-color: var(--c-text-muted);
    background: #172035;
}

.output-card:active {
    background: #1c2740;
}

.output-card.copied {
    border-left-color: var(--c-success) !important;
}

.output-card[data-format="DecimalDegrees"]        { border-left-color: var(--c-dd); }
.output-card[data-format="DegreesMinutesSeconds"]  { border-left-color: var(--c-dms); }
.output-card[data-format="Utm"]                    { border-left-color: var(--c-utm); }
.output-card[data-format="Mgrs"]                   { border-left-color: var(--c-mgrs); }
.output-card[data-format="PlusCode"]               { border-left-color: var(--c-plus); }

.output-format {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--c-text-muted);
    min-width: 5.5rem;
    flex-shrink: 0;
    transition: color 0.15s ease;
}

.output-card.copied .output-format {
    color: var(--c-success);
}

.output-value {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 1.0625rem;
    color: var(--c-text);
    word-break: break-all;
}

.copy-hint {
    font-size: 0.6875rem;
    color: var(--c-text-muted);
    flex-shrink: 0;
}

/* ============================================
   Location Context
   ============================================ */

.location-context {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.location-card {
    background: var(--c-bg-card);
    border: 1px solid var(--c-border);
    border-left: 3px solid var(--c-unlocode);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    cursor: pointer;
    user-select: none;
    transition: border-color 0.15s ease, background 0.15s ease;

    opacity: 0;
    transform: translateY(6px);
    animation: cardIn 0.3s var(--ease-out) forwards;
}

.location-card:hover {
    border-color: var(--c-text-muted);
    background: #172035;
}

.location-card:active {
    background: #1c2740;
}

.location-card.copied {
    border-left-color: var(--c-success);
}

.location-card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.location-code {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--c-unlocode);
    min-width: 5.5rem;
    flex-shrink: 0;
}

.location-card.copied .location-code {
    color: var(--c-success);
}

.location-name {
    flex: 1;
    font-size: 1.0625rem;
    color: var(--c-text);
}

.location-tz {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--c-text-secondary);
    margin-top: 0.375rem;
    padding-left: 6.25rem;
}

/* ============================================
   Nearby UN/LOCODEs
   ============================================ */

.nearby-section {
    opacity: 0;
    transform: translateY(6px);
    animation: cardIn 0.3s var(--ease-out) forwards;
}

.nearby-label {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--c-text-muted);
    display: block;
    margin-bottom: 0.375rem;
}

.nearby-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.nearby-item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-body);
    font-size: 0.8125rem;
    background: var(--c-bg-card);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    padding: 0.375rem 0.625rem;
    cursor: pointer;
    color: var(--c-text-secondary);
    transition: border-color 0.15s ease, color 0.15s ease;
}

.nearby-item:hover {
    border-color: var(--c-unlocode);
    color: var(--c-text);
}

.nearby-code {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--c-unlocode);
    font-size: 0.75rem;
}

.nearby-name {
    color: inherit;
}

.nearby-dist {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: var(--c-text-muted);
}

/* ============================================
   Animations
   ============================================ */

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes cardIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   Utility
   ============================================ */

.hidden {
    display: none !important;
}

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

@media (max-width: 600px) {
    .main {
        padding: 0 1rem 3rem;
    }

    .input-section {
        padding-top: 16vh;
    }

    .hero-title {
        font-size: 1.5rem;
    }

    #coord-input {
        font-size: 1.125rem;
        padding: 0.875rem 5rem 0.875rem 1rem;
    }

    .results-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .output-card {
        flex-wrap: wrap;
        gap: 0.3rem;
    }

    .output-format {
        min-width: auto;
        width: 100%;
    }

    .output-value {
        font-size: 0.9375rem;
    }

    .example-chip {
        font-size: 0.75rem;
    }

    .location-card-header {
        flex-wrap: wrap;
    }

    .location-code {
        min-width: auto;
    }

    .location-tz {
        padding-left: 0;
    }

    .nearby-list {
        flex-direction: column;
    }
}

/* ============================================
   Reduced Motion
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}
