/* Ditt Tarot: the interactive parts. Today's card, the reading (question, shuffle, fan,
   spread, flip, written reading), the journal and the quiz. Tokens come from base.css. */

[hidden] { display: none !important; }

/* ---------- A table of our own when the page did not put us on one ---------- */
.is-own-table { border-radius: 14px; padding: clamp(20px, 4vw, 44px) clamp(14px, 3vw, 36px); }

/* ---------- Turning cards: .flip > .flip-inner > .flip-back + .flip-front ---------- */
.flip {
  position: relative; display: block; padding: 0; border: 0; background: none; color: inherit;
  aspect-ratio: var(--card-ratio); perspective: 1400px; cursor: pointer; border-radius: var(--card-radius);
}
.flip:disabled { cursor: default; }
.flip-inner { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform 0.65s cubic-bezier(0.3, 0.7, 0.2, 1); }
.flip.is-flipped .flip-inner { transform: rotateY(180deg); }
.flip.no-anim .flip-inner { transition: none; }
.flip-face {
  position: absolute; inset: 0; overflow: hidden; border-radius: var(--card-radius); background: var(--ink);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 14px 28px -14px rgba(20, 4, 10, 0.85);
}
.flip-front { transform: rotateY(180deg); }
.flip-face img { width: 100%; height: 100%; object-fit: cover; }
img.is-reversed { rotate: 180deg; }
.flip:not(:disabled):hover .flip-back { outline: 1px solid var(--brass); outline-offset: 3px; }

/* ---------- Today's card (laid out on the home page by home.css) ---------- */
.daily-stage { display: grid; gap: 28px; justify-items: center; text-align: center; }
.daily-deck { position: relative; width: var(--deck-w, clamp(180px, 24vw, 270px)); }
.daily-deck::before, .daily-deck::after {
  content: ''; position: absolute; inset: 0; border-radius: var(--card-radius);
  background: url('/img/cards/back.webp') center / cover; filter: brightness(0.55);
  transition: opacity 0.5s;
}
.daily-deck::before { rotate: -4deg; translate: -6px 4px; }
.daily-deck::after { rotate: 3deg; translate: 5px 6px; filter: brightness(0.7); }
.daily-deck:has(.is-flipped)::before, .daily-deck:has(.is-flipped)::after { opacity: 0.35; }
.daily-card { width: 100%; z-index: 1; transition: translate 0.25s; }
.daily-card:not(:disabled):hover { translate: 0 -6px; }
.daily-card .flip-face { box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08) inset, 0 28px 50px -22px rgba(10, 2, 5, 0.95); }
.daily-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin: 0; }
.daily-name { font-size: var(--step-3); margin-bottom: 0.2em; outline: none; }
.daily-advice { font-family: var(--display); font-style: italic; font-size: var(--step-1); line-height: 1.4; max-width: 34ch; }
.daily-links { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 24px; }
.daily-streak { font-size: var(--step--1); color: var(--on-table-soft); margin: 20px 0 0; }
.daily-horoscope { margin: 6px 0 0; font-size: var(--step--1); }
.daily-horoscope a { color: var(--brass); text-decoration-color: rgba(210, 168, 90, 0.45); }
.daily-horoscope a:hover { text-decoration-color: currentColor; }
.keywords { color: var(--brass); font-size: var(--step--1); letter-spacing: 0.02em; }

/* ---------- Reading: status line and question ---------- */
.reader-status { font-family: var(--display); font-size: var(--step-1); text-align: center; margin: 0 auto 18px; max-width: 40ch; }
.reader-status:empty { margin: 0; }
#reading-app { margin-bottom: clamp(32px, 5vw, 56px); }
.ads-preview ins.adsbygoogle { text-decoration: none; }
.reader-ask { display: grid; gap: 10px; max-width: 34rem; margin: 0 auto; }
.reader-label { font-family: var(--display); font-size: var(--step-2); line-height: 1.1; }
.reader-hint { color: var(--on-table-soft); font-size: var(--step--1); margin: 0; }
.reader-input {
  font: inherit; color: var(--on-table); background: rgba(20, 4, 10, 0.35);
  border: 1px solid var(--table-rule); border-radius: 8px; padding: 12px 14px; min-height: 48px; margin-bottom: 10px;
}
.reader-input:focus { border-color: var(--brass); outline: none; box-shadow: 0 0 0 2px rgba(210, 168, 90, 0.35); }
.reader-ask .button { justify-self: start; margin-top: 14px; }

