:root {
    color-scheme: dark;
    --bg: #15120e;
    --bg-elevated: rgba(37, 30, 21, 0.92);
    --bg-soft: rgba(71, 57, 40, 0.8);
    --surface: rgba(24, 20, 15, 0.78);
    --surface-strong: rgba(45, 34, 21, 0.96);
    --line: rgba(255, 204, 0, 0.18);
    --text: #f1e6cd;
    --muted: #c5b289;
    --accent: #ffcc00;
    --accent-strong: #f0a81f;
    --danger: #cc6f42;
    --parchment: #f5e6c8;
    --shadow: 0 24px 50px rgba(0, 0, 0, 0.28);
    --radius-lg: 24px;
    --radius-md: 18px;
    --radius-sm: 12px;
    --max-width: 1280px;
    --route-progress: 0;
}

body[data-theme="parchment"] {
    color-scheme: light;
    --bg: #efe0bb;
    --bg-elevated: rgba(245, 230, 200, 0.94);
    --bg-soft: rgba(226, 207, 168, 0.84);
    --surface: rgba(255, 248, 231, 0.88);
    --surface-strong: rgba(245, 230, 200, 0.96);
    --line: rgba(87, 54, 25, 0.12);
    --text: #352413;
    --muted: #6d5338;
    --accent: #b47d08;
    --accent-strong: #8f5b04;
    --danger: #a55434;
    --shadow: 0 24px 50px rgba(95, 64, 20, 0.16);
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Georgia, "Times New Roman", serif;
    background:
        radial-gradient(circle at top left, rgba(255, 204, 0, 0.18), transparent 20%),
        radial-gradient(circle at right 20%, rgba(128, 79, 30, 0.18), transparent 18%),
        linear-gradient(180deg, rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.24)),
        var(--bg);
    color: var(--text);
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    width: min(calc(100% - 32px), var(--max-width));
    margin: 0 auto;
    padding: 24px 0 48px;
}

.hero-card,
.card,
.dialog-panel {
    border: 1px solid var(--line);
    background: var(--bg-elevated);
    box-shadow: var(--shadow);
}

.hero-card {
    display: grid;
    grid-template-columns: 1.6fr 0.8fr;
    gap: 20px;
    padding: 28px;
    border-radius: calc(var(--radius-lg) + 4px);
    overflow: hidden;
    position: relative;
}

.hero-card::before {
    content: "";
    position: absolute;
    inset: auto -10% -20% 52%;
    background: radial-gradient(circle, rgba(255, 204, 0, 0.2), transparent 55%);
    pointer-events: none;
}

.eyebrow,
.section-label {
    margin: 0 0 8px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.72rem;
}

.hero-copy h1,
.section-heading h2,
.dialog-panel h2 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 3.5rem);
    line-height: 0.95;
}

.hero-summary,
.mode-note,
.poi-summary,
.dialog-panel p,
.dialog-list,
.current-poi-body {
    color: var(--muted);
    line-height: 1.6;
}

.hero-actions {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: stretch;
    gap: 12px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 18px;
    margin-top: 20px;
}

.card {
    border-radius: var(--radius-lg);
    padding: 22px;
    backdrop-filter: blur(16px);
}

.progress-card {
    grid-column: span 4;
}

.map-card {
    grid-column: span 8;
}

.controls-card,
.achievements-card {
    grid-column: span 4;
}

.poi-card {
    grid-column: span 8;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 16px;
    margin-bottom: 20px;
}

.map-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.map-zoom-controls {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface);
}

.zoom-level-label {
    min-width: 52px;
    text-align: center;
    font-size: 0.84rem;
    color: var(--muted);
}

.status-pill {
    padding: 10px 14px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 204, 0, 0.08);
    color: var(--accent);
    font-size: 0.84rem;
}

.progress-ring-wrap {
    display: grid;
    place-items: center;
    position: relative;
    min-height: 220px;
}

.progress-ring {
    width: 220px;
    height: 220px;
    transform: rotate(-90deg);
}

.progress-ring-track,
.progress-ring-value {
    fill: none;
    stroke-width: 10;
}

.progress-ring-track {
    stroke: rgba(255, 255, 255, 0.08);
}

.progress-ring-value {
    stroke: var(--accent);
    stroke-linecap: round;
    stroke-dasharray: 326.73;
    stroke-dashoffset: calc(326.73 - (326.73 * var(--route-progress)) / 100);
    transition: stroke-dashoffset 350ms ease;
    filter: drop-shadow(0 0 12px rgba(255, 204, 0, 0.4));
}

.progress-ring-copy {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-align: center;
}

.progress-ring-copy strong {
    font-size: 2.2rem;
}

.progress-bar {
    width: 100%;
    height: 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
    margin-top: 14px;
}

