:root {
  --bg: #f7f1ea;
  --panel: #fffaf6;
  --panel-strong: #f2e3d4;
  --ink: #241b22;
  --muted: #756b68;
  --line: #e4d2c2;
  --accent: #8e3f56;
  --accent-dark: #4b2237;
  --green: #2f604e;
  --gold: #c28b42;
  --rose: #f8e6e9;
  --danger: #9b3b32;
  --shadow: 0 22px 60px rgba(75, 34, 55, 0.13);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 10%, rgba(194, 139, 66, 0.16), transparent 28%),
    radial-gradient(circle at 82% 0%, rgba(142, 63, 86, 0.18), transparent 30%),
    linear-gradient(145deg, rgba(47, 96, 78, 0.10), transparent 42%),
    var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.file-button {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

button:hover,
.file-button:hover {
  transform: translateY(-1px);
}

.primary {
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  color: #fffaf0;
  box-shadow: 0 12px 26px rgba(75, 34, 55, 0.28);
}

.secondary,
.file-button {
  background: #fff8f3;
  color: var(--accent-dark);
  border: 1px solid var(--line);
}

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.danger {
  background: #fff0ed;
  color: var(--danger);
  border: 1px solid rgba(155, 59, 50, 0.24);
}

/* 分级行宽：标题区是视觉可以宽，正文是阅读必须窄；背景渐变仍满屏 */
.app-shell {
  min-height: 100vh;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.hint,
.empty-state p {
  color: var(--muted);
  line-height: 1.7;
}

.list-panel,
.detail-panel,
.stats > div {
  background: rgba(255, 250, 246, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(50, 38, 27, 0.08);
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

#syncDialog {
  width: min(520px, calc(100vw - 28px));
}

.sync-dialog-body {
  padding: 22px;
  display: grid;
  gap: 16px;
}

#syncSetup {
  display: grid;
  gap: 12px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title h2,
.section-title h3 {
  font-size: 17px;
}

.section-title span {
  color: var(--muted);
  font-size: 13px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fffefd;
  color: var(--ink);
  border-radius: 8px;
  padding: 11px 12px;
  outline: 0;
}

textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.65;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(142, 63, 86, 0.14);
}

.sync-summary {
  display: grid;
  gap: 12px;
}

.sync-summary > p {
  color: var(--green);
  font-weight: 700;
}

.sync-summary .button-grid {
  grid-template-columns: 1fr 1fr;
}

.sync-summary .button-grid .primary {
  grid-column: 1 / -1;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.main {
  padding: 28px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto 22px;
}

.eyebrow {
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
  margin-bottom: 8px;
  font-weight: 700;
}

.topbar h2 {
  font-size: clamp(26px, 4vw, 46px);
  line-height: 1.15;
  max-width: 780px;
}

.tools {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 150px 150px auto auto;
  gap: 12px;
  max-width: 1080px;
  margin: 0 auto 16px;
}

.file-button input {
  display: none;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 1080px;
  margin: 0 auto 16px;
}

.stats > div {
  padding: 16px;
}

.stats span {
  display: block;
  font-size: 26px;
  font-weight: 800;
  color: var(--green);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats p {
  color: var(--muted);
  margin-top: 4px;
}

.daily-panel {
  background: rgba(255, 250, 246, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(50, 38, 27, 0.08);
  padding: 18px 22px;
  max-width: 1200px;
  margin: 0 auto 16px;
}

.daily-body {
  display: flex;
  gap: 18px;
  align-items: flex-start;
}

.daily-cards {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-content: start;
}

.daily-cards:has(.daily-card-img--sm) {
  grid-template-columns: 1fr 1fr;
}

.daily-card-img {
  width: 156px;
  border-radius: 10px;
  border: 1px solid var(--line);
  box-shadow: 0 10px 24px rgba(50, 38, 27, 0.18);
  display: block;
}

.daily-card-img--sm {
  width: 108px;
}

.daily-thesis {
  font-size: 17px;
  font-weight: 800;
  color: var(--accent-dark);
  line-height: 1.6;
  padding: 4px 0;
}

.daily-info {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.daily-info h3 {
  font-size: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.daily-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.daily-info p {
  line-height: 1.7;
  color: var(--ink);
  font-size: 14px;
}

.daily-question {
  border-left: 3px solid var(--gold);
  padding: 6px 0 6px 12px;
  color: var(--accent-dark);
  font-weight: 600;
  margin-top: 4px;
}

.daily-info .ghost {
  justify-self: start;
  margin-top: 4px;
}

.daily-nav {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.daily-nav button {
  flex: 1;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(290px, 380px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  max-width: 1200px;
  margin: 0 auto;
}

.list-panel,
.detail-panel {
  padding: 18px;
  min-height: 460px;
}

.record-list {
  display: grid;
  gap: 10px;
}

.record-card {
  text-align: left;
  width: 100%;
  padding: 14px;
  background: #fffdf8;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  /* 覆盖全局 button 的 justify-content: center，否则内容短时整块居中 */
  justify-content: stretch;
  justify-items: start;
  align-items: start;
}

.record-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(123, 78, 56, 0.12);
}

.record-meta,
.tags,
.detail-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.tag {
  border-radius: 999px;
  padding: 4px 9px;
  background: linear-gradient(135deg, var(--rose), #f7eddc);
  color: var(--accent-dark);
  font-size: 12px;
}

.record-card h3 {
  font-size: 16px;
  line-height: 1.45;
}

.record-card p {
  color: var(--muted);
  line-height: 1.5;
  font-size: 13px;
}

.detail-panel {
  background: rgba(255, 254, 253, 0.9);
}

.empty-state {
  min-height: 420px;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 10px;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.detail-head h2 {
  font-size: 28px;
  line-height: 1.25;
  margin: 8px 0 12px;
}

.detail-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.detail-section {
  border-top: 1px solid var(--line);
  padding-top: 18px;
  margin-top: 18px;
}

.detail-section h3 {
  font-size: 17px;
  margin-bottom: 10px;
}

.detail-section p {
  line-height: 1.8;
  white-space: pre-wrap;
}

/* 一张牌一行：真牌图在左，解读在右，长文字有足够行宽 */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.detail-card-visual {
  position: relative;
  flex: 0 0 132px;
  align-self: flex-start;
}

.detail-card-visual img {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  box-shadow: 0 10px 24px rgba(50, 38, 27, 0.16);
  display: block;
}

.detail-card-visual.reversed img {
  transform: rotate(180deg);
}

.tarot-card {
  border: 1px solid var(--line);
  background: #fffaf6;
  border-radius: 8px;
  padding: 14px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.tarot-card-body {
  min-width: 0;
}

.tarot-card h4 {
  margin: 8px 0;
  font-size: 16px;
}

.tarot-card p {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 6px;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* 花色配色 */
.suit-wands { --suit-bg1: #fbe3c6; --suit-bg2: #f0b87f; --suit-ink: #7a4712; --suit-line: rgba(122, 71, 18, 0.35); }
.suit-cups { --suit-bg1: #ddecf6; --suit-bg2: #a5c7de; --suit-ink: #2c5570; --suit-line: rgba(44, 85, 112, 0.35); }
.suit-swords { --suit-bg1: #eaeaf0; --suit-bg2: #c0c4d3; --suit-ink: #3d4257; --suit-line: rgba(61, 66, 87, 0.35); }
.suit-pents { --suit-bg1: #e3eedd; --suit-bg2: #b5d1a9; --suit-ink: #33562e; --suit-line: rgba(51, 86, 46, 0.35); }
.suit-major { --suit-bg1: #4b2237; --suit-bg2: #241430; --suit-ink: #f2d49b; --suit-line: rgba(242, 212, 155, 0.5); }
.suit-unknown { --suit-bg1: #f0ebe6; --suit-bg2: #ddd4cb; --suit-ink: #5c534e; --suit-line: rgba(92, 83, 78, 0.3); }

.card-face {
  flex: 0 0 84px;
  width: 84px;
  aspect-ratio: 3 / 5;
  border-radius: 10px;
  border: 1px solid var(--suit-line);
  background: linear-gradient(165deg, var(--suit-bg1), var(--suit-bg2));
  color: var(--suit-ink);
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: center;
  align-items: center;
  padding: 9px 6px;
  position: relative;
  box-shadow: 0 8px 18px rgba(50, 38, 27, 0.16);
}

.card-face::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid var(--suit-line);
  border-radius: 7px;
  pointer-events: none;
  opacity: 0.6;
}

.card-face-corner {
  font-family: Georgia, serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  min-height: 14px;
}

.card-face-symbol {
  font-size: 30px;
  line-height: 1;
  transition: transform 0.25s ease;
}

.card-face.reversed .card-face-symbol {
  transform: rotate(180deg);
}

.card-face-name {
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
}

.card-face-reversed {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 10px;
  background: rgba(36, 27, 34, 0.72);
  color: #fff4e4;
  border-radius: 999px;
  padding: 2px 6px;
  z-index: 1;
}

.card-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.card-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--suit-bg1);
  color: var(--suit-ink);
  border: 1px solid var(--suit-line);
}

.card-chip i {
  font-style: normal;
  font-size: 12px;
  line-height: 1;
}

.card-chip.reversed i {
  display: inline-block;
  transform: rotate(180deg);
}

.card-chip b {
  font-size: 10px;
  font-weight: 800;
  opacity: 0.85;
}

.review-item {
  border-left: 3px solid var(--gold);
  padding: 10px 0 10px 14px;
  margin-top: 10px;
}

dialog {
  width: min(900px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 0;
}

dialog::backdrop {
  background: rgba(36, 32, 28, 0.48);
}

form {
  padding: 22px;
  display: grid;
  gap: 16px;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.icon-button {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50%;
  background: #fff8f3;
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 24px;
  line-height: 1;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.cards-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 254, 253, 0.64);
}

#cardsContainer {
  display: grid;
  gap: 12px;
}

.card-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffefd;
}

.photo-uploader {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: linear-gradient(135deg, rgba(248, 230, 233, 0.72), rgba(255, 250, 246, 0.82));
}

.photo-uploader h3 {
  font-size: 17px;
}

.upload-box {
  min-height: 112px;
  border: 1px dashed rgba(142, 63, 86, 0.42);
  background: rgba(255, 254, 253, 0.68);
  border-radius: 8px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 18px;
  color: var(--accent-dark);
  cursor: pointer;
}

.upload-box input {
  display: none;
}

.upload-box span {
  font-weight: 800;
}

.upload-box small {
  color: var(--muted);
  line-height: 1.6;
}

.photo-preview {
  display: grid;
  gap: 10px;
}

.photo-preview img,
.record-thumb,
.detail-photo img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  object-fit: cover;
  display: block;
}

.photo-preview img {
  max-height: 280px;
}

.record-thumb {
  height: 118px;
}

.detail-photo {
  margin: 16px 0 4px;
}

.detail-photo img {
  max-height: 520px;
}

.card-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.dialog-actions > div,
.dialog-actions.right {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fffaf0;
  padding: 12px 16px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  box-shadow: var(--shadow);
  max-width: min(520px, calc(100vw - 32px));
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1050px) {
  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .main {
    padding: 16px;
  }

  .tools,
  .stats,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .detail-head,
  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar h2 {
    font-size: 30px;
  }

  .detail-actions,
  .dialog-actions > div,
  .dialog-actions.right {
    justify-content: stretch;
  }

  .detail-actions button,
  .dialog-actions button {
    flex: 1;
  }

  .daily-body {
    gap: 14px;
  }

  .daily-body {
    flex-direction: column;
  }

  .daily-cards {
    grid-template-columns: repeat(auto-fill, 96px);
    width: 100%;
  }

  .daily-card-img,
  .daily-card-img--sm {
    width: 118px;
  }

  .detail-card-visual {
    flex-basis: 104px;
  }

  .daily-card-img--sm {
    width: 96px;
  }

  .daily-nav {
    flex-direction: column;
  }
}
