:root {
  --red: #e81318;
  --red-dark: #b10f13;
  --red-soft: #fff1f1;
  --ink: #141414;
  --muted: #5b5b5b;
  --bg: #fff7f7;
  --card: #ffffff;
  --line: #f0d4d4;
  --shadow: 0 18px 50px rgba(180, 20, 20, 0.1);
  --radius: 18px;
  --font: "Sarabun", "Noto Sans Thai", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.65;
}
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
.container { width: min(1120px, 92vw); margin: 0 auto; }

.site-header {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255,255,255,.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(240,212,212,.8);
}
.nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .85rem 0;
}
.brand {
  display: flex; align-items: center; gap: .7rem;
  font-weight: 900; color: var(--ink); text-decoration: none;
}
.brand img {
  width: 42px; height: 42px; border-radius: 12px;
  box-shadow: 0 6px 16px rgba(232,19,24,.25);
}
.brand span { font-size: 1.2rem; letter-spacing: .01em; }
.nav-links { display: flex; flex-wrap: wrap; gap: .35rem 1.05rem; align-items: center; }
.nav-links a { color: var(--ink); font-weight: 700; font-size: .98rem; }
.nav-links a.nav-cta {
  background: var(--red); color: #fff !important;
  padding: .55rem 1rem; border-radius: 999px; text-decoration: none !important;
}
.nav-links a.nav-cta:hover { background: var(--red-dark); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .45rem; border: 0; cursor: pointer;
  background: var(--red); color: #fff !important;
  font-weight: 800; border-radius: 999px;
  padding: .82rem 1.35rem; text-decoration: none !important;
  box-shadow: 0 10px 24px rgba(232,19,24,.28);
  transition: transform .15s ease, background .15s ease;
}
.btn:hover { background: var(--red-dark); transform: translateY(-1px); }
.btn.secondary {
  background: #fff; color: var(--red) !important;
  border: 2px solid var(--red); box-shadow: none;
}
.btn.ghost {
  background: transparent; color: var(--ink) !important;
  border: 1px solid var(--line); box-shadow: none;
}

.hero {
  position: relative; overflow: hidden;
  padding: 4.5rem 0 3.5rem;
  background:
    radial-gradient(circle at 92% 8%, rgba(232,19,24,.22), transparent 42%),
    radial-gradient(circle at 8% 90%, rgba(232,19,24,.08), transparent 35%),
    linear-gradient(180deg, #fff, var(--bg));
}
.hero-grid {
  display: grid; gap: 2.2rem;
  grid-template-columns: 1.15fr .85fr; align-items: center;
}
@media (max-width: 900px) { .hero-grid { grid-template-columns: 1fr; } }
.eyebrow {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--red-soft); color: var(--red);
  font-weight: 800; font-size: .88rem;
  padding: .35rem .75rem; border-radius: 999px; margin-bottom: 1rem;
}
.hero h1 {
  font-size: clamp(2.1rem, 5vw, 3.35rem);
  line-height: 1.12; margin: 0 0 1rem; letter-spacing: -.02em;
}
.hero p.lead { font-size: 1.18rem; color: var(--muted); margin: 0 0 1.6rem; max-width: 36rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: .7rem; }
.hero-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 6px);
  padding: 1.5rem; box-shadow: var(--shadow);
}
.hero-card h3 { margin: 0 0 .55rem; font-size: 1.25rem; }
.hero-card ul { margin: .8rem 0 1.2rem; padding-left: 1.15rem; color: var(--muted); }
.hero-card li { margin: .35rem 0; }
.hero-visual {
  display: grid; gap: 1rem;
}
.hero-frame {
  margin: 0; position: relative;
  border-radius: calc(var(--radius) + 8px);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  background: #1a1a1a;
  aspect-ratio: 16 / 10;
}
.hero-frame .hero-photo {
  width: 100%; height: 100%; object-fit: cover;
  display: block; filter: brightness(.92) saturate(1.05);
}
.hero-frame .hero-shot {
  position: absolute;
  right: 4%; bottom: 6%;
  width: min(58%, 340px);
  border-radius: 14px;
  border: 3px solid #fff;
  box-shadow: 0 16px 40px rgba(0,0,0,.35);
  background: #fff;
}
.pill-row { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: 1rem; }
.pill {
  background: #fff; border: 1px solid var(--line);
  border-radius: 999px; padding: .35rem .7rem;
  font-size: .85rem; font-weight: 700; color: var(--muted);
}

.stats-band {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;
  margin-top: -1.5rem; position: relative; z-index: 2;
}
@media (max-width: 800px) { .stats-band { grid-template-columns: 1fr; margin-top: 1rem; } }
.stat-chip {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; box-shadow: 0 8px 24px rgba(0,0,0,.04);
}
.stat-chip .v { font-size: 1.35rem; font-weight: 900; color: var(--red); }
.stat-chip .l { color: var(--muted); font-size: .95rem; }