/* A switch built on a real checkbox; the knob position and fill carry the state. */
.switch { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; justify-self: start; position: relative; }
.switch-input { position: absolute; opacity: 0; width: 44px; height: 26px; margin: 0; cursor: pointer; }
.switch-track { width: 44px; height: 26px; border-radius: 13px; border: 1px solid var(--table-rule); background: rgba(20, 4, 10, 0.35); position: relative; flex: none; transition: background 0.2s; }
.switch-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--on-table-soft); transition: translate 0.2s, background 0.2s; }
.switch-input:checked + .switch-track { background: var(--brass); border-color: var(--brass); }
.switch-input:checked + .switch-track::after { translate: 18px 0; background: var(--table); }
.switch-input:focus-visible + .switch-track { outline: 2px solid var(--brass); outline-offset: 3px; }

/* ---------- Shuffle: a small pile riffling ---------- */
.pile { position: relative; height: 240px; display: grid; place-items: center; }
.pile img { position: absolute; width: 120px; border-radius: 8px; box-shadow: 0 10px 20px -12px rgba(0, 0, 0, 0.8); animation: riffle 0.75s cubic-bezier(0.4, 0, 0.2, 1) calc(var(--k) * 60ms) 2 alternate both; }
@keyframes riffle {
  from { translate: 0 0; rotate: 0deg; }
  50% { translate: calc((var(--k) - 3) * 26px) -10px; rotate: calc((var(--k) - 3) * 3deg); }
  to { translate: 0 calc(var(--k) * -1px); rotate: 0deg; }
}

/* ---------- The fan of 78 backs ---------- */
.fan-wrap { container-type: inline-size; margin-top: 18px; transition: opacity 0.35s, translate 0.35s; }
.fan-wrap.is-closed { opacity: 0; translate: 0 24px; }
.fan {
  --fw: clamp(58px, 8cqi, 92px);
  --d: calc(var(--fw) * 0.62);
  --spread: 74deg;
  --r: calc((100cqi - var(--fw) * 2) / 1.2);
  position: relative; height: calc(var(--fw) * 1.5 + var(--d) + var(--r) * 0.21 + 26px);
}
/* Two rows around one pivot: the front row sits lower and half a step to the side. */
.fan-card {
  --angle: calc(((var(--j) + var(--row) * 0.5) / 38.5 - 0.5) * var(--spread));
  position: absolute; left: calc(50% - var(--fw) / 2); top: calc(26px + var(--row) * var(--d)); width: var(--fw); aspect-ratio: var(--card-ratio);
  padding: 0; border: 0; background: none; border-radius: 6px; cursor: pointer;
  transform-origin: 50% calc(var(--r) - var(--row) * var(--d)); transform: rotate(var(--angle)) translateY(var(--lift, 0px));
  transition: transform 0.22s ease-out;
}
.fan-card img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; box-shadow: -5px 1px 7px -3px rgba(20, 4, 10, 0.8); }
.fan-card:hover, .fan-card:focus-visible { --lift: -22px; }
.fan-card.is-taken { visibility: hidden; }
.fan.is-gathered { --spread: 0deg; }
.fan.is-opening .fan-card { transition: transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) calc((var(--j) + var(--row) * 39) * 6ms); }
.fan.is-done .fan-card { pointer-events: none; }
.fan-hint { display: none; }

@media (max-width: 640px) {
  .fan { display: flex; height: auto; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; padding: 26px 24px 14px; margin: 0 calc(-1 * clamp(14px, 3vw, 36px)); scrollbar-width: thin; }
  .fan-card { position: relative; left: auto; top: auto; flex: 0 0 var(--fw); --fw: 66px; transform: translateY(var(--lift, 0px)); scroll-snap-align: center; }
  .fan-card + .fan-card { margin-left: -38px; }
  .fan-card:hover, .fan-card:focus-visible { --lift: -16px; }
  .fan.is-opening .fan-card { transition: transform 0.22s ease-out; }
  .fan-hint { display: block; text-align: center; font-size: var(--step--1); color: var(--on-table-soft); margin: 4px 0 0; }
}

