/* Flagbound — open-world flag collector
   Palette: deep ink sea, moss forest, brass instruments, parchment paper. */

:root {
    --fb-ink: #08121d;
    --fb-ink-2: #0d1b2a;
    --fb-ink-3: #13293d;
    --fb-panel: #0f2333;
    --fb-panel-2: #16324a;
    --fb-brass: #d8a94a;
    --fb-brass-soft: #f0cf8a;
    --fb-parchment: #f4e8d2;
    --fb-parchment-dim: #cdbb9c;
    --fb-moss: #2f5d50;
    --fb-danger: #c8553d;
    --fb-line: rgba(216, 169, 74, 0.28);
    --fb-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    padding-top: max(var(--app-header-h, 72px), 56px);
    background: var(--fb-ink);
    color: var(--fb-parchment);
    font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-tap-highlight-color: transparent;
}

.fb-main {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    height: calc(100dvh - max(var(--app-header-h, 72px), 56px));
    min-height: calc(100dvh - max(var(--app-header-h, 72px), 56px));
}

/* ---------- Header ---------- */

.fb-header {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
    padding: 10px 14px;
    background: linear-gradient(180deg, rgba(8, 18, 29, 0.98), rgba(8, 18, 29, 0.82));
    border-bottom: 1px solid var(--fb-line);
    z-index: 5;
}

.fb-back {
    color: var(--fb-parchment-dim);
    text-decoration: none;
    font-size: 0.86rem;
    letter-spacing: 0.02em;
    padding: 6px 8px;
    border-radius: 8px;
    transition: color 0.2s ease, background 0.2s ease;
}

.fb-back:hover,
.fb-back:focus-visible {
    color: var(--fb-brass-soft);
    background: rgba(216, 169, 74, 0.1);
}

.fb-title {
    margin: 0;
    flex: 1;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(1.05rem, 2.4vw, 1.45rem);
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--fb-brass-soft);
    text-align: center;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}

.fb-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.fb-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--fb-parchment-dim);
    cursor: pointer;
    transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.fb-icon-btn svg {
    width: 21px;
    height: 21px;
    fill: currentColor;
}

.fb-icon-btn:hover,
.fb-icon-btn:focus-visible {
    color: var(--fb-brass-soft);
    background: rgba(216, 169, 74, 0.12);
    border-color: var(--fb-line);
    outline: none;
}

/* ---------- Stage ---------- */

.fb-stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    background: #0a1826;
    touch-action: none;
}

.fb-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* ---------- HUD ---------- */

.fb-hud {
    position: absolute;
    inset: 0;
    pointer-events: none;
    padding: 12px 12px 20px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto 1fr auto;
    gap: 8px;
}

.fb-chip {
    justify-self: start;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border: 1px solid var(--fb-line);
    border-radius: 999px;
    background: rgba(8, 18, 29, 0.72);
    backdrop-filter: blur(6px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    font-size: 0.78rem;
}

.fb-chip-label {
    color: var(--fb-parchment-dim);
    letter-spacing: 0.14em;
    font-size: 0.64rem;
}

.fb-chip-value {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--fb-brass-soft);
    font-variant-numeric: tabular-nums;
}

.fb-chip-total {
    color: var(--fb-parchment-dim);
    font-weight: 500;
}

.fb-chip-flags {
    grid-column: 1;
    grid-row: 1;
}

.fb-chip-biome {
    grid-column: 1;
    grid-row: 2;
    align-self: start;
}

/* Compass */

.fb-compass {
    grid-column: 2;
    grid-row: 1 / span 2;
    justify-self: end;
    position: relative;
    width: 78px;
    height: 78px;
    border-radius: 50%;
    border: 2px solid rgba(216, 169, 74, 0.5);
    background:
        radial-gradient(circle at 35% 30%, rgba(240, 207, 138, 0.22), transparent 55%),
        conic-gradient(from 0deg, #12293c, #0a1826, #12293c, #0a1826, #12293c);
    box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.65), 0 6px 18px rgba(0, 0, 0, 0.35);
}

.fb-compass-ring {
    position: absolute;
    inset: 9px;
    border-radius: 50%;
    border: 1px dashed rgba(244, 232, 210, 0.28);
}

.fb-compass-needle {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 0;
    height: 0;
    transform: translate(-50%, -50%) rotate(0deg);
    transition: transform 0.18s linear;
}

.fb-compass-needle::before {
    content: "";
    position: absolute;
    left: -6px;
    top: -27px;
    width: 12px;
    height: 30px;
    background: linear-gradient(180deg, var(--fb-brass-soft), var(--fb-brass));
    clip-path: polygon(50% 0, 100% 82%, 50% 68%, 0 82%);
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.55));
}

