@import url('https://fonts.googleapis.com/css2?family=Cinzel+Decorative:wght@700&family=Cinzel:wght@500;700&family=EB+Garamond:ital,wght@0,400;0,600;1,400&display=swap');

:root {
  --stone-dark: #0f0a1a;
  --stone-line: #3a3350;
  --gold: #cda355;
  --gold-light: #f0d18c;
  --parchment: #e8dcbe;
  --parchment-ink: #2b2013;
  --violet-deep: #1c1230;
  --violet-mid: #2c1d47;

  --fire-glow: #ff6a3d;
  --water-glow: #4fc3f7;
  --beast-glow: #e0b83f;
  --plant-glow: #6bbf59;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  color: var(--parchment);
  font-family: 'EB Garamond', serif;
  overflow: hidden;
  background-image:
    linear-gradient(180deg, rgba(10,7,18,0.5), rgba(8,6,14,0.65)),
    url('../assets/ui/background.webp');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}


h1, h2, h3, .heading {
  font-family: 'Cinzel', serif;
  letter-spacing: 0.03em;
  margin: 0;
}

button {
  font-family: 'Cinzel', serif;
  cursor: pointer;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ---------- Score (floating, no header bar) ---------- */
.favor {
  position: absolute;
  top: 8px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 5;
}

.favor-tally {
  width: 28px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image: url('../assets/ui/circle-small.webp');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.favor-tally .val {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  color: var(--gold-light);
  font-size: 0.85rem;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* ---------- New-game button (top, between the score badges) ---------- */
.btn-newgame {
  /* Vertical centering of the label is done with an absolutely-positioned
     span (top/left 50% + translate), not line-height or flex — both of
     those looked centered in headless Chrome but rendered the text
     noticeably high on real mobile browsers (buttons get special
     baseline/line-height handling in some engines, e.g. Samsung
     Internet). Absolute-centering a plain span sidesteps that entirely. */
  position: relative;
  display: block;
  width: fit-content;
  min-width: 220px;
  height: 72px;
  padding: 0 56px;
  margin: 0;
  background-color: transparent;
  background-image: url('../assets/ui/pill-purple.webp');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  border: none;
  appearance: none;
  cursor: pointer;
}
.btn-newgame span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--gold-light);
  font-family: 'Cinzel', serif;
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}
.btn-newgame:active { filter: brightness(0.9); }

/* ---------- Board layout ---------- */
/* Visual hierarchy, top to bottom: a compact, muted opponent strip (info
   only, never needs interaction) — the altar, the scrollable middle where
   tricks are actually decided — then the player's own board, pinned full-
   size and full-color at the bottom since it's what you touch every turn.
   Only the altar area (.scroll-region) scrolls; the opponent strip and the
   player's board never shrink and are never clipped, so a full turn fits
   on one screen without scrolling on most devices. */
.board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 48px 10px 6px;
  gap: 4px;
  overflow-y: auto;
  overflow-x: hidden;
}

.scroll-region {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding-bottom: 2px;
}

.player-zone {
  border: 1px solid var(--stone-line);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(0,0,0,0.15));
  padding: 5px 5px 3px;
}

.player-zone--pinned {
  flex-shrink: 0;
  border: none;
}

/* The opponent strip is deliberately the opposite of the player board:
   small, borderless, desaturated — a glance, not a focus. */
.opponent-zone {
  flex-shrink: 0;
  padding: 4px 8px 2px;
  filter: saturate(0.5) brightness(0.78);
  opacity: 0.92;
}

/* ---------- Table (pairs of tokens) ---------- */
.table-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  justify-items: center;
  margin-bottom: 4px;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

/* Your own table: bigger tokens than the grid cells strictly need, so
   neighbors overlap slightly instead of sitting in a rigid boxed grid. */
#player-table .diamond-token {
  height: 135%;
}
#player-table .table-slot { z-index: 1; }
#player-table .table-slot:hover { z-index: 2; }
/* Pull the second row up into the first so the two rows overlap instead
   of stacking full-height — this is the main lever on the board's total
   vertical footprint. */
#player-table .table-slot:nth-child(n+6) { margin-top: -26px; }

/* Opponent's table: same 10 slots, drawn small — it's a glance, not a
   board you play from. */
.table-grid--mini {
  max-width: 240px;
  margin: 0 auto 3px;
  gap: 2px;
}
.table-grid--mini .rank-medallion { width: 15px; height: 15px; font-size: 0.42rem; top: 6px; border-width: 1px; }

