/* site.css — ThaiSignLSTM
 * ดีไซน์ mobile-first : โทนฟ้า-เทอร์ควอยซ์ / ครีม / ส้ม (ต่อยอดจากธีมเดิมใน Figma)
 * โครงหน้าจอแบบแอปมือถือ : แถบหัว → กล้อง → แผงเนื้อหาเลื่อนได้ → แถบแท็บล่าง
 */
:root {
    /* พื้นหลัง/ตัวอักษร */
    --bg: #f4f7fb;
    --surface: #ffffff;
    --ink: #0f1b2d;
    --muted: #64748b;

    /* แบรนด์ */
    --brand: #0ea5b7;
    --brand-2: #22d3ee;
    --brand-deep: #00599f;
    --header-from: #0ea5b7;
    --header-to: #4cd6e8;

    /* การ์ด/แผง */
    --panel: #fff8ef;
    --panel-border: #f6e3cd;
    --line: #e6edf5;

    /* กล่องคำที่แปลได้ */
    --word-bg: #1f2f42;
    --word-bg-2: #2c4257;
    --word-thai: #ffd98a;
    --word-sub: #a9b6c5;
    --confbar-bg: rgba(255,255,255,.14);

    /* สถานะ */
    --ok: #22c55e;
    --warn: #f59e0b;
    --danger: #e5484d;

    /* ปุ่ม */
    --btn-yellow: #f9c74f;
    --btn-yellow-ink: #3b2a06;
    --btn-dark: #273449;
    --btn-accent: #f97e4f;

    /* ช่องกรอก */
    --input-bg: #ffffff;
    --input-border: #d7e2ee;
    --input-text: #0f1b2d;

    /* เงา */
    --sh-1: 0 1px 2px rgba(15,27,45,.06), 0 2px 8px rgba(15,27,45,.05);
    --sh-2: 0 4px 16px rgba(15,27,45,.10);
    --sh-float: 0 6px 20px rgba(0,0,0,.35);

    --r-sm: 10px;
    --r-md: 14px;
    --r-lg: 20px;

    --appbar-h: 58px;
    --tabbar-h: 62px;
    --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: "Noto Sans Thai", "Sarabun", "Segoe UI", Tahoma, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}

iconify-icon { display: inline-block; vertical-align: -0.14em; }

/* ===================== โครงแอป ===================== */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ---------- App bar : โลโก้เล็ก + ชื่อแอปบรรทัดเดียวกัน ---------- */
.appbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    height: calc(var(--appbar-h) + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 14px 0;
    background: linear-gradient(100deg, var(--header-from), var(--header-to));
    box-shadow: 0 2px 14px rgba(14,165,183,.28);
    position: relative;
    z-index: 20;
}

.logo {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(255,255,255,.7);
}

.brand {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -.01em;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0,0,0,.12);
}

.model-chip {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 42%;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,.22);
    backdrop-filter: blur(6px);
    font-size: 11px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
}
.model-chip span:last-child { overflow: hidden; text-overflow: ellipsis; }

.dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(34,197,94,.3); }
.dot.wait { background: var(--warn); box-shadow: 0 0 0 3px rgba(245,158,11,.3); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* ---------- shell ---------- */
.shell {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* ===================== กล้อง ===================== */
.stage-col {
    flex: 0 0 auto;
    padding: 10px 10px 0;
}

.stage {
    position: relative;
    height: 40dvh;
    min-height: 200px;
    max-height: 400px;
    background: #0b1220;
    border-radius: var(--r-lg);
    overflow: hidden;
    box-shadow: var(--sh-2);
}

#video { display: none; }

/* object-fit: cover → ภาพไม่ยืด (ครอปแทนการดึงยืด) */
#overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
#overlay.mirror { transform: scaleX(-1); }

.cam-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #7c8ba1;
    font-size: 13px;
    pointer-events: none;
    background: radial-gradient(120% 80% at 50% 40%, #16233a 0%, #0b1220 100%);
}
.ph-icon { font-size: 40px; opacity: .7; }

/* แถบบนของกล้อง */
.stage-top {
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    pointer-events: none;
}
.stage-top > * { pointer-events: auto; }

.status-pill {
    flex: 0 1 auto;
    min-width: 0;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(8,15,28,.55);
    backdrop-filter: blur(10px);
    color: #e8f0fa;
    font-size: 12px;
    line-height: 1.35;
    box-shadow: 0 2px 10px rgba(0,0,0,.25);
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 0;
    background: var(--surface);
    color: var(--ink);
    font-size: 21px;
    cursor: pointer;
    transition: transform .15s ease, background .15s ease;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn.glass {
    margin-left: auto;
    background: rgba(8,15,28,.55);
    backdrop-filter: blur(10px);
    color: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,.3);
}
.icon-btn.glass.spin iconify-icon { animation: flip .45s ease; }
@keyframes flip { from { transform: rotateY(0); } to { transform: rotateY(180deg); } }

/* แถบล่างของกล้อง — ปุ่มลอย ชิดขอบล่าง ไม่บังมือกลางจอ */
.stage-bottom {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 10px;
    display: flex;
    justify-content: center;
}

.cam-fab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 44px;
    padding: 0 20px;
    border: 0;
    border-radius: 999px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--sh-float);
    transition: transform .15s ease, filter .15s ease;
}
.cam-fab iconify-icon { font-size: 22px; }
.cam-fab:active { transform: scale(.95); }
.cam-fab.start { background: var(--btn-yellow); color: var(--btn-yellow-ink); }
.cam-fab.stop { background: var(--danger); color: #fff; }
.cam-fab:disabled { opacity: .6; cursor: not-allowed; }

/* ===================== แผงเนื้อหา ===================== */
.panel-col {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.panel-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 12px 16px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--r-lg);
    padding: 14px;
    box-shadow: var(--sh-1);
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 18px 0 8px;
}
.section-head:first-child { margin-top: 0; }
.panel h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--brand-deep);
}
.step {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}

