/* ── reset ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }

body {
    font-family: 'Noto Sans KR', 'Apple SD Gothic Neo', sans-serif;
    background: var(--bg);
    color: var(--t1);
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

/* ── 헤더 ── */
header {
    flex-shrink: 0;
    background: var(--header);
    height: 52px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,.07);
}

.hd-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hd-icon { font-size: 20px; line-height: 1; flex-shrink: 0; }
.hd-brand { display: flex; flex-direction: column; min-width: 0; }
.hd-title { font-size: 15px; font-weight: 900; line-height: 1.2; letter-spacing: -0.5px; }
.hd-title .accent { color: var(--accent); }
.hd-title .plain  { color: rgba(255,255,255,.88); }
.hd-sub { font-size: 10px; color: rgba(255,255,255,.32); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 400; letter-spacing: 0.3px; text-transform: uppercase; }

.hd-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.count-tag {
    background: var(--accent); color: #fff;
    font-size: 11px; font-weight: 700;
    padding: 3px 8px; border-radius: 1px;
    letter-spacing: 0.2px;
}
.visit-tag {
    background: #166534; color: #fff;
    font-size: 11px; font-weight: 700;
    padding: 3px 8px; border-radius: 1px;
    display: none;
}

/* ── 레이아웃 (데스크탑: 사이드바 + 지도) ── */
.layout {
    flex: 1; min-height: 0;
    display: flex;
}

/* ── 사이드바 ── */
.sidebar {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border-right: 1px solid var(--bd);
    overflow: hidden;
}

.sidebar-search {
    padding: 12px;
    border-bottom: 1px solid var(--bd);
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.search-input {
    flex: 1; min-width: 0;
    height: 34px; padding: 0 10px;
    border: 1px solid var(--bd);
    border-radius: 1px;
    background: var(--in);
    color: var(--t1);
    font-family: inherit; font-size: 13px;
    outline: none;
    transition: border-color 150ms, background 150ms;
}
.search-input::placeholder { color: var(--t3); }
.search-input:focus { border-color: var(--accent); background: var(--white); }

.search-btn {
    height: 34px; padding: 0 13px;
    background: var(--accent); color: #fff;
    border: none; border-radius: 1px;
    font-family: inherit; font-size: 12px; font-weight: 700;
    cursor: pointer; white-space: nowrap; flex-shrink: 0;
    letter-spacing: 0.1px;
    transition: background 120ms;
}
.search-btn:hover  { background: var(--accent-d); }
.search-btn:active { opacity: .86; }

/* 카테고리 탭 */
.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--bd);
    flex-shrink: 0;
}
.fp {
    flex: 1; height: 38px; padding: 0;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--t3);
    font-family: inherit; font-size: 12px; font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: color 120ms, border-color 120ms;
}
.fp:hover { color: var(--t2); }
.fp.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }

/* 검색 행 wrapper (데스크탑: 투명, 모바일: 행 컨테이너) */
.sidebar-row {
    display: contents; /* 데스크탑에서 wrapper처럼 보이지 않음 */
}

/* 뒤로가기 버튼 */
.sb-back {
    padding: 10px 12px;
    border-bottom: 1px solid var(--bd);
    flex-shrink: 0;
}
.back-btn {
    display: inline-flex; align-items: center;
    height: 28px; padding: 0 10px;
    border: 1px solid var(--bd); border-radius: 1px;
    background: none; color: var(--accent);
    font-family: inherit; font-size: 12px; font-weight: 700;
    text-decoration: none; white-space: nowrap;
    transition: background 120ms, border-color 120ms;
}
.back-btn:hover { background: var(--accent-w); border-color: var(--accent); }

/* ── 지역 필터 ── */
.region-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--bd);
    flex-shrink: 0;
}
.rchip {
    height: 24px; padding: 0 9px;
    border: 1px solid var(--bd); border-radius: 12px;
    background: none; color: var(--t3);
    font-family: inherit; font-size: 11px; font-weight: 500;
    cursor: pointer; white-space: nowrap;
    transition: background 100ms, color 100ms, border-color 100ms;
}
.rchip:hover { color: var(--t2); border-color: var(--t2); }
.rchip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }

