/*
 * Hồi Quy: Trung Cổ — Game UI/UX design system (Phiên 10; đổi sang nền sáng ở bản 1.0.8).
 * docs/UI_DESIGN_SYSTEM.md has the full rationale.
 *
 * BẢN 1.0.8 — YÊU CẦU THIẾT KẾ RÕ RÀNG TỪ CHỦ DỰ ÁN: "tối ưu giao diện game với nền sáng, chữ tối
 * đi" — đổi từ bảng màu tối ban đầu (Phiên 10) sang "bản thảo Trung cổ" nền GIẤY DA SÁNG (parchment)
 * + mực nâu đậm gần đen cho chữ, vẫn giữ đúng các màu điểm nhấn (vàng kim/đỏ rượu/xanh rêu/xanh
 * đêm/tím Ma quỷ) — chỉ đổi hướng sáng/tối của nền + chữ chính, không đổi "chất liệu" thẩm mỹ. Các
 * cảnh có tâm trạng riêng biệt CỐ Ý vẫn tối hơn (Địa ngục `#120c08`, Thần giới dùng `--hq-night`) —
 * xem `ornaments.css` — như một khoảnh khắc kịch tính có chủ đích, không phải nền chính của game.
 * Font hệ thống (`Georgia, 'Noto Serif', 'Times New Roman', 'Segoe UI', serif`) — không tải font
 * ngoài, có dấu tiếng Việt đầy đủ vì đều là font hệ điều hành.
 */

:root {
  --hq-paper: #f6ecd8;
  --hq-paper-light: #eeddb8;
  --hq-ink: #2b1d10;
  --hq-ink-dim: #6c5a41;
  --hq-wine: #7a1f2b;
  --hq-wine-bright: #a8303f;
  --hq-moss: #3f5c3a;
  --hq-moss-bright: #5c8a54;
  --hq-night: #1c2b4a;
  --hq-night-bright: #35548c;
  --hq-gold: #93690f;
  --hq-gold-bright: #c9a227;
  --hq-devil-purple: #5a2d82;
  --hq-devil-purple-bright: #7c3fae;
  --hq-danger: #a3291b;
  --hq-font: Georgia, 'Noto Serif', 'Times New Roman', 'Segoe UI', serif;
  --hq-radius: 8px;
}

/* Site light-mode fallback still gets the manuscript look — this is a deliberate design commitment,
   not a light/dark toggle (the game world doesn't change with the visitor's OS theme). */
.hq-app {
  box-sizing: border-box;
  max-width: 430px;
  min-width: 320px;
  margin: 0 auto;
  min-height: 70vh;
  padding: 0;
  background:
    radial-gradient(ellipse at top, rgba(147, 105, 15, 0.08), transparent 60%),
    var(--hq-paper);
  color: var(--hq-ink);
  font-family: var(--hq-font);
  border-radius: var(--hq-radius);
  overflow: hidden;
  position: relative;
  box-shadow: 0 0 0 1px rgba(147, 105, 15, 0.25), 0 8px 24px rgba(43, 29, 16, 0.22);
}

.hq-app *, .hq-app *::before, .hq-app *::after {
  box-sizing: inherit;
}

.hq-screen {
  padding: 1.5rem 1.25rem;
  min-height: 70vh;
  display: flex;
  flex-direction: column;
}

/*
 * BUG FIX (báo lỗi thật từ chủ dự án sau khi phát hành 1.0.0): `app.js`'s showScreen() hides every
 * inactive screen via the native `hidden` attribute/property (`screens[key].hidden = key !== name`).
 * The browser's own UA stylesheet has `[hidden] { display: none; }`, but it has the SAME specificity
 * (0,1,0) as the `.hq-screen { display: flex; }` rule above — and author stylesheets always win over
 * the UA stylesheet at equal specificity, so `.hq-screen`'s `display: flex` silently overrode the
 * native hidden behaviour, leaving every screen (landing, loading, main, result, trial-exhausted,
 * cta, error) visible and stacked at once. Fixing this WITHIN the author stylesheet — an
 * `[hidden]`-qualified selector has higher specificity (0,2,0) than the bare `.hq-screen` rule, so it
 * wins without needing `!important`.
 */
