/*
Theme Name: Ride
Description: Photoblog เบาๆ สำหรับมือถือ: ไม่มีฟอนต์/ไอคอนจากภายนอก, masonry, โหลดเมื่อใกล้เห็น
Author: iannnnn
Version: 1.7.2
*/

:root {
    --bg: #fff;
    --fg: #222;
    --muted: #7a7f87;
    --line: #ececec;
    --card: #f3f3f3;
    --accent: #111;
    --on-accent: #fff;
    --danger: #c62828;
    --gap: 12px;
    color-scheme: light;
}

/* โหมดมืด: ตามเครื่อง ยกเว้นผู้ใช้กดเลือกเองด้วยปุ่มสลับ (data-theme) */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #121212;
        --fg: #e8e8e8;
        --muted: #9a9ea6;
        --line: #2a2a2a;
        --card: #1d1d1d;
        --accent: #f2f2f2;
        --on-accent: #111;
        --danger: #ef5350;
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #121212;
    --fg: #e8e8e8;
    --muted: #9a9ea6;
    --line: #2a2a2a;
    --card: #1d1d1d;
    --accent: #f2f2f2;
    --on-accent: #111;
    --danger: #ef5350;
    color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Sukhumvit Set", "Leelawadee UI", Tahoma, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--fg);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
img { display: block; max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Icons */
.i {
    width: 20px; height: 20px; flex: none;
    fill: none; stroke: currentColor; stroke-width: 2;
    stroke-linecap: round; stroke-linejoin: round;
}

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    min-height: 40px; padding: 0 .9rem;
    border: 1px solid var(--line); border-radius: 999px;
    background: var(--bg); color: inherit;
    font: inherit; font-size: .9rem; font-weight: 600;
    text-decoration: none; cursor: pointer;
    list-style: none;
}
.btn::-webkit-details-marker { display: none; }
.btn:hover { background: var(--card); }
.btn.icon { width: 40px; padding: 0; border-color: transparent; background: transparent; }
.btn.icon:hover { background: var(--card); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; min-height: 48px; font-size: 1rem; }
.btn:disabled { opacity: .5; cursor: default; }

.bar { display: flex; align-items: center; gap: .25rem; padding: .5rem; }
.sp { flex: 1; }

/* ปุ่มสลับโหมด: โชว์พระจันทร์ตอนสว่าง พระอาทิตย์ตอนมืด */
.theme-toggle .t-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .t-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .t-moon { display: none; }
.no-js .theme-toggle, .no-js .play-btn { display: none; }