.fb-compass-needle::after {
    content: "";
    position: absolute;
    left: -4px;
    top: 2px;
    width: 8px;
    height: 22px;
    background: rgba(244, 232, 210, 0.35);
    clip-path: polygon(50% 100%, 100% 12%, 50% 24%, 0 12%);
}

.fb-compass-lock {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--fb-brass-soft);
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 3px rgba(216, 169, 74, 0.2);
    opacity: 0;
}

.fb-compass.is-locked {
    border-color: var(--fb-brass-soft);
    animation: fb-lock-pulse 1.6s ease-in-out infinite;
}

.fb-compass.is-locked .fb-compass-lock {
    opacity: 1;
}

@keyframes fb-lock-pulse {
    0%, 100% { box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.65), 0 0 0 0 rgba(240, 207, 138, 0.45); }
    50% { box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.65), 0 0 0 8px rgba(240, 207, 138, 0); }
}

.fb-compass-copy {
    position: absolute;
    top: 96px;
    right: 12px;
    display: grid;
    justify-items: end;
    gap: 2px;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(8, 18, 29, 0.6);
    backdrop-filter: blur(4px);
    text-align: right;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    color: var(--fb-parchment-dim);
}

.fb-compass-distance {
    font-weight: 700;
    color: var(--fb-brass-soft);
    font-variant-numeric: tabular-nums;
}

/* Stamina */

.fb-stamina {
    grid-column: 1;
    grid-row: 3;
    align-self: end;
    width: min(230px, 46vw);
    display: grid;
    gap: 4px;
}

.fb-stamina-label {
    font-size: 0.6rem;
    letter-spacing: 0.16em;
    color: var(--fb-parchment-dim);
    text-shadow: 0 1px 3px rgba(8, 18, 29, 0.9);
}

.fb-stamina-track {
    height: 8px;
    border-radius: 999px;
    background: rgba(8, 18, 29, 0.8);
    border: 1px solid rgba(244, 232, 210, 0.18);
    overflow: hidden;
}

.fb-stamina-fill {
    height: 100%;
    width: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #4f9d7a, #7fc7a0);
    transition: width 0.16s linear, background 0.3s ease;
}

.fb-stamina-fill.is-low {
    background: linear-gradient(90deg, var(--fb-danger), #e08a6a);
}

/* Toast + weather */

.fb-toast,
.fb-weather {
    position: absolute;
    left: 50%;
    transform: translate(-50%, -8px);
    margin: 0;
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 0.8rem;
    letter-spacing: 0.04em;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 4;
}

.fb-toast {
    top: 64px;
    background: rgba(240, 207, 138, 0.95);
    color: #14202c;
    font-weight: 700;
    box-shadow: var(--fb-shadow);
}

.fb-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.fb-weather {
    bottom: 96px;
    background: rgba(8, 18, 29, 0.82);
    border: 1px solid var(--fb-line);
    color: var(--fb-brass-soft);
}

.fb-weather.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.fb-threat {
    position: absolute;
    top: 112px;
    left: 50%;
    transform: translate(-50%, -8px);
    margin: 0;
    padding: 7px 18px;
    border-radius: 999px;
    border: 1px solid rgba(255, 168, 136, 0.6);
    background: rgba(122, 35, 24, 0.9);
    color: #ffe3d7;
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
    z-index: 4;
}

.fb-threat.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
    animation: fb-threat-pulse 1s ease-in-out infinite;
}

@keyframes fb-threat-pulse {
    0%, 100% { box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35), 0 0 0 0 rgba(200, 85, 61, 0.5); }
    50% { box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35), 0 0 0 8px rgba(200, 85, 61, 0); }
}

/* Interact button */

.fb-interact {
    position: absolute;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%);
    z-index: 4;
    padding: 13px 26px;
    border: 1px solid var(--fb-brass);
    border-radius: 999px;
    background: linear-gradient(180deg, #f0cf8a, #d8a94a);
    color: #1a1206;
    font-weight: 800;
    font-size: 0.82rem;
    letter-spacing: 0.14em;
    box-shadow: 0 10px 28px rgba(216, 169, 74, 0.35);
    cursor: pointer;
    animation: fb-bob 1.8s ease-in-out infinite;
}

.fb-interact:active {
    transform: translateX(-50%) scale(0.97);
}

@keyframes fb-bob {
    0%, 100% { margin-bottom: 0; }
    50% { margin-bottom: 5px; }
}

/* Touch joystick */

.fb-touch {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 3;
    display: none;
}