.hq-screen[hidden] {
  display: none;
}

.hq-screen:focus {
  outline: none; /* focus is for screen-reader/keyboard nav announcement, not a visible ring here */
}

/* ---------- Landing ---------- */

.hq-screen-landing {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1.25rem;
}

.hq-app-title {
  font-size: 1.6rem;
  letter-spacing: 0.03em;
  color: var(--hq-gold);
  margin: 0;
}

.hq-tagline {
  color: var(--hq-ink-dim);
  font-size: 0.95rem;
  margin: 0 0 0.5rem;
}

.hq-gender-choice {
  display: flex;
  gap: 1rem;
}

/* ---------- Buttons ---------- */

.hq-btn,
.hq-choice-btn,
.hq-rebirth-btn,
.hq-retry-btn {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.85rem 1.1rem;
  border-radius: var(--hq-radius);
  border: 1px solid rgba(147, 105, 15, 0.35);
  background: var(--hq-paper-light);
  color: var(--hq-ink);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  min-height: 44px; /* touch target */
  box-shadow: 0 1px 2px rgba(43, 29, 16, 0.08);
}

/*
 * BUG FIX (đổi theme sang nền sáng, bản 1.0.8): trạng thái hover trước đây đổi nền nút sang
 * `--hq-night` (xanh đêm rất tối) mà KHÔNG đổi màu chữ — đúng trên theme tối cũ (chữ `--hq-ink` sáng
 * màu vẫn đọc được trên nền tối), nhưng `--hq-ink` giờ là nâu đậm gần đen (chữ tối cho nền sáng), nên
 * nếu giữ nguyên sẽ ra chữ tối trên nền tối — gần như không đọc được. Đổi hover sang một tông giấy
 * đậm hơn (vẫn thuộc phổ màu sáng), giữ chữ tối luôn đọc được, thêm hiệu ứng nhấc nhẹ + đổ bóng cho
 * cảm giác "được nhấn" rõ ràng hơn.
 */
.hq-btn:hover,
.hq-choice-btn:hover:not(:disabled),
.hq-rebirth-btn:hover,
.hq-retry-btn:hover {
  background: #e3cd9c;
  border-color: var(--hq-gold);
  box-shadow: 0 3px 8px rgba(43, 29, 16, 0.14);
  transform: translateY(-1px);
}

.hq-btn:active,
.hq-choice-btn:active:not(:disabled) {
  transform: scale(0.98);
  box-shadow: 0 1px 2px rgba(43, 29, 16, 0.08);
}

.hq-btn:focus-visible,
.hq-choice-btn:focus-visible,
.hq-rebirth-btn:focus-visible,
.hq-retry-btn:focus-visible {
  outline: 2px solid var(--hq-gold);
  outline-offset: 2px;
}

/* ---------- HUD (portrait, age/title, stats, assets) ---------- */
/*
 * THIẾT KẾ LẠI (bản 1.0.9 — yêu cầu rõ ràng từ chủ dự án, kèm ảnh giao diện tham khảo): đổi từ hàng
 * chip chữ đơn giản sang lưới thẻ có biểu tượng + thanh tài sản nổi bật, theo đúng bố cục ảnh mẫu.
 * QUAN TRỌNG: ảnh mẫu có 1 ô hiển thị "Đức" — CỐ Ý KHÔNG làm theo phần đó, vì `true_virtue` là chỉ
 * số ẨN theo luật khóa cứng của dự án (`docs/DATA_CONTRACTS.md`: "KHÔNG hiển thị cho client") — lộ
 * ra sẽ phá vỡ cơ chế "chọn theo bản năng, không theo điểm số hiển thị" cốt lõi của toàn bộ game.
 * Thay vào đó dùng đúng 3 chỉ số THẬT SỰ hiển thị: Tuổi, Sức khỏe, Danh vọng (xem `renderHud()`
 * trong app.js) — Tài sản vẫn ở thanh riêng (tiêu chí nghiệm thu Phiên 10, không đổi).
 */