.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0; }

/* ---------- การ์ดผลลัพธ์ ---------- */
.result-card {
    text-align: center;
    padding: 16px 16px 14px;
    border-radius: var(--r-md);
    background: linear-gradient(160deg, var(--word-bg-2), var(--word-bg));
    box-shadow: var(--sh-2);
}
.result-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--word-sub); }
.th-big {
    font-size: clamp(38px, 12vw, 52px);
    font-weight: 800;
    line-height: 1.15;
    color: var(--word-thai);
    word-break: break-word;
}
.roman { color: var(--word-sub); font-size: 14px; min-height: 21px; }
.conf { font-size: 12px; color: var(--word-sub); margin-top: 4px; }

.confbar {
    height: 8px;
    background: var(--confbar-bg);
    border-radius: 999px;
    overflow: hidden;
    margin: 10px 0 0;
}
.result-card .confbar { margin-top: 12px; }
#trainBar { background: linear-gradient(90deg, var(--brand), var(--ok)); }
.panel > .confbar { background: rgba(15,27,45,.10); margin: 10px 0; }
.confbar-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--brand-2), var(--ok));
    transition: width .25s ease;
}

/* ---------- สวิตช์อ่านออกเสียง ---------- */
.switch-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px 0 0;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    cursor: pointer;
    user-select: none;
}
.switch-icon { display: inline-flex; color: var(--brand); font-size: 20px; }
.switch-text { flex: 1; font-size: 14px; font-weight: 500; }
.switch-row input {
    position: absolute;
    width: 1px;
    height: 1px;
    min-height: 0;
    margin: 0;
    padding: 0;
    opacity: 0;
    pointer-events: none;
}
.switch-ui {
    flex: 0 0 auto;
    width: 44px;
    height: 26px;
    border-radius: 999px;
    background: #cbd5e1;
    position: relative;
    transition: background .2s ease;
}
.switch-ui::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,.25);
    transition: transform .2s ease;
}
.switch-row input:checked ~ .switch-ui { background: var(--brand); }
.switch-row input:checked ~ .switch-ui::after { transform: translateX(18px); }
.switch-row input:focus-visible ~ .switch-ui { outline: 2px solid var(--brand-deep); outline-offset: 2px; }

/* ---------- ประโยค ---------- */
.sentence {
    min-height: 76px;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 4px solid var(--btn-accent);
    border-radius: var(--r-md);
    padding: 12px;
    box-shadow: var(--sh-1);
}
.sentence:empty::before {
    content: attr(data-empty);
    color: #9aa8b8;
    font-size: 14px;
}
.chip {
    padding: 5px 12px;
    border-radius: 999px;
    background: #eefaf9;
    border: 1px solid #c9eef1;
    color: #0b4f5c;
    font-size: 19px;
    font-weight: 600;
    animation: pop .22s ease;
}
@keyframes pop { from { transform: scale(.8); opacity: 0; } }

/* ===================== ปุ่ม ===================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 44px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    transition: transform .12s ease, filter .15s ease;
}
.btn iconify-icon { font-size: 19px; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }

.btn.primary { background: var(--btn-yellow); color: var(--btn-yellow-ink); box-shadow: 0 2px 8px rgba(249,199,79,.45); }
.btn.primary iconify-icon { color: #d33; }
.btn.accent { background: linear-gradient(135deg, var(--btn-accent), #f9c74f); color: #3b2a06; box-shadow: 0 3px 12px rgba(249,126,79,.35); }
.btn.dark { background: var(--btn-dark); color: #eef4fb; }
.btn.ghost { background: transparent; border-color: var(--input-border); color: var(--muted); }
.btn.ghost:active { background: rgba(15,27,45,.05); }

/* ===================== ฟอร์ม ===================== */
.row { display: flex; gap: 8px; align-items: center; }
.select-wrap { position: relative; flex: 1; min-width: 0; }
.select-caret {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--muted);
    font-size: 20px;
}

