:root {
    color-scheme: light dark;
    --bg: #f3f6fb;
    --surface: #ffffff;
    --surface-2: #e9f0fa;
    --line: #d7e1ef;
    --text: #12233f;
    --muted: #5b6d88;
    --brand: #0a6fc2;
    --brand-strong: #075a9f;
    --on-brand: #ffffff;
    --bubble-mine: #0a6fc2;
    --chat-bg: #ffffff;
    --on-mine: #ffffff;
    --ok: #137a4b;
    --ok-bg: #dcf5e8;
    --danger: #c0303f;
    --danger-bg: #fde6e8;
    --online: #1fb36b;
    --radius: 14px;
    --sidebar: 240px;
    --tabbar: 62px;
    font-family: "IBM Plex Sans Thai", "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1a33;
        --surface: #12264a;
        --surface-2: #1a3360;
        --line: #264270;
        --text: #eaf1fb;
        --muted: #a0b3cf;
        --brand: #3aa0ee;
        --brand-strong: #6bbaf5;
        --on-brand: #06213d;
        --bubble-mine: #1774c4;
        --on-mine: #ffffff;
        --ok: #7fe3b0;
        --ok-bg: #123f30;
        --danger: #ff8f9a;
        --danger-bg: #47202a;
    }
}

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.55;
}

h1, h2, p { margin: 0; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sprite { position: absolute; }
.icon { width: 22px; height: 22px; flex: none; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error-text { color: var(--danger); }
[hidden] { display: none !important; }

.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
}
.brand img { width: 34px; height: 30px; object-fit: contain; }

/* โครงหน้า */
.page {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    padding: 20px 16px;
}
.has-nav .page { padding-bottom: calc(var(--tabbar) + 24px + env(safe-area-inset-bottom)); }

.sidebar { display: none; }

.tabbar {
    position: fixed;
    inset: auto 0 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    height: calc(var(--tabbar) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--line);
}
.tabbar a {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--muted);
    font-size: 12px;
}
.tabbar a:hover { text-decoration: none; }
.tabbar a[aria-current] { color: var(--brand); font-weight: 600; }
.tabbar .badge { position: absolute; top: 6px; left: calc(50% + 6px); }

.badge {
    display: inline-block;
    min-width: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--danger);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    line-height: 20px;
    text-align: center;
}

@media (min-width: 900px) {
    .has-nav { padding-left: var(--sidebar); }
    .has-nav .page { padding: 28px 32px; }
    .tabbar { display: none; }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        display: flex;
        flex-direction: column;
        gap: 24px;
        width: var(--sidebar);
        padding: 22px 14px;
        background: var(--surface);
        border-right: 1px solid var(--line);
    }
    .sidebar .brand { padding: 0 10px; }
    .sidebar nav { display: flex; flex-direction: column; gap: 4px; }
    .sidebar nav a, .sidebar-foot a {
        display: flex;
        align-items: center;
        gap: 12px;
        min-height: 44px;
        padding: 8px 10px;
        border-radius: 10px;
        color: var(--text);
    }
    .sidebar nav a:hover, .sidebar-foot a:hover { background: var(--surface-2); text-decoration: none; }
    .sidebar nav a[aria-current] { background: var(--surface-2); color: var(--brand); font-weight: 600; }
    .sidebar nav .badge { margin-left: auto; }
    .sidebar-foot { display: flex; flex-direction: column; gap: 4px; margin-top: auto; }
    .sidebar-foot span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .mode-link { color: var(--muted) !important; font-size: 14px; }
}

/* ส่วนประกอบพื้นฐาน */
.page-title { font-size: 26px; line-height: 1.3; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

section { display: flex; flex-direction: column; gap: 12px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; }
.section-head h2 { font-size: 18px; }

.panel {
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.note { font-size: 14px; }
.empty {
    padding: 28px 16px;
    background: var(--surface);
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    color: var(--muted);
    text-align: center;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 46px;
    padding: 8px 20px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: var(--brand);
    color: var(--on-brand);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.button:hover { background: var(--brand-strong); text-decoration: none; }
.button.small { min-height: 38px; padding: 6px 14px; font-size: 14px; }
.button.small .icon { width: 18px; height: 18px; }
.button.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.button.ghost:hover { background: var(--surface-2); }
.button.danger { color: var(--danger); }

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text);
    cursor: pointer;
}
.icon-button:hover { background: var(--surface-2); }
.icon-button.primary { background: var(--brand); color: var(--on-brand); }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 4px 12px;
    border: 1px solid var(--line);
    border-radius: 17px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}
.chip:hover { background: var(--surface-2); text-decoration: none; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--online); }

.actions { display: flex; align-items: center; gap: 8px; flex-direction: row; }
.actions.wrap, .settings-foot { flex-wrap: wrap; flex-direction: row; }

.flash { padding: 12px 16px; border-radius: 12px; font-weight: 500; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--danger-bg); color: var(--danger); }

