/* Tarot: các lá (úp, ngửa, ngược), bố cục của các kiểu trải bài, dải bộ bài, hộp thoại, và những phần mà
   class Tailwind sẽ phải lặp lại. Cùng bảng màu với shared/js/tailwind-theme.js, thêm màu chàm đậm cho các lá. */

/* Trang không tải shared/css/app.css, và quy tắc [hidden] riêng của Tailwind thua một utility display (flex,
   grid) trên cùng element: hidden phải thắng ở mọi nơi, như app.css làm. */
[hidden] { display: none !important; }

:root { --tr-indigo: #3b2f6b; --tr-indigo-soft: #ece8f7; --tr-ratio: 0.577; }

/* Footer nằm ở đáy màn hình khi một bước ngắn ("Lần xem của tôi" với một hai dòng): body
   là một cột (<site-header>, <site-footer> là display: contents), và các ghi chú phía trên footer (.tr-foot) chiếm
   phần chỗ còn lại, nên chúng và footer cùng nằm ở đáy. Các khối căn giữa giữ nguyên toàn bộ chiều rộng, mà nếu
   không thì margin auto của cột sẽ co chúng lại vừa nội dung. */
body { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
body > main, body > div { width: 100%; }
.tr-foot { margin-top: auto; padding-top: 24px; }

/* Nút. */
.tr-primary, .tr-secondary, .tr-danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 18px;
  border-radius: 999px; font-size: 0.875rem; font-weight: 600; transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.tr-primary { background: #b8461f; color: #fff; box-shadow: 0 8px 18px -12px rgb(184 70 31 / 0.8); }
.tr-primary:hover { background: #7a361d; }
.tr-primary:disabled { background: #d7c8b7; color: #65584e; box-shadow: none; cursor: default; }
.tr-secondary { border: 1px solid #d7c8b7; background: #faf6f0; color: #2b231e; }
.tr-secondary:hover { border-color: #9c4728; }
.tr-danger { border: 1px solid #e2b4a3; background: #fff; color: #9c2f1d; }
.tr-danger:hover { border-color: #9c2f1d; }

.tr-note { font-size: 0.78rem; line-height: 1.5; color: #71645a; }
.tr-field {
  border: 1px solid #d7c8b7; border-radius: 12px; background: #fff; padding: 8px 12px; font-size: 0.9rem; color: #2b231e;
  resize: vertical; min-height: 44px;
}
.tr-field:focus { outline: none; border-color: #9c4728; box-shadow: 0 0 0 3px rgb(156 71 40 / 0.2); }

/* Tab. */
.tr-tabs { display: flex; gap: 6px; border-bottom: 1px solid #e8ded2; }
.tr-tabs a { padding: 8px 12px; font-size: 0.875rem; font-weight: 600; color: #65584e; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tr-tabs a[aria-current="page"] { color: #7a361d; border-color: #9c4728; }

/* Các lựa chọn kiểu trải bài và các nút chủ đề. */
.tr-choices button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 9px 12px; text-align: left;
  border: 1px solid #e8ded2; border-radius: 14px; background: #fff; transition: border-color 0.15s, box-shadow 0.15s;
}
.tr-choices button:hover { border-color: #d7c8b7; }
.tr-choices button[aria-pressed="true"] { border-color: var(--tr-indigo); background: var(--tr-indigo-soft); box-shadow: inset 0 0 0 1px var(--tr-indigo); }
.tr-choices .tr-count { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--tr-indigo); }
.tr-choices .tr-name { font-size: 0.85rem; font-weight: 600; line-height: 1.3; }
.tr-pills button {
  min-height: 34px; padding: 5px 14px; border: 1px solid #d7c8b7; border-radius: 999px; background: #fff; font-size: 0.85rem; font-weight: 500;
}
/* Điện thoại: bốn chủ đề trên một hàng. */
@media (max-width: 639px) { .tr-pills button { padding: 5px 4px; font-size: 0.8rem; } }
.tr-pills button[aria-pressed="true"] { background: var(--tr-indigo); border-color: var(--tr-indigo); color: #fff; }

/* Một lá: một nút chứa ảnh scan (hoặc mặt sau). Ngược: ảnh xoay nửa vòng. */
.tr-card {
  position: relative; display: block; width: 100%; aspect-ratio: 240 / 416; padding: 0; border: 0; border-radius: 8%/4.6%;
  overflow: hidden; background: var(--tr-indigo); box-shadow: 0 6px 14px -10px rgb(43 35 30 / 0.6);
}
.tr-card img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform 0.4s ease; }
.tr-card.is-reversed img { transform: rotate(180deg); }
.tr-card .tr-fallback { position: absolute; inset: 0; display: grid; place-items: center; padding: 8%; color: #fff; font-size: 0.75rem; text-align: center; }
.tr-card:focus-visible { outline: 3px solid #f2b45a; outline-offset: 2px; }
button.tr-card { cursor: pointer; }
/* Lật lá. */
.tr-card.is-flipping { animation: tr-flip 0.5s ease both; }
@keyframes tr-flip { 0% { transform: rotateY(90deg); opacity: 0.4; } 100% { transform: rotateY(0); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .tr-card.is-flipping { animation: none; } .tr-card img { transition: none; } }

/* Các vị trí khi rút bài: một hàng ô. */
.tr-slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 52px)); gap: 8px; }
.tr-slots li { display: flex; flex-direction: column; gap: 4px; font-size: 0.62rem; line-height: 1.25; color: #65584e; text-align: center; }
.tr-slot-empty { aspect-ratio: 240 / 416; border: 2px dashed #d7c8b7; border-radius: 8%/4.6%; }

/* Bộ bài: 78 lá úp, chồng lên nhau, cuộn ngang trên điện thoại. */
.tr-deck { display: flex; overflow-x: auto; padding: 6px 4px 14px; scroll-snap-type: x proximity; overscroll-behavior-x: contain; }
.tr-deck .tr-card { flex: 0 0 52px; width: 52px; margin-right: -32px; scroll-snap-align: start; transition: transform 0.15s; }
.tr-deck .tr-card:hover, .tr-deck .tr-card:focus-visible { transform: translateY(-10px); z-index: 1; }
.tr-deck .tr-card.is-taken { visibility: hidden; }
@media (min-width: 640px) { .tr-deck { flex-wrap: wrap; overflow: visible; row-gap: 12px; } .tr-deck .tr-card { flex-basis: 56px; width: 56px; margin-right: -34px; } }

/* Các kiểu trải bài. */
.tr-layout { display: grid; gap: 10px; justify-content: center; }
.tr-layout figure { position: relative; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.tr-layout figcaption { font-size: 0.68rem; line-height: 1.25; color: #65584e; text-align: center; }
.tr-layout[data-spread="daily"] { grid-template-columns: minmax(0, 150px); }
.tr-layout[data-spread="three"], .tr-layout[data-spread="love"] { grid-template-columns: repeat(3, minmax(0, 112px)); }
/* Celtic Cross: hình chữ thập (1–6) bên trái, cây gậy (7–10) bên phải từ dưới lên; lá 2 nằm ngang qua lá 1. */
.tr-layout[data-spread="celtic"] {
  grid-template-columns: repeat(5, minmax(0, 78px)); column-gap: 8px; row-gap: 6px;
  grid-template-areas: ". p5 . . p10" "p4 x p6 . p9" ". p3 . . p8" ". . . . p7";
}
.tr-layout[data-spread="celtic"] [data-pos="1"], .tr-layout[data-spread="celtic"] [data-pos="2"] { grid-area: x; }
/* Xoay figure, không xoay lá: animation lật lá tự đặt transform riêng. */
.tr-layout[data-spread="celtic"] [data-pos="2"] { z-index: 1; justify-self: center; align-self: start; width: 100%; transform: rotate(90deg) scale(0.92); }
/* Không có chú thích thì figure đã xoay chỉ là lá bài, nên tâm của nó là tâm lá 1. */
.tr-layout[data-spread="celtic"] [data-pos="2"] figcaption { display: none; }
.tr-layout[data-spread="celtic"] [data-pos="3"] { grid-area: p3; }
.tr-layout[data-spread="celtic"] [data-pos="4"] { grid-area: p4; }
.tr-layout[data-spread="celtic"] [data-pos="5"] { grid-area: p5; }
.tr-layout[data-spread="celtic"] [data-pos="6"] { grid-area: p6; }
.tr-layout[data-spread="celtic"] [data-pos="7"] { grid-area: p7; }
.tr-layout[data-spread="celtic"] [data-pos="8"] { grid-area: p8; }
.tr-layout[data-spread="celtic"] [data-pos="9"] { grid-area: p9; }
.tr-layout[data-spread="celtic"] [data-pos="10"] { grid-area: p10; }
@media (max-width: 479px) {
  .tr-layout[data-spread="celtic"] { column-gap: 6px; row-gap: 4px; }
  .tr-layout figcaption { font-size: 0.62rem; }
}

/* Các đoạn chữ, mỗi lá một đoạn: hàng đầu (lá nhỏ, vị trí, tên, chiều), đoạn chữ chiếm toàn bộ chiều rộng bên dưới. */
.tr-texts { align-items: start; }
@media (min-width: 900px) { .tr-texts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tr-text { padding: 12px 14px; border: 1px solid #e8ded2; border-radius: 16px; background: #fff; }
.tr-text-head { display: flex; align-items: center; gap: 10px; }
.tr-text-head .tr-card { flex: none; width: 34px; }
.tr-text h4 { font-size: 0.95rem; font-weight: 600; line-height: 1.3; }
.tr-pos { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--tr-indigo); }
.tr-side { font-size: 0.75rem; color: #65584e; }
.tr-core { margin-top: 8px; font-size: 0.9rem; line-height: 1.6; }
.tr-lead { font-style: italic; color: #65584e; }
.tr-line { margin-top: 8px; padding: 8px 12px; border-radius: 12px; background: var(--tr-indigo-soft); font-size: 0.85rem; line-height: 1.5; }
.tr-line strong { color: var(--tr-indigo); }

.tr-summary { padding: 14px 16px; border-radius: 16px; background: #f3ece2; }
.tr-summary li { padding-left: 16px; position: relative; font-size: 0.9rem; line-height: 1.5; }
.tr-summary li::before { content: "✦"; position: absolute; left: 0; color: var(--tr-indigo); }

/* Gemini. */
.tr-ai { padding: 14px 16px; border: 1px solid #d9d2ee; border-radius: 16px; background: #faf9fe; }
.tr-qa-q { font-size: 0.8rem; font-weight: 600; color: var(--tr-indigo); }
.tr-qa-a { margin-top: 4px; font-size: 0.9rem; line-height: 1.6; white-space: pre-line; }

/* "Lần xem của tôi". */
.tr-row { display: flex; width: 100%; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid #e8ded2; border-radius: 14px; background: #fff; text-align: left; font-size: 0.9rem; }
.tr-row:hover { border-color: #d7c8b7; }
/* Một dòng có nút xoá trong cùng thẻ: thùng rác nhỏ, mờ cho đến khi hover; chạm lần đầu biến nó thành
   viên "Xoá?" nhỏ, chạm lần hai thì xoá. */
.tr-row-item { display: flex; align-items: center; gap: 2px; padding-right: 8px; border: 1px solid #e8ded2; border-radius: 14px; background: #fff; transition: border-color 0.15s; }
.tr-row-item:hover { border-color: #d7c8b7; }
.tr-row-item .tr-row { flex: 1; min-width: 0; border: 0; background: transparent; }
.tr-row-delete {
  flex: none; display: inline-flex; align-items: center; justify-content: center; height: 32px; min-width: 32px; padding: 0 8px;
  border-radius: 999px; background: transparent; color: #a3958a; font-size: 0.75rem; font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.tr-row-delete svg { width: 16px; height: 16px; }
.tr-row-delete:hover, .tr-row-delete:focus-visible { background: #fbebe6; color: #9c2f1d; outline: none; }
.tr-row-delete[data-armed] { background: #fbe1d8; color: #9c2f1d; }
.tr-row-cards { display: flex; flex-shrink: 0; }
.tr-row-cards .tr-card { width: 26px; }
/* Chồng lên nhau một chút, cái cuối giữ toàn bộ chiều rộng để chữ bên cạnh bắt đầu không đè lên nó. */
.tr-row-cards .tr-card:not(:last-child) { margin-right: -12px; }
.tr-badge { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: var(--tr-indigo-soft); color: var(--tr-indigo); font-size: 0.7rem; font-weight: 700; }

/* Một lá, cỡ lớn; trên điện thoại là một tấm trượt lên từ đáy. */
.tr-dialog { width: min(640px, calc(100% - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 0; border-radius: 20px; background: #faf6f0; color: #2b231e; }
.tr-dialog::backdrop { background: rgb(36 28 23 / 0.55); }
.tr-dialog-body { position: relative; display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 18px; padding: 20px; }
.tr-dialog-image { width: 200px; height: auto; aspect-ratio: 240 / 416; border-radius: 8%/4.6%; object-fit: cover; }
.tr-dialog-image.is-reversed { transform: rotate(180deg); }
.tr-close { position: absolute; right: 12px; top: 12px; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 999px; background: #f3ece2; z-index: 1; }
@media (max-width: 639px) {
  .tr-dialog { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 20px 20px 0 0; max-height: 88dvh; }
  .tr-dialog-body { grid-template-columns: 1fr; gap: 14px; padding: 18px 16px 24px; }
  .tr-dialog-image { width: 130px; justify-self: center; }
}