select, input {
    width: 100%;
    min-height: 44px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--input-text);
    padding: 9px 12px;
    border-radius: var(--r-sm);
    font-family: inherit;
    font-size: 15px;      /* ≥16px กัน iOS ซูม ที่ input; select ใช้ 15px ได้ */
    appearance: none;
    -webkit-appearance: none;
}
input { font-size: 16px; }
select { padding-right: 34px; text-overflow: ellipsis; }
select:focus, input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,165,183,.15); }

.addword { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 10px; }

/* ===================== รายการคำศัพท์ (การ์ด — อ่านง่ายบนมือถือ) ===================== */
.words-list { display: flex; flex-direction: column; gap: 8px; }

.word-card {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 4px 10px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    box-shadow: var(--sh-1);
}
.word-main { min-width: 0; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.word-thai { font-size: 17px; font-weight: 700; }
.word-roman { font-size: 12.5px; color: var(--muted); }
.word-meta { grid-column: 1; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.word-id {
    padding: 1px 7px;
    border-radius: 999px;
    background: #fff1f2;
    color: #ad2327;
    font-size: 11.5px;
    font-weight: 600;
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.count-badge {
    padding: 1px 8px;
    border-radius: 999px;
    background: #eefaf9;
    color: #0b6274;
    font-size: 11.5px;
    font-weight: 600;
}
.count-badge.low { background: #fff7ed; color: #b45309; }
.word-actions { grid-row: 1 / span 2; display: flex; gap: 4px; }
.word-actions .icon-btn { width: 38px; height: 38px; font-size: 19px; background: #f4f7fb; color: var(--muted); }
.word-actions .icon-btn.danger { background: #fff1f2; color: var(--danger); }

.empty-note { padding: 14px; text-align: center; color: var(--muted); font-size: 13px; }

/* ===================== แถบแท็บล่าง (ไม่บังกล้อง) =====================
 * อยู่ในโฟลว์ปกติท้าย .panel-col — ไม่ใช้ position:fixed
 * จึงไม่เพี้ยนเวลาแถบ URL ของเบราว์เซอร์มือถือยุบ/ยืด
 */
.tabbar {
    flex: 0 0 auto;
    z-index: 30;
    display: flex;
    gap: 4px;
    height: calc(var(--tabbar-h) + var(--safe-b));
    padding: 6px 10px var(--safe-b);
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(15,27,45,.06);
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: 0;
    border-radius: var(--r-md);
    background: transparent;
    color: var(--muted);
    font-family: inherit;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    transition: color .18s ease, background .18s ease;
}
.tab iconify-icon { font-size: 24px; transition: transform .18s ease; }
.tab.active { color: var(--brand-deep); background: #e8f8fb; }
.tab.active iconify-icon { transform: translateY(-1px) scale(1.06); }

/* ===================== แท็บเล็ต / เดสก์ท็อป ===================== */
@media (min-width: 900px) {
    :root { --appbar-h: 68px; }
    .app { height: auto; min-height: 100vh; overflow: visible; }

    .appbar { padding-inline: 28px; gap: 14px; }
    .logo { width: 44px; height: 44px; }
    .brand { font-size: 26px; }
    .model-chip { font-size: 13px; padding: 6px 14px; max-width: none; }

    .shell {
        display: grid;
        grid-template-columns: minmax(0, 1.05fr) minmax(360px, .95fr);
        gap: 24px;
        width: 100%;
        max-width: 1180px;
        margin: 0 auto;
        padding: 24px 28px 32px;
        align-items: start;
    }

    .stage-col { padding: 0; position: sticky; top: 24px; }
    .stage { height: auto; max-height: none; aspect-ratio: 4 / 3; }
    .stage-top { top: 12px; left: 12px; right: 12px; }
    .status-pill { font-size: 13px; padding: 8px 14px; }
    .stage-bottom { bottom: 14px; }

    .panel-col { min-height: 0; }
    .panel-scroll { overflow: visible; padding: 0; }
    .panel { padding: 20px; }

    .tabbar {
        position: static;
        order: -1;
        height: auto;
        padding: 0;
        margin-bottom: 14px;
        background: transparent;
        backdrop-filter: none;
        border: 0;
        gap: 8px;
    }
    .tab {
        flex-direction: row;
        gap: 8px;
        min-height: 46px;
        font-size: 15px;
        background: #fff;
        border: 1px solid var(--line);
        box-shadow: var(--sh-1);
    }
    .tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }

    .addword { grid-template-columns: 1fr 1fr 1fr auto; }
    .word-card { grid-template-columns: 1.4fr auto auto; }
    .word-meta { grid-column: auto; grid-row: 1; }
    .word-actions { grid-row: 1; }
}

/* จอสูงน้อย (มือถือแนวนอน) — ลดขนาดกล้องลง */
@media (max-height: 620px) and (max-width: 899px) {
    .stage { height: 34dvh; min-height: 170px; }
    .th-big { font-size: 34px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
