/* ดีไซน์หลักของ index / reviews / 365-recon (หน้า secondhand ใช้ไฟล์ของตัวเอง) */

@view-transition {
    navigation: auto;
}

:root {
    color-scheme: light;
    --bg: #f4f4f5;
    --bg-dot: rgba(24, 24, 27, .09);
    --surface: #fff;
    --surface-2: #ececee;
    --ink: #111114;
    --ink-2: #55555d;
    --ink-3: #8a8a93;
    --line: rgba(17, 17, 20, .1);
    --bar: rgba(244, 244, 245, .94);
    --shadow: 0 1px 2px rgba(17, 17, 20, .05), 0 8px 24px rgba(17, 17, 20, .05);
    --shadow-lift: 0 2px 4px rgba(17, 17, 20, .06), 0 18px 40px rgba(17, 17, 20, .12);
    --accent: #111114;
    --on-accent: #fff;
    --red: #dc2626;
    --line-green: #06c755;
    --shopee: #ee4d2d;
    --gutter: 16px;
    --font-ui: 'Prompt', system-ui, sans-serif;
    --font-text: 'Sarabun', 'Prompt', system-ui, sans-serif;
    --font-fight: 'Oswald', 'Prompt', sans-serif;
    --ease-out: cubic-bezier(.16, 1, .3, 1);
    --ease-in: cubic-bezier(.4, 0, 1, 1);
    --spring: cubic-bezier(.34, 1.4, .64, 1);
    --spring-soft: cubic-bezier(.22, 1.1, .36, 1);
}

@supports (transition-timing-function: linear(0, 1)) {
    :root {
        --spring: linear(0, .006, .025 2.8%, .101 6.1%, .539 18.9%, .721 25.3%, .849 31.5%, .937 38.1%, .968 41.8%, .991 45.7%, 1.006 50.1%, 1.015 55%, 1.017 63.9%, 1.001 85.9%, 1);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #09090b;
    --bg-dot: rgba(255, 255, 255, .07);
    --surface: #17171a;
    --surface-2: #232327;
    --ink: #f5f5f6;
    --ink-2: #b0b0b8;
    --ink-3: #7c7c85;
    --line: rgba(255, 255, 255, .1);
    --bar: rgba(9, 9, 11, .92);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lift: 0 18px 40px rgba(0, 0, 0, .55);
    --accent: #f5f5f6;
    --on-accent: #09090b;
}

:root[data-platform="shopee"],
[data-platform="shopee"] {
    --accent: var(--shopee);
    --on-accent: #fff;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    scrollbar-gutter: stable;
}

html.is-locked {
    overflow: hidden;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-ui);
    line-height: 1.5;
    overflow-x: clip;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ol {
    margin: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    touch-action: manipulation;
}

img, video, iframe {
    display: block;
    max-width: 100%;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.icon {
    display: inline-block;
    flex: none;
    width: 1.25em;
    height: 1em;
    fill: currentColor;
    vertical-align: -.125em;
}

/* ---------- ปุ่มพื้นฐาน ---------- */
.icon-btn {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink);
    font-size: 13px;
    font-weight: 600;
    transition: transform .4s var(--spring), background-color .2s;
}

.icon-btn:active {
    transform: scale(.88);
    transition-duration: .1s;
}

@media (hover: hover) {
    .icon-btn:hover {
        background: var(--surface-2);
    }
}

.icon-btn--line {
    background: var(--line-green);
    border-color: transparent;
    color: #fff;
    font-size: 17px;
}

.icon-btn--line span {
    display: none;
    font-size: 13px;
}

@media (hover: hover) {
    .icon-btn--line:hover {
        background: #05b34c;
    }
}

@media (min-width: 640px) {
    .icon-btn--line {
        width: auto;
        padding: 0 14px;
    }

    .icon-btn--line span {
        display: inline;
    }
}

.theme-sun {
    display: none;
}

[data-theme="dark"] .theme-sun {
    display: inline-block;
}

[data-theme="dark"] .theme-moon {
    display: none;
}

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    min-height: 52px;
    padding: 12px 22px;
    border-radius: 16px;
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
    transition: transform .4s var(--spring), opacity .2s;
}

.btn-primary:active {
    transform: scale(.97);
    transition-duration: .1s;
}

@media (hover: hover) {
    .btn-primary:hover {
        opacity: .88;
    }
}

/* ---------- แถบด้านบน ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 60px;
    padding: 0 var(--gutter);
    background: var(--bar);
}

.topbar-end {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand {
    display: none;
    margin-left: 4px;
    font-weight: 800;
    font-size: 16px;
    letter-spacing: -.01em;
}

@media (min-width: 480px) {
    .brand {
        display: block;
    }
}

/* ---------- ตัวสลับ 2 ทางแบบมีแถบเลื่อน ---------- */
.segment {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 3px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line);
}