/* Header */
.top {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: .25rem;
    padding: .5rem .5rem .5rem 1rem;
    padding-top: max(.5rem, env(safe-area-inset-top));
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}
.brand { flex: 1; font-size: 1.15rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand a { text-decoration: none; }

.filter-form {
    position: absolute; left: 0; right: 0; top: 100%;
    display: grid; grid-template-columns: 1fr 1fr; gap: .5rem;
    padding: .75rem 1rem 1rem;
    background: var(--bg); border-bottom: 1px solid var(--line);
}
.filter-form input, .filter-form select {
    min-height: 44px; padding: 0 .75rem;
    border: 1px solid var(--line); border-radius: 10px;
    background: var(--bg); color: inherit; font: inherit;
}
.filter-form input, .filter-form button { grid-column: 1 / -1; }
.filters[open] > summary { background: var(--card); }

.active-filter { padding: .75rem 1rem 0; color: var(--muted); font-size: .9rem; }
.active-filter a { margin-left: .5rem; color: var(--fg); }

/* Grid: ไม่มี JS ใช้ CSS columns, มี JS จัดเป็น masonry เรียงซ้ายไปขวา */
.grid { --cols: 2; column-count: var(--cols); column-gap: var(--gap); padding: var(--gap); }
.grid.masonry { display: flex; align-items: flex-start; gap: var(--gap); column-count: auto; }
.col { flex: 1 1 0; min-width: 0; }

.card { break-inside: avoid; margin-bottom: calc(var(--gap) * 1.75); }
.card-link { display: block; text-decoration: none; }
.media { position: relative; display: block; border-radius: 6px; overflow: hidden; background: var(--card); }
.media img { width: 100%; height: auto; }
.card-link:hover img { opacity: .9; }
.no-js img.lazy { display: none; }
img.lazy { opacity: 0; transition: opacity .25s; }
img.lazy.loaded { opacity: 1; }

.count {
    position: absolute; top: 6px; right: 6px;
    display: inline-flex; align-items: center; gap: 3px;
    padding: 2px 7px; border-radius: 999px;
    background: rgba(0, 0, 0, .55); color: #fff;
    font-size: .75rem; font-weight: 600;
}
.count .i { width: 13px; height: 13px; }

.info { display: block; padding: .4rem .15rem 0; }
.info time { display: block; color: var(--muted); font-size: .8rem; }
.info .text {
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3;
    overflow: hidden; font-size: .9rem; color: var(--fg);
}

/* โพสต์ล่าสุด (หน้าแรก): มือถือเป็นรูปใหญ่เต็มกว้าง, จอคอมแบ่งครึ่ง ซ้ายชื่อเว็บ + วันที่/แคปชัน ขวารูป */
.latest { padding: 1rem var(--gap) 0; }
.hero-title { display: none; }
.lead .media { width: fit-content; max-width: 100%; border-radius: 10px; }
.lead .media img { width: auto; max-width: 100%; max-height: 78vh; }
.lead .info { padding: .75rem .1rem 0; }
.lead time { font-size: .85rem; }
.lead .text { margin-top: .2rem; font-size: 1.2rem; line-height: 1.5; font-weight: 500; }
.latest + .grid { margin-top: 1.75rem; padding-top: calc(var(--gap) + 1rem); border-top: 1px solid var(--line); }
@media (min-width: 900px) {
    .latest {
        display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr; column-gap: 3rem;
        padding: 2.5rem clamp(1.5rem, 4vw, 4rem) 0;
    }
    /* ชื่อเว็บใหญ่บนหน้านี้แล้ว ซ่อนตัวเล็กบนแถบหัว (ยังอ่านได้ด้วย screen reader) */
    body:has(.latest) .top .brand a { opacity: 0; }
    .hero-title {
        display: block; grid-column: 1; grid-row: 1;
        /* --len = ส่วนที่ยาวที่สุดของชื่อ ย่อให้พอดีคอลัมน์ ไม่ตัดกลางคำ */
        font-size: clamp(2.5rem, min(8vw, (46vw - 1.5rem) / (var(--len, 4) * .6)), 9rem); font-weight: 800; line-height: .95; letter-spacing: -.035em;
        overflow-wrap: anywhere;
    }
    .lead, .lead .card-link { display: contents; }
    .lead .media { grid-column: 2; grid-row: 1 / 3; justify-self: end; align-self: start; }
    .lead .media img { max-height: calc(100vh - 8rem); }
    .lead .info { grid-column: 1; grid-row: 2; align-self: end; max-width: 30rem; padding: 2rem 0 .25rem; }
    .lead time { font-size: .95rem; }
    .lead .text { font-size: 1.5rem; line-height: 1.45; -webkit-line-clamp: 4; line-clamp: 4; }
    .lead .card-link:hover img { opacity: .92; }
    .lead .card-link:focus-visible { outline: none; }
    .lead .card-link:focus-visible .media { outline: 2px solid var(--accent); outline-offset: 3px; }
    .latest + .grid { margin-top: 3rem; }
}

/* หน้าโพสต์: ซ่อนหน้าธรรมดาระหว่างเปิดสไลด์โชว์ (app.js เอา class ออกถ้าโหลดไม่สำเร็จ) */
.rs-boot body { background: #0f0f10; }
.rs-boot body > header, .rs-boot body > main { visibility: hidden; }

.more { display: flex; width: max-content; margin: 1rem auto 2.5rem; }
.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }

@media (min-width: 700px)  { .grid { --cols: 3; } :root { --gap: 20px; } }
@media (min-width: 1000px) { .grid { --cols: 4; } }
@media (min-width: 1300px) { .grid { --cols: 5; } }
@media (min-width: 1700px) { .grid { --cols: 6; } }

/* Post view (single + popup) */
.gallery-wrap { position: relative; }
.gallery {
    display: flex; overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory; scrollbar-width: none;
    height: min(72dvh, 125vw);
}
.gallery::-webkit-scrollbar { display: none; }
.gallery > img, .gallery > noscript img {
    flex: 0 0 100%; width: 100%; height: 100%;
    object-fit: contain; scroll-snap-align: center;
}
.g-btn {
    position: absolute; top: 50%; transform: translateY(-50%);
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%;
    background: var(--bg); color: var(--fg); cursor: pointer;
}
.g-prev { left: 12px; }
.g-next { right: 12px; }
.g-count {
    position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
    padding: 1px 8px; border-radius: 999px;
    background: rgba(0, 0, 0, .55); color: #fff; font-size: .75rem;
}
@media (hover: none) { .g-btn { display: none; } }
.no-js .g-btn, .no-js .g-count { display: none; }

.caption { max-width: 40rem; margin: 0 auto; padding: 1rem; }
.caption time { color: var(--muted); font-size: .9rem; }
.caption .text { margin-top: .25rem; line-height: 1.65; }
.caption .text p + p { margin-top: .6rem; }
.caption-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; min-height: 40px; }

