/* ==========================================================================
   ไพ่สามกอง — Design System
   Plain CSS. Mobile-first, fast, accessible, SEO-friendly.
   ========================================================================== */

:root {
  /* Palette */
  --felt-900: #0b3d2e;
  --felt-800: #0f5138;
  --felt-700: #146c4b;
  --gold-500: #d4af37;
  --gold-400: #e5c860;
  --gold-600: #b8952c;
  --red-card: #c0392b;
  --ink-900: #16211d;
  --ink-700: #33403a;
  --ink-500: #5c6b64;
  --paper: #ffffff;
  --paper-2: #f6f8f6;
  --paper-3: #eef2ef;
  --line: #dbe4de;

  /* Typography */
  --font-body: "Sarabun", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-head: "Prompt", "Noto Sans Thai", system-ui, sans-serif;

  /* Layout */
  --wrap: 1120px;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 33, 29, .06), 0 2px 8px rgba(16, 33, 29, .06);
  --shadow-md: 0 6px 24px rgba(16, 33, 29, .12);
}

/* ---------- Reset-ish ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink-900);
  background: var(--paper-2);
  line-height: 1.75;
  font-size: 1.02rem;
  overflow-x: hidden;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--felt-700); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { font-family: var(--font-head); line-height: 1.3; color: var(--ink-900); font-weight: 600; }
h1 { font-size: clamp(1.7rem, 4.5vw, 2.6rem); margin: 0 0 .5em; }
h2 { font-size: clamp(1.35rem, 3.2vw, 1.9rem); margin: 1.8em 0 .6em; }
h3 { font-size: clamp(1.1rem, 2.4vw, 1.3rem); margin: 1.4em 0 .4em; }
p { margin: 0 0 1.1em; }

.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: 20px; }

/* ---------- Skip link ---------- */
.skip { position: absolute; left: -9999px; top: 0; background: var(--gold-500); color: #000; padding: 10px 16px; z-index: 200; border-radius: 0 0 8px 0; }
.skip:focus { left: 0; }

/* ---------- Header / Nav ---------- */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--felt-900);
  color: #fff;
  box-shadow: var(--shadow-md);
}
.nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding-block: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-head); font-weight: 700; font-size: 1.25rem; color: #fff; }
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 38px; height: 38px; border-radius: 9px;
  background: linear-gradient(145deg, var(--gold-400), var(--gold-600));
  display: grid; place-items: center; color: var(--felt-900); font-size: 1.2rem; font-weight: 800;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25);
}
.brand small { display: block; font-size: .62rem; font-weight: 400; color: var(--gold-400); letter-spacing: .12em; }

.nav-links { display: flex; align-items: center; gap: 4px; list-style: none; margin: 0; padding: 0; }
.nav-links a {
  color: #e9f3ee; padding: 8px 14px; border-radius: 8px; font-size: .96rem; font-weight: 500;
  display: block; transition: background .15s;
}
.nav-links a:hover { background: rgba(255,255,255,.1); text-decoration: none; }
.nav-links a[aria-current="page"] { background: var(--gold-500); color: var(--felt-900); }

.nav-toggle { display: none; background: none; border: 0; color: #fff; cursor: pointer; padding: 8px; }
.nav-toggle svg { width: 26px; height: 26px; }

@media (max-width: 820px) {
  .nav-toggle { display: block; }
  .nav-links {
    position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    background: var(--felt-800);
    max-height: 0; overflow: hidden; transition: max-height .28s ease;
  }
  .nav-links.open { max-height: 420px; }
  .nav-links a { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.08); border-radius: 0; }
}