.table-slot {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* A second tile still waits face-down under this one — a dim diamond
   peeking out diagonally behind, without revealing what it actually is. */
.diamond-token-peek {
  position: absolute;
  top: 50%;
  left: 50%;
  height: 80%;
  width: auto;
  aspect-ratio: 485 / 624;
  background-image: var(--diamond-bg);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  transform: translate(calc(-50% + 7px), calc(-50% + 7px));
  opacity: 0.5;
  filter: brightness(0.6) saturate(0.7);
  pointer-events: none;
}
.diamond-token-peek.fam-fire  { --diamond-bg: url('../assets/ui/diamond-fire.webp'); }
.diamond-token-peek.fam-water { --diamond-bg: url('../assets/ui/diamond-water.webp'); }
.diamond-token-peek.fam-beast { --diamond-bg: url('../assets/ui/diamond-beast.webp'); }
.diamond-token-peek.fam-plant { --diamond-bg: url('../assets/ui/diamond-plant.webp'); }
#player-table .diamond-token-peek { height: 118%; }

.diamond-token {
  height: 92%;
  width: auto;
  aspect-ratio: 485 / 624;
  position: relative;
  background-image: var(--diamond-bg);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  filter: drop-shadow(0 0 calc(4px + 10px * var(--i, 0.3)) var(--fam-glow, transparent));
  transition: transform 0.15s ease;
}
.diamond-token.fam-fire  { --diamond-bg: url('../assets/ui/diamond-fire.webp'); }
.diamond-token.fam-water { --diamond-bg: url('../assets/ui/diamond-water.webp'); }
.diamond-token.fam-beast { --diamond-bg: url('../assets/ui/diamond-beast.webp'); }
.diamond-token.fam-plant { --diamond-bg: url('../assets/ui/diamond-plant.webp'); }

.table-slot.playable .diamond-token {
  cursor: pointer;
  filter: drop-shadow(0 0 10px var(--fam-glow, #fff));
}
.table-slot.playable .diamond-token:hover { transform: scale(1.08); }
.table-slot.disabled .diamond-token { opacity: 0.45; filter: grayscale(0.55); }
.table-slot.empty { visibility: hidden; }

.token-inner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rank-medallion {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--parchment), #b3a374);
  border: 1.5px solid var(--gold);
  color: var(--parchment-ink);
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

.monster-img {
  width: 56%;
  height: 56%;
  object-fit: contain;
  filter: drop-shadow(0 0 6px var(--fam-glow, transparent));
  pointer-events: none;
  user-select: none;
}

/* ---------- Hand ---------- */
.hand-row {
  display: flex;
  gap: 6px;
  justify-content: space-between;
  flex-wrap: nowrap;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  min-height: 120px;
}

.hand-card {
  width: 78px;
  height: 117px;
  min-width: 0;
  flex-shrink: 1;
  perspective: 400px;
  position: relative;
}
.hand-card:hover { z-index: 2; }

/* Opponent's hand: a small fanned stack of card backs — the count reads
   from the stack, no card needs to be told apart. */
.hand-row--mini {
  justify-content: center;
  width: auto;
  max-width: none;
  margin: 0;
  gap: 0;
  min-height: 36px;
}
.hand-row--mini .hand-card { flex-shrink: 0; }
.hand-row--mini .hand-card {
  width: 26px;
  height: 36px;
  margin-left: -14px;
}
.hand-row--mini .hand-card:first-child { margin-left: 0; }

.card-frame {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background-image: url('../assets/ui/card-front.webp');
  background-size: cover;
  background-position: center;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  box-shadow: 0 0 calc(3px + 9px * var(--i, 0.3)) var(--fam-glow, transparent), 0 3px 6px rgba(0,0,0,0.6);
  transition: transform 0.15s ease;
  overflow: hidden;
}

.hand-card.playable .card-frame { cursor: pointer; }
.hand-card.playable .card-frame:hover { transform: translateY(-6px); }
.hand-card.disabled .card-frame { opacity: 0.4; filter: grayscale(0.5); cursor: default; }

.card-frame .rank-medallion { top: 6px; }

.card-frame .monster-art {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 10px;
}
.card-frame .monster-art .monster-img { width: 82%; height: 82%; }

.card-frame .nameplate {
  width: 100%;
  background: var(--parchment);
  color: var(--parchment-ink);
  font-family: 'Cinzel', serif;
  font-size: 0.62rem;
  font-weight: 600;
  text-align: center;
  padding: 3px 2px;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hand-card.back .card-frame {
  background-image: url('../assets/ui/card-back.webp');
  background-size: cover;
  background-position: center;
}

/* ---------- Altar ---------- */
#altar {
  position: relative;
  margin: 4px auto;
  width: 100%;
  max-width: 420px;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-radius: 14px;
  padding: 9px 12px 7px;
  background-color: var(--stone-dark);
  background-image:
    radial-gradient(ellipse at 50% 30%, rgba(255,120,60,0.15), transparent 65%),
    linear-gradient(180deg, rgba(10,7,15,0.35), rgba(10,7,15,0.55)),
    url('../assets/ui/altar.webp');
  background-size: cover, cover, contain;
  background-repeat: no-repeat, no-repeat, no-repeat;
  background-position: center;
  box-shadow: 0 0 30px rgba(255, 90, 40, 0.15), inset 0 0 30px rgba(0,0,0,0.6);
  text-align: center;
}

#altar::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 16px;
  pointer-events: none;
  box-shadow: 0 0 14px 2px rgba(255, 106, 61, 0.22);
  animation: ember-pulse 2.6s ease-in-out infinite;
}

@keyframes ember-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.favorite-banner {
  font-size: 0.7rem;
  color: var(--parchment);
  opacity: 0.85;
  margin-bottom: 6px;
}
.favorite-banner .fam { color: var(--gold-light); font-weight: 600; }

/* ---------- Tug-of-war (trick lead indicator) ---------- */
.tug-of-war {
  max-width: 300px;
  margin: 0 auto 5px;
}

.tug-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tug-label {
  flex: none;
  width: 52px;
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gold);
  opacity: 0.9;
}
.tug-label.left { text-align: right; }
.tug-label.right { text-align: left; }

.tug-track {
  position: relative;
  flex: 1;
  height: 10px;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(255,106,61,0.30), rgba(20,16,12,0.5) 48%, rgba(20,16,12,0.5) 52%, rgba(79,195,247,0.28));
  border: 1px solid var(--gold);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.6);
}

