:root {
    color-scheme: light;
    --background: #f7f1e8;
    --surface: #fffdf8;
    --text: #251b16;
    --muted: #6a5d55;
    --brand: #6f1d1b;
    --brand-dark: #4d1211;
    --accent: #d7a83d;
    --border: #ded2c4;
    --success: #23643b;
    --shadow: 0 12px 35px rgba(63, 37, 24, 0.12);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--background); }
body { margin: 0; min-height: 100%; color: var(--text); background: var(--background); }
button, input { font: inherit; }
button { touch-action: manipulation; }

.app-header {
    position: sticky;
    z-index: 1000;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: calc(0.8rem + env(safe-area-inset-top)) 1rem 0.8rem;
    color: white;
    background: linear-gradient(135deg, var(--brand-dark), var(--brand));
    box-shadow: 0 4px 20px rgba(0,0,0,.15);
}

.player-navigation {
    display: flex;
    justify-content: flex-end;
    margin: 1rem 0 0.75rem;
}

.back-button {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 44px;
    padding: 0.65rem 1rem;
    border: 1px solid #d9c8bb;
    border-radius: 0.75rem;
    color: #6f1d1b;
    background: #fffdf8;
    font-weight: 700;
    text-decoration: none;
}

    .back-button:hover {
        border-color: #6f1d1b;
        background: #f7eee7;
    }

    .back-button:focus-visible {
        outline: 3px solid #1d5f8a;
        outline-offset: 3px;
    }

.back-link {
    color: inherit;
    font-weight: 650;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, serif; font-size: clamp(1.45rem, 5vw, 2.2rem); }
h2 { margin-bottom: .45rem; font-family: Georgia, serif; }

.eyebrow {
    margin-bottom: .2rem;
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--accent);
}

.badge {
    flex: none;
    padding: .4rem .65rem;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 800;
}
.badge--off { background: rgba(255,255,255,.16); }
.badge--on { background: #dff3e5; color: var(--success); }

main {
    width: min(1100px, 100%);
    margin: 0 auto;
    padding: 1rem 1rem calc(3rem + env(safe-area-inset-bottom));
}

.control-panel, .places-section {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.status { margin-bottom: .8rem; line-height: 1.5; color: var(--muted); }
.status--warning { color: #8b4d00; }
.status--error { color: #9b1c1c; }

.button-row { display: flex; flex-wrap: wrap; gap: .6rem; }
.button {
    min-height: 46px;
    padding: .7rem 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    background: white;
    font-weight: 750;
    cursor: pointer;
}
.button:hover { filter: brightness(.97); }
.button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button--primary { border-color: var(--brand); color: white; background: var(--brand); }

.technical-details { margin-top: 1rem; color: var(--muted); }
.technical-details summary { cursor: pointer; font-weight: 750; color: var(--text); }
dl { display: grid; gap: .35rem; }
dl div { display: grid; grid-template-columns: 9rem 1fr; gap: .5rem; }
dt { font-weight: 700; }
dd { margin: 0; overflow-wrap: anywhere; }
.link-button { border: 0; padding: .4rem 0; color: var(--brand); background: transparent; text-decoration: underline; cursor: pointer; }

.map-section { margin: 1rem 0; }
#map {
    height: min(56vh, 560px);
    min-height: 350px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
}
.map-note { margin: .6rem .25rem 0; font-size: .84rem; line-height: 1.4; color: var(--muted); }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.places-list { display: grid; gap: .75rem; }
.place-card {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: .75rem;
    padding: .9rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: white;
}
.place-card--visited { border-color: #97c7a8; background: #f1faf4; }
.place-card h3 { margin: 0 0 .25rem; }
.place-card p { margin-bottom: 0; color: var(--muted); }
.place-distance { margin-top: .35rem !important; font-size: .85rem; font-weight: 700; }
.place-actions { display: flex; flex-direction: column; justify-content: center; gap: .4rem; }
.small-button { min-height: 40px; padding: .55rem .7rem; font-size: .85rem; }
.visited-mark { font-size: .78rem; font-weight: 800; color: var(--success); }

.story-dialog {
    width: min(620px, calc(100% - 2rem));
    max-height: 85vh;
    padding: 1.4rem;
    border: 0;
    border-radius: 20px;
    color: var(--text);
    background: var(--surface);
    box-shadow: 0 24px 80px rgba(0,0,0,.28);
}
.story-dialog::backdrop { background: rgba(28, 18, 13, .65); backdrop-filter: blur(3px); }
.story-dialog p { line-height: 1.65; }
.dialog-close { float: right; width: 42px; height: 42px; border: 0; border-radius: 50%; font-size: 1.7rem; background: #eee5da; cursor: pointer; }

.user-location-marker {
    width: 18px;
    height: 18px;
    border: 3px solid white;
    border-radius: 50%;
    background: #1263d6;
    box-shadow: 0 0 0 3px rgba(18,99,214,.3);
}

@media (min-width: 760px) {
    main { padding-top: 1.4rem; }
    .control-panel { display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 1.5rem; }
    .technical-details { grid-column: 1 / -1; }
    .places-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