body.fb-touch-mode .fb-touch {
    display: block;
}

body.fb-touch-mode .fb-hud {
    padding-bottom: 154px;
}

.fb-joystick {
    position: absolute;
    left: 18px;
    bottom: 24px;
    width: 118px;
    height: 118px;
    border-radius: 50%;
    border: 1px solid rgba(244, 232, 210, 0.22);
    background: rgba(8, 18, 29, 0.45);
    backdrop-filter: blur(4px);
    pointer-events: auto;
    touch-action: none;
}

.fb-joystick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 50px;
    height: 50px;
    margin: -25px 0 0 -25px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #f0cf8a, #b98d34);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
    transition: transform 0.06s linear;
}

body.fb-touch-mode .fb-stamina {
    height: 30px;
    padding-bottom: 0;
}

/* ---------- Overlays ---------- */

.fb-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: grid;
    place-items: center;
    padding: 18px;
    background: radial-gradient(circle at 50% 40%, rgba(19, 41, 61, 0.72), rgba(4, 9, 15, 0.92));
    backdrop-filter: blur(5px);
    overflow-y: auto;
    touch-action: auto;
}

.fb-overlay.hidden,
.hidden {
    display: none !important;
}

.fb-panel {
    width: min(520px, 100%);
    padding: 26px 24px 24px;
    border: 1px solid var(--fb-line);
    border-radius: 18px;
    background:
        linear-gradient(180deg, rgba(22, 50, 74, 0.96), rgba(15, 35, 51, 0.98)),
        repeating-linear-gradient(45deg, rgba(216, 169, 74, 0.04) 0 2px, transparent 2px 7px);
    box-shadow: var(--fb-shadow), inset 0 1px 0 rgba(244, 232, 210, 0.12);
    text-align: center;
}

.fb-panel-wide {
    width: min(700px, 100%);
}

.fb-panel-start {
    position: relative;
    overflow: hidden;
}

.fb-panel-start::after {
    content: "";
    position: absolute;
    right: -60px;
    top: -70px;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    border: 1px dashed rgba(216, 169, 74, 0.25);
    pointer-events: none;
}

.fb-kicker {
    margin: 0 0 6px;
    font-size: 0.66rem;
    letter-spacing: 0.28em;
    color: var(--fb-brass);
    text-transform: uppercase;
}

.fb-panel-title {
    margin: 0 0 10px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(1.4rem, 4.2vw, 2rem);
    letter-spacing: 0.06em;
    color: var(--fb-brass-soft);
}

.fb-tagline {
    margin: 0 auto 16px;
    max-width: 42ch;
    color: var(--fb-parchment);
    line-height: 1.55;
    font-size: 0.95rem;
}

.fb-hint {
    margin: 0 auto 18px;
    max-width: 40ch;
    color: var(--fb-parchment-dim);
    font-size: 0.78rem;
    line-height: 1.5;
}

.fb-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.fb-btn {
    padding: 12px 26px;
    border-radius: 999px;
    border: 1px solid transparent;
    font-weight: 800;
    font-size: 0.82rem;
    letter-spacing: 0.12em;
    cursor: pointer;
    transition: transform 0.12s ease, filter 0.18s ease, background 0.18s ease;
}

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

.fb-btn-primary {
    background: linear-gradient(180deg, #f0cf8a, #d8a94a);
    color: #1a1206;
    box-shadow: 0 8px 22px rgba(216, 169, 74, 0.28);
}

.fb-btn-primary:hover,
.fb-btn-primary:focus-visible {
    filter: brightness(1.08);
    outline: none;
}

.fb-btn-ghost {
    background: transparent;
    border-color: rgba(244, 232, 210, 0.28);
    color: var(--fb-parchment-dim);
}

.fb-btn-ghost:hover,
.fb-btn-ghost:focus-visible {
    border-color: var(--fb-brass);
    color: var(--fb-brass-soft);
    outline: none;
}

.fb-btn-danger {
    background: var(--fb-danger);
    color: #fff3ec;
}

.fb-save-note {
    margin: 14px 0 0;
    min-height: 1em;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    color: var(--fb-parchment-dim);
}

.fb-stat-line {
    margin: 4px 0;
    font-size: 0.88rem;
    color: var(--fb-parchment-dim);
}

.fb-stat-line b {
    color: var(--fb-brass-soft);
    font-variant-numeric: tabular-nums;
}

.fb-confirm {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--fb-line);
    font-size: 0.84rem;
    color: var(--fb-parchment);
}

/* Flag reward */

