/* ============================================================
   style.css — The Witching Hour v8
   Card constrained by both height AND width so it never clips.
   Text size tracks card width, not viewport width.
   ============================================================ */

:root {
  --gold:        #d4a830;
  --gold-bright: #f0c840;
  --blue:        #5a8fd0;
  --slate:       #8888bb;
  --cream:       #f0e6c8;
  --cream-80:    rgba(240,230,200,0.80);
  --cream-50:    rgba(240,230,200,0.50);
  --cream-25:    rgba(240,230,200,0.25);
  --bg:          #0d0810;
  --surface:     rgba(255,255,255,0.06);
  --border:      rgba(240,230,200,0.18);
  --gap:         clamp(5px, 1.5vh, 10px);

  /* Card max dimensions — 64:89 ratio, never larger than this */
  --card-max-w: 300px;
  --card-max-h: 417px; /* 300 * 89/64 = 417px */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--cream);
  font-family: 'Lato', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ─────────────────────────────────────────────── */
.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(8px, 2vh, 18px) max(1rem, 4vw) clamp(8px, 2vh, 14px);
  gap: var(--gap);
}

.app > * {
  width: 100%;
  max-width: min(var(--card-max-w), 92vw);
  flex-shrink: 0;
}

/* ── Header ─────────────────────────────────────────────────── */
.app-title {
  font-family: 'Cinzel', Georgia, serif;
  font-size: clamp(11px, 2.6vw, 15px);
  font-weight: 500;
  color: var(--gold-bright);
  letter-spacing: 1px;
  text-align: center;
  text-transform: uppercase;
}

.app-sub {
  font-size: clamp(13px, 3.4vw, 16px);
  font-weight: 400;
  color: var(--cream-80);
  text-align: center;
  font-style: italic;
}

.sheet-status {
  font-size: 11px;
  color: var(--cream-50);
  text-align: center;
  min-height: 13px;
  line-height: 1;
  transition: opacity 0.6s;
}

/* ── Tier buttons ───────────────────────────────────────────── */
.tier-selector {
  display: flex;
  gap: 5px;
}