.section { padding: 3.4rem 0; }
.section.alt { background: #fff; border-block: 1px solid var(--line); }
.section-head { margin-bottom: 1.6rem; max-width: 40rem; }
.section-head h2 { margin: 0 0 .45rem; font-size: clamp(1.6rem, 3vw, 2rem); }
.section-head p { margin: 0; color: var(--muted); }

.grid-3 {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(3, 1fr);
}
.grid-2 {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(2, 1fr);
}
@media (max-width: 900px) {
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
}
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.25rem 1.3rem;
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card .icon {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--red-soft); font-size: 1.25rem; margin-bottom: .8rem;
}
.card h3 { margin: 0 0 .45rem; font-size: 1.1rem; }
.card p { margin: 0; color: var(--muted); }
.benefit-card { display: flex; flex-direction: column; gap: .2rem; }
.benefit-card a { margin-top: auto; padding-top: .9rem; font-weight: 800; }

.gallery-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(4, 1fr);
}
@media (max-width: 1000px) { .gallery-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .gallery-grid { grid-template-columns: 1fr; } }
.gallery-item {
  margin: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,.04);
}
.gallery-item.wide { grid-column: span 2; }
@media (max-width: 600px) { .gallery-item.wide { grid-column: span 1; } }
.gallery-item img {
  display: block; width: 100%; height: 220px;
  object-fit: cover; background: #f3e8e8;
}
.gallery-item.wide img { height: 280px; }
.gallery-item figcaption {
  padding: .75rem 1rem;
  font-weight: 700; font-size: .95rem; color: var(--ink);
}
.platform-showcase {
  margin: 0 0 1.2rem;
  border-radius: calc(var(--radius) + 6px);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background: #fff;
}
.platform-showcase img {
  display: block; width: 100%; height: auto; max-height: 420px; object-fit: cover;
}

.step {
  display: grid; gap: .7rem;
  grid-template-columns: auto 1fr; align-items: start;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.2rem;
}
.step-num {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--red); color: #fff;
  display: grid; place-items: center; font-weight: 900;
}
.step h3 { margin: 0 0 .25rem; }
.step p { margin: 0; color: var(--muted); }

