:root {
  --mint-1: #74ead0;
  --mint-2: #5fcdac;
  --mint-3: #54bfa0;
  --ink: #101614;
  --muted: #6b7a75;
  --line: #e7efec;
  --bg: #ffffff;
  --soft: #f3faf7;
  --danger: #d6453d;
  --radius-card: 30px;
  --nav-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, "SF Pro Text", "Noto Sans Thai", "Sarabun", system-ui, sans-serif;
  line-height: 1.45;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { font: inherit; }
a { color: inherit; }

.wrap { max-width: 880px; margin: 0 auto; padding: 0 20px; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255,255,255,.86);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  padding-top: env(safe-area-inset-top);
}
.top .wrap { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { font-weight: 700; font-size: 1rem; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.brand i {
  width: 26px; height: 26px; border-radius: 9px; display: inline-grid; place-items: center;
  background: radial-gradient(120% 100% at 50% 0%, var(--mint-1), var(--mint-3));
}
.brand i svg { width: 15px; height: 15px; fill: #fff; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 999px; font-weight: 600; font-size: .92rem;
  background: var(--soft); color: #1d7a63; border: 1px solid #d6efe6;
}
.chip.solid { background: var(--mint-2); color: #fff; border-color: transparent; }

/* ---------- page header ---------- */
h1.page-title { font-size: 1.65rem; margin: 22px 0 18px; font-weight: 800; letter-spacing: -.2px; }
.sub { color: var(--muted); font-size: .92rem; margin: -10px 0 18px; }

/* ---------- product cards (เหมือนการ์ดของแอป Shortcuts) ---------- */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
@media (min-width: 860px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 18px; } }

.card {
  position: relative; display: block; width: 100%; text-align: left;
  container-type: inline-size;
  aspect-ratio: 452 / 232;
  border-radius: 22px;
  color: #fff;
  background: radial-gradient(130% 120% at 50% 0%, var(--mint-1) 0%, var(--mint-2) 55%, var(--mint-3) 100%);
  box-shadow: 0 18px 24px -18px rgba(70, 180, 150, .75);
  transition: transform .16s ease, box-shadow .16s ease;
  overflow: hidden;
}
.card:active { transform: scale(.97); }
.card .ico { position: absolute; left: 7%; top: 11%; width: 16cqw; height: 16cqw; min-width: 28px; min-height: 28px; color: rgba(255,255,255,.92); }
.card .ico svg { width: 100%; height: 100%; }
.card .play {
  position: absolute; right: 6%; top: 10%; width: 13cqw; height: 13cqw; min-width: 26px; min-height: 26px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(255,255,255,.2);
}
.card .play svg { width: 45%; height: 45%; fill: #fff; margin-left: 6%; }
.card .meta { position: absolute; left: 7%; right: 6%; bottom: 9%; }
.card .title {
  display: block; font-weight: 600; font-size: clamp(.95rem, 7.4cqw, 1.5rem); line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card .price { display: block; margin-top: 2px; font-size: clamp(.72rem, 4.6cqw, .95rem); font-weight: 600; opacity: .85; }
.card.owned .play { background: #fff; }
.card.owned .play svg { fill: var(--mint-3); margin: 0; }

.empty { text-align: center; color: var(--muted); padding: 48px 0; }

/* ---------- bottom nav ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav .wrap { display: grid; grid-template-columns: repeat(4, 1fr); height: var(--nav-h); }
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; font-size: .72rem; font-weight: 600; color: var(--muted);
}
.nav a svg { width: 24px; height: 24px; fill: currentColor; }
.nav a.on { color: #25a784; }

/* ---------- panels / forms ---------- */
.panel { background: var(--soft); border: 1px solid #dff1ea; border-radius: 24px; padding: 20px; margin-bottom: 16px; }
.panel h2 { margin: 0 0 4px; font-size: 1.05rem; }
.panel p { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }
.step-n {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--mint-2); color: #fff; font-size: .8rem; font-weight: 700; margin-right: 8px;
}
.pay-box { display: flex; gap: 16px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.pay-qr { width: 150px; height: 150px; border-radius: 16px; background: #fff; border: 1px solid var(--line); object-fit: contain; }
.pay-info b { display: block; font-size: 1.05rem; }
.pay-info span { color: var(--muted); font-size: .92rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 22px; border-radius: 16px; font-weight: 700;
  background: radial-gradient(130% 160% at 50% 0%, var(--mint-1), var(--mint-3));
  color: #fff; width: 100%; font-size: 1rem;
  box-shadow: 0 14px 20px -14px rgba(70,180,150,.9);
}
.btn:disabled { opacity: .5; box-shadow: none; cursor: not-allowed; }
.btn.ghost { background: #fff; color: #1d7a63; border: 1px solid #cfeade; box-shadow: none; }
.btn.small { width: auto; padding: 8px 14px; font-size: .88rem; border-radius: 12px; }

.drop {
  margin-top: 14px; border: 2px dashed #a8dccb; border-radius: 20px; background: #fff;
  padding: 22px; text-align: center; color: var(--muted); cursor: pointer;
}
.drop.has { border-style: solid; }
.drop img { max-width: 100%; max-height: 260px; border-radius: 12px; display: block; margin: 0 auto 10px; }
.drop strong { color: #1d7a63; }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%; padding: 13px 14px; border-radius: 14px; border: 1px solid #cfe5dd; background: #fff; font-size: 1rem;
}
.field input:focus { outline: 2px solid var(--mint-2); border-color: transparent; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list small { color: var(--muted); display: block; }
.plus { color: #1d9a76; font-weight: 700; }
.minus { color: var(--danger); font-weight: 700; }

.lib-item { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 22px; margin-bottom: 12px; background: var(--soft); border: 1px solid #dff1ea; }
.lib-item .mini {
  flex: none; width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center;
  background: radial-gradient(130% 120% at 50% 0%, var(--mint-1), var(--mint-3));
}
.lib-item .mini { color: #fff; }
.lib-item .mini svg { width: 28px; height: 28px; }
.lib-item .grow { flex: 1; min-width: 0; }
.lib-item .grow b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-item .grow small { color: var(--muted); }

/* ---------- bottom sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10,25,20,.4); z-index: 50; opacity: 0; transition: opacity .2s; }
.scrim.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  max-width: 560px; margin: 0 auto;
  background: #fff; border-radius: 30px 30px 0 0;
  padding: 10px 22px calc(22px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .26s cubic-bezier(.2,.8,.2,1);
  max-height: 88vh; overflow: auto;
}
.sheet.show { transform: translateY(0); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: #d8e4df; margin: 0 auto 16px; }
.sheet .hero {
  height: 120px; border-radius: 24px; display: grid; place-items: center; margin-bottom: 16px;
  background: radial-gradient(130% 140% at 50% 0%, var(--mint-1), var(--mint-3));
}
.sheet .hero { color: #fff; }
.sheet .hero svg { width: 56px; height: 56px; }
.sheet h3 { margin: 0 0 6px; font-size: 1.3rem; }
.sheet .desc { color: var(--muted); margin: 0 0 16px; white-space: pre-line; }
.sheet .row { display: flex; justify-content: space-between; margin-bottom: 14px; font-weight: 600; }
.sheet .row span:last-child { color: #1d7a63; }
.sheet .stack { display: grid; gap: 10px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px); z-index: 80;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: min(92vw, 460px); padding: 12px 18px; border-radius: 16px;
  background: #13211d; color: #fff; font-size: .92rem; font-weight: 600; text-align: center;
  transition: all .22s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }
.toast.ok { background: #1d9a76; }

.success { text-align: center; padding: 8px 0 4px; }
.success .big { font-size: 2rem; font-weight: 800; color: #1d9a76; }

.spin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid rgba(255,255,255,.45); border-top-color: #fff; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--soft); border-radius: 14px; padding: 4px; margin-bottom: 16px; }
.tabs button { padding: 9px; border-radius: 11px; font-weight: 700; color: var(--muted); }
.tabs button.on { background: #fff; color: #1d7a63; box-shadow: 0 2px 8px rgba(0,0,0,.06); }

.skeleton { background: linear-gradient(100deg, #eef5f2 30%, #f8fbfa 50%, #eef5f2 70%); background-size: 200% 100%; animation: sk 1.2s linear infinite; border-radius: 22px; aspect-ratio: 452/232; }
@keyframes sk { to { background-position: -200% 0; } }

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

/* ---------- รูปปกสินค้า ---------- */
.sheet .hero { height: 200px; overflow: hidden; }
.sheet .hero svg { width: 84px; height: 84px; }
.sheet .hero.has-img img { width: 100%; height: 100%; object-fit: cover; }
.lib-item .mini { overflow: hidden; width: 60px; height: 60px; }
.lib-item .mini img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- ลองใช้ API ---------- */
.field textarea { width: 100%; padding: 13px 14px; border-radius: 14px; border: 1px solid #cfe5dd; background: #fff; font: inherit; min-height: 84px; resize: vertical; }
.result { margin-top: 14px; padding: 14px; background: var(--soft); border: 1px solid #dff1ea; border-radius: 18px; word-break: break-word; }
.result img, .result video { max-width: 100%; border-radius: 12px; display: block; margin: 0 auto 10px; }
.result pre { margin: 0; white-space: pre-wrap; font-size: .88rem; }
.result p { margin: 8px 0 0; }

/* ซ่อนแถบเลื่อน (ยังเลื่อนได้ตามปกติ) */
.sheet { scrollbar-width: none; -ms-overflow-style: none; }
.sheet::-webkit-scrollbar { display: none; width: 0; }
.sheet { overscroll-behavior: contain; }
.scrim { touch-action: none; }

/* ---------- กล่องอัปโหลดรูป (minimal) ---------- */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  min-height: 132px; margin-top: 14px; padding: 20px 16px; text-align: center;
  border: 1.5px dashed #b4e0d1; border-radius: 20px; background: #fbfefd;
  color: var(--muted); cursor: pointer; transition: background .15s, border-color .15s;
}
.drop:active { background: #f0faf6; border-color: var(--mint-2); }
.drop:not(.has)::before {
  content: ""; width: 30px; height: 30px; background: var(--mint-2);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 15V4M7.5 8.5 12 4l4.5 4.5'/%3E%3Cpath d='M4 15v3.5A1.5 1.5 0 0 0 5.5 20h13a1.5 1.5 0 0 0 1.5-1.5V15'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 15V4M7.5 8.5 12 4l4.5 4.5'/%3E%3Cpath d='M4 15v3.5A1.5 1.5 0 0 0 5.5 20h13a1.5 1.5 0 0 0 1.5-1.5V15'/%3E%3C/svg%3E") center / contain no-repeat;
}
.drop.has { border-style: solid; border-color: #cfeade; background: #fff; }
.drop > div { font-size: .95rem; }

/* ---------- ช่องกรอกข้อความ (minimal) ---------- */
.field span { font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; letter-spacing: .1px; }
.field input, .field textarea {
  padding: 11px 14px; border-radius: 14px; border: 1px solid #dcebe5; background: #fbfefd; font-size: 1rem;
}
.field textarea { height: 46px; min-height: 46px; max-height: 160px; field-sizing: content; resize: none; line-height: 1.4; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--mint-2); box-shadow: 0 0 0 3px rgba(95,205,172,.18); background: #fff; }

/* ---------- สีปุ่มตามความหมาย ---------- */
.btn.warn { background: radial-gradient(130% 160% at 50% 0%, #f9c565, #ee9418); box-shadow: 0 14px 20px -14px rgba(238,148,24,.9); }
.btn.info { background: radial-gradient(130% 160% at 50% 0%, #7ab6ff, #3b82ee); box-shadow: 0 14px 20px -14px rgba(59,130,238,.9); }
.btn.ghost.info { background: #f3f8ff; color: #2a6bd0; border: 1px solid #cfe0fa; box-shadow: none; }
.btn.ghost.bad { background: #fff6f5; color: #c93d35; border: 1px solid #f3cbc8; box-shadow: none; }
.btn.ghost.quiet { background: #f6f8f7; color: #5d6b66; border: 1px solid #e3eae7; box-shadow: none; }
