@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&family=Noto+Sans+Thai:wght@400;600;700;800;900&family=Fredoka:wght@500;600;700&display=swap');

:root {
  --bg: #f7efe0;
  --bg2: #f1e6d2;
  --panel: #fffdf8;
  --panel-2: #f6efe2;
  --ink: #5f4a3a;
  --ink-soft: #9c8straight;
  --ink-soft: #a08b76;
  --brown: #6f523c;
  --brown-d: #58402e;
  --pink: #ef9fb0;
  --pink-d: #e07f95;
  --gold: #c99a4e;
  --line: #ece1cd;

  /* result group theme (overridden per type) */
  --accent: #7b5ea7;
  --accent-soft: #d9c9ef;
  --accent-bg: #f3edfa;
}

* , *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--bg); }

body {
  font-family: 'Nunito', 'Noto Sans Thai', sans-serif;
  color: var(--ink);
  background: linear-gradient(170deg, var(--bg) 0%, var(--bg2) 100%);
  background-attachment: fixed;
  min-height: 100dvh;
}

.hidden { display: none !important; }

/* ---------------- App bar ---------------- */
.appbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 28px; gap: 14px;
  position: sticky; top: 0; z-index: 20;
  background: rgba(247,239,224,.82); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; cursor: pointer; }
.brand-logo { height: 62px; width: auto; display: block; }
.appbar-right { display: flex; align-items: center; gap: 12px; }

.chip {
  font-family: inherit; font-weight: 800; font-size: 14px;
  color: var(--ink); background: var(--panel);
  border: 1.5px solid var(--line); border-radius: 999px;
  padding: 9px 16px; cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
  box-shadow: 0 2px 6px rgba(120,90,60,.08); transition: transform .1s, box-shadow .1s;
}
.chip:hover { box-shadow: 0 4px 10px rgba(120,90,60,.14); }
.chip:active { transform: translateY(1px); }
.chip-ico { font-size: 15px; }

.auth-user { display: inline-flex; align-items: center; gap: 8px; }
.auth-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--pink);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}

.lang { display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 15px; color: var(--ink-soft); user-select: none; }
.lang span[data-lang] { cursor: pointer; padding: 2px 2px; }
.lang span[data-lang].active { color: var(--ink); border-bottom: 2px solid var(--brown); }
.lang .sep { color: var(--line); }