/* ---------- The spread on the table ---------- */
.spread-wrap { container-type: inline-size; }
.spread-grid {
  --gap: clamp(10px, 3cqi, 28px);
  --cols: 1;
  display: grid; justify-content: center; gap: 18px var(--gap);
  grid-template-columns: repeat(var(--cols), var(--cw));
}
.spread-grid[data-spread='one-card'], .spread-grid[data-spread='yes-no'] { --cw: min(210px, 56cqi); grid-template-areas: 'p1'; }
.spread-grid[data-spread='three-card'] { --cols: 3; --cw: min(180px, calc((100cqi - 2 * var(--gap)) / 3)); grid-template-areas: 'p1 p2 p3'; }
/* Love: you, what connects, the other; below, what stands in the way and where it is heading. */
.spread-grid[data-spread='love'] {
  --cols: 6; --cw: min(160px, calc((100cqi - 2 * var(--gap)) / 3));
  grid-template-columns: repeat(6, calc((var(--cw) - var(--gap)) / 2));
  grid-template-areas: 'p1 p1 p3 p3 p2 p2' '. p4 p4 p5 p5 .';
}
/* Decision: where you stand, then path A above path B, each followed by its outcome. */
.spread-grid[data-spread='decision'] {
  --cols: 3; --cw: min(160px, calc((100cqi - 2 * var(--gap)) / 3));
  grid-template-areas: 'p1 p2 p4' 'p1 p3 p5';
}
.spread-grid[data-spread='decision'] .slot:first-child { align-self: center; }
/* Celtic cross: the cross on the left (2 lies across 1), the staff of four on the right. */
.spread-grid[data-spread='celtic-cross'] {
  --cw: min(104px, calc(100cqi / 5.8));
  --gap: calc(var(--cw) * 0.36);
  grid-template-columns: repeat(3, var(--cw)) calc(var(--cw) * 0.2) var(--cw);
  grid-template-rows: repeat(8, calc(var(--cw) * 0.75));
  row-gap: calc(var(--cw) * 0.1);
  grid-template-areas: '. . . . p10' '. p5 . . p10' '. p5 . . p9' 'p4 p1 p6 . p9' 'p4 p1 p6 . p8' '. p3 . . p8' '. p3 . . p7' '. . . . p7';
}
.spread-grid[data-spread='celtic-cross'] .slot:nth-child(2) { grid-area: p1 !important; z-index: 1; }
.spread-grid[data-spread='celtic-cross'] .slot:nth-child(2) > :first-child { rotate: 90deg; }

.slot { display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: 0; }
.slot-card, .slot-empty { width: var(--cw); flex: none; }
.slot-empty {
  aspect-ratio: var(--card-ratio); border-radius: var(--card-radius); border: 1px dashed var(--table-rule);
  display: grid; place-items: center; padding: 8px; text-align: center;
  font-family: var(--display); font-size: clamp(0.85rem, 2.4cqi, 1.05rem); line-height: 1.15; color: var(--on-table-soft);
}
.slot-caption { text-align: center; width: calc(var(--cw) + var(--gap)); font-size: var(--step--1); line-height: 1.35; }
/* The caption repeats the position only once a card lies there; the empty place shows it. */
.slot:has(.slot-empty) .slot-caption { visibility: hidden; }
.slot-caption p, .spread-legend p { margin: 0; }
.slot-position { color: var(--on-table-soft); }
.slot-name { font-family: var(--display); font-size: 1.12rem; line-height: 1.15; margin-top: 2px !important; color: var(--on-table); }
.slot-keywords { color: var(--brass); font-size: 0.8rem; margin-top: 3px !important; }
.slot-number {
  position: absolute; top: 6px; left: 6px; z-index: 2; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px;
  background: var(--table); color: var(--brass); border: 1px solid var(--brass); font: 600 0.75rem/20px var(--body); text-align: center;
}