/* ---------- Hero ---------- */
.hero {
  background:
    radial-gradient(1200px 400px at 80% -10%, rgba(212,175,55,.25), transparent 60%),
    linear-gradient(160deg, var(--felt-800), var(--felt-900));
  color: #fff; padding: clamp(40px, 8vw, 88px) 0;
  position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 22px 22px; opacity: .5; pointer-events: none;
}
.hero .wrap { position: relative; z-index: 1; display: grid; grid-template-columns: 1.15fr .85fr; gap: 40px; align-items: center; }
.hero h1 { color: #fff; }
.hero p.lead { font-size: 1.15rem; color: #dcece4; max-width: 42ch; }
.hero .kicker { display: inline-block; background: rgba(212,175,55,.18); color: var(--gold-400); border: 1px solid rgba(212,175,55,.4); padding: 5px 14px; border-radius: 999px; font-size: .82rem; font-weight: 600; letter-spacing: .04em; margin-bottom: 18px; }

@media (max-width: 820px) {
  .hero .wrap { grid-template-columns: 1fr; gap: 28px; }
  .hero-cards { order: -1; }
}

/* Decorative card fan */
.hero-cards { display: flex; justify-content: center; }
.card-fan { position: relative; width: 260px; height: 220px; }
.pcard {
  position: absolute; width: 108px; height: 152px; background: #fff; border-radius: 12px;
  box-shadow: var(--shadow-md); border: 1px solid #e6e6e6;
  display: grid; place-items: center; font-weight: 800; font-family: var(--font-head);
  font-size: 2.4rem; top: 34px; left: 76px; transform-origin: bottom center;
}
.pcard.c1 { transform: rotate(-22deg) translateX(-6px); }
.pcard.c2 { transform: rotate(0deg); z-index: 2; }
.pcard.c3 { transform: rotate(22deg) translateX(6px); }
.pcard .suit { font-size: 1.1rem; position: absolute; top: 8px; left: 10px; }
.pcard.red { color: var(--red-card); }
.pcard.black { color: #1a1a1a; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 24px; border-radius: 999px; font-weight: 600; font-family: var(--font-head);
  cursor: pointer; border: 2px solid transparent; transition: transform .12s, box-shadow .15s;
  text-decoration: none; font-size: 1rem;
}
.btn:hover { text-decoration: none; transform: translateY(-2px); }
.btn-primary { background: linear-gradient(145deg, var(--gold-400), var(--gold-600)); color: var(--felt-900); box-shadow: var(--shadow-md); }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.5); }
.btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-row { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 26px; }

/* ---------- Layout: content + sidebar ---------- */
.page { padding-block: clamp(28px, 5vw, 56px); }
.layout { display: grid; grid-template-columns: 1fr 300px; gap: 44px; align-items: start; }
@media (max-width: 940px) { .layout { grid-template-columns: 1fr; } }

.content { min-width: 0; }
.content > p, .content > ul, .content > ol { max-width: 68ch; }

/* Byline (ผู้เขียน + วันที่อัปเดต) เพื่อ E-E-A-T */
.byline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; font-size: .86rem; color: var(--ink-500); margin: 0 0 24px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.byline .author { display: inline-flex; align-items: center; gap: 9px; font-weight: 600; color: var(--ink-700); }
.byline .author .ava { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(145deg, var(--gold-400), var(--gold-600)); display: grid; place-items: center; color: var(--felt-900); font-family: var(--font-head); font-size: .95rem; font-weight: 700; }
.byline .dot { color: var(--line); }
.byline time { color: var(--ink-500); }

/* Breadcrumb */
.crumbs { font-size: .85rem; color: var(--ink-500); margin-bottom: 18px; }
.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; }
.crumbs li::after { content: "›"; margin-left: 6px; color: var(--line); }
.crumbs li:last-child::after { content: ""; }

/* ---------- Cards / callouts ---------- */
.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow-sm); margin: 0 0 22px;
}
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.feature { text-align: left; }
.feature .ico { width: 46px; height: 46px; border-radius: 11px; display: grid; place-items: center; background: var(--paper-3); font-size: 1.5rem; margin-bottom: 12px; }
.feature h3 { margin-top: 0; }