/* เมนู ⋯ แก้ไข/ลบ */
.post-menu { position: relative; }
.post-menu > summary { color: var(--muted); }
.post-menu .menu {
    position: absolute; right: 0; top: 100%; z-index: 5;
    min-width: 160px; padding: .35rem; margin-top: 4px;
    border: 1px solid var(--line); border-radius: 12px;
    background: var(--bg); box-shadow: 0 10px 30px rgba(0, 0, 0, .15);
}
.post-menu .menu a, .post-menu .menu button {
    display: flex; align-items: center; gap: .6rem; width: 100%;
    padding: .6rem .75rem; border: 0; border-radius: 8px;
    background: none; color: inherit; font: inherit; font-size: .9rem; text-align: left; text-decoration: none; cursor: pointer;
}
.post-menu .menu a:hover, .post-menu .menu button:hover { background: var(--card); }
.post-menu .menu .danger { color: var(--danger); }
.post-menu .menu .i { width: 18px; height: 18px; }

.post-nav {
    display: flex; justify-content: space-between; gap: .5rem;
    padding: .5rem 1rem calc(.75rem + env(safe-area-inset-bottom));
}

/* New post */
.compose { max-width: 32rem; margin: 0 auto; padding: 0 1rem 2rem; }
.compose .bar { padding: .75rem 0; }
.compose h1 { font-size: 1.2rem; }
.drop {
    position: relative; display: flex; flex-direction: column; align-items: center; gap: .5rem;
    padding: 2.5rem 1rem; border: 2px dashed var(--line); border-radius: 12px;
    color: var(--muted); text-align: center; cursor: pointer;
}
.drop .i { width: 32px; height: 32px; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.previews { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: .75rem 0 0; list-style: none; }
.previews li { position: relative; aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: var(--card); }
.previews img { width: 100%; height: 100%; object-fit: cover; }
.previews progress { position: absolute; left: 4px; right: 4px; bottom: 4px; width: calc(100% - 8px); height: 4px; }
.previews li.done::after, .previews li.error::after {
    position: absolute; top: 4px; right: 4px; padding: 0 6px; border-radius: 999px;
    color: #fff; font-size: .7rem; font-weight: 700;
}
.previews li.done::after { content: "✓"; background: #2e7d32; }
.previews li.error::after { content: "!"; background: var(--danger); }
.opt { display: flex; align-items: center; gap: .5rem; margin: 1rem 0; color: var(--muted); font-size: .85rem; }
.opt input { width: 18px; height: 18px; accent-color: var(--accent); }
.compose textarea {
    width: 100%; margin-bottom: 1rem; padding: .75rem;
    border: 1px solid var(--line); border-radius: 10px;
    background: var(--bg); color: inherit; font: inherit; resize: vertical;
}
.status { min-height: 1.5em; margin-top: .75rem; color: var(--muted); font-size: .9rem; text-align: center; }
.status.error { color: var(--danger); }
