/* POPNIX Flood - สายน้ำไทย 3 มิติ (/3d/?v=th): ต่อจาก view3d.css (แผง กระจก ปุ่ม ของเล่นลอยน้ำ) + ส่วนของหน้าทั้งประเทศ
   ทุก animation วนหยุดใต้ prefers-reduced-motion (ท้ายไฟล์) */
.th3d { --th-river: #1f86b8; --th-sea: #a9d2e6; --th-drop: #2ba7dd; --th-drop-2: #7fd3f5; }
@media (prefers-color-scheme: dark) { .th3d { --th-river: #4fb8e6; --th-sea: #0d2a3e; --th-drop: #45bdf0; --th-drop-2: #a5e6ff; } }
.th-noscript { position: relative; z-index: 200; margin: 88px 16px 16px; padding: 14px 18px; border-radius: 14px; background: #fff8e6; color: #3a2a00; font: 16px/1.6 sans-serif; }

/* หัว: ชื่อเปลี่ยนตามจังหวัดที่อยู่กลางจอ */
.th-head h1 { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.th-head h1 small { font-size: .5em; font-weight: 500; color: var(--accent); letter-spacing: .02em; }
.th-stats dt { white-space: nowrap; }
.v3-stats .c-rise { color: var(--accent); }
.th-bkk { color: var(--strong); }

/* แผงล่าง: 3 ทางสำรวจ + ข้อความความจริง */
.th-sheet { left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(760px, calc(100% - 32px)); padding: 12px 12px 10px;
    animation: thUp .7s var(--ease-out) both; }
@keyframes thUp { from { opacity: 0; transform: translate(-50%, 24px); } }
.th-acts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.th-act { display: flex; align-items: center; gap: 10px; min-height: 64px; padding: 8px 12px; border-radius: 18px; border: 1px solid var(--glass-line); background: var(--shell);
    color: var(--text); font: inherit; text-align: left; cursor: pointer; transition: transform .35s var(--ease), background-color .3s var(--ease), border-color .3s var(--ease); }
.th-act:hover { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.th-act:active { transform: scale(.97); }
.th-act[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.th-act b { display: block; color: var(--strong); font-size: .98rem; line-height: 1.3; }
.th-act small { display: block; color: var(--muted); font-size: .8rem; line-height: 1.4; }
.th-truth { margin: 10px 4px 0; color: var(--muted); font-size: .78rem; line-height: 1.5; }
.th-truth i { color: var(--accent); }
.th-truth .t-short { display: none; }

/* ไอคอนวาดเอง: หยดน้ำมีหน้า (น้องน้ำตัวจิ๋ว) หมุดจังหวัด เรือหางยาวบนคลื่น */
.th-ic { position: relative; flex: none; width: 46px; height: 46px; border-radius: 14px; background: var(--accent-soft); overflow: hidden; }
.th-ic::before, .th-ic::after { content: ""; position: absolute; }
.th-ic-drop::before { left: 13px; top: 8px; width: 20px; height: 20px; border-radius: 0 50% 50% 50%; transform: rotate(45deg); background: linear-gradient(135deg, var(--th-drop-2), var(--th-drop));
    box-shadow: inset -3px -3px 0 rgba(0, 0, 0, .08); animation: thDrop 2.6s ease-in-out infinite; }
.th-ic-drop::after { left: 18px; top: 20px; width: 10px; height: 5px; border-radius: 0 0 6px 6px; border: 1.6px solid rgba(10, 40, 60, .7); border-top: 0; animation: thDrop 2.6s ease-in-out infinite; }
@keyframes thDrop { 0%, 100% { translate: 0 0; } 50% { translate: 0 6px; } }
.th-ic-pin::before { left: 13px; top: 7px; width: 20px; height: 20px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--crit); box-shadow: inset 0 0 0 6px color-mix(in srgb, #fff 35%, var(--crit)); }
.th-ic-pin::after { left: 11px; top: 30px; width: 24px; height: 8px; border-radius: 50%; border: 2px solid var(--crit); opacity: .6; animation: thRing 2.2s ease-out infinite; }
@keyframes thRing { from { transform: scale(.4); opacity: .9; } to { transform: scale(1.4); opacity: 0; } }
.th-ic-boat { background: linear-gradient(var(--accent-soft) 60%, color-mix(in srgb, var(--th-river) 30%, transparent) 60%); }
.th-ic-boat::before { left: 6px; top: 22px; width: 32px; height: 9px; border-radius: 0 0 14px 4px; background: #8a5a33; transform-origin: 50% 100%; animation: thRock 2.4s ease-in-out infinite;
    box-shadow: 22px -9px 0 -3px #c0392b; }
.th-ic-boat::after { left: -20px; top: 30px; width: 90px; height: 6px; background: radial-gradient(circle at 6px 0, transparent 5px, color-mix(in srgb, var(--th-river) 70%, #fff) 6px) 0 0 / 12px 6px repeat-x;
    animation: thWave 1.8s linear infinite; }
@keyframes thRock { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg) translateY(-1px); } }
@keyframes thWave { to { transform: translateX(12px); } }

/* การ์ด: สถานี เขื่อน จังหวัด เส้นทาง การล่อง */
.th-card { left: 16px; top: auto; bottom: 16px; width: min(400px, calc(100% - 32px)); max-height: calc(100dvh - 310px); overflow-y: auto; padding: 16px 18px 14px; animation: thCard .5s var(--ease-out) both; }
@keyframes thCard { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.th-x { position: absolute; right: 10px; top: 10px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--shell); color: var(--muted); cursor: pointer; }
.th-x:hover { color: var(--strong); }
.th-card h2 { font-size: 1.3rem; line-height: 1.35; margin: 2px 40px 0 0; color: var(--strong); }
.th-k { margin: 0 40px 0 0; color: var(--accent); font-size: .82rem; font-weight: 600; line-height: 1.45; }
.th-sub, .th-gap, .th-time { margin: 4px 0 0; color: var(--muted); font-size: .88rem; line-height: 1.5; }
.th-time { font-size: .82rem; }
.th-val { margin: 8px 0 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.th-val b { font-size: 1.7rem; color: var(--strong); line-height: 1.1; }
.th-card .lv, .th-trlist .tr-v { font-size: .86rem; font-weight: 600; }
.lv-crit { color: var(--crit); } .lv-warn { color: var(--warn); } .lv-ok { color: var(--ok); } .lv-off, .lv-unk { color: var(--muted); }
.th-big { margin: 4px 0 0; color: var(--muted); } .th-big b { font-size: 2.6rem; line-height: 1.05; color: var(--strong); letter-spacing: -.01em; }
.th-fine { margin: 10px 0 0; color: var(--faint, var(--muted)); font-size: .76rem; line-height: 1.5; }
.th-city { margin: 6px 0 4px; padding: 10px 12px; border-radius: 14px; background: var(--shell); color: var(--text); font-size: .85rem; line-height: 1.5; }
.th-cardrow { display: flex; gap: 14px; align-items: flex-start; }
.th-cardtx { flex: 1; min-width: 0; }
.th-cacts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.th-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--core); color: var(--strong);
    font: inherit; font-size: .92rem; cursor: pointer; text-decoration: none; }
.th-btn.th-pri { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.th-pst { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.th-pst span { padding: 6px 10px; border-radius: 12px; background: var(--shell); font-size: .82rem; color: var(--muted); }
.th-pst b { display: block; font-size: 1.35rem; line-height: 1.15; color: var(--strong); }
.th-pst .lv-crit b { color: var(--crit); } .th-pst .lv-warn b { color: var(--warn); }

/* หลอดวัดในการ์ด (ค่าจริง: ท้องน้ำ ตลิ่ง ระดับน้ำ) */
.th-gauge { flex: none; width: 64px; height: 116px; overflow: visible; }
.th-gauge .g-glass { fill: color-mix(in srgb, var(--th-river) 10%, transparent); stroke: var(--line-2); stroke-width: 1.5; }
.th-gauge .g-water { opacity: .9; } .th-gauge .g-wave { opacity: .95; animation: thGauge 2.2s ease-in-out infinite alternate; }
.th-gauge .g-bank { stroke: var(--strong); stroke-width: 1.4; stroke-dasharray: 3 2; }
.th-gauge .g-t { fill: var(--muted); font-size: 8.5px; }
.th-gauge .g-spill { animation: thSpill 1.4s ease-in infinite; }
@keyframes thGauge { from { transform: translateX(-6px); } to { transform: translateX(4px); } }
@keyframes thSpill { from { transform: translateY(-4px); opacity: 1; } to { transform: translateY(10px); opacity: 0; } }
/* ถังเขื่อนในการ์ด */
.th-tank { flex: none; width: 92px; height: 82px; overflow: visible; }
.th-tank .tk-body { fill: var(--shell); stroke: var(--line-2); stroke-width: 1.6; }
.th-tank .tk-water { fill: #3aa0cf; } .th-tank .tk-water.full { fill: var(--crit); }
.th-tank .tk-wave { fill: none; stroke: #bfe7f7; stroke-width: 2; animation: thTank 2.4s linear infinite; }
.th-tank .tk-rim { fill: none; stroke: var(--line-2); stroke-width: 1.4; }
.th-tank .tk-pc { fill: #fff; font-size: 15px; font-weight: 700; paint-order: stroke; stroke: rgba(0, 0, 0, .35); stroke-width: 2.4px; }
@keyframes thTank { to { transform: translateX(-14px); } }

/* รายการสถานีบนเส้นทางน้ำ */
.th-trlist { list-style: none; margin: 12px 0 0; padding: 0; counter-reset: tr; border-left: 2px dashed color-mix(in srgb, var(--th-river) 55%, transparent); }
.th-trlist li { position: relative; }
.th-trlist li::before { content: ""; position: absolute; left: -6px; top: 18px; width: 10px; height: 10px; border-radius: 50%; background: var(--th-river); border: 2px solid var(--core); }
.th-trlist button { display: grid; grid-template-columns: 62px minmax(0, 1fr) auto; gap: 8px; align-items: center; width: 100%; padding: 8px 6px 8px 14px; border: 0; background: none;
    color: var(--text); font: inherit; text-align: left; cursor: pointer; border-radius: 12px; }
.th-trlist button:hover { background: var(--shell); }
.tr-d { color: var(--accent); font-size: .82rem; font-weight: 600; white-space: nowrap; }
.tr-n b { display: block; color: var(--strong); font-size: .88rem; font-weight: 600; line-height: 1.35; } .tr-n small { color: var(--muted); font-size: .76rem; }
.tr-v { text-align: right; } .tr-v small { display: block; color: var(--muted); font-weight: 400; font-size: .74rem; }
.th-drop { display: inline-block; width: 12px; height: 12px; margin-right: 6px; border-radius: 0 50% 50% 50%; transform: rotate(45deg) translateY(1px); background: var(--th-drop); }

/* หมุดของเส้นทาง */
.th-pin { pointer-events: none; }
.th-pin-start i { display: block; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; box-shadow: 0 0 0 0 var(--accent); animation: thPing 1.8s ease-out infinite; }
@keyframes thPing { from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 70%, transparent); } to { box-shadow: 0 0 0 22px transparent; } }
.th-pin-snap i { display: block; width: 12px; height: 12px; border-radius: 50%; border: 2px dashed var(--th-river); background: var(--core); }
.th-pin-head svg { width: 30px; height: 38px; overflow: visible; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .35)); animation: thBob .6s ease-in-out infinite alternate; }
.th-pin-head .dp-b { fill: var(--th-drop); stroke: #fff; stroke-width: 1.6; } .th-pin-head .dp-e { fill: #0c2533; }
.th-pin-head .dp-m { fill: none; stroke: #0c2533; stroke-width: 1.4; stroke-linecap: round; } .th-pin-head .dp-s { fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; opacity: .8; }
@keyframes thBob { from { transform: translateY(0) rotate(-6deg); } to { transform: translateY(-3px) rotate(6deg); } }
.th-pin-sea, .th-pin-exit, .th-pin-sink { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--core); border: 2px solid var(--th-river); color: var(--th-river);
    box-shadow: 0 8px 18px -8px rgba(0, 0, 0, .5); animation: thPop .6s cubic-bezier(.34, 1.56, .64, 1) both; }
.th-pin-exit { border-color: var(--warn); color: var(--warn); width: 28px; height: 28px; font-size: .8rem; }
@keyframes thPop { from { transform: scale(.2); opacity: 0; } }
body.th-picking #map3d canvas { cursor: crosshair; }
body.th-picking .th-act#traceBtn .th-ic { box-shadow: 0 0 0 2px var(--accent); }

/* ป้ายภาษาไทยบนแผนที่ */
.th-labels { position: absolute; inset: 0; pointer-events: none; z-index: 4; overflow: hidden; font-family: var(--font); }
.th-lb { position: absolute; left: 0; top: 0; white-space: nowrap; transition: opacity .35s var(--ease); will-change: transform; translate: -50% -50%; }
.th-lb.off { opacity: 0 !important; }
.lb-r { color: var(--th-river); font-size: 12.5px; font-weight: 600; letter-spacing: .03em; font-style: italic; text-shadow: 0 0 4px var(--bg), 0 0 2px var(--bg), 0 0 8px var(--bg); }
.lb-p { color: var(--strong); font-size: 12px; font-weight: 500; opacity: .7; text-shadow: 0 0 5px var(--bg), 0 0 2px var(--bg); }
.lb-p.hot { opacity: 1; display: flex; flex-direction: column; align-items: center; padding: 3px 9px 4px; border-radius: 12px; background: var(--glass); border: 1px solid color-mix(in srgb, var(--crit) 60%, transparent);
    -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); box-shadow: 0 8px 18px -10px rgba(0, 0, 0, .6); text-shadow: none; translate: -50% -100%; }
.lb-p.hot b { font-size: 12.5px; font-weight: 600; } .lb-p.hot span { font-size: 11px; color: var(--crit); font-weight: 600; }
.lb-d { display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--strong); text-shadow: 0 0 4px var(--bg), 0 0 2px var(--bg); translate: -50% 8px; }
.lb-d b { font-weight: 600; } .lb-d span { color: #3aa0cf; font-weight: 700; } .lb-d.full span { color: var(--crit); }

/* ฉากเปิด */
.th-intro { position: fixed; z-index: 40; left: 0; right: 0; top: 0; pointer-events: none; }
.th-cap { position: absolute; left: 50%; top: calc(50% - 10px); transform: translate(-50%, 8px); margin: 0; max-width: min(560px, calc(100vw - 40px)); padding: 10px 18px; border-radius: 16px;
    background: var(--glass); border: 1px solid var(--glass-line); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); color: var(--strong); font-size: 1.05rem; line-height: 1.45;
    text-align: center; opacity: 0; transition: opacity .6s var(--ease), transform .6s var(--ease-out); }
.th-cap.on { opacity: 1; transform: translate(-50%, 0); }
#thIntro { position: fixed; inset: 0; }
#skipBtn { position: fixed; right: 16px; bottom: calc(24px + env(safe-area-inset-bottom)); pointer-events: auto; min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--glass-line);
    background: var(--glass); color: var(--strong); font: inherit; cursor: pointer; -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }
body.is-loading .th-sheet, body.is-loading .th-intro { display: none; }

/* เลือกจังหวัด */
.th-pick { position: fixed; z-index: 45; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 10px 12px;
    border-radius: 18px; background: var(--core); border: 1px solid var(--line-2); box-shadow: var(--shadow); }
.th-pick label { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.th-pick select { min-height: 44px; max-width: 58vw; font: inherit; font-size: 16px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--shell); color: var(--strong); padding: 0 10px; }
.th-pick button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--shell); color: var(--muted); cursor: pointer; }

/* คำอธิบาย: ซ่อนจนกดปุ่ม i ทุกขนาดจอ (ภาพทั้งประเทศต้องการพื้นที่) */
.th3d .v3-info { display: inline-flex; }
.th-legend:not(.show) { display: none; }
.th-legend { left: auto; right: 16px; top: 140px; bottom: auto; width: min(320px, calc(100% - 32px)); max-height: calc(100dvh - 300px); }
.th-dots i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.th-dots .d-crit { background: var(--crit); } .th-dots .d-warn { background: var(--warn); } .th-dots .d-ok { background: var(--ok); }
.th-dots .d-unk { background: var(--muted); } .th-dots .d-off { background: none; border: 1.6px solid var(--off); }
.th-credit { margin-top: 12px !important; font-size: .74rem !important; }
.mzi-capy { width: 34px; }

/* คาปิบาราล่องเรือ (เขื่อนเกินความจุ) */
.mz-capy .mz-bob { animation: capyBob 3.4s ease-in-out var(--d) infinite; transform-origin: 50% 80%; }
@keyframes capyBob { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(3.5deg) translateY(-1.5px); } }
.mz .cp-flag { transform-box: fill-box; transform-origin: 0% 50%; animation: flag 1.1s ease-in-out infinite alternate; }
.mz .cp-eye { transform-box: fill-box; transform-origin: 50% 50%; animation: capyBlink 4.6s infinite; }
@keyframes capyBlink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
.th-mz { z-index: 3; }
.th-mz .mz-pop { scale: var(--fs, 1); }

/* ระหว่างเปิดการ์ด/ล่อง: ซ่อนแผงล่างไม่ให้ซ้อน */
body.th-carding .th-sheet, body.th-touring .th-sheet { display: none; }
body.th-touring .v3-tools { opacity: .55; }

@media (max-width: 760px) {
    /* หัวกะทัดรัด: ภาพทั้งประเทศต้องเหลือพื้นที่บนจอ ~400x700 */
    .th-head { padding: 10px 12px 10px; border-radius: 20px; }
    .th-head .brand span { display: none; } .th-head .brand { position: absolute; right: 12px; top: 10px; margin: 0; }
    .th-head h1 { font-size: 1.3rem; margin-right: 36px; } .th-head .live { margin-top: 4px; font-size: .78rem; }
    .th-stats { margin-top: 8px; gap: 5px; } .th-stats div { padding: 5px 8px; border-radius: 12px; } .th-stats dd { font-size: 1.12rem; } .th-stats dt { font-size: .68rem; }
    .th3d .v3-badge { top: 10px; }
    /* เปิดการ์ด: หัวเหลือแค่ชื่อกับเวลา แถวปุ่มซ่อน ให้แผนที่เหลือพื้นที่เห็นเส้นทาง */
    body.th-carding .th-stats, body.th-carding .th-top .v3-right { display: none; }
    .th-truth .t-long { display: none; } .th-truth .t-short { display: inline; }
    .th-sheet { left: 10px; right: 10px; width: auto; transform: none; bottom: calc(10px + env(safe-area-inset-bottom)); padding: 8px 8px 8px; border-radius: 20px; }
    @keyframes thUp { from { opacity: 0; transform: translateY(24px); } }
    .th-acts { gap: 6px; }
    .th-act { flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 4px; min-height: 92px; padding: 8px 4px; border-radius: 16px; }
    .th-act small { display: none; }
    .th-act b { font-size: .86rem; }
    .th-ic { width: 40px; height: 40px; }
    .th-truth { font-size: .72rem; margin-top: 6px; }
    .th-card { left: 10px; right: 10px; top: auto; bottom: calc(10px + env(safe-area-inset-bottom)); width: auto; max-height: 48dvh; border-radius: 22px; padding: 14px 16px 12px; }
    .th-big b { font-size: 2.2rem; }
    .th-stats dt { min-height: 0; font-size: .72rem; }
    .th-legend { left: 10px; right: 10px; width: auto; top: auto; bottom: 150px; max-height: calc(100dvh - 380px); }
    .th-pick { bottom: calc(120px + env(safe-area-inset-bottom)); }
    .th-cap { top: auto; bottom: 96px; font-size: .95rem; }
    #skipBtn { bottom: auto; top: calc(220px + env(safe-area-inset-top)); right: 10px; }
    .v3d.th3d .maplibregl-ctrl-bottom-right { bottom: 176px; }
    .v3d.th3d .maplibregl-ctrl-attrib.maplibregl-compact, .v3d.th3d .maplibregl-ctrl-attrib.maplibregl-compact-show { bottom: 128px; }
}
@media (max-width: 380px) { .th-act b { font-size: .8rem; } .v3-head h1 { font-size: 1.3rem; } }
@media (prefers-reduced-motion: reduce) {
    .th-sheet, .th-card, .th-ic::before, .th-ic::after, .th-gauge .g-wave, .th-gauge .g-spill, .th-tank .tk-wave, .th-pin-start i, .th-pin-head svg, .th-pin-sea, .th-pin-exit, .th-pin-sink,
    .mz-capy .mz-bob, .mz .cp-flag, .mz .cp-eye { animation: none !important; }
    .th-cap, .th-lb, .th-act { transition: none; }
}
