:root {
    --bg: #f0ede8;
    --bg2: #f5f3f0;
    --card: #fff;
    --text: #1a1814;
    --text2: #555;
    --text3: #888;
    --border: rgba(26,24,20,0.1);
    --border2: rgba(26,24,20,0.2);
    --accent: #2563eb;
}

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

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.logo {
    color: var(--text);
    text-decoration: none;
    font-family: 'Fraunces', serif;
    font-size: 1.2rem;
    font-weight: 500;
}

.nav-link {
    color: var(--text3);
    text-decoration: none;
    font-size: 0.95rem;
    min-height: 44px;
    display: flex;
    align-items: center;
}

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

.search-form {
    display: flex;
    gap: 0.5rem;
    flex: 1;
    min-width: 200px;
    max-width: 400px;
}

.search-form input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border2);
    border-radius: 6px;
    background: var(--bg2);
    color: var(--text);
    font-size: 0.95rem;
}

.search-form button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-size: 0.95rem;
    min-height: 44px;
    min-width: 44px;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    gap: 0.5rem;
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.filter-form select {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border2);
    border-radius: 6px;
    background: var(--card);
    color: var(--text);
    font-size: 0.85rem;
    min-height: 44px;
}

.stats {
    color: var(--text3);
    font-size: 0.9rem;
}

/* Grid */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 4px;
    padding: 4px;
}

.card {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 4px;
    display: block;
    background: var(--bg2);
}

.card img,
.card video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s;
}

.card:hover img,
.card:hover video {
    transform: scale(1.05);
}

.badge-video,
.badge-audio {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.5);
    color: #fff;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}

.audio-thumb {
    width: 100%;
    height: 100%;
    background: var(--bg2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.card.no-gps {
    border: 2px solid #f59e0b;
    opacity: 0.7;
}

.card.no-gps:hover {
    opacity: 1;
}

.card-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 6px 8px;
    background: linear-gradient(transparent, rgba(0,0,0,0.6));
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #eee;
}

.no-image {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text3);
    font-size: 0.85rem;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem;
}

.pagination a {
    color: var(--accent);
    text-decoration: none;
    padding: 0.5rem 1rem;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.pagination span { color: var(--text3); }

/* Detail page */
.detail {
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem;
}

.detail-media {
    margin-bottom: 1.5rem;
}

.detail-media img,
.detail-media video {
    width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
    background: var(--bg2);
}

.detail-info h1 {
    font-size: 1.3rem;
    margin-bottom: 0.75rem;
    white-space: pre-line;
}

.description {
    color: var(--text2);
    margin-bottom: 1rem;
    white-space: pre-line;
}

dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.4rem 1rem;
    margin-bottom: 1.5rem;
}

dt { color: var(--text3); font-size: 0.9rem; }
dd { font-size: 0.9rem; }
dd a { color: var(--accent); }

.exif-data {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--bg2);
    border-radius: 8px;
}

.exif-data h2 {
    font-size: 0.95rem;
    color: var(--text3);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.exif-data dl {
    margin-bottom: 0;
}

.detail-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.detail-nav a {
    color: var(--accent);
    text-decoration: none;
    min-height: 44px;
    display: flex;
    align-items: center;
}

/* Tags */
.tags-header {
    padding: 1rem;
}

.tags-header h1 {
    font-size: 1.2rem;
    color: var(--text3);
    font-weight: 400;
}

/* Places */
.places-list {
    max-width: 700px;
    margin: 0 auto;
    padding: 0 1rem 2rem;
}

.country-group {
    margin-bottom: 2px;
}

.country-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg2);
    border-radius: 6px;
    cursor: pointer;
    list-style: none;
    min-height: 44px;
}

.country-header::-webkit-details-marker { display: none; }

.country-header::before {
    content: '▸';
    color: var(--text3);
    transition: transform 0.15s;
}

details[open] .country-header::before {
    transform: rotate(90deg);
}

.country-link {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: 1.05rem;
}

.country-link:hover { color: var(--accent); }

.country-count {
    color: var(--text3);
    font-size: 0.85rem;
}

.city-cloud {
    padding: 0.5rem 1rem 1rem 2rem;
    line-height: 2.2;
}

.section-title {
    padding: 0.5rem 1rem 0;
    font-size: 1rem;
    color: var(--text3);
    font-weight: 600;
}

.tag-cloud {
    padding: 0.5rem 1rem;
    line-height: 2.2;
}

.tag {
    display: inline-block;
    color: var(--accent);
    text-decoration: none;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    transition: background 0.15s;
}

.tag:hover {
    background: var(--bg2);
    color: var(--text);
}

.tag-count {
    font-size: 0.65em;
    color: var(--text3);
    margin-left: 0.2em;
    vertical-align: super;
}

