/* 靈籤集 · Shared CSS */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+TC:wght@400;500;700&family=Noto+Sans+Thai:wght@400;500;600;700&family=Ma+Shan+Zheng&display=swap');

/* ─── CSS Variables ─── */
:root {
  --temple-color: #8b1a1a;
  --temple-color-light: rgba(139,26,26,0.12);
  --temple-color-mid: rgba(139,26,26,0.35);
  --bg: #f9f4eb;
  --bg-card: #fffdf8;
  --bg-section: #fdf8f0;
  --text: #2a1f14;
  --text-muted: #6b5744;
  --text-light: #9c8472;
  --border: rgba(139,100,60,0.18);
  --border-strong: rgba(139,100,60,0.35);
  --shadow-sm: 0 2px 8px rgba(80,40,10,0.08);
  --shadow-md: 0 4px 20px rgba(80,40,10,0.13);
  --shadow-lg: 0 8px 40px rgba(80,40,10,0.18);
  --radius: 14px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --font-zh: 'Ma Shan Zheng', 'Noto Serif TC', serif;
  --font-th: 'Noto Sans Thai', sans-serif;
  --font-serif: 'Noto Serif TC', serif;
  --stripe-h: 5px;
  --transition: all 0.22s cubic-bezier(0.4,0,0.2,1);
}

