/* ThukThuk: one small stylesheet, no web fonts, no framework.
   Thai script needs taller lines than Latin; system fonts cover both
   (Leelawadee UI on Windows, Thonburi on Apple, Noto Sans Thai on Android). */

:root {
  --bg: #f6f7f5;
  --panel: #fff;
  --text: #1c2321;
  --muted: #5f6b66;
  --line: #dfe4e1;
  --brand: #0d6b45;
  --brand-ink: #fff;
  --accent: #ffc531;
  --price: #b4380b;
  --best: #fff7da;
  --ok: #17803d;
  --warn: #a15c00;
  --later: #5f6b66;
  --chip: #eef2ef;
  --on: #e3f1e9;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111614;
    --panel: #1a211e;
    --text: #e6ebe8;
    --muted: #9aa7a1;
    --line: #2c3632;
    --brand: #0f4f35;
    --price: #ff9a6b;
    --best: #2c2a17;
    --ok: #5fd28b;
    --warn: #f2b45c;
    --later: #9aa7a1;
    --chip: #232c28;
    --on: #173527;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", "Leelawadee UI", Thonburi, "Noto Sans Thai", sans-serif;
}

a { color: inherit; }
h1 { font-size: 1.4rem; margin: .4rem 0 1rem; line-height: 1.3; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .6rem; }
h2 a { text-decoration: none; }
h2 a:hover { text-decoration: underline; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; font-weight: normal; }