/* ฟอร์ม */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label, .form fieldset { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 15px; }
.form small { color: var(--muted); font-weight: 400; font-size: 13px; }
.form input:not([type="radio"], [type="checkbox"]), .form textarea, .form select,
.composer input, .image-panel input, .bet-fields input {
    width: 100%;
    min-height: 46px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-size: 16px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .choices { flex-direction: row; flex-wrap: wrap; gap: 18px; padding: 0; border: 0; }
.form .choices legend { padding: 0; margin-bottom: 5px; }
.form .choices label { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.form .check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.trap { position: absolute; left: -9999px; }

.auth-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 420px;
    margin: 4vh auto;
    padding: 24px 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
}
.auth-card h1 { font-size: 24px; }
.detail { overflow: auto; font-size: 13px; text-align: left; }

/* หน้าต้อนรับ */
.landing { gap: 32px; }
.landing-top { display: flex; align-items: center; justify-content: space-between; }
.hero { display: flex; flex-direction: column; gap: 14px; padding: 16px 0; }
.hero h1 { font-size: clamp(30px, 8vw, 44px); line-height: 1.25; }
.hero p { max-width: 520px; color: var(--muted); font-size: 17px; }
.hero .actions { flex-wrap: wrap; margin-top: 8px; }
.feature-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.feature-list li {
    display: flex;
    gap: 14px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.feature-list .icon { color: var(--brand); }
.feature-list div { display: flex; flex-direction: column; }
.feature-list span { color: var(--muted); font-size: 14px; }
.landing-foot { color: var(--muted); font-size: 14px; text-align: center; }

/* โปรไฟล์และสถิติ */
.avatar { width: 44px; height: 44px; flex: none; border-radius: 50%; object-fit: cover; background: var(--surface-2); }
.avatar.sm { width: 30px; height: 30px; }
.avatar.md { width: 52px; height: 52px; }
.avatar.lg { width: 84px; height: 84px; }
.avatar-wrap { position: relative; display: inline-flex; flex: none; }
.avatar-wrap .dot { position: absolute; right: 1px; bottom: 1px; width: 12px; height: 12px; border: 2px solid var(--surface); box-sizing: content-box; }
.name-icon { max-height: 18px; vertical-align: -3px; }

.profile-card {
    position: relative;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
}
.profile-card > .icon-button { position: absolute; top: 8px; right: 8px; }
.back-link { display: inline-flex; align-items: center; gap: 4px; align-self: flex-start; min-height: 44px; margin: -10px 0 -14px -6px; padding-right: 12px; color: var(--text); font-weight: 600; }
.profile-main { flex: 1; min-width: 0; }
.profile-main h1 { font-size: 21px; line-height: 1.3; overflow-wrap: anywhere; }
.profile-main .muted { font-size: 14px; }
.level { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 14px; }
.level progress {
    flex: 1;
    min-width: 40px;
    height: 8px;
    overflow: hidden;
    border: 0;
    border-radius: 4px;
    background: var(--surface-2);
    accent-color: var(--brand);
    appearance: none;
}
.level progress::-webkit-progress-bar { background: var(--surface-2); }
.level progress::-webkit-progress-value { background: var(--brand); }
.level progress::-moz-progress-bar { background: var(--brand); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stats.three { grid-template-columns: repeat(3, 1fr); }
.stats div {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.stats span { font-size: 13px; }
.stats b { font-size: 17px; overflow-wrap: anywhere; }
@media (min-width: 600px) { .stats:not(.three) { grid-template-columns: repeat(4, 1fr); } }

.notices { gap: 8px; }
.notices a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--surface-2);
    border-radius: 12px;
    color: var(--text);
    font-weight: 500;
}

.room-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 600px) { .room-grid { grid-template-columns: repeat(3, 1fr); } }
.room {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
}
.room:hover { border-color: var(--brand); text-decoration: none; }
.room span { font-size: 13px; }

.shortcuts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.shortcuts a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 4px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    text-align: center;
}
.shortcuts a:hover { border-color: var(--brand); text-decoration: none; }
.shortcuts .icon { color: var(--brand); }

/* รายการ */
.list {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    overflow: hidden;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.row { display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row.unread b:first-child { font-weight: 700; }
.row.unread { background: var(--surface-2); }
.row-main { display: flex; align-items: center; flex: 1; gap: 12px; min-width: 0; color: var(--text); }
.row-main:hover { text-decoration: none; }
.row-text { display: flex; flex-direction: column; min-width: 0; }
.row-text b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.row .push { margin-left: auto; }
.row-between { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.rank { width: 26px; flex: none; color: var(--muted); font-weight: 700; text-align: center; }
.ranking li:nth-child(-n + 3) .rank { color: var(--brand); }

.tabs { display: flex; gap: 8px; }
.tabs a {
    padding: 7px 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
    color: var(--text);
    font-size: 14px;
}
.tabs a[aria-current] { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }

.pager { display: flex; align-items: center; justify-content: center; gap: 16px; }
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.mail { display: flex; flex-direction: column; gap: 10px; }
.mail h1 { font-size: 20px; overflow-wrap: anywhere; }
.mail-body { overflow-wrap: anywhere; }
.balance b { color: var(--brand); font-size: 20px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.about { margin-top: 12px; overflow-wrap: anywhere; }