.fb-flag-frame {
    display: grid;
    place-items: center;
    margin: 6px auto 16px;
    padding: 10px;
    width: min(320px, 100%);
    border-radius: 10px;
    background: linear-gradient(180deg, #fbf4e4, #e8d9bd);
    box-shadow: inset 0 0 0 1px rgba(8, 18, 29, 0.18), 0 12px 28px rgba(0, 0, 0, 0.35);
}

.fb-flag-frame img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 5 / 3;
    object-fit: contain;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.22));
}

.fb-fact {
    margin: 0 auto 18px;
    max-width: 40ch;
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--fb-parchment);
}

.fb-fact-label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.62rem;
    letter-spacing: 0.22em;
    color: var(--fb-brass);
}

/* Map + collection */

.fb-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.fb-panel-head .fb-panel-title {
    margin: 0;
}

#mapCanvas {
    width: 100%;
    height: auto;
    border-radius: 12px;
    border: 1px solid var(--fb-line);
    background: var(--fb-ink);
    image-rendering: auto;
}

.fb-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 12px 0 0;
    font-size: 0.72rem;
    color: var(--fb-parchment-dim);
}

.fb-legend-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
}

.fb-legend-open {
    background: var(--fb-brass-soft);
}

.fb-legend-locked {
    border: 1px solid var(--fb-parchment-dim);
}

.fb-atlas {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    max-height: min(62vh, 560px);
    overflow-y: auto;
    padding: 2px;
}

.fb-atlas-card {
    border: 1px solid rgba(244, 232, 210, 0.14);
    border-radius: 12px;
    padding: 10px;
    background: rgba(8, 18, 29, 0.45);
    text-align: left;
}

.fb-atlas-card.is-locked {
    display: grid;
    place-items: center;
    min-height: 132px;
    border-style: dashed;
    color: var(--fb-parchment-dim);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-align: center;
}

.fb-atlas-card img {
    display: block;
    width: 100%;
    aspect-ratio: 5 / 3;
    object-fit: contain;
    border-radius: 6px;
    background: #f7efdd;
    padding: 4px;
}

.fb-atlas-name {
    display: block;
    margin-top: 8px;
    font-weight: 700;
    font-size: 0.82rem;
    color: var(--fb-brass-soft);
}

.fb-atlas-fact {
    display: block;
    margin-top: 4px;
    font-size: 0.7rem;
    line-height: 1.4;
    color: var(--fb-parchment-dim);
}

/* ---------- Small screens ---------- */

@media (max-width: 560px) {
    .fb-header {
        padding: 8px 10px;
        gap: 6px;
    }

    .fb-back {
        width: 34px;
        height: 34px;
        padding: 0;
        max-width: none;
        font-size: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    .fb-back::before {
        content: "←";
        font-size: 16px;
    }

    .fb-title {
        font-size: 0.95rem;
        letter-spacing: 0.1em;
    }

    body.fb-touch-mode .fb-interact {
        bottom: 150px;
    }

    .fb-icon-btn {
        width: 34px;
        height: 34px;
        min-width: 0;
        min-height: 0;
    }

    .fb-compass {
        width: 66px;
        height: 66px;
    }

    .fb-compass-copy {
        top: 82px;
        font-size: 0.62rem;
    }

    .fb-chip {
        padding: 6px 10px;
    }

    .fb-chip-biome {
        font-size: 0.7rem;
    }

    .fb-panel {
        padding: 20px 16px;
    }

    .fb-atlas {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .fb-weather {
        bottom: 150px;
        font-size: 0.72rem;
        max-width: 86vw;
        white-space: normal;
        text-align: center;
    }

    .fb-threat {
        top: 170px;
        font-size: 0.66rem;
        max-width: 88vw;
        white-space: normal;
        text-align: center;
    }
}

@media (max-height: 640px) {
    .fb-title {
        font-size: 1rem;
    }

    .fb-chip,
    .fb-compass-copy {
        font-size: 0.66rem;
    }

    .fb-stamina {
        width: 180px;
    }

    .fb-panel {
        padding-top: 18px;
        padding-bottom: 18px;
    }
}

@media (max-width: 360px) {
    .fb-title {
        font-size: 0.82rem;
        letter-spacing: 0.02em;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@media (prefers-reduced-motion: reduce) {
    .fb-interact,
    .fb-compass.is-locked,
    .fb-threat.is-visible {
        animation: none;
    }

    .fb-compass-needle {
        transition: none;
    }
}

/* The fixed site header is 56px on phones even when the shared token is 52px. */
html body {
    padding-top: max(var(--app-header-h, 72px), 56px);
}

.fb-map-hint {
    margin: 6px 0 0;
    text-align: center;
    font-size: 0.82rem;
    color: #f0cf8a;
}