/* Visual timeline */
.vis-timeline {
    padding: 1rem;
    max-width: 900px;
    margin: 0 auto 2rem;
}

.vis-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.vis-legend-item {
    font-size: 0.8rem;
    color: var(--text2);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.vis-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.vis-row {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
}

.vis-year-label {
    width: 50px;
    font-size: 0.8rem;
    color: var(--text3);
    text-align: right;
    padding-right: 0.75rem;
    flex-shrink: 0;
}

.vis-bar {
    flex: 1;
    height: 24px;
    background: var(--bg2);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.vis-month-marker {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--border);
}

.vis-month-marker::after {
    content: attr(data-month);
    position: absolute;
    top: -14px;
    left: 2px;
    font-size: 0.55rem;
    color: var(--text3);
}

.vis-stay-block {
    position: absolute;
    top: 2px;
    bottom: 2px;
    border-radius: 3px;
    min-width: 4px;
    opacity: 0.85;
    transition: opacity 0.15s;
    cursor: pointer;
}

.vis-stay-block:hover {
    opacity: 1;
    z-index: 1;
    box-shadow: 0 0 0 2px var(--text);
}

/* Text timeline */
.timeline {
    max-width: 700px;
    margin: 0 auto;
    padding: 0 1rem 2rem;
}

.timeline-year {
    margin-bottom: 0.5rem;
}

.timeline-year > .year-label {
    font-size: 1.5rem;
    color: var(--text2);
    font-weight: 700;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.75rem;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.timeline-year > .year-label::-webkit-details-marker { display: none; }

.timeline-year > .year-label::before {
    content: '▸';
    color: var(--text3);
    font-size: 1rem;
    transition: transform 0.15s;
}

details[open].timeline-year > .year-label::before {
    transform: rotate(90deg);
}

.year-count {
    font-size: 0.85rem;
    color: var(--text3);
    font-weight: 400;
}

.timeline-stay {
    display: block;
    text-decoration: none;
    padding: 0.75rem 1rem;
    margin-bottom: 2px;
    border-radius: 6px;
    border-left: 3px solid var(--accent);
    background: var(--card);
    transition: background 0.15s;
}

.timeline-stay:hover {
    background: var(--bg2);
}

.stay-dates {
    font-size: 0.8rem;
    color: var(--text3);
}

.stay-location {
    font-size: 1.1rem;
    color: var(--text);
    font-weight: 600;
    margin: 0.15rem 0;
}

.stay-meta {
    font-size: 0.8rem;
    color: var(--text3);
}

.nogps-badge {
    color: #f59e0b;
    margin-left: 0.3rem;
}

/* Mobile */
@media (max-width: 600px) {
    header { padding: 0.75rem; }
    .search-form { max-width: none; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 2px; padding: 2px; }
    .detail { padding: 0.5rem; }
    .detail-info h1 { font-size: 1.1rem; }
}

/* Settings */
.settings-page { max-width: 600px; margin: 0 auto; padding: 1rem; }
.settings-page h1 { margin-bottom: 1.5rem; }
.settings-section { margin-bottom: 2rem; padding: 1.5rem; background: var(--card); border: 1px solid var(--border); border-radius: 8px; }
.settings-section h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }
.settings-hint { color: var(--text3); font-size: 0.85rem; margin-bottom: 1rem; }
.settings-hint code { background: var(--bg2); padding: 2px 6px; border-radius: 3px; font-size: 0.8rem; }
.settings-row { margin-bottom: 0.75rem; }
.settings-row label { display: block; font-size: 0.85rem; color: var(--text2); margin-bottom: 0.25rem; }
.settings-row input { width: 100%; padding: 0.5rem; background: var(--bg2); border: 1px solid var(--border2); border-radius: 4px; color: var(--text); font-size: 0.95rem; box-sizing: border-box; }
.settings-status { padding: 0.75rem; border-radius: 6px; margin-top: 0.75rem; font-size: 0.9rem; }
.settings-status.connected { background: #dcfce7; color: #166534; }
.settings-status.disconnected { background: #fef3c7; color: #92400e; }
.btn-save { padding: 0.6rem 1.5rem; background: var(--accent); color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 0.95rem; }
.btn-save:hover { background: #1d4ed8; }
.btn-connect { display: inline-block; margin-top: 0.5rem; padding: 0.4rem 1rem; background: #00b0b9; color: #fff; border-radius: 4px; text-decoration: none; font-size: 0.85rem; }
.btn-small { margin-left: 0.5rem; padding: 0.2rem 0.6rem; background: #dc2626; color: #fff; border-radius: 4px; text-decoration: none; font-size: 0.8rem; }
.settings-message { padding: 0.75rem; background: #dcfce7; color: #166534; border-radius: 6px; margin-bottom: 1rem; }