/* ---------------- Buttons ---------------- */
.btn {
  font-family: 'Fredoka','Nunito','Noto Sans Thai',sans-serif; font-weight: 700;
  border: none; border-radius: 999px; cursor: pointer;
  padding: 13px 26px; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.btn-lg { padding: 16px 40px; font-size: 18px; }
.btn-primary { background: var(--brown); color: #fff8ef; box-shadow: 0 6px 0 var(--brown-d); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--brown-d); }
.btn-ghost { background: var(--panel); color: var(--ink); border: 1.5px solid var(--line); box-shadow: 0 3px 8px rgba(120,90,60,.08); }
.btn-ghost:hover { border-color: var(--pink); }
.btn-accent { background: var(--accent); color: #fff; box-shadow: 0 6px 0 rgba(0,0,0,.12); }

/* ---------------- Views ---------------- */
.view { max-width: 1180px; margin: 0 auto; padding: 26px 28px 70px; }

/* ---------------- Home ---------------- */
#view-home { position: relative; overflow: hidden; }
.home-hero { text-align: center; padding: 40px 10px 10px; }
.home-logo { width: min(420px, 78%); height: auto; filter: drop-shadow(0 8px 16px rgba(150,110,70,.18)); }
.home-tagline { font-size: 20px; color: var(--ink); margin: 18px auto 26px; max-width: 40ch; font-weight: 700; }
.home-about {
  max-width: 760px; margin: 30px auto 0; background: var(--panel);
  border: 1.5px solid var(--line); border-radius: 22px; padding: 26px 30px;
  box-shadow: 0 10px 30px rgba(150,110,70,.10);
}
.home-about p { font-size: 15.5px; line-height: 1.85; color: var(--ink); margin-bottom: 14px; }
.home-about p:first-child { font-weight: 800; font-size: 18px; color: var(--brown); }
.home-about p:last-child { margin-bottom: 0; }
.social {
  text-align: center; margin: 26px auto 0; font-weight: 800; color: var(--pink-d);
  display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap;
}
.social .ig, .social .tt { display: inline-flex; align-items: center; gap: 5px; }
.home-cat-peek { position: absolute; right: 18px; bottom: -6px; font-size: 74px; opacity: .9; pointer-events: none; }

/* ---------------- Test ---------------- */
.test-topbar { display: flex; align-items: center; gap: 20px; margin-bottom: 18px; }
.test-progress { flex: 1; }
.track { position: relative; height: 16px; background: #fff; border: 1.5px solid var(--line); border-radius: 999px; }
.track-fill { height: 100%; background: linear-gradient(90deg, var(--pink) 0%, var(--brown) 100%); border-radius: 999px; width: 0; transition: width .4s ease; }
.walker { position: absolute; top: -14px; left: 0; transform: translateX(-50%); font-size: 22px; transition: left .4s ease; }
.track-meta { display: flex; justify-content: space-between; margin-top: 8px; font-size: 13px; color: var(--ink-soft); font-weight: 700; }
.qbadge {
  display: flex; align-items: center; gap: 8px; background: var(--panel);
  border: 1.5px solid var(--line); border-radius: 16px; padding: 8px 16px; text-align: center;
  box-shadow: 0 3px 10px rgba(150,110,70,.1); font-size: 13px; color: var(--ink-soft); font-weight: 700;
}
.qbadge b { font-size: 17px; color: var(--ink); font-weight: 900; }
.qbadge-paw { font-size: 16px; }

.test-headrow { display: flex; align-items: flex-end; justify-content: space-between; margin: 6px 2px 14px; gap: 14px; }
.test-instruction { color: var(--ink-soft); font-weight: 700; font-size: 15px; }
.scale-ends { display: flex; gap: 260px; font-size: 12px; color: var(--ink-soft); font-weight: 800; white-space: nowrap; }

.qlist { display: flex; flex-direction: column; }
.qrow {
  display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 14px;
  padding: 14px 6px; border-bottom: 1px dashed var(--line);
}
.qrow:last-child { border-bottom: none; }
.qnum { width: 38px; height: 38px; border-radius: 50%; background: var(--panel-2); display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--ink-soft); }
.qtext { font-size: 15.5px; font-weight: 600; line-height: 1.5; }
.scale-row { display: flex; align-items: center; gap: 10px; }
.paw {
  border: none; background: transparent; cursor: pointer; padding: 3px; line-height: 0;
  border-radius: 50%; transition: transform .1s;
}
.paw svg { display: block; }
.paw:hover { transform: scale(1.15); }
.paw.selected { background: rgba(0,0,0,.04); box-shadow: 0 0 0 3px rgba(0,0,0,.06); transform: scale(1.12); }

.test-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 26px; gap: 16px; }
.mascot { display: flex; align-items: center; gap: 10px; }
.mascot-cat { font-size: 40px; }
.mascot-bubble { background: var(--panel); border: 1.5px solid var(--line); border-radius: 14px; padding: 8px 14px; font-size: 13px; color: var(--ink-soft); font-weight: 700; max-width: 240px; text-align: center; }

/* ---------------- Result ---------------- */
.result-head { text-align: center; margin-bottom: 22px; }
.result-head h1 { font-family: 'Fredoka','Noto Sans Thai',sans-serif; font-size: 40px; color: var(--ink); font-weight: 700; }
.result-head p { color: var(--ink-soft); font-weight: 700; margin-top: 4px; }

.result-grid { display: grid; grid-template-columns: 400px 1fr; gap: 24px; align-items: start; }

.cat-card { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.cat-card-img { width: 100%; border-radius: 18px; display: block; box-shadow: 0 14px 40px rgba(120,90,60,.20); }
.card-dl { width: 100%; }

/* gallery of all 16 cards */
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px; }
.gallery-item { cursor: pointer; border-radius: 14px; overflow: hidden; box-shadow: 0 8px 22px rgba(120,90,60,.14); transition: transform .12s, box-shadow .12s; background: #fff; }
.gallery-item:hover { transform: translateY(-4px); box-shadow: 0 14px 30px rgba(120,90,60,.22); }
.gallery-item img { width: 100%; display: block; }

/* card lightbox */
#card-modal { align-items: center; }
.card-modal-inner { position: relative; max-width: 460px; width: 100%; }
.card-modal-inner img { width: 100%; border-radius: 16px; box-shadow: 0 24px 60px rgba(0,0,0,.4); display: block; }
.card-modal-inner .modal-close { position: absolute; top: -14px; right: -14px; z-index: 2; }

.cat-card-frame-legacy { background: var(--accent-bg); border-radius: 26px; padding: 16px; box-shadow: 0 14px 40px rgba(120,90,60,.14); }
.cat-card-inner { border: 3px solid var(--accent-soft); border-radius: 20px; padding: 20px 18px; background: linear-gradient(180deg, #fff 0%, var(--accent-bg) 100%); text-align: center; position: relative; }
.cat-card-tag { display: inline-block; background: #fff; border: 1.5px solid var(--accent-soft); color: var(--ink-soft); font-weight: 800; font-size: 12px; padding: 5px 14px; border-radius: 999px; }
.cat-card-code { font-family: 'Fredoka',sans-serif; font-size: 58px; font-weight: 700; color: var(--accent); line-height: 1.05; margin-top: 8px; letter-spacing: .04em; }
.cat-card-name { font-weight: 900; font-size: 20px; color: var(--ink); background: #fff; border: 1.5px solid var(--accent-soft); border-radius: 999px; display: inline-block; padding: 4px 18px; margin-top: 2px; }
.cat-card-art { margin: 16px 0 12px; }
.cat-card-art img { width: 100%; border-radius: 16px; display: block; }
.cat-card-art .placeholder { width: 100%; aspect-ratio: 1/1; border-radius: 16px; background: repeating-linear-gradient(45deg, var(--accent-bg), var(--accent-bg) 12px, #fff 12px, #fff 24px); display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--accent); font-weight: 800; gap: 8px; border: 2px dashed var(--accent-soft); }
.cat-card-art .placeholder .big { font-size: 64px; }
.cat-card-quote { font-style: italic; color: var(--ink); font-weight: 700; font-size: 15px; line-height: 1.5; margin-top: 6px; }
.cat-card-quote::before { content: "“"; } .cat-card-quote::after { content: "”"; }

.result-right { display: flex; flex-direction: column; gap: 18px; }
.panel { background: var(--panel); border: 1.5px solid var(--line); border-radius: 20px; padding: 18px 22px; box-shadow: 0 8px 24px rgba(150,110,70,.08); }
.panel-title { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 900; color: var(--ink); font-size: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }

.cf-list { display: flex; flex-direction: column; gap: 11px; }
.cf-row { display: grid; grid-template-columns: 34px 34px 1fr 46px; align-items: center; gap: 10px; }
.cf-ico { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 15px; color: #fff; }
.cf-code { font-weight: 900; font-size: 14px; }
.cf-mid { display: flex; flex-direction: column; gap: 3px; }
.cf-name { font-size: 12px; color: var(--ink-soft); font-weight: 700; }
.cf-track { height: 12px; background: #f0e9db; border-radius: 999px; overflow: hidden; }
.cf-fill { height: 100%; border-radius: 999px; width: 0; transition: width .8s ease; }
.cf-pct { font-weight: 900; font-size: 14px; text-align: right; }

.about-desc { font-size: 14.5px; line-height: 1.7; color: var(--ink); margin-bottom: 12px; }
.fun-facts { list-style: none; display: flex; flex-direction: column; gap: 7px; }
.fun-facts li { font-size: 13.5px; color: var(--ink-soft); font-weight: 700; padding-left: 22px; position: relative; }
.fun-facts li::before { content: "🐾"; position: absolute; left: 0; }

.result-actions { display: flex; align-items: flex-start; justify-content: center; gap: 18px; margin-top: 26px; flex-wrap: wrap; }
.save-wrap { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.save-wrap small { color: var(--ink-soft); font-size: 12px; }

.disclaimer { text-align: center; color: var(--ink-soft); font-size: 12px; font-style: italic; margin-top: 18px; }

/* ---------------- Collection ---------------- */
.collection-head { text-align: center; margin-bottom: 24px; }
.collection-head h1 { font-family: 'Fredoka','Noto Sans Thai',sans-serif; font-size: 34px; color: var(--ink); }
.collection-head p { color: var(--ink-soft); font-weight: 700; margin-top: 6px; }
.col-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.col-item { background: var(--panel); border: 1.5px solid var(--line); border-radius: 18px; padding: 16px; text-align: center; box-shadow: 0 6px 18px rgba(150,110,70,.08); cursor: pointer; transition: transform .1s; }
.col-item:hover { transform: translateY(-3px); }
.col-item img { width: 100%; border-radius: 12px; }
.col-item .placeholder-mini { width: 100%; aspect-ratio: 1/1; border-radius: 12px; background: var(--accent-bg); display: flex; align-items: center; justify-content: center; font-size: 46px; }
.col-item .code { font-family: 'Fredoka',sans-serif; font-size: 26px; font-weight: 700; margin-top: 8px; }
.col-item .name { font-weight: 800; color: var(--ink); }
.col-item .date { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.col-empty { text-align: center; padding: 50px 20px; color: var(--ink-soft); font-weight: 700; font-size: 16px; }

/* ---------------- Modal ---------------- */
.modal-overlay { position: fixed; inset: 0; z-index: 60; background: rgba(70,50,35,.5); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { position: relative; background: var(--panel); border-radius: 26px; padding: 34px 30px 28px; max-width: 420px; width: 100%; text-align: center; box-shadow: 0 24px 60px rgba(0,0,0,.28); border: 3px solid var(--pink); animation: pop .3s ease; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-close { position: absolute; top: 14px; right: 16px; border: none; background: var(--panel-2); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 15px; color: var(--ink); font-weight: 800; }
.modal-close:hover { background: var(--pink); color: #fff; }
.modal-cat { font-size: 40px; }
.modal h2 { font-family: 'Fredoka','Noto Sans Thai',sans-serif; font-size: 24px; color: var(--brown); margin: 6px 0 12px; }
.modal p { font-size: 14.5px; line-height: 1.7; color: var(--ink); }
.donate-qr { width: 220px; height: auto; border-radius: 14px; margin: 16px auto; display: block; border: 1px solid var(--line); }
.donate-note { font-size: 12px; color: var(--ink-soft); margin-top: 12px; }

/* ---------------- Toast ---------------- */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); background: var(--brown); color: #fff; padding: 12px 22px; border-radius: 999px; font-weight: 800; z-index: 80; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: pop .25s ease; }

/* ---------------- Responsive ---------------- */
@media (max-width: 860px) {
  .result-grid { grid-template-columns: 1fr; }
  .cat-card { max-width: 420px; margin: 0 auto; }
  .scale-ends { display: none; }
  .qrow { grid-template-columns: 34px 1fr; }
  .scale-row { grid-column: 1 / -1; justify-content: space-between; gap: 4px; }
  .brand-logo { height: 48px; }
  .home-logo { width: 82%; }
}