.tier-btn {
  flex: 1;
  padding: clamp(6px, 1.1vh, 10px) 3px;
  border-radius: 99px;
  border: 1.5px solid var(--cream-25);
  background: transparent;
  color: var(--cream-50);
  font-family: 'Lato', sans-serif;
  font-weight: 400;
  font-size: clamp(10px, 2.5vw, 12px);
  line-height: 1.3;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.tier-btn:hover { border-color: var(--cream-50); color: var(--cream-80); }
.tier-btn.active.t1 { border-color: var(--gold);  background: rgba(212,168,48,0.15); color: var(--gold-bright); font-weight: 500; }
.tier-btn.active.t2 { border-color: var(--blue);  background: rgba(90,143,208,0.15); color: #a8d0f8;            font-weight: 500; }
.tier-btn.active.t3 { border-color: var(--slate); background: rgba(136,136,187,0.15);color: #c8c8e8;            font-weight: 500; }

/* ── Card stage ─────────────────────────────────────────────── */
.stage {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: min(var(--card-max-w), 92vw);
}

/*
  The shuffle-area uses BOTH max-width and max-height.
  Whichever dimension is the binding constraint wins.

  On a tall phone (Portrait Pro Max):
    - Stage height might be 480px → capped at --card-max-h (417px)
    - Width = 417 * 64/89 = 300px ✓

  On a short phone (older SE in portrait):
    - Stage height might be 280px → height: 100% = 280px
    - Width = 280 * 64/89 = 201px ✓ (well under max-width)

  object-fit: cover on the image fills whatever size the box is.
*/
.shuffle-area {
  height: 100%;
  max-height: var(--card-max-h);
  width: auto;
  aspect-ratio: 64 / 89;
  max-width: min(var(--card-max-w), 92vw);
  position: relative;
}

.shuffle-card,
.reveal-card,
.idle-card {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  overflow: hidden;
}

.shuffle-card {
  transform-origin: bottom center;
  will-change: transform, opacity;
  box-shadow: 0 8px 32px rgba(0,0,0,0.75);
}

.shuffle-card img,
.idle-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 14px;
  display: block;
}

.reveal-card {
  opacity: 0;
  will-change: transform, opacity;
  box-shadow: 0 8px 40px rgba(0,0,0,0.85);
  pointer-events: none;
}

.reveal-card .front-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 14px;
}

.idle-card {
  box-shadow: 0 6px 28px rgba(0,0,0,0.65);
  transition: opacity 0.3s;
}

/* ── Question text ──────────────────────────────────────────────
   Font size tracks the card's actual rendered width.
   Card is min(300px, 92vw).
   On a 430px wide Pro Max: card = 300px, so vw-based sizing
   would over-scale. We use container queries via cqi to
   measure the card itself, with a vw fallback for older Safari.

   Practical approach: use a tighter clamp.
   At 300px card width, we want ~15px text.
   300px card / 430px viewport = 70% of vw.
   So 5vw * 0.70 = 3.5vw ≈ 15px. Use 3.5vw as the fluid value,
   capped firmly at 15px max so it never grows beyond that.
──────────────────────────────────────────────────────────────── */
.reveal-card .question-overlay {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 38%;
  bottom: 10%;
  width: 70%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;	
}

.reveal-card .question-text {
  font-family: 'Lato', Arial, sans-serif;
  font-weight: 500;
  /* Min 12px on tiny screens, fluid 3.5vw in mid range,
     hard cap at 15px so it never outgrows the card */
  font-size: clamp(12px, 3.8vw, 15px);
  line-height: 1.2;
  color: #ffffff;
  text-align: center;
  text-shadow:
    0 1px 4px rgba(0,0,0,0.9),
    0 2px 16px rgba(0,0,0,0.6);
}

/* ── Draw button ────────────────────────────────────────────── */
.draw-btn {
  width: 100%;
  padding: clamp(11px, 1.6vh, 16px);
  border-radius: 10px;
  font-family: 'Cinzel', Georgia, serif;
  font-size: clamp(12px, 3vw, 14px);
  font-weight: 500;
  letter-spacing: 2px;
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid var(--gold);
  background: rgba(212,168,48,0.1);
  color: var(--gold-bright);
}
.draw-btn:not(:disabled):hover { background: rgba(212,168,48,0.22); color: #fff; }
.draw-btn:disabled { opacity: 0.35; cursor: default; }
.draw-btn.t2 { border-color: var(--blue);  background: rgba(90,143,208,0.1);  color: #a8d0f8; }
.draw-btn.t2:not(:disabled):hover { background: rgba(90,143,208,0.22);  color: #fff; }
.draw-btn.t3 { border-color: var(--slate); background: rgba(136,136,187,0.1); color: #c8c8e8; }
.draw-btn.t3:not(:disabled):hover { background: rgba(136,136,187,0.22); color: #fff; }

/* ── Timer ──────────────────────────────────────────────────── */
.timer-section {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: clamp(9px, 1.4vh, 15px) clamp(12px, 3vw, 18px);
}

.timer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.timer-display {
  font-family: 'Cinzel', Georgia, serif;
  font-size: clamp(22px, 6vw, 32px);
  font-weight: 500;
  color: var(--cream);
  letter-spacing: 3px;
  transition: color 0.4s;
  line-height: 1;
}
.timer-display.warn  { color: #f0a830; }
.timer-display.alert { color: #f06050; }

.timer-controls { display: flex; gap: 6px; flex-shrink: 0; }

.timer-btn {
  padding: clamp(7px, 1vh, 10px) clamp(10px, 2.5vw, 15px);
  border-radius: 8px;
  border: 1.5px solid var(--cream-25);
  background: transparent;
  color: var(--cream-80);
  font-family: 'Lato', sans-serif;
  font-weight: 500;
  font-size: clamp(11px, 2.8vw, 13px);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.timer-btn:hover { border-color: var(--cream-80); color: var(--cream); }
.timer-btn.reset-timer-btn { color: var(--cream-50); border-color: rgba(240,230,200,0.15); }
.timer-btn.reset-timer-btn:hover { border-color: var(--cream-25); color: var(--cream-80); }

.timer-message {
  font-size: clamp(11px, 2.8vw, 13px);
  font-weight: 400;
  font-style: italic;
  color: var(--gold-bright);
  margin-top: clamp(5px, 0.9vh, 9px);
  text-align: center;
  min-height: 16px;
  opacity: 0;
  transition: opacity 0.5s;
  line-height: 1.4;
}

/* ── Suggest button ──────────────────────────────────────────── */
.suggest-btn {
  width: 100%;
  max-width: var(--card-max-w);
  padding: clamp(10px, 1.4vh, 13px);
  border-radius: 8px;
  border: 1px solid rgba(240,230,200,0.22);
  background: transparent;
  color: rgba(240,230,200,0.65);
  font-family: 'Cinzel', Georgia, serif;
  font-size: clamp(10px, 2.6vw, 12px);
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s;
}
.suggest-btn:hover {
  border-color: rgba(240,230,200,0.45);
  color: var(--cream);
}

/* ── Meta row ───────────────────────────────────────────────── */
.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}
.counter {
  font-size: clamp(11px, 2.7vw, 13px);
  font-weight: 400;
  color: var(--cream-50);
}
.meta-link {
  font-size: clamp(11px, 2.7vw, 13px);
  font-family: 'Lato', sans-serif;
  font-weight: 400;
  background: none;
  border: none;
  color: var(--cream-50);
  cursor: pointer;
  padding: 0;
  transition: color 0.2s;
}
.meta-link:hover { color: var(--cream); }

/* ── Modal ──────────────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}
.modal {
  background: #1e1428;
  border: 1.5px solid rgba(240,230,200,0.2);
  border-radius: 14px;
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
  margin: auto;
}
.modal-title {
  font-family: 'Cinzel', Georgia, serif;
  font-size: 15px;
  font-weight: 500;
  color: var(--gold-bright);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}
.modal-sub {
  font-size: 13px;
  font-weight: 400;
  color: var(--cream-80);
  margin-bottom: 1.1rem;
  line-height: 1.6;
}
.modal-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--cream-50);
  letter-spacing: 1px;
  text-transform: uppercase;
  display: block;
  margin-bottom: 7px;
}
.modal-textarea {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(240,230,200,0.2);
  border-radius: 8px;
  color: var(--cream);
  font-family: 'Lato', sans-serif;
  font-weight: 400;
  font-size: 14px;
  line-height: 1.6;
  padding: 11px 13px;
  resize: vertical;
  min-height: 80px;
  margin-bottom: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}
.modal-textarea:focus { border-color: var(--gold); }
.modal-textarea::placeholder { color: rgba(240,230,200,0.25); }
.modal-select {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(240,230,200,0.2);
  border-radius: 8px;
  color: var(--cream);
  font-family: 'Lato', sans-serif;
  font-weight: 400;
  font-size: 13px;
  padding: 10px 13px;
  margin-bottom: 1.1rem;
  outline: none;
  cursor: pointer;
  appearance: none;
}
.modal-select option { background: #1e1428; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }
.modal-btn {
  padding: 14px;
  border-radius: 8px;
  font-family: 'Cinzel', Georgia, serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 1.5px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--cream-80);
  width: 100%;
  text-align: center;
}
.modal-btn:hover { border-color: var(--cream-50); color: var(--cream); }
.modal-btn.primary { background: rgba(212,168,48,0.15); color: var(--gold-bright); border-color: var(--gold); }
.modal-btn.primary:hover { background: rgba(212,168,48,0.28); }
.modal-btn.primary.full { padding: 16px; font-size: 13px; letter-spacing: 2px; }
.modal-btn.cancel {
  border: none;
  background: none;
  color: var(--cream-50);
  font-size: 11px;
  padding: 4px;
  letter-spacing: 1px;
}
.modal-btn.cancel:hover { color: var(--cream-80); background: none; border: none; }
.modal-btn:disabled { opacity: 0.35; cursor: default; }
.submit-status { font-size: 13px; font-weight: 400; min-height: 18px; margin-top: 11px; line-height: 1.5; }
.submit-status.success { color: #80d890; }
.submit-status.error   { color: #e08070; }
#preview-offer {
  display: none;
  margin-top: 12px;
}
#preview-offer button {
  width: 100%;
  padding: 14px;
  border-radius: 8px;
  font-family: 'Cinzel', Georgia, serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 1.5px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1.5px solid var(--cream-25);
  background: transparent;
  color: var(--cream-80);
  text-decoration: none;
}
#preview-offer button:hover {
  border-color: var(--cream-50);
  color: var(--cream);
}

/* ── Animations ─────────────────────────────────────────────── */
@keyframes fanOut {
  0%   { transform: rotate(0deg) translateY(0);             opacity: 1; }
  30%  { transform: rotate(var(--fan-r)) translateY(-18px); opacity: 1; }
  70%  { transform: rotate(var(--fan-r)) translateY(-18px); opacity: 1; }
  100% { transform: rotate(0deg) translateY(0);             opacity: 0; }
}
@keyframes flipIn {
  0%   { opacity: 0; transform: perspective(600px) rotateY(90deg) scale(0.95); }
  40%  { opacity: 1; transform: perspective(600px) rotateY(0deg)  scale(1.03); }
  100% { opacity: 1; transform: perspective(600px) rotateY(0deg)  scale(1);    }
}