.cta-band {
  margin: 1rem 0 0;
  background: linear-gradient(135deg, #e81318, #9e0b10);
  color: #fff; border-radius: calc(var(--radius) + 8px);
  padding: 2rem 1.6rem;
  display: flex; flex-wrap: wrap; gap: 1rem;
  align-items: center; justify-content: space-between;
  box-shadow: var(--shadow);
}
.cta-band h2 { margin: 0 0 .35rem; font-size: 1.6rem; }
.cta-band p { margin: 0; opacity: .92; }
.cta-band .btn {
  background: #fff; color: var(--red) !important; box-shadow: none;
}
.cta-band .btn.secondary {
  background: transparent; color: #fff !important; border-color: rgba(255,255,255,.55);
}

.muted { color: var(--muted); }
.posts { display: grid; gap: 1rem; }
.post-item {
  display: grid; gap: 1rem; grid-template-columns: 200px 1fr;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
  color: inherit; text-decoration: none !important;
}
.post-item:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
@media (max-width: 700px) { .post-item { grid-template-columns: 1fr; } }
.post-item .thumb {
  min-height: 150px;
  background:
    linear-gradient(135deg, rgba(232,19,24,.18), rgba(232,19,24,.02)),
    #f7e4e4 center/cover no-repeat;
}
.post-item .body { padding: 1.05rem 1.15rem 1.15rem 0; }
@media (max-width: 700px) { .post-item .body { padding: 0 1rem 1rem; } }
.post-item h3 { margin: .35rem 0; color: var(--ink); }

.article {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.6rem;
  box-shadow: 0 8px 28px rgba(0,0,0,.03);
}
.article h1 { margin-top: 0; }
.article-meta { color: var(--muted); font-size: .95rem; margin-bottom: 1.2rem; }
.prose img { border-radius: 12px; }
.prose h2 { margin-top: 1.6rem; }

.site-footer {
  margin-top: 2rem; padding: 2.4rem 0 2rem;
  border-top: 1px solid var(--line);
  background: #fff;
  color: var(--muted); font-size: .95rem;
}
.footer-grid {
  display: grid; gap: 1.2rem;
  grid-template-columns: 1.4fr 1fr 1fr;
}
@media (max-width: 800px) { .footer-grid { grid-template-columns: 1fr; } }
.footer-grid h4 { margin: 0 0 .5rem; color: var(--ink); }
.footer-grid a { display: block; margin: .25rem 0; color: var(--muted); font-weight: 600; }

/* [hidden] must win over display:grid — otherwise login + dashboard stack. */
[hidden] { display: none !important; }
.admin-shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.admin-shell[hidden] { display: none !important; }
/* Body-class gate: never paint the shell until auth flips to .is-authed.
   Explicitly SHOW #appView when authed — Safari/WebKit can leave display:none
   stuck after toggling [hidden] + the :not(.is-authed) rule (blank page). */
body:not(.is-authed) #appView {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}
body.is-authed #loginView {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}
body.is-authed #appView,
body.is-authed #appView.admin-shell {
  display: grid !important;
  visibility: visible !important;
  pointer-events: auto !important;
}
body.auth-checking #loginView .login-box::after {
  content: 'กำลังตรวจสอบสิทธิ์…';
  display: block;
  margin-top: .85rem;
  color: var(--muted);
  font-weight: 700;
  font-size: .92rem;
}
@media (max-width: 900px) {
  .admin-shell { grid-template-columns: 1fr; }
  body.is-authed #appView.admin-shell { grid-template-columns: 1fr !important; }
}
.admin-topbar { display: none; }
.nav-backdrop { display: none; }
.admin-side {
  background: linear-gradient(180deg, #1b1b1b, #2a1212); color: #fff; padding: 1.2rem;
}
.admin-side a {
  display: block; color: #fff; padding: .55rem .7rem; border-radius: 10px;
  font-weight: 700; margin: .2rem 0;
}
.admin-side a.active, .admin-side a:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.admin-side .nav-group {
  margin: .95rem 0 .25rem;
  padding: 0 .7rem;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: rgba(255,255,255,.42);
}
.admin-main { padding: 1.2rem; background: var(--bg); }

/* Mobile: compact hamburger + slide-out drawer instead of a full-page menu. */
@media (max-width: 900px) {
  body.is-authed #appView.admin-shell {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto 1fr;
    grid-template-areas: "topbar" "main";
  }
  .admin-topbar { grid-area: topbar; }
  .admin-main { grid-area: main; min-width: 0; }
  .admin-side, .nav-backdrop { grid-area: topbar; }
  .admin-topbar {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .65rem .8rem;
    background: #1b1b1b;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 60;
    min-height: 52px;
  }
  .admin-topbar img {
    width: 28px;
    height: 28px;
    border-radius: 7px;
  }
  .admin-topbar-text { min-width: 0; flex: 1; }
  .admin-topbar-text strong { display: block; font-size: .92rem; line-height: 1.2; }
  .admin-topbar-text span {
    display: block;
    font-size: .75rem;
    color: rgba(255,255,255,.62);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .nav-toggle {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 12px;
    background: rgba(255,255,255,.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
  }
  .nav-toggle span {
    display: block;
    width: 16px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: transform .2s ease, opacity .2s ease;
  }
  body.nav-open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  body.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
  body.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(10, 8, 8, .46);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  body.nav-open .nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .admin-side {
    position: fixed;
    top: 52px;
    left: 0;
    bottom: 0;
    width: min(280px, 86vw);
    z-index: 50;
    transform: translateX(-105%);
    transition: transform .22s ease;
    overflow-y: auto;
    box-shadow: none;
  }
  body.nav-open .admin-side {
    transform: translateX(0);
    box-shadow: 12px 0 32px rgba(0,0,0,.28);
  }
  .admin-main { padding: 1rem .85rem 1.4rem; }
}
.admin-main .panel {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem;
}
label { display: block; font-weight: 700; margin: .7rem 0 .3rem; }
input[type=text], input[type=email], input[type=password], input[type=url], textarea, select {
  width: 100%; padding: .75rem .85rem; border-radius: 12px;
  border: 1px solid #ddd; font: inherit; background: #fff;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid rgba(232,19,24,.25); border-color: var(--red);
}
textarea { min-height: 160px; resize: vertical; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .55rem; border-bottom: 1px solid var(--line); font-size: .95rem; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 800px) { .stats-grid { grid-template-columns: 1fr; } }
.stat { padding: 1rem; border-radius: var(--radius); background: #fff; border: 1px solid var(--line); }
.stat .n { font-size: 2rem; font-weight: 900; color: var(--red); }
/* Full-page auth gate so login never stacks over the admin shell. */
.platform-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem 2rem;
  background:
    radial-gradient(ellipse 80% 60% at 20% 0%, rgba(232, 19, 24, .12), transparent 55%),
    linear-gradient(165deg, #fff9f9 0%, #fff 50%, #fff5f5 100%);
}
.platform-gate[hidden] { display: none !important; }
.platform-gate .login-box { width: min(440px, 100%); margin: 0; }

.login-box {
  max-width: 440px; margin: 3.5rem auto; padding: 1.7rem;
  background: #fff; border-radius: calc(var(--radius) + 4px);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.login-box h1 { margin: 0 0 .4rem; font-size: 1.55rem; }
.badge {
  display: inline-block; padding: .15rem .5rem; border-radius: 999px;
  background: #fde8e8; color: var(--red); font-size: .8rem; font-weight: 800;
}
.badge.draft { background: #eee; color: #555; }
.err { color: #b00020; font-weight: 700; }
.ok { color: #0a7a32; font-weight: 700; }
.tabs-inline { display: flex; gap: .5rem; margin: 1rem 0; }
.tabs-inline[hidden] { display: none !important; }
.tabs-inline button {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: .45rem .9rem; font-weight: 800; cursor: pointer;
  /* Keep tabs visually distinct from primary .btn CTAs */
  width: auto; flex: 1; max-width: none;
}
.tabs-inline button.active {
  background: #fff5f5; color: var(--red); border-color: var(--red);
}
