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

html, body {
  font-family: "Noto Sans Thai", "Noto Sans", system-ui, -apple-system,
               BlinkMacSystemFont, "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--cj-bg);
  color: var(--cj-text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
}

::selection { background: var(--cj-gold); color: #1C1C1E; }

img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: inherit; text-decoration: none; }

:focus-visible { outline: 2px solid var(--cj-red); outline-offset: 2px; border-radius: 4px; }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--cj-bg);
  position: relative;
}

#page {
  padding-top: max(var(--space-4), var(--tg-content-safe-area-inset-top, 0px));
  padding-bottom: calc(var(--nav-height) + var(--tg-content-safe-area-inset-bottom, 0px) + var(--space-4));
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 var(--space-4);
  margin-bottom: var(--space-3);
}
.app-header .logo { height: 34px; width: auto; }
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  position: relative;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn .dot {
  position: absolute;
  top: 10px;
  right: 11px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--cj-red);
  border: 2px solid var(--cj-surface);
}

/* ---------- Welcome Hero ---------- */
.hero {
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
  background: var(--cj-ivory);
  border-radius: var(--radius-card);
  padding: var(--space-4) var(--space-5);
  margin: 0 var(--space-4);
  min-height: 170px;
  overflow: hidden;
}
.hero-text { flex: 1.25; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.hero-line1 { font-size: var(--fs-hero); font-weight: 700; line-height: 1.25; }
.hero-line2 { font-size: var(--fs-hero); font-weight: 700; line-height: 1.25; color: var(--cj-red); }
.hero-sub { font-size: var(--fs-secondary); color: var(--cj-text-secondary); line-height: 1.5; margin-top: var(--space-2); }
.hero-mascot { flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0; }
.hero-mascot img { width: 100%; max-height: 190px; object-fit: contain; }

/* ---------- Website CTA ---------- */
.cta-card {
  background: var(--cj-surface);
  border: 1px solid var(--cj-border);
  border-radius: var(--radius-card);
  padding: 14px;
  margin: var(--space-4) var(--space-4) 0;
}
.btn-website {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 80px;
  padding: var(--space-3) var(--space-4);
  background: linear-gradient(135deg, var(--cj-red) 0%, var(--cj-red-grad) 100%);
  border: 2px solid var(--cj-gold);
  border-radius: var(--radius-row);
  transition: transform 0.1s ease;
}
.btn-website:active { background: var(--cj-red-deep); transform: scale(0.985); }
.btn-website svg { width: 32px; height: 32px; color: #FFFFFF; flex-shrink: 0; }
.btn-website-text { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.btn-website-title {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #FFFFFF;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.3;
}
.btn-website-title svg { width: 18px; height: 18px; }
.btn-website-sub { color: rgba(255, 255, 255, 0.9); font-size: var(--fs-secondary); font-weight: 400; line-height: 1.4; }
.cta-disclosure {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: var(--space-3);
  color: var(--cj-text-secondary);
  font-size: var(--fs-caption);
}
.cta-disclosure svg { width: 18px; height: 18px; color: var(--cj-gold); flex-shrink: 0; }

/* ---------- Sections ---------- */
.section-title {
  font-size: var(--fs-section);
  font-weight: 700;
  line-height: 1.35;
  margin: var(--space-6) var(--space-4) var(--space-3);
}

/* ---------- Menu rows ---------- */
.menu-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 var(--space-4);
}
.menu-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 76px;
  background: var(--cj-surface);
  border: 1px solid var(--cj-border);
  border-radius: var(--radius-row);
  padding: 12px 14px;
  text-align: left;
  transition: background 0.12s ease;
}
.menu-row:active { background: var(--cj-pressed); border-color: var(--cj-pressed-border); }
.menu-icon-tile {
  width: 52px;
  height: 52px;
  background: var(--cj-ivory);
  border-radius: var(--radius-icon);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.menu-icon-tile img { width: 30px; height: 30px; object-fit: contain; }
.menu-text { flex: 1; min-width: 0; }
.menu-title { display: block; font-size: var(--fs-menu); font-weight: 600; line-height: 1.4; }
.menu-sub { display: block; font-size: var(--fs-secondary); color: var(--cj-text-secondary); line-height: 1.45; margin-top: 1px; }
.tile-icon { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; color: var(--cj-red); }
.tile-icon svg { width: 28px; height: 28px; }
.menu-chevron { width: 24px; height: 24px; color: #A9A49C; flex-shrink: 0; }

/* ---------- Announcement card ---------- */
.announce-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  background: var(--cj-ivory);
  border: 1px solid var(--cj-border-gold);
  border-radius: var(--radius-row);
  padding: var(--space-4);
  margin: 0 var(--space-4);
  min-height: 88px;
  transition: background 0.12s ease;
}
.announce-card:active { background: #FBEFD6; }
.announce-card .pin { width: 24px; height: 24px; color: var(--cj-red); flex-shrink: 0; margin-top: 2px; }
.announce-body { flex: 1; min-width: 0; }
.announce-headline {
  font-size: var(--fs-body);
  font-weight: 600;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.announce-more { display: flex; align-items: center; gap: 2px; color: var(--cj-red); font-size: var(--fs-secondary); margin-top: var(--space-1); }
.announce-more svg { width: 16px; height: 16px; }

/* ---------- Page header (internal pages) ---------- */
.page-header { display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-4); min-height: 48px; }
.back-btn {
  display: none;
  align-items: center;
  gap: 4px;
  min-height: 48px;
  padding: 0 var(--space-2);
  font-size: var(--fs-body);
  font-weight: 600;
  color: var(--cj-text);
}
.back-btn svg { width: 22px; height: 22px; }
body.no-native-back .back-btn { display: flex; }
.page-title { font-size: var(--fs-title); font-weight: 700; line-height: 1.3; margin: var(--space-2) var(--space-4) var(--space-4); }

/* ---------- Cards (news / benefits / activities) ---------- */
.list { display: flex; flex-direction: column; gap: var(--space-3); margin: 0 var(--space-4) var(--space-6); }
.card {
  display: block;
  width: 100%;
  background: var(--cj-surface);
  border: 1px solid var(--cj-border);
  border-radius: var(--radius-row);
  padding: var(--space-4);
  text-align: left;
}
.card:active { background: var(--cj-pressed); border-color: var(--cj-pressed-border); }
.card-date { font-size: var(--fs-caption); color: var(--cj-text-secondary); margin-bottom: 4px; }
.card-image {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid var(--cj-border);
  background: var(--cj-disabled-bg);
  margin-bottom: var(--space-3);
}
.detail-image {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: 18px;
  border: 1px solid var(--cj-border);
  background: var(--cj-disabled-bg);
  margin-bottom: var(--space-3);
}
.card-title { font-size: var(--fs-menu); font-weight: 600; line-height: 1.4; }
.card-desc { font-size: var(--fs-secondary); color: var(--cj-text-secondary); line-height: 1.5; margin-top: 4px; }
.card-row { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-2); color: var(--cj-text-secondary); font-size: var(--fs-secondary); }
.card-row svg { width: 17px; height: 17px; flex-shrink: 0; }

.badge {
  display: inline-block;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  padding: 6px 12px;
  border-radius: 999px;
  margin-bottom: var(--space-2);
}
.badge-success { background: var(--cj-success-bg); color: var(--cj-success); }
.badge-warning { background: var(--cj-warning-bg); color: var(--cj-warning); }
.badge-neutral { background: var(--cj-disabled-bg); color: var(--cj-disabled-text); }

/* ---------- Detail page body ---------- */
.detail-body { margin: 0 var(--space-4) var(--space-6); display: flex; flex-direction: column; gap: var(--space-3); }
.detail-body p { font-size: var(--fs-body); line-height: 1.55; }
.detail-meta { display: flex; align-items: center; gap: 6px; color: var(--cj-text-secondary); font-size: var(--fs-secondary); margin-bottom: var(--space-2); }
.detail-meta svg { width: 17px; height: 17px; }

/* ---------- Buttons ---------- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  min-height: var(--touch-recommended);
  border-radius: 18px;
  font-size: var(--fs-menu);
  font-weight: 600;
  transition: transform 0.1s ease;
}
.btn:active { transform: scale(0.985); }
.btn svg { width: 22px; height: 22px; }
.btn-primary { background: var(--cj-red); color: #FFFFFF; }
.btn-primary:active { background: var(--cj-red-deep); }
.btn-secondary { background: var(--cj-surface); border: 1px solid var(--cj-border); color: var(--cj-text); }
.btn-secondary:active { background: var(--cj-pressed); }
.btn-loading { pointer-events: none; opacity: 0.75; }

/* ---------- Support page ---------- */
.support-actions { display: flex; flex-direction: column; gap: var(--space-3); margin: 0 var(--space-4); }
.support-actions .btn { min-height: 64px; }

/* ---------- FAQ ---------- */
.faq-list { display: flex; flex-direction: column; gap: 10px; margin: var(--space-3) var(--space-4) var(--space-6); }
.faq-item { background: var(--cj-surface); border: 1px solid var(--cj-border); border-radius: 18px; overflow: hidden; }
.faq-q {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--touch-recommended);
  padding: var(--space-3) var(--space-4);
  font-size: var(--fs-body);
  font-weight: 600;
  text-align: left;
}
.faq-q svg { width: 20px; height: 20px; flex-shrink: 0; color: var(--cj-text-secondary); transition: transform 0.18s ease; }
.faq-item.open .faq-q svg { transform: rotate(180deg); }
.faq-a { display: none; padding: 0 var(--space-4) var(--space-4); font-size: var(--fs-secondary); color: var(--cj-text-secondary); line-height: 1.55; }
.faq-item.open .faq-a { display: block; }

/* ---------- More page ---------- */
.setting-row { display: flex; flex-direction: column; gap: var(--space-3); align-items: stretch; }
.segmented {
  display: flex;
  background: var(--cj-disabled-bg);
  border-radius: 14px;
  padding: 4px;
  gap: 4px;
}
.segmented button {
  flex: 1;
  min-height: 44px;
  border-radius: 11px;
  font-size: var(--fs-secondary);
  font-weight: 600;
  color: var(--cj-text-secondary);
}
.segmented button[aria-pressed="true"] { background: var(--cj-surface); color: var(--cj-red); box-shadow: var(--shadow-card); }
.more-version { text-align: center; color: var(--cj-disabled-text); font-size: var(--fs-caption); padding: var(--space-6) 0 var(--space-4); }

/* ---------- Empty / Error / Offline states ---------- */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-6);
}
.state img { width: 150px; height: 150px; object-fit: contain; margin-bottom: var(--space-2); }
.state-title { font-size: var(--fs-section); font-weight: 700; line-height: 1.35; }
.state-body { font-size: var(--fs-secondary); color: var(--cj-text-secondary); line-height: 1.5; }
.state-actions { display: flex; flex-direction: column; gap: var(--space-3); width: 100%; max-width: 280px; margin-top: var(--space-5); }