.segment::before {
    content: "";
    position: absolute;
    top: 3px;
    bottom: 3px;
    left: 3px;
    width: calc(50% - 3px);
    border-radius: 999px;
    background: var(--accent);
    transition: transform .5s var(--spring), background-color .25s;
}

.segment[data-value="2"]::before {
    transform: translateX(100%);
}

.segment button {
    position: relative;
    height: 32px;
    min-width: 38px;
    padding: 0 8px;
    border-radius: 999px;
    color: var(--ink-3);
    font-size: 13px;
    font-weight: 600;
    transition: color .25s;
}

.segment button[aria-pressed="true"] {
    color: var(--on-accent);
}

/* ---------- หน้าต่างลอย ---------- */
.dlg {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--ink);
    overflow: hidden;
}

.dlg[open] {
    display: flex;
}

.dlg::backdrop {
    background: transparent;
}

.scrim {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    opacity: 0;
    transition: opacity .3s ease;
}

.dlg.is-open .scrim {
    opacity: 1;
}

.panel {
    position: relative;
    outline: none;
    background: var(--surface);
}

/* แบบเด้งออกจากจุดที่กด */
.dlg--pop {
    align-items: center;
    justify-content: center;
    padding: var(--gutter);
}

.dlg--pop .panel {
    width: 100%;
    max-width: 380px;
    max-height: 100%;
    border-radius: 24px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: scale(.55);
    transition: transform .22s var(--ease-in), opacity .18s ease;
}

.dlg--pop.is-open .panel {
    opacity: 1;
    transform: none;
    transition: transform .52s var(--spring), opacity .16s ease;
}

.pop-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 16px 8px 20px;
}

.pop-head h3 {
    font-size: 17px;
    font-weight: 600;
}

.pop-head .icon-btn {
    width: 36px;
    height: 36px;
    background: var(--surface-2);
    border: 0;
}

.pop-body {
    padding: 4px 20px 20px;
    overflow-y: auto;
    font-family: var(--font-text);
    font-size: 15px;
    line-height: 1.7;
    color: var(--ink-2);
}

/* แบบแผ่นเลื่อนจากด้านล่าง */
.dlg--sheet {
    align-items: flex-end;
    justify-content: center;
}

.dlg--sheet .panel {
    width: 100%;
    height: calc(100% - 28px);
    border-radius: 28px 28px 0 0;
    overflow: hidden;
    transform: translateY(102%);
    transition: transform .28s var(--ease-in);
    will-change: transform;
}

.dlg--sheet.is-open .panel {
    transform: none;
    transition: transform .55s var(--spring);
}

.dlg--sheet.is-measuring .panel {
    transform: none;
    transition: none;
}

.sheet-handle {
    position: absolute;
    z-index: 6;
    top: 0;
    left: 0;
    right: 64px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 10px 0 0 64px;
    touch-action: none;
    cursor: grab;
}

.sheet-handle span {
    width: 44px;
    height: 5px;
    border-radius: 99px;
    background: rgba(255, 255, 255, .85);
    box-shadow: 0 0 4px rgba(0, 0, 0, .35);
}

@media (min-width: 900px) {
    .dlg--sheet {
        align-items: center;
        padding: 24px;
    }

    .dlg--sheet .panel {
        height: auto;
        border-radius: 28px;
        transform: translateY(26px) scale(.97);
        opacity: 0;
        transition: transform .24s var(--ease-in), opacity .2s ease;
    }

    .dlg--sheet.is-open .panel {
        opacity: 1;
        transition: transform .55s var(--spring), opacity .2s ease;
    }

    .sheet-handle {
        display: none;
    }
}

/* ---------- สถานะว่าง/ผิดพลาด ---------- */
.notice {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 64px 16px;
    text-align: center;
    color: var(--ink-3);
    font-size: 15px;
    animation: rise .5s var(--ease-out) both;
}

.notice .btn-primary {
    width: auto;
    min-height: 44px;
    border-radius: 999px;
    font-size: 14px;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
}

/* ---------- เปลี่ยนธีม/ภาษา ---------- */
html[data-vt="theme"]::view-transition-old(root),
html[data-vt="theme"]::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}

html[data-vt="theme"]::view-transition-old(root) {
    z-index: 1;
}

html[data-vt="theme"]::view-transition-new(root) {
    z-index: 2;
}

::view-transition-group(root) {
    animation-duration: .24s;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        animation-delay: 0ms !important;
        transition-duration: .01ms !important;
    }
}