.tug-center-mark {
  position: absolute;
  left: 50%;
  top: -3px;
  bottom: -3px;
  width: 1px;
  background: var(--gold-light);
  opacity: 0.5;
}

.tug-marker {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 28px;
  background-image: url('../assets/ui/tug-marker.webp');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.6));
  transform: translate(-50%, -50%);
  transition: left 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.tug-count {
  text-align: center;
  font-family: 'Cinzel', serif;
  font-size: 0.62rem;
  color: var(--parchment);
  opacity: 0.75;
  margin-top: 4px;
  letter-spacing: 0.04em;
}

.offer-slots {
  display: flex;
  justify-content: center;
  gap: 16px;
  align-items: center;
  min-height: 76px;
}

.offer-slot {
  width: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.offer-slot .offer-card {
  width: 50px;
  height: 74px;
}

.offer-slot .offer-card.empty {
  border: 2px dashed rgba(205, 163, 85, 0.35);
  border-radius: 8px;
  height: 74px;
}

.offer-card.burning .card-frame {
  animation: burn-away 1.05s ease-in forwards;
}

@keyframes burn-away {
  0%   { filter: saturate(1) brightness(1); transform: scale(1); }
  35%  { filter: saturate(2) brightness(1.6) hue-rotate(-20deg); box-shadow: 0 0 26px 10px rgba(255,90,20,0.7); }
  100% { filter: saturate(0.2) brightness(0.4); transform: scale(0.75) translateY(10px); opacity: 0; }
}

.offer-card.winning .card-frame {
  animation: glorify 1.05s ease-out;
}
@keyframes glorify {
  0% { box-shadow: 0 0 6px var(--fam-glow, gold); }
  40% { box-shadow: 0 0 30px 8px var(--gold-light); transform: translateY(-6px) scale(1.06); }
  100% { box-shadow: 0 0 10px var(--fam-glow, gold); transform: translateY(0) scale(1); }
}

.altar-message {
  min-height: 1.4em;
  margin-top: 10px;
  font-family: 'Cinzel', serif;
  font-size: 0.8rem;
  color: var(--gold-light);
}

/* ---------- Controls / modals ---------- */
#controls {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 4px 0 6px;
}

.btn-gold {
  background: linear-gradient(180deg, var(--gold-light), var(--gold));
  border: 1px solid #7a5c26;
  color: #2b2013;
  font-weight: 700;
  padding: 8px 22px;
  border-radius: 8px;
  font-size: 0.95rem;
  box-shadow: 0 3px 0 #7a5c26, 0 4px 10px rgba(0,0,0,0.5);
}
.btn-gold:active { transform: translateY(2px); box-shadow: 0 1px 0 #7a5c26; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 9, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: linear-gradient(180deg, #241d16, #171210);
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 24px 22px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 0 40px rgba(0,0,0,0.7);
}

.modal h2 {
  font-family: 'Cinzel Decorative', serif;
  color: var(--gold-light);
  margin-bottom: 12px;
  font-size: 1.2rem;
}

.modal p { margin: 6px 0; }
.modal .score-line { font-size: 1.05rem; color: var(--parchment); }
.modal .score-line b { color: var(--gold-light); }

.modal .btn-gold { margin-top: 16px; }