/* ---------- Skeleton ---------- */
.skel {
  border-radius: var(--radius-row);
  background: linear-gradient(100deg, #F0EDE8 40%, #F9F7F3 50%, #F0EDE8 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-hero { height: 170px; margin: 0 var(--space-4); border-radius: var(--radius-card); }
.skel-row { height: 76px; }
.skel-list { display: flex; flex-direction: column; gap: 10px; margin: var(--space-4); }

/* ---------- Bottom navigation ---------- */
.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  margin: 0 auto;
  max-width: 480px;
  display: flex;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--cj-border);
  padding: 6px 0 calc(6px + var(--tg-content-safe-area-inset-bottom, 0px));
  z-index: 10;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 56px;
  padding-top: 6px;
  color: #747478;
  position: relative;
}
.tab svg { width: 25px; height: 25px; }
.tab span { font-size: 14.5px; font-weight: 500; line-height: 1.3; }
.tab.active { color: var(--cj-red); }
.tab.active::after {
  content: "";
  position: absolute;
  bottom: 4px;
  width: 30px;
  height: 3px;
  border-radius: 3px;
  background: var(--cj-red);
}

/* ---------- Large text mode adjustments ---------- */
html.large-text body { font-size: var(--fs-body); }
html.large-text .btn-website-title { font-size: 23px; }
html.large-text .btn-website-sub { font-size: 17px; }

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Hover (pointer devices only) ---------- */
@media (hover: hover) {
  .menu-row:hover { background: var(--cj-pressed); border-color: var(--cj-pressed-border); }
  .card:hover { background: var(--cj-pressed); border-color: var(--cj-pressed-border); }
  .announce-card:hover { background: #FBEFD6; }
  .btn-website:hover { filter: brightness(1.06); }
  .btn-primary:hover { background: var(--cj-red-deep); }
  .btn-secondary:hover { background: var(--cj-pressed); }
  .faq-q:hover { background: var(--cj-pressed); }
  .tab:hover { color: #55555A; }
  .tab.active:hover { color: var(--cj-red); }
}

/* ---------- Small screens ---------- */
@media (max-width: 359px) {
  html { --fs-hero: 25px; --fs-title: 22px; }
  .hero { padding: var(--space-3) var(--space-4); }
  .cta-card, .menu-list, .list, .announce-card { margin-left: var(--space-3); margin-right: var(--space-3); }
  .section-title { margin-left: var(--space-3); margin-right: var(--space-3); }
}