.hq-hud {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}

/*
 * BUG FIX (báo lỗi thật từ chủ dự án: "không hiện hình ảnh gì" ở đây) — trước đây chỉ là một vòng
 * tròn gradient trống, không có bất kỳ hình vẽ nào. Không có hệ thống chân dung nhân vật thật (chưa
 * xây — xem docs/MEDIA_SYSTEM.md mục "Không hiện thực"), nhưng thay vì để trống hoàn toàn, vẽ một
 * biểu tượng người trừu tượng (đầu + vai, hình học đơn giản) bằng SVG nhúng trực tiếp — cùng phong
 * cách "trừu tượng/hình học, không đồ họa máu me" đã dùng cho mọi ornament khác trong `ornaments.css`.
 * Cố ý trung tính (không phân biệt theo giới tính) — tránh rập khuôn hình ảnh theo giới.
 */
.hq-portrait {
  position: relative;
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(160deg, var(--hq-night), var(--hq-paper-light));
  border: 2px solid var(--hq-gold);
  box-shadow: 0 2px 6px rgba(43, 29, 16, 0.18);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 56 56'%3E%3Ccircle cx='28' cy='21' r='10' fill='none' stroke='%23c9a227' stroke-width='2' opacity='0.65'/%3E%3Cpath d='M10 50 Q28 30 46 50' fill='none' stroke='%23c9a227' stroke-width='2' opacity='0.65'/%3E%3C/svg%3E"),
    linear-gradient(160deg, var(--hq-night), var(--hq-paper-light));
  background-repeat: no-repeat;
  background-position: center;
  background-size: 60%, cover;
}

.hq-hud-info {
  min-width: 0;
}

.hq-hud-age-profession {
  display: block;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--hq-ink);
}

/*
 * BUG FIX/thiết kế lại: chấm tín hiệu route trước đây là một ô riêng trong lưới HUD (`grid-template-
 * columns: 56px 1fr auto`) — giờ chuyển thành huy hiệu nhỏ ở góc dưới-phải chân dung, giống vị trí
 * huy hiệu trong ảnh tham khảo, không chiếm thêm không gian ngang.
 */
.hq-route-signal {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--hq-paper);
  opacity: 0.7;
  background: var(--hq-moss);
}

.hq-route-signal[data-route='devil'] {
  background: var(--hq-devil-purple-bright);
}

/* Lưới 3 thẻ chỉ số (Tuổi/Sức khỏe/Danh vọng — KHÔNG có Đức, xem ghi chú đầu mục HUD). */
.hq-hud-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.hq-stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.55rem 0.3rem;
  border-radius: var(--hq-radius);
  background: var(--hq-paper-light);
  border: 1px solid rgba(147, 105, 15, 0.2);
  text-align: center;
}

.hq-stat-icon {
  width: 20px;
  height: 20px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.hq-stat-card--hourglass .hq-stat-icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='none' stroke='%236c5a41' stroke-width='1.6' stroke-linecap='round'%3E%3Cpath d='M6 3 L18 3 M6 21 L18 21'/%3E%3Cpath d='M7 3 L17 3 L9 12 L17 21 L7 21 L15 12 Z'/%3E%3C/g%3E%3C/svg%3E");
}

.hq-stat-card--heart .hq-stat-icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 20 C6 15.5 2 12 2 8 C2 5 4.3 3 7 3 C9 3 10.8 4.2 12 6 C13.2 4.2 15 3 17 3 C19.7 3 22 5 22 8 C22 12 18 15.5 12 20 Z' fill='none' stroke='%23a3291b' stroke-width='1.6' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.hq-stat-card--shield .hq-stat-icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2 L20 5 L20 11 C20 16 16.6 19.7 12 21 C7.4 19.7 4 16 4 11 L4 5 Z' fill='none' stroke='%2335548c' stroke-width='1.6' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.hq-stat-label {
  font-size: 0.68rem;
  color: var(--hq-ink-dim);
}