/* Header */
.top { background: var(--brand); color: var(--brand-ink); }
.top-row { display: flex; align-items: center; gap: 1rem; min-height: 52px; }
.logo { display: flex; align-items: baseline; gap: .4rem; text-decoration: none; font-weight: 700; }
.logo-th { font-size: 1.35rem; color: var(--accent); }
.logo-en { font-size: .95rem; letter-spacing: .02em; }
.tagline { margin-left: auto; align-self: center; opacity: .8; font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* Search box (header) and its suggestions */
.search { position: relative; flex: 1; max-width: 560px; display: flex; }
.search input {
  flex: 1; min-width: 0; font: inherit; font-size: .95rem; padding: .35rem .7rem;
  border: 0; border-radius: 6px 0 0 6px; background: #fff; color: #1c2321;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.search button {
  font: inherit; font-size: .9rem; padding: .35rem .9rem; border: 0; border-radius: 0 6px 6px 0;
  background: var(--accent); color: #3a2c00; font-weight: 700; cursor: pointer;
}
.suggest {
  position: absolute; top: calc(100% + 2px); left: 0; right: 0; z-index: 20; margin: 0; padding: .25rem 0;
  list-style: none; background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; box-shadow: 0 6px 20px rgb(0 0 0 / .18);
}
.suggest a {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 .8rem; padding: .35rem .8rem;
  text-decoration: none;
}
.suggest span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest small { grid-column: 1; color: var(--muted); font-size: .78rem; }
.suggest b { grid-column: 2; grid-row: 1 / 3; align-self: center; color: var(--price); }
.suggest li.on, .suggest li:hover { background: var(--on); }
.lang {
  margin-left: auto; flex-shrink: 0; font-size: .85rem; text-decoration: none;
  border: 1px solid rgb(255 255 255 / .45); border-radius: 4px; padding: .1rem .5rem;
}
.lang:hover { background: rgb(255 255 255 / .12); }
.tabs { display: flex; gap: .2rem; }

/* Search results */
.group { margin-top: 1.4rem; }
.group h2 { margin: 0 0 .5rem; }
.more { margin: .4rem 0 0; font-size: .9rem; }
.tabs a {
  text-decoration: none; padding: .3rem .8rem .35rem; border-radius: 6px 6px 0 0;
  font-size: .9rem; font-weight: 600; opacity: .9;
}
.tabs a:hover { background: rgb(255 255 255 / .12); }
.tabs a.on { background: var(--bg); color: var(--text); opacity: 1; }

main { padding-top: .5rem; padding-bottom: 2rem; }

.crumbs { font-size: .85rem; color: var(--muted); margin-top: .8rem; }
.crumbs a { color: var(--muted); }
.intro { margin: -.5rem 0 1rem; color: var(--muted); }
.notice { background: var(--panel); border: 1px dashed var(--line); border-radius: 6px; padding: 1rem; color: var(--muted); }

/* Category tree */
.dept h2 { font-size: 1.15rem; }
.cards {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.card {
  display: flex; flex-direction: column; gap: .1rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: .7rem .8rem;
}
.card-name { font-weight: 700; text-decoration: none; }
.card-name:hover { text-decoration: underline; }
.leafcard:hover { border-color: var(--brand); }
.from { color: var(--price); }
.leaves { list-style: none; margin: .35rem 0 0; padding: 0; font-size: .9rem; line-height: 1.7; }
.leaves a { text-decoration: none; }
.leaves a:hover { text-decoration: underline; }
.leaves a.empty { color: var(--muted); }
.leaves .muted { font-size: .8rem; }

/* Chips: variants, quick picks, active filters */
.picks { margin: 1rem 0 0; line-height: 2.1; }
.chip {
  display: inline-block; padding: .05rem .55rem; border-radius: 999px; line-height: 1.6;
  background: var(--chip); border: 1px solid var(--line); text-decoration: none; font-size: .85rem; white-space: nowrap;
}
a.chip:hover { border-color: var(--brand); }
.chip b, .chip span { color: var(--price); font-weight: 600; }
.chip.on { background: var(--on); border-color: var(--brand); }
.chip.x { background: var(--on); border-color: var(--brand); }

/* Product rows */
.rows { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.row {
  display: grid; grid-template-columns: 72px minmax(0, 1fr) auto; grid-template-areas: "thumb main price";
  gap: .2rem 1rem; padding: .6rem .8rem; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row-main { grid-area: main; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.row-price { grid-area: price; display: flex; flex-direction: column; align-items: flex-end; text-align: right; white-space: nowrap; }
/* Images: product shots sit on white in both themes; a missing one shows
   the grey category icon on a neutral tile. Fixed sizes: nothing jumps. */
.thumb { grid-area: thumb; width: 72px; height: 72px; }
.thumb img, .main-img img {
  display: block; width: 100%; height: 100%; object-fit: contain;
  background: #fff; border: 1px solid var(--line); border-radius: 6px;
}
img.ph { background: var(--chip); padding: 12%; }
.pname { font-weight: 600; text-decoration: none; }
.pname:hover { text-decoration: underline; }
.ctx { font-size: .75rem; color: var(--brand); font-weight: 600; }
@media (prefers-color-scheme: dark) { .ctx { color: var(--ok); } }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .25rem; }
.price { font-weight: 700; text-decoration: none; font-size: 1.1rem; color: var(--price); }
.price small { font-size: .7rem; font-weight: 400; color: var(--muted); }
.unit { font-size: .8rem; color: var(--muted); }

/* Category listing: filters left, results right */
.listing { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 1.2rem; align-items: start; margin-top: 1rem; }
.filters { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: .3rem .8rem .8rem; font-size: .9rem; }
.filters-head { display: none; }
.facet h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: .8rem 0 .3rem; }
.facet ul { list-style: none; margin: 0; padding: 0; }
.facet li { display: flex; align-items: baseline; gap: .4rem; }
.facet .n { margin-left: auto; color: var(--muted); font-size: .8rem; }
/* Yes/no filters have no heading: set the first one apart from the list above. */
.facet:not(.toggle) + .toggle { margin-top: .7rem; padding-top: .5rem; border-top: 1px solid var(--line); }
.opt { display: inline-flex; align-items: baseline; gap: .45rem; text-decoration: none; padding: .1rem 0; }
a.opt:hover { color: var(--brand); text-decoration: underline; }
.opt.off { color: var(--muted); opacity: .6; }
.box {
  flex-shrink: 0; width: .85rem; height: .85rem; border: 1.5px solid var(--muted); border-radius: 3px;
  position: relative; top: .1rem; background: var(--panel);
}
.opt.on .box { background: var(--brand); border-color: var(--brand); }
.opt.on .box::after {
  content: ""; position: absolute; left: .22rem; top: .03rem; width: .25rem; height: .5rem;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.opt.on { font-weight: 600; }
.price-inputs { display: flex; gap: .3rem; align-items: center; }
.price-inputs input {
  width: 0; flex: 1; min-width: 0; padding: .25rem .4rem; font: inherit; font-size: .85rem;
  border: 1px solid var(--line); border-radius: 4px; background: var(--bg); color: var(--text);
}
.price-inputs button, .filter-btn {
  font: inherit; font-size: .85rem; padding: .25rem .6rem; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink);
}
.toolbar { display: flex; align-items: baseline; gap: .8rem; margin-bottom: .6rem; }
.filter-btn { display: none; text-decoration: none; white-space: nowrap; }
.sorts { font-size: .88rem; display: flex; flex-wrap: wrap; gap: .25rem .8rem; }
.sorts a { color: var(--muted); }
.sorts a:hover { color: var(--text); }
.sorts b { border-bottom: 2px solid var(--accent); }
.active { margin: 0 0 .6rem; line-height: 2.1; }
.clear { font-size: .85rem; color: var(--muted); }
.pager { display: flex; flex-wrap: wrap; gap: .3rem; margin: .8rem 0; align-items: center; }
.pager a, .pager b, .pager span { padding: .15rem .55rem; border-radius: 4px; text-decoration: none; }
.pager a { background: var(--panel); border: 1px solid var(--line); }
.pager a:hover { border-color: var(--brand); }
.pager b { background: var(--brand); color: var(--brand-ink); }

/* Tables */
.list {
  width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
}
.list th, .list td { padding: .45rem .7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.list th { font-size: .8rem; font-weight: 600; color: var(--muted); background: var(--bg); }
.list tr:last-child td { border-bottom: 0; }
.list .num { text-align: right; white-space: nowrap; }
.list .small { display: block; }
.total { font-weight: 700; color: var(--price); }
tr.best td { background: var(--best); }
.tag {
  display: inline-block; margin-left: .3rem; padding: 0 .35rem; border-radius: 3px;
  background: var(--accent); color: #3a2c00; font-size: .7rem; font-weight: 700; vertical-align: 1px;
}
.free { color: var(--ok); font-weight: 600; }
.stock { display: block; font-size: .8rem; white-space: nowrap; }
.stock::before { content: "● "; }
.stock.ok { color: var(--ok); }
.stock.warn { color: var(--warn); }
.stock.later { color: var(--later); }
.terms { font-size: .85rem; }
.terms.official { color: var(--ok); font-weight: 600; }
.terms.official::before { content: "✓ "; }
.terms.none { color: var(--warn); }

/* Product page */
.hero { display: flex; gap: 1.2rem; align-items: flex-start; margin: .6rem 0 .4rem; }
.main-img { flex-shrink: 0; width: 220px; height: 220px; }
.main-img img { border-radius: 8px; }
.hero-info { min-width: 0; flex: 1; }
.hero h1 { margin-top: 0; }
.hero .best-box { margin-top: .6rem; }
.variants { margin: -.4rem 0 .6rem; line-height: 2.1; }
.switch { margin: -.2rem 0 .5rem; font-size: .9rem; display: flex; flex-wrap: wrap; gap: .2rem 1.2rem; }
.product { display: grid; gap: 1.2rem; grid-template-columns: minmax(0, 1fr) 280px; align-items: start; }
.product h2:first-child { margin-top: 0; }
.specs { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: .8rem 1rem; }
.best-box { margin: 0 0 .4rem; display: flex; flex-direction: column; font-size: .85rem; color: var(--muted); }
.best-box b { font-size: 1.6rem; color: var(--price); line-height: 1.2; }
.specs dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .25rem .8rem; font-size: .9rem; }
.specs dt { color: var(--muted); }
.specs dd { margin: 0; }

.foot { color: var(--muted); font-size: .8rem; padding-bottom: 2rem; }
.foot p { margin: 0; border-top: 1px solid var(--line); padding-top: .8rem; }
.foot p + p { border-top: 0; padding-top: .3rem; }
.foot a { color: var(--muted); }

/* Text pages (privacy, the feed spec) */
.prose { max-width: 72ch; }
.prose ul { padding-left: 1.2rem; }
.prose li { margin: .6rem 0; line-height: 1.65; }
.prose h2 { margin-top: 2rem; font-size: 1.15rem; }
.prose pre { overflow-x: auto; padding: .8rem; background: var(--chip); border: 1px solid var(--line); border-radius: 6px; font-size: .85rem; }
.spec-table { border-collapse: collapse; width: 100%; }
.spec-table th, .spec-table td { text-align: left; vertical-align: top; padding: .5rem .6rem; border-top: 1px solid var(--line); }
.spec-table th { white-space: nowrap; width: 1%; }
.spec-table small { color: var(--muted); word-break: break-all; }
.ship-label { display: none; color: var(--muted); }

/* Phones. Filters become a full-screen panel opened by the "Filters"
   link (#filters :target, no script); each offer becomes a two-line card
   with the total top right, so the deciding number is never scrolled away. */
@media (max-width: 760px) {
  .tagline { display: none; }
  .top-row { flex-wrap: wrap; row-gap: .45rem; padding-top: .5rem; padding-bottom: .5rem; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .cards { grid-template-columns: 1fr 1fr; }
  .listing { grid-template-columns: minmax(0, 1fr); margin-top: .6rem; }
  .filters { display: none; }
  .filters:target {
    display: block; position: fixed; inset: 0; z-index: 10; overflow-y: auto;
    border-radius: 0; border: 0; padding: .8rem 1rem 2rem;
  }
  .filters-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 1rem; }
  .filter-btn { display: inline-block; }
  .toolbar { align-items: flex-start; }
  .sorts { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; padding-bottom: .2rem; min-width: 0; }
  .row { grid-template-columns: 56px minmax(0, 1fr); grid-template-areas: "thumb main" "thumb price"; gap: .2rem .7rem; }
  .thumb { width: 56px; height: 56px; }
  .row-price { flex-direction: row; align-items: baseline; gap: .6rem; }
  .hero { gap: .8rem; }
  .main-img { width: 120px; height: 120px; }
  .hero h1 { font-size: 1.15rem; }
  .product { grid-template-columns: 1fr; }
  .list th, .list td { padding: .4rem .5rem; }
  #offers thead { display: none; }
  #offers tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .15rem .8rem;
    grid-template-areas: "shop total" "terms ship";
    padding: .55rem .7rem; border-bottom: 1px solid var(--line);
  }
  #offers tr:last-child { border-bottom: 0; }
  #offers tr.best { background: var(--best); }
  #offers td { display: block; padding: 0; border: 0; background: none; }
  #offers .shop { grid-area: shop; }
  #offers .total { grid-area: total; }
  #offers td.terms { grid-area: terms; }
  #offers .ship { grid-area: ship; font-size: .85rem; }
  #offers .price-cell { display: none; }
  #offers .ship-label { display: inline; }
}
