/* ================================================================
   กระดานราคาทองจอทีวี — ธีม "ครีมสว่าง-กรอบแดง"
   ออกแบบสำหรับจอ 16:9 ดูจากระยะ 3–5 เมตร ทุกขนาดสัมพัทธ์กับ viewport
   ================================================================ */

/* ---- ฟอนต์ไทย self-host (ไม่พึ่ง Google Fonts CDN) ---- */
@font-face {
  font-family: 'Sarabun';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('./fonts/sarabun-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Sarabun';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('./fonts/sarabun-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Sarabun';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('./fonts/sarabun-700.woff2') format('woff2');
}
@font-face {
  font-family: 'Sarabun';
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url('./fonts/sarabun-800.woff2') format('woff2');
}
/* ฟอนต์ทางเลือก (เลือกได้ในหน้า Settings) — self-host ทั้งหมด */
@font-face { font-family: 'Noto Sans Thai'; font-weight: 400; font-display: swap; src: url('./fonts/notosansthai-400.woff2') format('woff2'); }
@font-face { font-family: 'Noto Sans Thai'; font-weight: 700; font-display: swap; src: url('./fonts/notosansthai-700.woff2') format('woff2'); }
@font-face { font-family: 'Noto Sans Thai'; font-weight: 800; font-display: swap; src: url('./fonts/notosansthai-800.woff2') format('woff2'); }
@font-face { font-family: 'Prompt'; font-weight: 400; font-display: swap; src: url('./fonts/prompt-400.woff2') format('woff2'); }
@font-face { font-family: 'Prompt'; font-weight: 700; font-display: swap; src: url('./fonts/prompt-700.woff2') format('woff2'); }
@font-face { font-family: 'Prompt'; font-weight: 800; font-display: swap; src: url('./fonts/prompt-800.woff2') format('woff2'); }
@font-face { font-family: 'Kanit'; font-weight: 400; font-display: swap; src: url('./fonts/kanit-400.woff2') format('woff2'); }
@font-face { font-family: 'Kanit'; font-weight: 700; font-display: swap; src: url('./fonts/kanit-700.woff2') format('woff2'); }
@font-face { font-family: 'Kanit'; font-weight: 800; font-display: swap; src: url('./fonts/kanit-800.woff2') format('woff2'); }

:root {
  /* พาเลตต์ตามสเปคที่ approve แล้ว */
  --cream: #FFF8E1;
  --red: #C62828;
  --logo-bg: #FFD75E;
  --logo-fg: #7A1F1F;
  --shop: #FFE082;
  --tagline: #FFCDA8;
  --title: #6D4C00;
  --navy: #0C447C;
  --price: #B71C1C;
  --gold-line: #F0B429;
  --up: #1B7A2E;
  --down: #B71C1C;

  /* สเกลตัวอักษร: ยึด "ตัวเลขราคา" เป็นฐาน แล้วไล่สัดส่วน — ปรับได้จากหน้า Settings ผ่านตัวแปรด้านล่าง */
  --font: 'Sarabun';       /* ฟอนต์ (Settings) */
  --price-vh: 26;          /* ขนาดตัวเลขราคา หน่วย vh (Settings) */
  --label-ratio: 0.72;     /* ป้ายขายออก/รับซื้อ เทียบตัวเลขราคา (Settings) */
  --label-gap: 0.18;       /* ระยะห่าง ป้าย↔ราคา เทียบตัวเลขราคา (Settings) */
  --title-ratio: 0.37;     /* หัวเรื่อง + วันนี้ (Settings) */
  --footer-ratio: 0.20;    /* header/footer (Settings) */

  --num: clamp(40px, calc(var(--price-vh) * 1vh), 28vw); /* ตัวเลขราคา (คุมพื้นที่กลางเท่านั้น) */
  --lbl: calc(var(--num) * var(--label-ratio));          /* ป้ายขายออก/รับซื้อ */
  --ttl: calc(var(--num) * var(--title-ratio));          /* หัวเรื่อง + วันนี้ */

  /* header/footer มีหน่วยของตัวเอง (--ui) ไม่ผูกกับขนาดราคา → เพิ่มขนาดราคาได้โดยแถบไม่โตตาม
     คุมขนาดแถบด้วย --footer-ratio (ค่ามาตรฐาน 0.20 = คูณ 1) */
  --ui: calc(clamp(16px, 4.4vh, 4.6vw) * var(--footer-ratio) / 0.20);
  --hdr: var(--ui);                       /* ข้อความแถบล่าง */
  --shop-sz: calc(var(--ui) * 1.25);
  --tag-sz: calc(var(--ui) * 0.66);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--cream);
  font-family: var(--font), 'Sarabun', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  cursor: none; /* kiosk: ซ่อนเคอร์เซอร์ */
}

/* board ขยายเกินจอ 6px ทุกด้าน → ขยับ ±2px กัน burn-in ไม่เผยขอบ */
.board {
  position: fixed;
  top: -6px; left: -6px;
  width: calc(100vw + 12px);
  height: calc(100vh + 12px);
  display: flex;
  flex-direction: column;
  background: var(--cream);
  will-change: transform;
  transition: transform 1.5s ease-in-out;
}

/* ---------- Header ---------- */
.topbar {
  flex: 0 0 auto;
  background: var(--red);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--ui) * 0.5) calc(var(--ui) * 1.2);
  gap: 1em;
}
.brand { display: flex; align-items: center; gap: calc(var(--ui) * 0.8); min-width: 0; }
.logo {
  flex: 0 0 auto;
  width: calc(var(--ui) * 2.7);
  height: calc(var(--ui) * 2.7);
  border-radius: 50%;
  background: var(--logo-bg);
  color: var(--logo-fg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: calc(var(--ui) * 1.1);
  letter-spacing: 0.02em;
  overflow: hidden;
}
/* โหมดโลโก้รูป: พื้นขาว ใส่รูปเต็มวงกลม (เห็นทั้งโลโก้) */
.logo.logo--image { background: #fff; padding: 4%; }
.logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand-text { min-width: 0; }
.shop {
  color: var(--shop);
  font-weight: 800;
  font-size: var(--shop-sz);
  line-height: 1.05;
  white-space: nowrap;
}
.tagline {
  color: var(--tagline);
  font-weight: 500;
  font-size: var(--tag-sz);
  line-height: 1.1;
  white-space: nowrap;
  margin-top: calc(var(--shop-sz) * 0.18); /* เว้นจากชื่อร้าน ไม่ให้ทับกัน */
}
.clockbox { text-align: right; flex: 0 0 auto; }
.clock {
  color: var(--shop);
  font-weight: 700;
  font-size: calc(var(--ui) * 1.5);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.today {
  color: var(--tagline);
  font-weight: 500;
  font-size: var(--tag-sz);
  line-height: 1.2;
  white-space: nowrap;
}

/* ---------- กลาง ---------- */
.content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(var(--num) * 0.04) calc(var(--num) * 0.34);
  min-height: 0;
  overflow: hidden; /* กันไม่ให้เนื้อหาล้นไปทับแถบบน/ล่างเมื่อตั้งขนาดใหญ่ */
}
.titlerow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5em;
  white-space: nowrap;
  margin-bottom: calc(var(--num) * 0.06);
}
.title {
  color: var(--title);
  font-weight: 800;
  font-size: var(--ttl);
  line-height: 1;
}
.change {
  font-weight: 800;
  font-size: var(--ttl);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.change--up { color: var(--up); }
.change--down { color: var(--down); }
.change--flat { color: var(--title); opacity: 0.75; }

/* grid 2 คอลัมน์ร่วมกันทั้งสองแถว: ป้ายชิดขวาตรงกัน + ราคาตรงกันทุกหลัก */
.prices {
  display: grid;
  grid-template-columns: max-content max-content;
  justify-content: end;         /* ทั้งบล็อกชิดขวา */
  align-items: baseline;
  column-gap: calc(var(--num) * var(--label-gap)); /* ระยะป้าย↔ราคา สเกลตามตัวเลขราคา ปรับได้จาก Settings */
  row-gap: calc(var(--num) * 0.07);
}
.prow { display: contents; }    /* ให้ป้าย+ราคาเป็นลูกของ grid โดยตรง */
.plabel {
  color: var(--navy);
  font-weight: 800;
  font-size: var(--lbl);
  line-height: 1;
  white-space: nowrap; /* ห้ามตัดบรรทัด "ขายออก"/"รับซื้อ" */
  text-align: right;   /* ป้ายชิดขวา → "ออก"/"ซื้อ" ตรงกัน */
}
.pvalue {
  color: var(--price);
  font-weight: 800;
  font-size: var(--num);
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums; /* เลขกว้างเท่ากัน → ตรงกันทุกหลัก */
  letter-spacing: 0.005em;
  border-radius: 0.08em;
  padding: 0 0.06em;
  transition: background-color 0.4s ease-out;
  text-align: right;   /* ราคาชิดขวา → หลักตรงกันทั้งสองแถว */
}
/* เส้นทองคั่นสองแถว */
.grule {
  grid-column: 1 / -1;   /* คั่นเต็มความกว้างทั้งสองคอลัมน์ */
  height: 2px;
  background: var(--gold-line);
  width: 100%;
}

/* flash ตอนราคาเปลี่ยน (จางกลับใน ~2s) */
.pvalue.flash-up { background-color: rgba(27, 122, 46, 0.28); transition: background-color 0.05s; }
.pvalue.flash-down { background-color: rgba(183, 28, 28, 0.24); transition: background-color 0.05s; }

/* ---------- Footer ---------- */
.botbar {
  flex: 0 0 auto;
  background: var(--red);
  color: var(--shop);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--ui) * 0.42) calc(var(--ui) * 1.2);
  font-size: var(--hdr);
  font-weight: 500;
}
.announce { font-variant-numeric: tabular-nums; white-space: nowrap; }
.freshness { display: flex; align-items: center; gap: 0.4em; white-space: nowrap; }
.dot {
  width: 0.62em; height: 0.62em; border-radius: 50%;
  background: #4CAF50; /* เขียว = สด */
  flex: 0 0 auto;
}
.freshtext { }

/* สถานะ stale: จุดแดงกะพริบ + ข้อความเตือน */
.botbar.stale .dot { background: #FF5252; animation: blink 1s steps(1) infinite; }
.botbar.stale .freshtext { color: #FFD1D1; font-weight: 700; }
@keyframes blink { 50% { opacity: 0.15; } }

/* ปุ่มเต็มจอ — มุมขวาบน จางๆ, ซ่อนตัวเมื่อเข้าเต็มจอแล้ว */
.fsbtn {
  position: fixed;
  top: 14px; right: 14px;
  z-index: 50;
  width: 44px; height: 44px;
  border: none; border-radius: 10px;
  background: rgba(0,0,0,0.28);
  color: #fff;
  font-size: 22px; line-height: 1;
  cursor: pointer;
  opacity: 0.35;
  transition: opacity 0.2s;
}
.fsbtn:hover { opacity: 1; }
body.is-fullscreen .fsbtn { display: none; }
