:root {
  color-scheme: dark;
  --ink: #10132b;
  --ivory: #fff5e4;
  --subtle: #d2cce2;
  --gold: #f2d493;
  --muted-gold: #b49664;
  --line: rgba(226, 215, 255, .18);
  --serif: "Songti SC", "Noto Serif CJK SC", "SimSun", "STSong", Georgia, serif;
  --sans: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--ivory); font-family: var(--sans); background: #11142d; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: wait; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
h1, h2, p { margin: 0; }

.scenery {
  position: absolute;
  inset: 0 0 auto;
  height: min(1000px, 120vh);
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(13, 15, 38, .12) 0%, rgba(16, 18, 44, .16) 52%, #11142d 100%),
    linear-gradient(90deg, rgba(15, 16, 40, .88), rgba(18, 20, 53, .14) 78%),
    url("night-lake.webp") center 61% / cover no-repeat,
    radial-gradient(ellipse at 75% 28%, #303060, #13162f 67%);
}
body { position: relative; isolation: isolate; min-height: 100vh; min-height: 100svh; }
.site { max-width: 1192px; margin: 0 auto; padding: 0 40px; }
.masthead {
  min-height: 93px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}
.brand, .header-actions { display: flex; align-items: center; gap: 12px; }
.brand {
  border: 0; background: none; padding: 0; text-align: left;
  font-size: 18px; font-weight: 650; letter-spacing: .07em; white-space: nowrap;
}
.brand-icon {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px;
  background: #f4d79c; color: #211832; font: 27px/1 Georgia, serif;
}
.header-actions { gap: 22px; }
#today { color: var(--subtle); font-size: 13px; white-space: nowrap; }
#today::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); margin: 0 8px 2px 0; }
.quiet-button {
  border: 1px solid var(--line); border-radius: 100px; background: rgba(23, 23, 55, .62);
  min-height: 42px; padding: 9px 16px; font-size: 13px; white-space: nowrap;
}
.quiet-button:hover, .mood-button:hover { background-color: #302b54; border-color: #81729e; }
.quiet-button span:first-child { margin-right: 3px; }

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(340px, .95fr);
  grid-template-areas: "heading stage" "mode stage" "copy stage";
  grid-template-rows: auto auto auto;
  align-content: center;
  align-items: start;
  min-height: 550px;
  column-gap: 30px;
  padding: 40px 0;
}
.hero-heading { grid-area: heading; }
.mode-panel { grid-area: mode; padding-top: 22px; }
.hero-copy { grid-area: copy; position: relative; z-index: 1; padding-top: 24px; }
.hero:not([data-phase="ready"]) { grid-template-areas: "mode stage" "copy stage"; grid-template-rows: auto 1fr; }
.hero:not([data-phase="ready"]) .mode-panel { padding-top: 0; }
.hero:not([data-phase="ready"]) .hero-copy { align-self: center; }
.mode-options {
  display: inline-flex; gap: 4px; padding: 4px; margin: 0;
  border: 1px solid var(--line); border-radius: 100px; background: rgba(15, 15, 39, .5);
}
.mode-button {
  padding: 10px 22px; min-height: 44px; border: 1px solid transparent; border-radius: 100px;
  background: transparent; font-size: 14px; color: var(--subtle);
}
.mode-button:hover { color: var(--ivory); background: #302b54; }
.mode-button[aria-pressed="true"] { background: #4c3d55; border-color: #a88b6470; color: var(--gold); }
.mode-panel .intro { margin-top: 12px; font-size: 14px; }
.draw-again { margin: 16px 0 0 10px; min-height: 53px; border-radius: 11px; }
h1, #result-title { font: 700 clamp(38px, 4.3vw, 56px)/1.3 var(--serif); letter-spacing: -.035em; }
h1 span { color: var(--gold); }
.intro { max-width: 440px; margin-top: 20px; color: var(--subtle); font-size: 16px; line-height: 1.85; }
.moods { padding: 0; margin: 0; border: 0; min-inline-size: 0; }
.moods legend { padding: 0; margin-bottom: 14px; font-size: 14px; }
.moods legend span { color: #bbb2d3; font-size: 12px; }
.mood-options { display: flex; flex-wrap: wrap; gap: 8px; max-width: 344px; }
.mood-button {
  flex: 0 0 calc((100% - 24px) / 4); min-height: 44px;
  border: 1px solid var(--line); border-radius: 100px; background: rgba(34, 30, 68, .45);
  padding: 9px 12px; text-align: center; font-size: 14px;
}
.mood-button[aria-pressed="true"] { background: #4c3d55; border-color: var(--gold); color: #fff0cb; }
.mood-hint { max-width: 344px; min-height: 28px; margin-top: 12px; color: var(--subtle); font-size: 14px; line-height: 28px; }
.draw-primary { width: min(100%, 344px); margin-top: 16px; }
.primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 53px; margin-top: 22px; padding: 10px 23px; border: 1px solid #ffe2a9; border-radius: 11px;
  background: #f3d395; color: #24172c; font: 700 15px/1.4 var(--sans);
  text-decoration: none; box-shadow: 0 6px 24px rgba(15, 12, 34, .32);
}
.primary:hover { background: #ffe6b4; }
.primary span { font-size: 18px; }
.text-button { border: 0; background: transparent; padding: 6px 0; color: var(--gold); font-size: 13px; min-height: 38px; text-align: left; }
.text-button:hover { text-decoration: underline; }
.back-link { margin: 0 0 10px; }
.result-kind { color: var(--gold); font-size: 13px; margin-bottom: 10px; }
#result-title { font-size: clamp(36px, 5vw, 66px); }
#result-view .intro { margin-top: 14px; }
.result-verse { max-width: 460px; margin-top: 18px; color: var(--gold); font: 500 23px/1.7 var(--serif); text-wrap: pretty; }
.reading-label { margin: 24px 0 0; color: var(--gold); font: 600 14px/1.5 var(--sans); }
#result-reading, #detail-reading { white-space: pre-line; }
#result-view .reading-label:not([hidden]) + .intro, #card-dialog .reading-label:not([hidden]) + .intro { margin-top: 10px; }
.action-note { max-width: 460px; margin-top: 19px; padding: 15px 17px; border-left: 2px solid #d3ab75; border-radius: 0 9px 9px 0; background: rgba(31, 27, 58, .8); }
.action-note strong { display: block; color: var(--gold); font-size: 14px; margin-bottom: 8px; }
.action-note p { line-height: 1.8; font-size: 16px; }
.status { line-height: 1.65; font-size: 14px; }
.status { margin-top: 10px; color: var(--subtle); }
#ritual-title { font: 700 clamp(28px, 4vw, 42px)/1.4 var(--serif); color: var(--gold); }
.ritual-back { display: block; margin-top: 16px; }
#result-view { animation: show-reading .3s ease-out; }
@keyframes show-reading { from { opacity: 0; } to { opacity: 1; } }

.stage { grid-area: stage; align-self: center; min-height: 410px; position: relative; display: grid; place-items: center; isolation: isolate; }
.stage::before {
  content: ""; position: absolute; width: 94%; height: 91%; z-index: -1;
  background: radial-gradient(ellipse, rgba(113, 84, 163, .47), rgba(59, 44, 119, .15) 57%, transparent 72%);
}
.orbit {
  position: absolute; width: min(88%, 415px); aspect-ratio: 1;
  border: 1px solid rgba(224, 189, 147, .23); border-radius: 50%;
}
.orbit-inner { width: min(78%, 365px); border-style: dashed; border-color: rgba(222, 187, 151, .16); }
.spark { position: absolute; color: #f7d9a4; text-shadow: 0 0 14px #f1ad7b; line-height: 1; }
.spark-top { top: 3%; left: 50%; font-size: 19px; }
.spark-left { left: 12%; top: 37%; font-size: 25px; }
.spark-right { right: 11%; top: 49%; font-size: 29px; }
.spark-bottom { bottom: 6%; left: 32%; font-size: 17px; }
.deck { position: relative; width: 222px; height: 319px; perspective: 950px; --spread: 29px; }
.card, .under-card {
  position: absolute; inset: 0; border: 1px solid #d4b681; border-radius: 15px;
  background: linear-gradient(160deg, #30264e, #1b173a 62%, #302142);
  box-shadow: 0 22px 45px #0d0b249c;
}
.under-card { border-color: #947b65; }
.under-card { pointer-events: none; }
.under-card::before {
  content: ""; position: absolute; inset: 8px; border: 1px solid #a88b6470; border-radius: 10px;
  background: radial-gradient(circle at center, transparent 22%, #ba9b6740 22.5%, transparent 23%);
}
.under-left { transform: translate(calc(-1 * var(--spread)), 10px) rotate(-12deg); }
.under-right { transform: translate(var(--spread), 12px) rotate(12deg); }
.card { display: grid; place-items: center; overflow: hidden; color: #f6dba2; }
button.card { padding: 0; width: 100%; height: 100%; appearance: none; }
button.card {
  overflow: visible; transform-style: preserve-3d; background: transparent;
  transition: transform .7s cubic-bezier(.25, .7, .25, 1), box-shadow .25s;
}
.card-side {
  position: absolute; inset: -1px; display: grid; place-items: center; border-radius: 15px;
  border: 1px solid #d4b681; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: linear-gradient(160deg, #30264e, #1b173a 62%, #302142);
}
.card-front {
  transform: rotateY(180deg);
  background: radial-gradient(ellipse at 50% 46%, var(--face-color), transparent 68%), linear-gradient(155deg, #31284f, #191630);
}
button.card:disabled { cursor: default; }
button.card:not(:disabled):hover { border-color: #fff0cc; box-shadow: 0 0 26px #edca8c38, 0 22px 45px #0d0b249c; }
.stage-hint { position: absolute; bottom: -4px; color: var(--gold); font-size: 13px; text-align: center; }
.shuffling .under-left { animation: shuffle-left .6s ease-in-out 2; }
.shuffling .under-right { animation: shuffle-right .6s ease-in-out 2; }
.shuffling .card { animation: shuffle-front .6s ease-in-out 2; }
.deck.shaking { animation: deck-shake .3s ease-in-out 3; }
.dealing .under-card, .dealt .under-card { opacity: .18; transition: opacity .6s; }
.dealing .card { animation: deal-card 1.1s cubic-bezier(.2, .8, .2, 1) both; }
.dealt button.card { transform: translateY(-12px) scale(1.04); }
.dealt button.card.face { transform: translateY(-12px) scale(1.04) rotateY(180deg); }
.dealt button.card:not(:disabled) { box-shadow: 0 0 30px #efc98a45, 0 22px 45px #0d0b249c; }
#card-stage { scroll-margin-block: 25px; }
@keyframes deck-shake {
  0%, 100% { transform: rotate(0); }
  25% { transform: translateX(-4px) rotate(-3deg); }
  75% { transform: translateX(4px) rotate(3deg); }
}
@keyframes shuffle-left {
  0%, 100% { transform: translate(calc(-1 * var(--spread)), 10px) rotate(-12deg); }
  45% { transform: translate(calc(-2.5 * var(--spread)), -18px) rotate(-22deg); z-index: 2; }
  75% { transform: translate(0, 6px) rotate(4deg); z-index: 0; }
}
@keyframes shuffle-right {
  0%, 100% { transform: translate(var(--spread), 12px) rotate(12deg); }
  45% { transform: translate(calc(2.5 * var(--spread)), 20px) rotate(22deg); }
  75% { transform: translate(0, -10px) rotate(-4deg); }
}
@keyframes shuffle-front {
  0%, 100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(-22px) rotate(7deg); }
  75% { transform: translateY(8px) rotate(-5deg); }
}
@keyframes deal-card {
  0% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-50px) scale(1.06); }
  100% { transform: translateY(-12px) scale(1.04); }
}
.large-card::before, .large-card::after, .card-side::before, .card-side::after, .card-trim { content: ""; position: absolute; pointer-events: none; border-radius: 11px; }
.large-card::before, .card-side::before { inset: 7px; border: 1px solid rgba(232, 193, 125, .58); }
.large-card::after, .card-side::after { inset: 12px; border: 1px solid rgba(232, 193, 125, .24); }
.card-trim {
  inset: 16px;
  opacity: .65;
  background:
    radial-gradient(circle at 11% 12%, #edc88d 1px, transparent 2px),
    radial-gradient(circle at 88% 14%, #edc88d 1px, transparent 2px),
    radial-gradient(circle at 19% 70%, #edc88d 1px, transparent 2px),
    radial-gradient(circle at 84% 64%, #edc88d 1px, transparent 2px),
    radial-gradient(circle at 12% 87%, #edc88d 1px, transparent 2px),
    radial-gradient(circle at 87% 89%, #edc88d 1px, transparent 2px);
}
.card-medallion {
  width: 118px; height: 118px; border: 1px solid #a68661; border-radius: 50%;
  display: grid; place-items: center; position: relative;
  box-shadow: 0 0 0 7px rgba(234, 192, 123, .08), 0 0 29px rgba(229, 166, 99, .15);
  background: radial-gradient(circle, rgba(194, 127, 117, .26), transparent 68%);
}
.card-medallion::before, .card-medallion::after {
  content: ""; position: absolute; width: 7px; height: 7px; border: 1px solid #f0d49e; transform: rotate(45deg);
}
.card-medallion::before { left: -5px; }
.card-medallion::after { right: -5px; }
.card-medallion span { font: 86px/1 "Segoe UI Symbol", Georgia, serif; transform: translateY(-3px); text-shadow: 0 0 20px #f1c1876b; }
.card-star { position: absolute; font-size: 20px; color: #e7c68d; text-align: center; }
.top-star { top: 29px; }
.bottom-star { bottom: 30px; max-width: 82%; }
.card.face { background: radial-gradient(ellipse at 50% 46%, var(--face-color), transparent 68%), linear-gradient(155deg, #31284f, #191630); }
.card.face .bottom-star { font-family: var(--serif); font-size: 17px; letter-spacing: .06em; }

.weekly-panel {
  display: grid; grid-template-columns: auto 1fr auto; gap: 20px; align-items: center;
  padding: 22px 0; border-top: 1px solid var(--line);
}
.weekly-icon {
  display: grid; place-items: center; width: 52px; height: 52px;
  background: rgba(148, 117, 193, .1); border-radius: 50%;
  color: #e5d0fb; font: 32px/1 Georgia, serif;
}
.weekly-copy h2 { font-size: 16px; font-weight: 600; }
.weekly-copy p { color: var(--subtle); margin-top: 6px; font-size: 14px; line-height: 1.55; }
.weekly-button { color: var(--gold); padding-inline: 16px; background: transparent; }
footer { text-align: center; padding: 25px 0 30px; color: #bcb3d2; font-size: 12px; }
footer span { margin: 0 4px; }

dialog {
  width: min(430px, calc(100% - 28px)); max-height: calc(100% - 32px);
  color: var(--ivory); background: #201b39; border: 1px solid #5c5277;
  border-radius: 16px; padding: 18px; box-shadow: 0 20px 65px #080716;
}
dialog::backdrop { background: rgba(9, 8, 23, .77); }
dialog[open] { animation: open-dialog .22s ease-out; }
@keyframes open-dialog { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.dialog-head h2 { font-size: 21px; }
.icon-button { padding: 0; width: 42px; font-size: 22px; }
#history-empty, .share-help { color: var(--subtle); line-height: 1.6; font-size: 14px; }
.history-item {
  display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center;
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px;
  margin-top: 8px; background: #2e2648; text-align: left;
}
.history-item:hover { border-color: var(--gold); }
.history-item .symbol { color: var(--gold); font: 23px/1 "Segoe UI Symbol", serif; }
.history-item small { display: block; margin-top: 4px; color: var(--subtle); }
.connection-note { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 14px 16px; margin-top: 16px; border: 1px solid var(--line); border-radius: 12px; background: #25203e; font-size: 14px; line-height: 1.7; }
.connection-note > span { flex: 1 1 220px; }
.legacy-history { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 20px; }
.legacy-history h3 { margin: 0 0 10px; font-size: 16px; }
#history-retry { margin-top: 12px; }
#history-empty { margin-top: 14px; }
#share-image { display: block; width: min(100%, 290px, 46vh); height: auto; border-radius: 10px; margin: 14px auto 0; }
#download-link { display: flex; margin-top: 14px; }
#card-dialog { width: min(520px, calc(100% - 28px)); padding: 22px; }
#card-dialog .result-kind { margin: 0; }
.large-card { position: relative; width: 222px; height: 319px; margin: 10px auto 24px; }
.large-card .bottom-star { font-family: var(--serif); font-size: 17px; }
#detail-title { text-align: center; font: 700 30px/1.4 var(--serif); }
.detail-verse { text-align: center; color: var(--gold); margin-top: 14px; font: 500 21px/1.7 var(--serif); }
#card-dialog .intro { margin-top: 20px; }

@media (min-width: 761px) and (max-height: 900px) {
  .masthead { min-height: 80px; }
  .hero { min-height: 520px; padding-block: 30px; }
}

@media (max-width: 760px) {
  .site { padding-inline: 24px; }
  .masthead { min-height: 71px; }
  .hero { min-height: 0; grid-template-columns: minmax(0, 1fr); grid-template-areas: "heading" "mode" "stage" "copy"; padding: 22px 0 26px; gap: 0; }
  .hero-heading, .mode-panel, .hero-copy { text-align: center; }
  .mode-panel { padding-top: 16px; }
  .hero-copy { padding-top: 4px; min-width: 0; }
  .hero:not([data-phase="ready"]) { grid-template-areas: "mode" "stage" "copy"; grid-template-rows: auto auto auto; }
  .hero:not([data-phase="ready"]) .stage { margin-bottom: 20px; }
  .hero:not([data-phase="ready"]) .hero-copy { padding-top: 0; }
  .ritual-back { margin-inline: auto; }
  h1 { font-size: clamp(24px, 6.2vw, 34px); }
  h1 br { display: none; }
  .intro { margin: 13px auto 0; font-size: 16px; }
  .mode-panel .intro { margin-top: 10px; font-size: 14px; }
  .moods legend { margin-inline: auto; margin-bottom: 12px; }
  .mood-options { justify-content: center; margin-inline: auto; }
  .mood-hint { margin-inline: auto; }
  .primary { margin-top: 16px; }
  .stage { min-height: 266px; width: min(100%, 410px); margin: 10px auto 0; }
  .orbit { width: min(87%, 280px); }
  .orbit-inner { width: min(76%, 247px); }
  .deck { width: 146px; height: 211px; --spread: 19px; }
  .card-medallion { width: 79px; height: 79px; }
  .card-medallion span { font-size: 57px; }
  .top-star { top: 20px; }
  .bottom-star { bottom: 21px; }
  .card.face .bottom-star { font-size: 13px; }
  .large-card .card-medallion { width: 118px; height: 118px; }
  .large-card .card-medallion span { font-size: 86px; }
  .large-card.face .bottom-star { font-size: 17px; }
  .weekly-panel { padding: 18px 0; gap: 12px; }
  .weekly-icon { width: 42px; height: 42px; font-size: 27px; }
  .weekly-copy h2 { font-size: 16px; }
  .weekly-copy p { font-size: 12px; }
  .weekly-button { padding-inline: 10px; font-size: 12px; }
  .action-note { margin-inline: auto; text-align: left; }
}

@media (max-width: 390px) {
  .site { padding-inline: 16px; }
  #today { display: none; }
  .mood-button { padding-inline: 10px; }
  .weekly-panel { grid-template-columns: auto 1fr; }
  .weekly-button { grid-column: 2; justify-self: start; }
}

@media (max-width: 760px) and (max-height: 740px) {
  .masthead { min-height: 64px; }
  .hero { padding-top: 16px; }
  .mode-panel { padding-top: 12px; }
  .mode-options { padding: 3px; }
  .mode-button { min-height: 40px; padding-block: 8px; }
  .stage { min-height: 216px; margin-top: 6px; }
  .deck { width: 130px; height: 187px; --spread: 17px; }
  .orbit { width: min(87%, 228px); }
  .orbit-inner { width: min(76%, 200px); }
  .mood-hint { margin-top: 8px; }
}

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