:root {
  --cream: #fff5c9;
  --sun: #ffc83d;
  --sun-deep: #f29a1f;
  --leaf: #3f7d3a;
  --ink: #2f2a1c;
  --card: #fffdf3;
  --shadow: 0 10px 30px rgba(120, 84, 10, .16);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; background: var(--cream); }
body {
  font-family: "Noto Sans Thai", "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 10% 0%, #fffbe0 0, var(--cream) 45%, #ffe9a3 100%);
  min-height: 100vh;
  line-height: 1.55;
}

.app-shell { max-width: 960px; margin: 0 auto; padding: 16px 16px 40px; display: grid; gap: 28px; }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-weight: 600; letter-spacing: .08em; font-size: .95rem; }
.brand b { color: var(--sun-deep); }
.brand-flower { color: var(--sun-deep); font-size: 1.3rem; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: .68rem; letter-spacing: .12em; padding: 6px 12px; border-radius: 999px; background: #fff; box-shadow: var(--shadow); }
.status-pill i, .live-label i { width: 8px; height: 8px; border-radius: 50%; background: #3ac569; display: inline-block; }

/* ---------- intro ---------- */
.intro { text-align: center; padding: 20px 0 4px; display: grid; gap: 14px; justify-items: center; }
.eyebrow { font-size: .72rem; letter-spacing: .22em; color: var(--leaf); font-weight: 700; }
.intro h1 { font-size: clamp(2.2rem, 8vw, 3.6rem); line-height: 1.08; font-weight: 800; }
.intro h1 em { font-style: normal; color: var(--sun-deep); }
.intro p { max-width: 34rem; color: #5b5233; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 6px; }
.primary-button, .secondary-button { font: inherit; border: 0; border-radius: 999px; cursor: pointer; padding: 14px 26px; font-weight: 700; transition: transform .12s, box-shadow .12s; }
.primary-button { background: linear-gradient(135deg, var(--sun), var(--sun-deep)); color: #3a2600; box-shadow: 0 8px 20px rgba(242, 154, 31, .4); display: inline-flex; gap: 8px; align-items: center; }
.primary-button:disabled { opacity: .6; cursor: default; }
.secondary-button { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.primary-button:active, .secondary-button:active { transform: scale(.97); }
.tip { font-size: .85rem; color: #6b6140; }

/* ---------- scanner ---------- */
.scan-card { background: var(--card); border-radius: 26px; padding: 14px; box-shadow: var(--shadow); display: grid; gap: 10px; }
.scan-heading, .scan-footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: .78rem; letter-spacing: .06em; }
.scan-footer { color: #7a6f48; font-size: .74rem; }
.small-flower { color: var(--sun-deep); margin-right: 6px; }
.live-label { display: inline-flex; align-items: center; gap: 6px; color: #2f8f55; font-size: .68rem; letter-spacing: .12em; }

.camera-frame {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  max-height: 72vh;
  width: 100%;
  background: #14210f;
  isolation: isolate;
}
.camera-placeholder { position: absolute; inset: 0; display: grid; place-content: center; gap: 6px; text-align: center; color: #fff6cf; padding: 20px; background: linear-gradient(160deg, #2c4b22, #14210f); }
.placeholder-flower { font-size: 3rem; }
.camera-placeholder h2 { font-size: 1.3rem; }
.camera-placeholder p { opacity: .85; font-size: .92rem; }
.corner { position: absolute; width: 34px; height: 34px; border: 3px solid var(--sun); }
.corner-tl { top: 18px; left: 18px; border-right: 0; border-bottom: 0; border-top-left-radius: 12px; }
.corner-tr { top: 18px; right: 18px; border-left: 0; border-bottom: 0; border-top-right-radius: 12px; }
.corner-bl { bottom: 18px; left: 18px; border-right: 0; border-top: 0; border-bottom-left-radius: 12px; }
.corner-br { bottom: 18px; right: 18px; border-left: 0; border-top: 0; border-bottom-right-radius: 12px; }
.scan-line { position: absolute; left: 14%; right: 14%; height: 2px; background: linear-gradient(90deg, transparent, var(--sun), transparent); animation: scan 2.4s ease-in-out infinite; }
@keyframes scan { 0%, 100% { top: 22%; } 50% { top: 78%; } }

/* พื้นที่แสดงกล้อง + AR: ต้องไม่ใส่สีพื้นหลังทึบ ไม่งั้นบังภาพกล้อง */
.ar-host { position: absolute; inset: 0; z-index: 0; overflow: hidden; }
.ar-host a-scene { position: absolute !important; inset: 0; width: 100%; height: 100%; }

.camera-hud { position: absolute; left: 12px; top: 12px; z-index: 5; display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; background: rgba(0, 0, 0, .55); color: #fff; font-size: .85rem; backdrop-filter: blur(6px); }
.hud-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--sun); animation: pulse 1.2s infinite; }
.camera-hud.found .hud-dot { background: #3ac569; animation: none; }
@keyframes pulse { 50% { opacity: .3; } }

.camera-tools { position: absolute; right: 12px; top: 12px; z-index: 5; display: none; gap: 8px; }
body.ar-live .camera-tools { display: flex; }
.tool-button { width: 42px; height: 42px; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .55); color: #fff; font-size: 1.1rem; cursor: pointer; backdrop-filter: blur(6px); }

/* เปิดกล้องแล้วขยายเต็มจอ */
body.ar-live { overflow: hidden; }
body.ar-live .camera-frame { position: fixed; inset: 0; z-index: 50; max-height: none; border-radius: 0; aspect-ratio: auto; height: 100dvh; }

/* ---------- characters ---------- */
.section-title { text-align: center; margin-bottom: 14px; display: grid; gap: 4px; }
.section-title span { font-size: .72rem; letter-spacing: .2em; color: var(--leaf); font-weight: 700; }
.section-title em { font-style: normal; }
.section-title h2 { font-size: 1.5rem; }
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.char-card { background: var(--card); border-radius: 18px; padding: 10px; box-shadow: var(--shadow); display: grid; gap: 8px; }
.char-card img { width: 100%; aspect-ratio: 879 / 1199; object-fit: cover; border-radius: 12px; background: #f3e9b8; }
.char-card b { display: block; font-size: .95rem; }
.char-card span { font-size: .8rem; color: #7a6f48; }

/* ---------- steps ---------- */
.step-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.step { background: var(--card); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); display: grid; gap: 6px; }
.step-icon { font-size: 1.8rem; }
.step p { font-size: .9rem; color: #6b6140; }

footer { text-align: center; font-size: .8rem; color: #7a6f48; }
footer span { color: var(--sun-deep); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 100; max-width: 90vw; padding: 12px 18px; border-radius: 14px; background: rgba(30, 25, 10, .92); color: #fff; font-size: .9rem; opacity: 0; pointer-events: none; transition: .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