.hq-stat-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--hq-ink);
}

/* "Tài sản dòng riêng" — deliberately its OWN line, never merged into .hq-hud-stats
   (tiêu chí nghiệm thu Phiên 10). Thiết kế lại (1.0.9): thanh nổi bật riêng, viền vàng, icon túi
   tiền — theo đúng bố cục ảnh tham khảo. */
.hq-hud-assets {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding: 0.6rem 0.85rem;
  border-radius: var(--hq-radius);
  background: rgba(147, 105, 15, 0.08);
  border: 1px solid rgba(147, 105, 15, 0.3);
  font-size: 0.95rem;
  color: var(--hq-gold);
  font-weight: 700;
}

.hq-assets-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='none' stroke='%2393690f' stroke-width='1.6'%3E%3Cellipse cx='12' cy='7' rx='7' ry='3'/%3E%3Cpath d='M5 7 L5 15 C5 16.7 8.1 18 12 18 C15.9 18 19 16.7 19 15 L19 7'/%3E%3Cpath d='M5 11 C5 12.7 8.1 14 12 14 C15.9 14 19 12.7 19 11'/%3E%3C/g%3E%3C/svg%3E");
}

/* ---------- Scene ---------- */

/*
 * THIẾT KẾ LẠI (bản 1.0.9 — yêu cầu rõ ràng từ chủ dự án, kèm ảnh giao diện tham khảo): ảnh mẫu
 * không có khối minh họa lớn riêng — bố cục gọn hơn, đi thẳng từ HUD sang thẻ tường thuật có viền +
 * chữ hoa đầu dòng trang trí (drop cap) + hoa văn góc. `.hq-illustration` (thêm ở bản 1.0.5, theo
 * yêu cầu trước đó "vẽ hình cho khối minh họa") giờ không còn được `app.js` gắn vào HTML nữa — luật
 * CSS bên dưới (và các luật `.hq-illustration.hq-bg-*` trong `ornaments.css`) để lại KHÔNG XÓA
 * (không có gì tham chiếu, không ảnh hưởng gì) phòng trường hợp cần dùng lại sau này.
 */
.hq-narrative-card {
  position: relative;
  padding: 1.1rem 1.15rem;
  margin-bottom: 1rem;
  border-radius: var(--hq-radius);
  background: var(--hq-paper-light);
  border: 1px solid rgba(147, 105, 15, 0.3);
  box-shadow: 0 1px 3px rgba(43, 29, 16, 0.08);
}

.hq-scene-title {
  font-size: 1.15rem;
  margin: 0 0 0.6rem;
  color: var(--hq-gold);
}

.hq-narrative {
  font-size: 0.98rem;
  line-height: 1.6;
  min-height: 4.5em;
  cursor: pointer; /* tap-to-reveal affordance */
}

/* Chữ hoa đầu dòng trang trí (drop cap) — theo đúng ảnh tham khảo. `::first-letter` áp dụng ngay khi
   ký tự đầu tiên xuất hiện trong DOM, kể cả khi `typewriter.js` đang gõ chữ dần từng ký tự. */
.hq-narrative::first-letter {
  font-size: 2.6em;
  font-weight: 700;
  color: var(--hq-gold);
  float: left;
  line-height: 0.85;
  padding-right: 0.08em;
  padding-top: 0.05em;
}

.hq-choices {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: auto;
}

/* Thiết kế lại: bố cục hàng ngang icon tròn màu | nhãn | chevron — theo ảnh tham khảo. */
.hq-choice-btn {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  text-align: left;
}

.hq-choice-label {
  flex: 1 1 auto;
  min-width: 0;
}

.hq-choice-icon {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 16px 16px;
}