.callout { border-left: 4px solid var(--gold-500); background: #fffdf3; padding: 16px 20px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin: 22px 0; }
.callout.tip { border-color: var(--felt-700); background: #f1faf5; }
.callout.warn { border-color: var(--red-card); background: #fdf3f2; }
.callout strong { font-family: var(--font-head); }

/* ---------- Steps ---------- */
.steps { list-style: none; counter-reset: step; padding: 0; margin: 24px 0; }
.steps > li { position: relative; padding: 4px 0 22px 62px; }
.steps > li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 0; top: 0; width: 42px; height: 42px; border-radius: 50%;
  background: var(--felt-800); color: #fff; font-family: var(--font-head); font-weight: 700;
  display: grid; place-items: center; font-size: 1.15rem;
}
.steps > li:not(:last-child)::after {
  content: ""; position: absolute; left: 20px; top: 46px; bottom: 4px; width: 2px; background: var(--line);
}
.steps h3 { margin: 6px 0 4px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 22px 0; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; min-width: 460px; background: #fff; }
th, td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--line); }
thead th { background: var(--felt-800); color: #fff; font-family: var(--font-head); font-weight: 600; }
tbody tr:nth-child(even) { background: var(--paper-2); }
tbody tr:hover { background: #f0f7f3; }
.rank-badge { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--gold-500); color: var(--felt-900); font-weight: 700; font-size: .85rem; }

/* Mini playing-card glyphs in text */
.mini-card { display: inline-grid; place-items: center; min-width: 26px; height: 34px; padding: 0 5px; border: 1px solid #d0d0d0; border-radius: 5px; background: #fff; font-weight: 700; font-family: var(--font-head); vertical-align: middle; box-shadow: 0 1px 1px rgba(0,0,0,.08); line-height: 1; }
.mini-card.red { color: var(--red-card); }
.mini-card.black { color: #1a1a1a; }

/* ---------- FAQ / accordion ---------- */
.faq-item { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 12px; background: #fff; overflow: hidden; }
.faq-item summary {
  cursor: pointer; padding: 16px 20px; font-family: var(--font-head); font-weight: 600; font-size: 1.05rem;
  list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: "+"; color: var(--felt-700); font-size: 1.5rem; font-weight: 400; transition: transform .2s; }
.faq-item[open] summary::after { transform: rotate(45deg); }
.faq-item .faq-body { padding: 0 20px 18px; }
.faq-item .faq-body p:last-child { margin-bottom: 0; }

/* ---------- Sidebar ---------- */
.sidebar { position: sticky; top: 84px; display: grid; gap: 22px; }
.toc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.toc h4 { margin: 0 0 12px; font-size: .82rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-500); }
.toc ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.toc a { display: block; padding: 7px 10px; border-radius: 7px; font-size: .92rem; color: var(--ink-700); border-left: 2px solid transparent; }
.toc a:hover { background: var(--paper-2); text-decoration: none; border-left-color: var(--gold-500); }

.side-cta { background: linear-gradient(160deg, var(--felt-800), var(--felt-900)); color: #fff; border-radius: var(--radius); padding: 24px; }
.side-cta h4 { color: #fff; margin: 0 0 8px; }
.side-cta p { color: #cfe3d9; font-size: .92rem; }

/* ---------- Related / next ---------- */
.related-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 20px; }
@media (max-width: 720px) { .related-grid { grid-template-columns: 1fr; } }
.related-card { display: block; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; transition: transform .12s, box-shadow .15s; }
.related-card:hover { text-decoration: none; transform: translateY(-3px); box-shadow: var(--shadow-md); }
.related-card .tag { font-size: .74rem; color: var(--gold-600); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.related-card h3 { margin: 6px 0; font-size: 1.1rem; }
.related-card p { margin: 0; font-size: .92rem; color: var(--ink-500); }

/* ---------- Section heading ---------- */
.section-head { text-align: center; max-width: 60ch; margin: 0 auto 8px; }
.section-head .eyebrow { color: var(--gold-600); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; font-size: .8rem; }

/* ---------- Footer ---------- */
.site-footer { background: var(--felt-900); color: #cfe3d9; padding: 48px 0 24px; margin-top: 60px; }
.footer-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 32px; }
@media (max-width: 720px) { .footer-grid { grid-template-columns: 1fr; gap: 24px; } }
.site-footer h4 { color: #fff; font-size: 1rem; margin: 0 0 14px; }
.site-footer a { color: #cfe3d9; }
.site-footer a:hover { color: var(--gold-400); }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.footer-bottom { border-top: 1px solid rgba(255,255,255,.12); margin-top: 32px; padding-top: 20px; font-size: .85rem; color: #9db8ac; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; }
.disclaimer { background: rgba(0,0,0,.2); border-radius: var(--radius-sm); padding: 14px 18px; font-size: .82rem; color: #a9c4b8; margin-top: 20px; }

/* ---------- Utilities ---------- */
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.hidden { display: none !important; }
.lead { font-size: 1.12rem; color: var(--ink-700); }
.pill-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0; }
.pill { background: var(--paper-3); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: .88rem; font-weight: 500; }

/* ---------- Sticky action bar (3 ปุ่มลัดด้านล่าง) ---------- */
.action-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 95;
  background: var(--felt-900);
  box-shadow: 0 -4px 22px rgba(0, 0, 0, .28);
  border-top: 1px solid rgba(255, 255, 255, .1);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.action-bar .ab-inner {
  max-width: 640px; margin-inline: auto; width: 100%;
  display: grid; grid-template-columns: repeat(3, 1fr);
}
.action-bar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 9px 6px 10px; color: #e9f3ee; text-decoration: none;
  font-family: var(--font-head); font-weight: 600; font-size: .84rem;
  border-left: 1px solid rgba(255, 255, 255, .07);
  transition: background .15s;
}
.action-bar a:first-child { border-left: 0; }
.action-bar a:hover, .action-bar a:focus-visible { background: rgba(255, 255, 255, .08); text-decoration: none; }
.action-bar a .ab-ico { font-size: 1.35rem; line-height: 1; }
.action-bar a.primary {
  background: linear-gradient(145deg, var(--gold-400), var(--gold-600));
  color: var(--felt-900); border-left-color: transparent;
}
.action-bar a.primary:hover, .action-bar a.primary:focus-visible { filter: brightness(1.06); }

/* เว้นที่ด้านล่างไม่ให้แถบทับเนื้อหา/ฟุตเตอร์ */
body { padding-bottom: 70px; }
@media (min-width: 1100px) {
  /* บนจอใหญ่ยกแถบลอยเป็นการ์ดกลางจอ ดูไม่เหมือนเมนูมือถือ */
  .action-bar { left: 50%; right: auto; transform: translateX(-50%); bottom: 18px; width: min(640px, calc(100% - 40px)); border-radius: 999px; overflow: hidden; border: 1px solid rgba(255,255,255,.12); }
  .action-bar a { padding-block: 12px; }
}

:focus-visible { outline: 3px solid var(--gold-500); outline-offset: 2px; border-radius: 4px; }

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

/* ==========================================================================
   เกมสาธิตไพ่สามกอง (game.html)
   ========================================================================== */
.game-shell { display: grid; gap: 22px; }

/* แผงคะแนน */
.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; text-align: center; }
.scoreboard .score-side { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 10px; }
.scoreboard .score-side.you { border-color: var(--felt-700); }
.scoreboard .score-side .who { font-family: var(--font-head); font-weight: 600; font-size: .9rem; color: var(--ink-500); }
.scoreboard .score-side .pts { font-family: var(--font-head); font-weight: 700; font-size: 2rem; line-height: 1.1; }
.scoreboard .score-side.you .pts { color: var(--felt-700); }
.scoreboard .vs { font-family: var(--font-head); font-weight: 700; color: var(--gold-600); }
.scoreboard .rounds { font-size: .78rem; color: var(--ink-500); margin-top: 2px; }

/* ปุ่มควบคุมเกม */
.game-controls { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-sm { padding: 9px 18px; font-size: .92rem; }
.btn-outline { background: #fff; border-color: var(--line); color: var(--ink-700); }
.btn-outline:hover { background: var(--paper-2); }
.btn[disabled] { opacity: .45; cursor: not-allowed; pointer-events: none; }

/* ไพ่ในเกม */
.gcard {
  position: relative; width: 54px; height: 78px; border-radius: 8px; background: #fff;
  border: 1px solid #cfd8d2; box-shadow: var(--shadow-sm); cursor: pointer; user-select: none;
  font-family: var(--font-head); font-weight: 700; padding: 5px 6px; transition: transform .1s, box-shadow .12s;
  display: flex; flex-direction: column; align-items: flex-start;
}
.gcard:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.gcard.red { color: var(--red-card); }
.gcard.black { color: #1a1a1a; }
.gcard .g-rank { font-size: 1rem; line-height: 1; }
.gcard .g-suit { font-size: 1.6rem; line-height: 1; margin: 2px auto 0; }
.gcard.selected { outline: 3px solid var(--gold-500); outline-offset: 2px; transform: translateY(-8px); box-shadow: var(--shadow-md); }
.gcard.static { cursor: default; }
.gcard.static:hover { transform: none; box-shadow: var(--shadow-sm); }

/* โซนมือ + กอง */
.zone { border: 2px dashed var(--line); border-radius: 12px; padding: 12px 14px; background: #fff; }
.zone.hand { background: var(--paper-2); }
.zone.armed { border-color: var(--gold-500); background: #fffdf3; box-shadow: 0 0 0 3px rgba(212,175,55,.15); }
.zone.invalid { border-color: var(--red-card); }
.zone-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.zone-head .z-title { font-family: var(--font-head); font-weight: 600; }
.zone-head .z-sub { font-size: .78rem; color: var(--ink-500); }
.zone-head .z-count { font-family: var(--font-head); font-weight: 700; font-size: .95rem; }
.zone-head .z-count.full { color: var(--felt-700); }
.zone-head .z-hand { font-size: .8rem; font-weight: 600; color: var(--gold-600); }
.zone-cards { display: flex; flex-wrap: wrap; gap: 8px; min-height: 84px; }
.zone-cards.empty::before { content: attr(data-empty); color: var(--ink-500); font-size: .85rem; align-self: center; }

.hint { font-size: .86rem; color: var(--ink-500); }
.foul-warn { display: none; }
.foul-warn.show { display: block; }

/* ผลลัพธ์การเทียบไพ่ */
.result-banner { border-radius: var(--radius); padding: 16px 20px; text-align: center; font-family: var(--font-head); font-weight: 700; font-size: 1.2rem; }
.result-banner.win { background: #eafaf1; color: #147a4b; border: 1px solid #b6e6cc; }
.result-banner.lose { background: #fdecea; color: #b23b30; border: 1px solid #f3c7c2; }
.result-banner.tie { background: var(--paper-3); color: var(--ink-700); border: 1px solid var(--line); }
.result-row td.win-cell { color: #147a4b; font-weight: 700; }
.result-row td.lose-cell { color: #b23b30; font-weight: 700; }
.result-row td.tie-cell { color: var(--ink-500); font-weight: 600; }

@media (max-width: 480px) {
  .gcard { width: 46px; height: 68px; padding: 4px 5px; }
  .gcard .g-suit { font-size: 1.35rem; }
  .gcard .g-rank { font-size: .9rem; }
  .zone-cards { gap: 6px; }
}