.spread-wrap.is-compact { display: grid; gap: 28px; justify-content: center; }
.spread-legend { margin: 0; padding: 0 0 0 1.6em; display: grid; gap: 10px; align-content: start; font-size: var(--step--1); line-height: 1.35; }
.spread-legend li::marker { color: var(--brass); font-weight: 600; }
@container (min-width: 760px) {
  .spread-wrap.is-compact { grid-template-columns: auto minmax(13rem, 18rem); align-items: center; }
  .spread-wrap.is-compact .spread-grid { --cw: min(104px, calc((100cqi - 21rem) / 5.8)); }
}
@container (max-width: 759px) {
  .spread-legend { grid-template-columns: 1fr 1fr; grid-template-rows: repeat(5, auto); grid-auto-flow: column; column-gap: 28px; }
}

/* ---------- After the cards: controls, yes/no answer, share ---------- */
.reader-controls { display: flex; flex-direction: column; align-items: center; gap: 22px; margin-top: 28px; text-align: center; }
.reader-controls:not(:has(> :not([hidden]))) { display: none; }
.yesno-answer { font-family: var(--display); font-size: var(--step-4); line-height: 1; color: var(--brass); margin: 0 0 8px; }
.yesno-text { max-width: 44ch; margin: 0 auto; font-size: var(--step-1); line-height: 1.45; }
.reader-after { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px 16px; }
.reader-saved { order: 3; flex-basis: 100%; margin: 0; font-size: var(--step--1); color: var(--on-table-soft); }
.share { display: contents; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: var(--step--1); cursor: pointer; }
.check input { position: static; opacity: 1; width: 18px; height: 18px; accent-color: var(--brass); }
.share-receipt { order: 2; flex-basis: 100%; margin: 0; font-size: var(--step--1); }
.share-receipt:empty { display: none; }
.share-url { font: inherit; width: min(100%, 28rem); padding: 6px 8px; border-radius: 6px; border: 1px solid var(--table-rule); background: rgba(20, 4, 10, 0.35); color: inherit; }

/* ---------- The written reading, on paper below the table ---------- */
.reader-reading:not(:empty) { margin-top: clamp(32px, 5vw, 56px); }
.reading { max-width: var(--measure); }
.reading-title { outline: none; }
.reading-question { margin: 0 0 20px; font-family: var(--display); font-style: italic; font-size: var(--step-2); line-height: 1.2; }
.reading-question p { quotes: '\201C' '\201D'; }
[data-lang='sv'] .reading-question p { quotes: '\201D' '\201D'; }
.reading-question p::before { content: open-quote; }
.reading-question p::after { content: close-quote; }
.reading-question.is-empty { font-size: var(--step-1); }
.reading-status { color: var(--ink-soft); font-size: var(--step--1); }
.reading-status:empty { display: none; }
.reading[aria-busy='true'] .reading-status::before { content: ''; display: inline-block; width: 0.7em; height: 0.7em; margin-right: 0.6em; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.9s linear infinite; vertical-align: -0.05em; }
@keyframes spin { to { rotate: 360deg; } }
.reading-cards { display: grid; gap: 32px; margin-top: 28px; }
.reading-card { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 20px; align-items: start; }
.reading-thumb { width: 76px; border-radius: 6px; }
.reading-card h3 { margin-bottom: 0.1em; }
.reading-name { font-weight: 600; margin-bottom: 0.6em; }
.reading-summary { margin-top: 36px; padding: 22px 26px 8px; background: var(--paper-2); border-radius: 12px; }
.reading-actions { margin-top: 16px; }
/* When the page puts the whole reading on the table, keep it centred and readable there. */
.table .reading { margin-inline: auto; }
.table .reading-status { color: var(--on-table-soft); }
.table .reading-summary { background: rgba(20, 4, 10, 0.32); }
.table .reading-name a { text-decoration-color: var(--table-rule); }
.reading-actions:empty { display: none; }
@media (max-width: 480px) { .reading-card { grid-template-columns: 52px minmax(0, 1fr); gap: 14px; } .reading-thumb { width: 52px; } }