.progress-fill {
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent-strong), var(--accent));
    transition: width 350ms ease;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 22px;
}

.stat-tile {
    padding: 16px;
    border-radius: var(--radius-md);
    background: var(--surface);
    border: 1px solid var(--line);
}

.stat-label {
    display: block;
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 0.84rem;
}

.stat-tile strong {
    font-size: 1.18rem;
}

.map-stage {
    position: relative;
    overflow: hidden;
    min-height: 420px;
    border-radius: calc(var(--radius-lg) - 6px);
    background:
        linear-gradient(135deg, rgba(245, 230, 200, 0.92), rgba(214, 186, 134, 0.94));
    border: 1px solid rgba(87, 54, 25, 0.12);
}

.parchment-layer {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 20%, rgba(120, 80, 32, 0.08), transparent 22%),
        radial-gradient(circle at 78% 35%, rgba(120, 80, 32, 0.12), transparent 20%),
        radial-gradient(circle at 55% 80%, rgba(120, 80, 32, 0.07), transparent 24%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(90, 62, 21, 0.06));
}

.map-image-svg {
    opacity: 0.9;
    filter: saturate(0.92) contrast(1.04);
}

.map-svg {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 420px;
    z-index: 1;
}

.map-stage.is-calibrating .map-svg {
    cursor: crosshair;
}

.map-stage.is-panning .map-svg {
    cursor: grabbing;
}

.map-asset-hint {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 16px;
    z-index: 2;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: rgba(255, 248, 233, 0.72);
    color: #5c3f19;
    border: 1px solid rgba(87, 54, 25, 0.16);
    font-size: 0.82rem;
    line-height: 1.45;
}

.route-shadow {
    fill: none;
    stroke: rgba(83, 48, 12, 0.22);
    stroke-width: 16;
    stroke-linecap: round;
}

.route-base,
.route-progress {
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: url(#routeGlow);
}

.route-base {
    stroke: rgba(255, 204, 0, 0.24);
    stroke-width: 4;
}

.route-progress {
    stroke: rgba(255, 204, 0, 0.8);
    stroke-width: 4;
    stroke-dasharray: 1200;
    stroke-dashoffset: calc(1200 - (1200 * var(--route-progress)) / 100);
    transition: stroke-dashoffset 500ms ease;
}

.waypoint,
.waypoint-label,
.waypoint-pin,
.waypoint-diamond {
    cursor: pointer;
}

.waypoint-pin {
    fill: #fff7df;
    stroke: #6c4c18;
    stroke-width: 2;
}

.waypoint-pin.is-active {
    fill: var(--accent);
    stroke: #5d3c08;
}

.waypoint-pin.is-complete {
    fill: #eed8a4;
}

.waypoint-diamond {
    fill: rgba(255, 204, 0, 0.8);
    stroke: #6b4712;
    stroke-width: 1.5;
}

.waypoint-label {
    fill: #ffcc00;
    font-size: 0.92rem;
    text-anchor: middle;
}

.traveler-pulse {
    fill: rgba(255, 204, 0, 0.22);
    animation: pulse 1800ms ease-out infinite;
}

.traveler-marker {
    fill: #2a1a08;
    stroke: #ffcc00;
    stroke-width: 4;
}

@keyframes pulse {
    0% {
        transform: scale(0.92);
        opacity: 0.9;
    }

    70% {
        transform: scale(1.18);
        opacity: 0;
    }

    100% {
        transform: scale(1.18);
        opacity: 0;
    }
}

.map-popover {
    position: absolute;
    z-index: 3;
    max-width: 240px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    background: rgba(44, 28, 12, 0.94);
    color: #f8eedc;
    box-shadow: 0 20px 32px rgba(0, 0, 0, 0.24);
}

.calibration-panel {
    margin-top: 12px;
    width: 100%;
    padding: 12px;
    border-radius: var(--radius-sm);
    background: rgba(38, 24, 11, 0.92);
    border: 1px solid rgba(255, 204, 0, 0.22);
    color: #f8ebcf;
}

.poi-editor-panel {
    margin-top: 12px;
    width: 100%;
    padding: 12px;
    border-radius: var(--radius-sm);
    background: rgba(30, 20, 10, 0.92);
    border: 1px solid rgba(255, 204, 0, 0.2);
    color: #f8ebcf;
}

.poi-editor-panel p {
    margin: 6px 0 10px;
    color: #e4d3ae;
    font-size: 0.82rem;
}

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

.poi-editor-grid .field-group {
    color: #e4d3ae;
}

.poi-editor-grid input,
.poi-editor-grid select {
    background: rgba(0, 0, 0, 0.18);
    color: #f8ebcf;
}

.poi-editor-buttons {
    margin-top: 10px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.calibration-panel p {
    margin: 6px 0 10px;
    color: #e4d3ae;
    font-size: 0.82rem;
}

.calibration-panel pre {
    margin: 0;
    max-height: 220px;
    overflow: auto;
    padding: 10px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.2);
    color: #f8ebcf;
    font-size: 0.76rem;
    line-height: 1.45;
    white-space: pre-wrap;
}

.calibration-buttons {
    margin-top: 10px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.map-popover h3 {
    margin: 0 0 6px;
    font-size: 1rem;
}

.map-popover p {
    margin: 0;
    line-height: 1.5;
    font-size: 0.92rem;
}

.button-row,
.settings-grid {
    display: grid;
    gap: 12px;
}

.manual-controls {
    margin-top: 18px;
}

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

.field-group {
    display: grid;
    gap: 8px;
    color: var(--muted);
}

.field-group input,
.field-group select {
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
}

.field-group input[type="range"] {
    padding: 0;
}

.button {
    min-height: 48px;
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.button:hover {
    transform: translateY(-1px);
}

.button-primary {
    background: linear-gradient(135deg, var(--accent-strong), var(--accent));
    border-color: rgba(255, 204, 0, 0.4);
    color: #2f1d08;
    font-weight: 700;
}

.button-ghost {
    background: var(--surface);
    color: var(--text);
}

.button-danger {
    background: rgba(204, 111, 66, 0.12);
    border-color: rgba(204, 111, 66, 0.28);
    color: #f6d0bf;
}

.button-small {
    min-height: 40px;
    padding: 10px 14px;
}

.achievements-grid,
.poi-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: row;
    gap: 12px;
}

.achievement-card,
.poi-item {
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--line);
    background: var(--surface);
}

.achievement-card {
    position: relative;
    overflow: hidden;
}

.achievement-card::before {
    content: "";
    position: absolute;
    inset: auto -25% -50% auto;
    width: 160px;
    height: 160px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 204, 0, 0.2), transparent 65%);
    opacity: 0;
    transition: opacity 200ms ease;
}