/* ─── Grade Colors ─── */
.grade-upper     { --grade-bg: #fff3cd; --grade-color: #856404; }
.grade-great     { --grade-bg: #d1e7dd; --grade-color: #0a5c36; }
.grade-good      { --grade-bg: #cfe2ff; --grade-color: #084298; }
.grade-middle    { --grade-bg: #e8e8e8; --grade-color: #444; }
.grade-lower     { --grade-bg: #f8d7da; --grade-color: #842029; }
.grade-unknown   { --grade-bg: #e9ecef; --grade-color: #555; }

/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-th);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Temple Stripe Header ─── */
.temple-stripe {
  height: var(--stripe-h);
  background: var(--temple-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

/* ─── Page Header ─── */
.page-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: var(--stripe-h);
  z-index: 99;
  box-shadow: var(--shadow-sm);
}

.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--temple-color-light);
  color: var(--temple-color);
  text-decoration: none;
  font-size: 18px;
  flex-shrink: 0;
  transition: var(--transition);
  border: none;
  cursor: pointer;
}
.back-btn:hover { background: var(--temple-color-mid); }

.header-info { flex: 1; min-width: 0; }
.header-temple-zh {
  font-family: var(--font-zh);
  font-size: 22px;
  color: var(--temple-color);
  line-height: 1;
  display: block;
}
.header-temple-th {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  display: block;
}

/* ─── Lang Toggle ─── */
.lang-toggle-btn {
  min-width: 44px;
  height: 44px;
  padding: 0 12px;
  border-radius: 22px;
  border: 1.5px solid var(--border-strong);
  background: var(--bg);
  color: var(--text-muted);
  font-family: var(--font-zh);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}
.lang-toggle-btn.active,
.lang-toggle-btn:hover {
  background: var(--temple-color);
  color: #fff;
  border-color: var(--temple-color);
}

/* ─── Main Content ─── */
.main-content {
  padding: 16px;
  max-width: 680px;
  margin: 0 auto;
  padding-bottom: 80px;
}

/* ─── Search Area ─── */
.search-section {
  margin-bottom: 20px;
}

.search-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: block;
  font-weight: 500;
}

.search-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.sign-input {
  flex: 1;
  width: 100%;
  height: 56px;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0 16px;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  background: var(--bg-card);
  transition: var(--transition);
  -webkit-appearance: none;
  appearance: none;
  font-family: var(--font-th);
}
.sign-input:focus {
  outline: none;
  border-color: var(--temple-color);
  box-shadow: 0 0 0 3px var(--temple-color-light);
}
.sign-input::placeholder { color: var(--text-light); font-size: 15px; font-weight: 400; }

/* hide number spinners */
.sign-input::-webkit-outer-spin-button,
.sign-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.sign-input[type=number] { -moz-appearance: textfield; }

/* Zhougong: input + random side by side */
.search-row--zhougong {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.search-row--zhougong .sign-input { flex: 1; width: auto; }

/* .search-btn removed — ใช้ Enter หรือ keyboard Go แทน */

/* Zhougong random button */
.random-btn {
  height: 56px;
  padding: 0 18px;
  border-radius: var(--radius);
  border: 2px solid var(--temple-color);
  background: transparent;
  color: var(--temple-color);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-th);
}
.random-btn:hover { background: var(--temple-color-light); }

/* ─── Error State ─── */
.error-msg {
  background: #fff3cd;
  border: 1px solid #ffecb5;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: #664d03;
  font-size: 14px;
  margin-top: 10px;
  display: none;
}
.error-msg.show { display: block; }

/* ─── Result Area ─── */
#result-area { display: none; }
#result-area.show { display: block; }

/* ─── Summary Card ─── */
.summary-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  animation: slideUp 0.3s cubic-bezier(0.4,0,0.2,1);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-stripe {
  height: var(--stripe-h);
  background: var(--temple-color);
}

.card-body {
  padding: 16px;
}

.card-top-row {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

/* Sign image column */
.sign-img-col {
  flex-shrink: 0;
  width: 76px;
}
.sign-img-col img {
  width: 76px;
  height: auto;
  border-radius: var(--radius-sm);
  display: block;
  box-shadow: var(--shadow-sm);
}

/* Sign info column */
.sign-info-col { flex: 1; min-width: 0; }

.sign-number {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 500;
}
.sign-number span {
  font-size: 20px;
  font-weight: 800;
  color: var(--temple-color);
  line-height: 1;
}

.grade-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
  background: var(--grade-bg);
  color: var(--grade-color);
}

.sign-title-zh {
  font-family: var(--font-zh);
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 6px;
  display: none;
}
.lang-zh .sign-title-zh { display: block; }
.sign-title-th {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 6px;
}
.lang-zh .sign-title-th { display: none; }

/* Poem */
.poem-block {
  background: var(--temple-color-light);
  border-left: 3px solid var(--temple-color);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 10px 12px;
  margin: 12px 0;
}
.poem-zh {
  font-family: var(--font-zh);
  font-size: 15px;
  color: var(--text);
  line-height: 1.8;
  white-space: pre-line;
  display: none;
}
.lang-zh .poem-zh { display: block; }
.poem-th {
  font-size: 14px;
  color: var(--text);
  line-height: 1.7;
  white-space: pre-line;
}
.lang-zh .poem-th { display: none; }

/* Summary text */
.summary-text {
  font-size: 14.5px;
  color: var(--text);
  line-height: 1.65;
  margin: 10px 0;
  padding: 10px 12px;
  background: var(--bg-section);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* Card actions */
.card-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.btn-expand {
  flex: 1;
  min-height: 44px;
  border-radius: var(--radius);
  border: 1.5px solid var(--temple-color);
  background: transparent;
  color: var(--temple-color);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-th);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-expand:hover { background: var(--temple-color-light); }
.btn-expand.expanded {
  background: var(--temple-color);
  color: #fff;
}

.btn-save {
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border-strong);
  background: var(--bg-section);
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}
.btn-save:hover { background: var(--border); }

/* ─── Save Menu (long press) ─── */
.save-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 200;
  min-width: 160px;
  display: none;
  animation: fadeIn 0.15s ease;
}
.save-menu.show { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

.save-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
  border: none;
  background: none;
  width: 100%;
  font-family: var(--font-th);
  text-align: left;
}
.save-menu-item:hover { background: var(--bg-section); }
.save-menu-item + .save-menu-item { border-top: 1px solid var(--border); }

/* ─── Full Version ─── */
.full-version {
  display: none;
  animation: slideDown 0.3s cubic-bezier(0.4,0,0.2,1);
}
.full-version.show { display: block; }

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Tabs ─── */
.tabs-bar {
  display: flex;
  gap: 0;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  overflow: hidden;
}

.tab-btn {
  flex: 1;
  min-height: 44px;
  padding: 0 10px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-th);
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tab-btn.active {
  color: var(--temple-color);
  border-bottom-color: var(--temple-color);
  background: var(--temple-color-light);
}
.tab-btn:not(.active):hover { background: var(--bg-section); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Sections ─── */
.sections-wrap {
  background: var(--bg-card);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  border: 1px solid var(--border);
  border-top: none;
  overflow: hidden;
}

/* When no tabs (Template A, C) */
.no-tabs .sections-wrap {
  border-radius: var(--radius-lg);
  border-top: 1px solid var(--border);
}

.section-item {
  border-bottom: 1px solid var(--border);
}
.section-item:last-child { border-bottom: none; }

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
  -webkit-user-select: none;
  min-height: 48px;
}
.section-header:hover { background: var(--bg-section); }

.section-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.section-label {
  flex: 1;
  min-width: 0;
}
.section-label-zh {
  font-family: var(--font-zh);
  font-size: 16px;
  font-weight: 500;
  color: var(--temple-color);
  display: none;
}
.lang-zh .section-label-zh { display: block; }
.section-label-th {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.lang-zh .section-label-th { display: none; }

.section-chevron {
  font-size: 12px;
  color: var(--text-light);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}
.section-item.open .section-chevron { transform: rotate(180deg); }

.section-body {
  display: none;
  padding: 0 16px 14px;
  animation: fadeIn 0.2s ease;
}
.section-item.open .section-body { display: block; }

.section-text-zh {
  font-family: var(--font-serif);
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.75;
  white-space: pre-line;
  margin-bottom: 6px;
  display: none;
}
.lang-zh .section-text-zh { display: block; }
.section-text-th {
  font-size: 14px;
  color: var(--text);
  line-height: 1.72;
  white-space: pre-line;
}
.lang-zh .section-text-th { display: none; }

/* ─── Section Icons Map ─── */

/* ─── Table (zhougong tab_table) ─── */
.sign-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  margin-top: 4px;
}
.sign-table th {
  background: var(--temple-color-light);
  color: var(--temple-color);
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1.5px solid var(--border-strong);
}
.sign-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
  line-height: 1.55;
}
.sign-table tr:last-child td { border-bottom: none; }
.sign-table tr:nth-child(even) td { background: var(--bg-section); }

/* ─── Export Card (hidden, for html2canvas) ─── */
#export-card {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 360px;
  font-family: var(--font-th);
  background: var(--bg-card);
}
.export-stripe { height: 6px; background: var(--temple-color); }
.export-body { padding: 20px; }
.export-temple-name {
  font-family: var(--font-zh);
  font-size: 20px;
  color: var(--temple-color);
  margin-bottom: 2px;
}
.export-sign-num {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.export-grade {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 12px;
  background: var(--grade-bg);
  color: var(--grade-color);
}
.export-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}
.export-poem {
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-line;
  margin-bottom: 10px;
}
.export-summary {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}
.export-watermark {
  font-family: var(--font-zh);
  font-size: 13px;
  color: var(--text-light);
  opacity: 0.4;
  text-align: center;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ─── Toast notification ─── */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(30,20,10,0.88);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: all 0.3s ease;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Overlay (close save menu) ─── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: none;
}
.overlay.show { display: block; }

/* ─── Special: sign-0 badge (yuelao) ─── */
.sign-king-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: 20px;
  background: linear-gradient(135deg, #ffd700, #ff8c00);
  color: #5c3500;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 8px;
  box-shadow: 0 2px 8px rgba(255,160,0,0.3);
}

/* ─── Empty / loading state ─── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ─── Responsive tablet ─── */
@media (min-width: 600px) {
  .main-content { padding: 20px 24px; }
  .sign-img-col { width: 96px; }
  .sign-img-col img { width: 96px; }
  .card-actions { flex-wrap: nowrap; }
}

/* ─── Responsive desktop ─── */
@media (min-width: 900px) {
  .main-content { padding: 28px 32px; }
  .sign-input { font-size: 26px; }
  .sign-img-col { width: 110px; }
  .sign-img-col img { width: 110px; }
}