.hq-choice-icon--a {
  background-color: rgba(53, 84, 140, 0.16);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2 L20 5 L20 11 C20 16 16.6 19.7 12 21 C7.4 19.7 4 16 4 11 L4 5 Z' fill='none' stroke='%2335548c' stroke-width='1.8' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.hq-choice-icon--b {
  background-color: rgba(63, 92, 58, 0.16);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21 C8 21 6 18 6 14 C6 9 12 3 12 3 C12 3 18 9 18 14 C18 18 16 21 12 21 Z' fill='none' stroke='%233f5c3a' stroke-width='1.8' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.hq-choice-icon--c {
  background-color: rgba(147, 105, 15, 0.16);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='none' stroke='%2393690f' stroke-width='1.8'%3E%3Cpath d='M12 3 L12 19'/%3E%3Cpath d='M6 6 L18 6'/%3E%3Cpath d='M6 6 L4 11 L8 11 Z'/%3E%3Cpath d='M18 6 L16 11 L20 11 Z'/%3E%3Cpath d='M8 19 L16 19'/%3E%3C/g%3E%3C/svg%3E");
}

.hq-choice-icon--d {
  background-color: rgba(122, 31, 43, 0.14);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='8' fill='none' stroke='%237a1f2b' stroke-width='1.8'/%3E%3Cpath d='M12 8 L12 16 M8 12 L16 12' stroke='%237a1f2b' stroke-width='1.8'/%3E%3C/svg%3E");
}

.hq-choice-chevron {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  opacity: 0.55;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 5 L16 12 L9 19' fill='none' stroke='%236c5a41' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.hq-choice-btn-locked {
  opacity: 0.55;
  cursor: default;
}

/* ---------- Stat delta animation ---------- */

.hq-delta {
  position: absolute;
  right: 0;
  top: -6px;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  animation: hq-float-up 1.4s ease-out forwards;
}

.hq-delta-positive {
  color: #d7f5df;
  background: var(--hq-moss);
}

.hq-delta-negative {
  color: #f5d7d7;
  background: var(--hq-wine);
}

@keyframes hq-float-up {
  0% { opacity: 0; transform: translateY(6px); }
  20% { opacity: 1; transform: translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* ---------- Birth transition ---------- */

.hq-screen-birth {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.hq-birth-summary {
  color: var(--hq-ink-dim);
  font-style: italic;
}

/* ---------- Loading ---------- */

.hq-screen-loading {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1rem;
}

.hq-loading-spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid rgba(201, 162, 39, 0.25);
  border-top-color: var(--hq-gold);
  animation: hq-spin 0.9s linear infinite;
}

@keyframes hq-spin {
  to { transform: rotate(360deg); }
}

/* ---------- Result ---------- */

.hq-result-row {
  margin: 0.4rem 0;
  font-size: 0.95rem;
}

/* ---------- Trial exhausted / CTA ---------- */

.hq-screen-trial-exhausted,
.hq-screen-cta {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1rem;
}

/* ---------- Error / offline ---------- */

.hq-screen-error {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1rem;
}

/* Trước là hồng nhạt (#f5d7d7) — đọc được trên nền tối cũ nhưng gần như vô hình trên giấy sáng
   (bản 1.0.8). Đổi sang đỏ rượu đậm, đủ tương phản trên nền sáng mới. */
.hq-error-message {
  color: var(--hq-wine-bright);
}

/* ---------- Devil route theming hook (Phiên 15 sets [data-hq-route="devil"] on .hq-app) ---------- */

.hq-app[data-hq-route='devil'] .hq-app-title,
.hq-app[data-hq-route='devil'] .hq-scene-title {
  color: var(--hq-devil-purple-bright);
}

/* ---------- Accessibility: reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .hq-app *,
  .hq-app *::before,
  .hq-app *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- Small-screen guarantee (320–430px) ---------- */

@media (max-width: 359px) {
  .hq-screen {
    padding: 1.1rem 0.9rem;
  }

  /* BUG FIX (thiết kế lại 1.0.9): `.hq-hud` không còn dùng `display: grid` (đổi sang `flex`) — luật
     `grid-template-columns` cũ ở đây đã thành no-op, chỉ cần thu nhỏ chân dung là đủ. */
  .hq-portrait {
    width: 44px;
    height: 44px;
  }

  .hq-hud-stats {
    gap: 0.35rem;
  }
}