.achievement-card.is-unlocked::before {
    opacity: 1;
}

.achievement-card.is-unlocked {
    border-color: rgba(255, 204, 0, 0.4);
}

.achievement-top,
.poi-top {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 12px;
}

.achievement-icon,
.poi-icon {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(255, 204, 0, 0.12);
    color: var(--accent);
    font-size: 1.2rem;
}

.achievement-card h3,
.poi-item h3 {
    margin: 0 0 6px;
    font-size: 1rem;
}

.achievement-card p,
.poi-item p {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}

.distance-chip {
    padding: 8px 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--accent);
    white-space: nowrap;
    font-size: 0.82rem;
}

.poi-item.is-active,
.achievement-card.is-current {
    outline: 2px solid rgba(255, 204, 0, 0.28);
}

.dialog-card {
    width: min(calc(100% - 32px), 560px);
    border: none;
    padding: 0;
    background: transparent;
}

.dialog-card::backdrop {
    background: rgba(7, 5, 4, 0.62);
    backdrop-filter: blur(6px);
}

.dialog-panel {
    padding: 24px;
    border-radius: 26px;
}

.dialog-list {
    padding-left: 18px;
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 20;
    max-width: 320px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    background: rgba(44, 28, 12, 0.96);
    color: #fff3de;
    border: 1px solid rgba(255, 204, 0, 0.28);
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.22);
}

@media (max-width: 1024px) {
    .hero-card,
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .progress-card,
    .map-card,
    .controls-card,
    .achievements-card,
    .poi-card {
        grid-column: auto;
    }

    .hero-actions {
        flex-direction: row;
    }
}

@media (max-width: 640px) {
    .app-shell {
        width: min(calc(100% - 20px), var(--max-width));
        padding-top: 14px;
    }

    .hero-card,
    .card,
    .dialog-panel {
        padding: 18px;
    }

    .hero-actions,
    .map-actions,
    .map-zoom-controls,
    .button-row,
    .stats-grid,
    .secondary-row {
        grid-template-columns: 1fr;
    }

    .map-actions {
        display: grid;
    }

    .map-zoom-controls {
        display: grid;
    }

    .poi-list {
        grid-template-columns: 1fr;
    }

    .poi-editor-grid,
    .poi-editor-buttons {
        grid-template-columns: 1fr;
    }

    .progress-ring {
        width: 180px;
        height: 180px;
    }

    .map-stage,
    .map-svg {
        min-height: 320px;
    }

    .map-popover {
        left: 12px !important;
        right: 12px;
        bottom: 12px !important;
        top: auto !important;
        max-width: none;
    }

    .map-asset-hint {
        right: 12px;
        bottom: 12px;
    }
}