/* ── 정렬 + 뷰 모드 툴바 ── */
.sidebar-tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    border-bottom: 1px solid var(--bd);
    flex-shrink: 0;
    gap: 8px;
}
.sort-btns, .view-btns { display: flex; gap: 3px; }
.sort-btn, .view-btn {
    height: 24px; padding: 0 8px;
    border: 1px solid var(--bd); border-radius: 2px;
    background: none; color: var(--t3);
    font-family: inherit; font-size: 11px; font-weight: 500;
    cursor: pointer; white-space: nowrap;
    transition: background 100ms, color 100ms, border-color 100ms;
}
.sort-btn:hover, .view-btn:hover { color: var(--t2); border-color: var(--t2); }
.sort-btn.on, .view-btn.on { background: var(--accent-w); border-color: var(--accent); color: var(--accent); font-weight: 700; }
.sort-btn:disabled { opacity: .35; cursor: default; }

/* ── 에피소드 그룹 ── */
.ep-group { border-bottom: 1px solid var(--bd); }
.ep-group-header {
    display: flex; align-items: center; gap: 6px;
    padding: 9px 14px; cursor: pointer;
    background: var(--in);
    transition: background 100ms;
}
.ep-group-header:hover { background: var(--bd); }
.ep-group-name { flex: 1; font-size: 11px; font-weight: 700; color: var(--t2); line-height: 1.3; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ep-group-count { font-size: 10px; color: var(--t3); flex-shrink: 0; }
.ep-group-arrow { font-size: 12px; color: var(--t3); flex-shrink: 0; transition: transform 200ms; }
.ep-group-body { overflow: hidden; transition: height 200ms ease; }
.ep-group.open .ep-group-arrow { transform: rotate(180deg); }
.ep-group .place-item { border-bottom: 1px solid var(--bd); }
.ep-group .place-item:last-child { border-bottom: none; }

/* ── 공유 버튼 ── */
.share-btn {
    display: flex; align-items: center; justify-content: center; gap: 5px;
    width: 100%; height: 38px;
    border: 1px solid var(--bd); border-radius: 2px; background: none;
    color: var(--t3); font-family: inherit; font-size: 12px; font-weight: 600;
    cursor: pointer; margin-bottom: 8px;
    transition: border-color 140ms, color 140ms;
}
.share-btn:hover { border-color: var(--t2); color: var(--t2); }

/* 장소 목록 */
.place-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.place-list::-webkit-scrollbar { width: 4px; }
.place-list::-webkit-scrollbar-track { background: transparent; }
.place-list::-webkit-scrollbar-thumb { background: var(--bd); border-radius: 2px; }

.place-item {
    padding: 11px 14px;
    border-bottom: 1px solid var(--bd);
    cursor: pointer;
    transition: background 100ms;
}
.place-item:hover { background: var(--in); }
.place-item.active { background: var(--accent-w); border-left: 2px solid var(--accent); padding-left: 12px; }

.pi-name {
    font-size: 13px; font-weight: 700;
    color: var(--t1); line-height: 1.3;
    margin-bottom: 4px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pi-meta {
    display: flex; align-items: center; gap: 5px;
    font-size: 11px; color: var(--t3);
}
.pi-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.pi-region-cat { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pi-visited { color: #16a34a; font-weight: 700; font-size: 10px; flex-shrink: 0; }
.pi-ep {
    margin-top: 4px;
    font-size: 11px; color: var(--t3);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.place-list-empty {
    padding: 40px 16px;
    text-align: center;
    color: var(--t3);
    font-size: 13px;
}

/* ── 지도 ── */
#map { flex: 1; min-width: 0; min-height: 0; position: relative; }

/* ── FAB ── */
.fab-group {
    position: absolute; bottom: 20px; right: 14px; z-index: 150;
    display: flex; flex-direction: column; gap: 8px;
}
.fab {
    width: 44px; height: 44px; border-radius: 50%; border: none;
    background: var(--header);
    box-shadow: 0 2px 10px rgba(0,0,0,.30);
    font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; line-height: 1;
    transition: transform 120ms, opacity 120ms;
}
@media (hover: hover) { .fab:hover { opacity: .78; } }
.fab:active { transform: scale(.88); }
.fab.on { background: #166534; }

/* ── 모바일: 사이드바 → 2열 필터바 ── */
@media (max-width: 767px) {
    .layout { flex-direction: column; }

    .sidebar {
        width: 100%;
        flex-shrink: 0;
        border-right: none;
        border-bottom: 1px solid var(--bd);
        flex-direction: column;
        height: auto;
        overflow: visible;
    }

    /* 1열: 검색 행 (back+search 또는 search 단독) */
    .sidebar-row {
        display: flex;
        align-items: center;
        height: 50px;
        border-bottom: 1px solid var(--bd);
    }

    .sidebar-search {
        flex: 1; min-width: 0;
        border-bottom: none;
        border-right: none;
        padding: 8px 12px;
        height: 50px;
    }
    .search-input { height: 34px; font-size: 16px; }
    .search-btn   { height: 34px; }

    .sb-back {
        padding: 0 12px;
        border-bottom: none;
        border-right: 1px solid var(--bd);
        flex-shrink: 0;
        display: flex; align-items: center;
        height: 50px;
    }
    .back-btn { height: 32px; }

    /* 2열: 카테고리 탭 */
    .sidebar-tabs {
        width: 100%;
        border-bottom: none;
        height: 40px;
    }
    .fp { flex: 1; height: 40px; font-size: 12px; }

    .place-list   { display: none; }
    .region-filter{ display: none; }
    .sidebar-tools{ display: none; }

    #map { flex: 1; min-height: 0; }

    .visit-btn  { height: 48px; font-size: 14px; }
    .yt-btn     { height: 48px; font-size: 14px; }
    .share-btn  { height: 44px; font-size: 13px; }
    .card-body  { padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
    .card       { border-radius: 12px 12px 0 0; max-height: 92dvh; }
    .card-thumb { height: 180px; }
}

/* ── 오버레이 ── */
.overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.46); z-index: 200;
    align-items: flex-end; justify-content: center;
}
@media (min-width: 540px) { .overlay { align-items: center; } }
.overlay.show { display: flex; }

/* ── 팝업 카드 ── */
.card {
    background: var(--white);
    width: 100%; max-width: 440px;
    border-radius: 3px 3px 0 0;
    max-height: 88dvh;
    display: flex; flex-direction: column; overflow: hidden; position: relative;
    box-shadow: 0 -4px 24px rgba(0,0,0,.18);
}
.overlay.show .card { animation: slideUp 200ms ease; }
@keyframes slideUp {
    from { transform: translateY(14px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
@media (min-width: 540px) {
    .card { border-radius: 3px; max-height: 85dvh; width: calc(100% - 40px); }
    @keyframes slideUp {
        from { transform: scale(.97) translateY(5px); opacity: 0; }
        to   { transform: scale(1)   translateY(0);   opacity: 1; }
    }
}

.drag-handle {
    width: 32px; height: 3px; background: var(--bd); border-radius: 2px;
    position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 5;
}
@media (min-width: 540px) { .drag-handle { display: none; } }

.card-close {
    position: absolute; top: 10px; right: 10px;
    width: 26px; height: 26px;
    background: rgba(0,0,0,.28); border: none;
    color: #fff; font-size: 11px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; z-index: 5;
    transition: background 120ms;
}
.card-close:hover { background: rgba(0,0,0,.52); }

/* ── 이미지 ── */
.card-img-wrap { position: relative; flex-shrink: 0; }
.card-thumb { width: 100%; height: 196px; object-fit: cover; display: block; }
@media (max-width: 539px) { .card-thumb { height: 168px; } }

.card-thumb-empty {
    width: 100%; height: 96px;
    background: var(--accent-w);
    display: flex; align-items: center; justify-content: center;
    font-size: 38px;
}

.card-img-caption {
    position: absolute; bottom: 0; left: 0; right: 0;
    padding: 32px 16px 14px;
    background: linear-gradient(to top, rgba(0,0,0,.72) 0%, transparent 100%);
}
.card-img-wrap.no-img .card-img-caption { display: none; }

.img-chip {
    display: inline-flex; align-items: center; gap: 2px;
    background: var(--accent); color: #fff;
    font-size: 10px; font-weight: 700;
    padding: 2px 7px; border-radius: 1px;
    margin-bottom: 6px; width: fit-content;
    letter-spacing: 0.3px;
}
.img-name { font-size: 19px; font-weight: 900; color: #fff; letter-spacing: -0.5px; line-height: 1.25; }

/* ── 카드 바디 ── */
.card-body { padding: 16px 16px 24px; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.fb-chip { display: none; }
.cat-chip {
    display: inline-flex; align-items: center; gap: 2px;
    background: var(--accent-w); color: var(--accent);
    font-size: 10px; font-weight: 700;
    padding: 2px 7px; border-radius: 1px; margin-bottom: 7px;
    letter-spacing: 0.3px;
}
.fb-name { display: none; }
.place-name { font-size: 18px; font-weight: 900; letter-spacing: -0.5px; line-height: 1.3; margin-bottom: 10px; }

.episode-label { font-size: 12px; color: var(--t2); line-height: 1.75; margin-bottom: 8px; }
.menu-label { font-size: 13px; font-weight: 700; color: var(--t1); margin-bottom: 7px; }
.addr-label { font-size: 12px; color: var(--t3); line-height: 1.75; margin-bottom: 10px; }
.dist-label { font-size: 12px; font-weight: 700; color: #1d4ed8; margin-bottom: 10px; display: none; }
@media (prefers-color-scheme: dark) { .dist-label { color: #93c5fd; } }

.divider { border: none; border-top: 1px solid var(--bd); margin: 13px 0; }

.visit-btn {
    width: 100%; height: 42px;
    display: flex; align-items: center; justify-content: center; gap: 5px;
    border: 1px solid var(--bd); border-radius: 2px; background: none;
    color: var(--t2); font-family: inherit; font-size: 13px; font-weight: 700;
    cursor: pointer; margin-bottom: 8px;
    transition: border-color 140ms, color 140ms, background 140ms;
}
.visit-btn:hover { border-color: var(--t1); color: var(--t1); }
.visit-btn.visited { border-color: #16a34a; color: #16a34a; background: #f0fdf4; }
@media (prefers-color-scheme: dark) {
    .visit-btn.visited { background: #052e16; border-color: #16a34a; color: #4ade80; }
}
.visit-count { font-size: 11px; color: var(--t3); text-align: center; margin-bottom: 10px; }

.yt-btn {
    height: 44px;
    display: flex; align-items: center; justify-content: center; gap: 7px;
    background: var(--accent); color: #fff;
    text-decoration: none; border-radius: 2px;
    font-size: 13px; font-weight: 700; letter-spacing: -0.1px;
    transition: background 120ms;
}
.yt-btn:hover  { background: var(--accent-d); }
.yt-btn:active { opacity: .9; }

/* ── 토스트 ── */
.toast {
    position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(12px);
    background: var(--t1); color: var(--bg);
    font-size: 13px; font-weight: 500;
    padding: 10px 18px; border-radius: 3px;
    box-shadow: 0 4px 14px rgba(0,0,0,.22);
    opacity: 0; pointer-events: none; z-index: 500;
    transition: opacity 180ms, transform 180ms;
    white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── 풋터 ── */
footer {
    flex-shrink: 0;
    background: var(--header);
    border-top: 1px solid rgba(255,255,255,.07);
    padding: 12px 16px;
    text-align: center;
}
.footer-ch {
    display: inline-flex; align-items: center; gap: 5px;
    color: var(--accent); font-size: 12px; font-weight: 700;
    text-decoration: none;
    border-bottom: 1px solid var(--accent);
    padding-bottom: 1px; margin-bottom: 8px;
    transition: opacity 150ms;
}
.footer-ch:hover { opacity: .72; }
.footer-note {
    font-size: 11px;
    color: rgba(255,255,255,.28);
    line-height: 1.9;
}
.footer-note a {
    color: rgba(255,255,255,.42);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.footer-note a:hover { color: var(--accent); }
.footer-toggle {
    background: none; border: none; cursor: pointer;
    font-size: 11px; color: rgba(255,255,255,.28); font-family: inherit;
    padding: 0; display: inline-flex; align-items: center; gap: 3px;
    transition: color 120ms;
}
.footer-toggle:hover { color: rgba(255,255,255,.5); }
.footer-detail {
    overflow: hidden; max-height: 0;
    transition: max-height 220ms ease;
}
.footer-detail.open { max-height: 40px; }

/* ── 댓글 ── */
.comment-section {
    margin-top: 14px;
    border-top: 1px solid var(--bd);
    padding-top: 13px;
}
.comment-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 9px;
}
.comment-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--t2);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    flex: 1;
}
.comment-count {
    font-size: 11px;
    color: var(--t3);
}
.comment-list {
    max-height: 200px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 10px;
    -webkit-overflow-scrolling: touch;
}
.comment-list::-webkit-scrollbar { width: 3px; }
.comment-list::-webkit-scrollbar-track { background: transparent; }
.comment-list::-webkit-scrollbar-thumb { background: var(--bd); border-radius: 2px; }
.comment-loading,
.comment-empty {
    font-size: 12px;
    color: var(--t3);
    text-align: center;
    padding: 10px 0;
}
.comment-item {
    background: var(--in);
    border-left: 2px solid var(--bd);
    padding: 8px 10px;
    transition: border-color 120ms;
}
.comment-item:hover { border-left-color: var(--accent); }
.comment-meta {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 3px;
}
.comment-nick {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    flex-shrink: 0;
}
.comment-date {
    font-size: 10px;
    color: var(--t3);
    flex: 1;
}
.comment-actions { display: flex; gap: 2px; flex-shrink: 0; }
.comment-act-btn {
    background: none;
    border: none;
    font-size: 10px;
    color: var(--t3);
    cursor: pointer;
    padding: 2px 4px;
    font-family: inherit;
    transition: color 120ms;
    line-height: 1;
}
.comment-act-btn:hover { color: var(--t1); }
.comment-content {
    font-size: 12px;
    color: var(--t2);
    line-height: 1.6;
    word-break: break-all;
}
.comment-form { display: flex; flex-direction: column; gap: 6px; }
.comment-form-row { display: flex; gap: 6px; }
.comment-input {
    background: var(--in);
    border: 1px solid var(--bd);
    border-radius: 2px;
    color: var(--t1);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    transition: border-color 120ms;
    padding: 7px 9px;
    width: 100%;
    resize: none;
    -webkit-appearance: none;
}
.comment-input::placeholder { color: var(--t3); }
.comment-input:focus { border-color: var(--accent); }
.comment-form-row .comment-input:first-child { flex: 1.4; }
.comment-form-row .comment-input:last-child  { flex: 1; }
.comment-submit {
    height: 38px;
    background: none;
    border: 1px solid var(--bd);
    border-radius: 2px;
    color: var(--t2);
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: border-color 130ms, color 130ms, background 130ms;
    letter-spacing: -0.1px;
}
.comment-submit:hover { border-color: var(--accent); color: var(--accent); }
.comment-submit:disabled { opacity: .4; cursor: default; }
@media (max-width: 767px) {
    .comment-list { max-height: 160px; }
    .comment-act-btn { padding: 4px 6px; }
}