/* ---------- Shared on paper ---------- */
.link-button { background: none; border: 0; padding: 10px 4px; font: inherit; font-size: var(--step--1); color: var(--ink-soft); text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 0.2em; cursor: pointer; }
.link-button:hover { color: var(--ink); text-decoration-color: currentColor; }
.button.danger { background: #8a1f2d; border-color: #8a1f2d; color: #fff; }
.button.danger:hover { background: #a3283a; }
.confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 14px 16px; background: var(--paper-2); border-radius: 10px; }
.confirm p { margin: 0 8px 0 0; flex-basis: 100%; font-weight: 600; }

/* ---------- Journal ---------- */
.journal { max-width: 860px; }
.journal-empty { padding: 28px 0; }
.journal-empty p { font-size: var(--step-1); max-width: 40ch; }
.journal-stats { display: flex; flex-wrap: wrap; gap: 12px 40px; margin: 0 0 36px; padding: 18px 0; border-block: 1px solid var(--rule); }
.journal-stats div { display: flex; flex-direction: column-reverse; }
.journal-stats dt { font-size: var(--step--1); color: var(--ink-soft); }
.journal-stats dd { margin: 0; font-family: var(--display); font-size: var(--step-2); line-height: 1.1; }
.journal-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.journal-list > li + li { border-top: 1px solid var(--rule); }
.entry { padding: 26px 0; }
.entry-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; }
.entry-title { margin: 0; outline: none; }
.entry-head time { font-size: var(--step--1); color: var(--ink-soft); }
.entry-question { font-family: var(--display); font-style: italic; font-size: var(--step-1); margin: 6px 0 14px; }
.entry-thumbs { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.entry-thumbs img { width: 52px; border-radius: 5px; }
.entry-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.entry-panel { margin-top: 22px; }
.entry-cards { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); }
.entry-card h3 { margin-bottom: 0.1em; }
.entry-card p { font-size: var(--step--1); }
.entry-note-field { display: grid; gap: 8px; margin-top: 24px; max-width: 40rem; }
.entry-note-field label { font-weight: 600; }
.entry-note { font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--rule); border-radius: 8px; padding: 10px 12px; resize: vertical; }
.entry-note:focus { outline: 2px solid var(--brass-ink); outline-offset: 1px; }
.entry-note-actions { display: flex; align-items: center; gap: 14px; }
.entry-saved { font-size: var(--step--1); color: var(--ink-soft); }
.journal-clear { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--rule); }

/* ---------- Quiz ---------- */
.quiz { max-width: 900px; }
.quiz-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; margin-bottom: 28px; }
.quiz-modes { display: inline-flex; padding: 4px; border-radius: 999px; background: var(--paper-2); }
.quiz-mode { font: 600 var(--step--1) / 1 var(--body); color: var(--ink-soft); background: none; border: 0; border-radius: 999px; padding: 11px 18px; min-height: 40px; cursor: pointer; }
.quiz-mode[aria-pressed='true'] { background: var(--ink); color: var(--paper); }
.quiz-meta { margin: 0; font-size: var(--step--1); color: var(--ink-soft); }
.quiz-progress { font-size: var(--step--1); color: var(--ink-soft); margin-bottom: 12px; }
.quiz-question { display: grid; gap: clamp(20px, 4vw, 48px); grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 680px) { .quiz-question { grid-template-columns: minmax(180px, 280px) minmax(0, 1fr); } }
.quiz-card { width: min(280px, 50vw); border-radius: var(--card-radius); box-shadow: 0 14px 28px -16px rgba(27, 42, 74, 0.6); justify-self: center; }
.quiz-card.is-keywords { width: min(200px, 46vw); }
.quiz-prompt { outline: none; }
.quiz-options { display: grid; gap: 10px; margin: 18px 0; }
.quiz-option {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: left;
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--rule); border-radius: 10px;
  padding: 13px 16px; min-height: 52px; cursor: pointer;
}
.quiz-option:not(:disabled):hover { border-color: var(--ink); }
.quiz-option:disabled { cursor: default; color: var(--ink-soft); }
.quiz-option.is-right { background: #e3efe6; border-color: #2f6b45; color: #1d4a2e; }
.quiz-option.is-wrong { background: #f6e1e3; border-color: #8a1f2d; color: #6e1622; }
.quiz-mark { flex: none; font-size: var(--step--1); font-weight: 600; }
.quiz-feedback:empty { display: none; }
.quiz-verdict { font-family: var(--display); font-size: var(--step-1); margin-bottom: 0.3em; }
.quiz-feedback p { max-width: 52ch; }
.quiz-result { padding: 12px 0; }
.quiz-final { font-family: var(--display); font-size: var(--step-3); line-height: 1.1; }
