:root {
  --bg-0: #0b0620;
  --bg-1: #150a33;
  --gold: #e8c46a;
  --gold-soft: rgba(232, 196, 106, 0.55);
  --ink: #f3ead8;
  --card-w: 120px;
  --card-h: calc(var(--card-w) * 1.68);
  --radius: 12px;
  font-size: 16px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 700px at 80% -10%, #2a1655 0%, transparent 60%),
    radial-gradient(900px 600px at 10% 110%, #1d1046 0%, transparent 55%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  color: var(--ink);
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

.stars {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-repeat: repeat;
}
.stars--a {
  background-image:
    radial-gradient(1.6px 1.6px at 20% 30%, #fff8 50%, transparent 51%),
    radial-gradient(1.4px 1.4px at 70% 65%, #ffe9b0aa 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 45% 85%, #fff6 50%, transparent 51%),
    radial-gradient(1.8px 1.8px at 85% 15%, #fff9 50%, transparent 51%);
  background-size: 340px 340px;
  animation: twinkle 5s ease-in-out infinite alternate;
}
.stars--b {
  background-image:
    radial-gradient(1.3px 1.3px at 30% 70%, #fff7 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 60% 20%, #e8c46a99 50%, transparent 51%),
    radial-gradient(1.1px 1.1px at 90% 80%, #fff5 50%, transparent 51%);
  background-size: 260px 260px;
  animation: twinkle 7s ease-in-out infinite alternate-reverse;
}
@keyframes twinkle {
  from { opacity: 0.35; }
  to   { opacity: 0.95; }
}

.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
}

.brand {
  font-family: Cinzel, serif;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 1.15rem;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(232, 196, 106, 0.35);
  white-space: nowrap;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.progress {
  font-size: 0.85rem;
  color: var(--gold);
  opacity: 0.9;
  min-width: 64px;
  text-align: right;
}

.btn {
  font-family: inherit;
  font-weight: 600;
  border-radius: 999px;
  padding: 9px 18px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.btn:active { transform: scale(0.96); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: default; box-shadow: none; }

.btn--gold {
  border: 1px solid var(--gold);
  background: linear-gradient(180deg, #f4d98c, #cfa14a);
  color: #241503;
  box-shadow: 0 4px 18px rgba(232, 196, 106, 0.35);
}
.btn--gold:hover { box-shadow: 0 6px 26px rgba(232, 196, 106, 0.55); transform: translateY(-1px); }

.btn--ghost {
  border: 1px solid rgba(243, 234, 216, 0.35);
  background: transparent;
  color: var(--ink);
}
.btn--ghost:hover { background: rgba(243, 234, 216, 0.08); }

.btn--big {
  width: 100%;
  font-size: 1.05rem;
  padding: 13px 22px;
  margin-top: 22px;
}

.play-area {
  position: relative;
  z-index: 2;
  flex: 1;
  overflow: hidden;
}

.hintbar {
  position: relative;
  z-index: 5;
  text-align: center;
  font-size: 0.78rem;
  color: rgba(243, 234, 216, 0.65);
  padding: 10px 14px 14px;
  pointer-events: none;
}

.card {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
  perspective: 900px;
  touch-action: none;
  cursor: grab;
  will-change: left, top;
  animation: dealIn 0.55s cubic-bezier(0.2, 0.9, 0.25, 1.2) both;
}
.card:active { cursor: grabbing; }
.card:focus-visible { outline: 2px dashed var(--gold); outline-offset: 4px; }

.card__pos {
  position: absolute;
  top: -17px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: calc(var(--card-w) * 0.17);
  color: var(--gold);
  background: rgba(11, 6, 32, 0.9);
  border: 1px solid var(--gold-soft);
  padding: 1px 8px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 3;
}
@keyframes dealIn {
  from { opacity: 0; transform: translateY(40px) rotate(4deg) scale(0.8); }
  to   { opacity: 1; }
}

.card__inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.65s cubic-bezier(0.35, 0.9, 0.3, 1);
}
.card.flipped .card__inner { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.55);
}

.face--back {
  background:
    radial-gradient(circle at 50% 42%, rgba(232,196,106,0.16) 0 26%, transparent 27%),
    repeating-linear-gradient(45deg, #1b1040 0 8px, #211349 8px 16px),
    #170c38;
  border: 2px solid #3b2a72;
}
.face--back::after {
  content: "✵";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--card-w) * 0.44);
  color: var(--gold);
  text-shadow: 0 0 16px rgba(232, 196, 106, 0.8);
}
.face--back::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid var(--gold-soft);
  border-radius: calc(var(--radius) - 5px);
}

.face--front {
  transform: rotateY(180deg);
  background:
    radial-gradient(140% 100% at 50% 0%, #2c1a58 0%, #191038 55%, #120a2a 100%);
  border: 2px solid var(--gold-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}
.face--front::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(232, 196, 106, 0.3);
  border-radius: calc(var(--radius) - 4px);
  pointer-events: none;
}

.front-body {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 8px 6px;
  text-align: center;
}
.front-body.is-reversed { transform: rotate(180deg); }

.card__numeral {
  font-family: Cinzel, serif;
  font-size: calc(var(--card-w) * 0.14);
  color: var(--gold);
  letter-spacing: 0.12em;
}
.card__symbol {
  font-size: calc(var(--card-w) * 0.38);
  filter: drop-shadow(0 0 10px rgba(232, 196, 106, 0.45));
}
.card__name {
  font-size: calc(var(--card-w) * 0.1);
  line-height: 1.2;
  font-weight: 600;
  color: var(--ink);
}

.cards--tiny .card__name { display: none; }
.cards--tiny .card__symbol { font-size: calc(var(--card-w) * 0.46); }

.rev-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: #3d1030;
  border: 1px solid #ff7ab8;
  color: #ffd7ec;
  font-size: calc(var(--card-w) * 0.085);
  padding: 2px 7px;
  border-radius: 999px;
  z-index: 2;
}

.hidden { display: none !important; }

.config-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(8, 4, 22, 0.72);
  backdrop-filter: blur(6px);
  padding: 18px;
}

.config-card {
  width: min(420px, 94vw);
  background:
    radial-gradient(140% 120% at 50% 0%, #241350 0%, #150a33 60%, #10082a 100%);
  border: 1px solid var(--gold-soft);
  border-radius: 18px;
  padding: 34px 30px 28px;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6), 0 0 40px rgba(232, 196, 106, 0.12);
  animation: configIn 0.5s ease both;
}
@keyframes configIn {
  from { opacity: 0; transform: translateY(18px) scale(0.97); }
  to   { opacity: 1; }
}

.config-emblem {
  font-size: 2.2rem;
  color: var(--gold);
  text-shadow: 0 0 22px rgba(232, 196, 106, 0.7);
  animation: spinSlow 9s linear infinite;
  display: inline-block;
}
@keyframes spinSlow {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.config-card h2 {
  font-family: Cinzel, serif;
  font-size: 1.7rem;
  color: var(--gold);
  margin-top: 8px;
  letter-spacing: 0.04em;
}

.config-sub {
  margin-top: 8px;
  font-size: 0.88rem;
  color: rgba(243, 234, 216, 0.75);
}

.count-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 26px;
  font-size: 0.95rem;
}
.spread-select {
  width: 100%;
  margin-top: 16px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(243, 234, 216, 0.06);
  color: var(--ink);
  border: 1px solid rgba(243, 234, 216, 0.25);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.spread-select:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.count-row strong {
  font-family: Cinzel, serif;
  font-size: 2rem;
  color: var(--gold);
  text-shadow: 0 0 14px rgba(232, 196, 106, 0.5);
}

input[type="range"] {
  width: 100%;
  margin-top: 12px;
  accent-color: var(--gold);
  height: 28px;
  cursor: pointer;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
  font-size: 0.9rem;
  cursor: pointer;
}
.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
  cursor: pointer;
}

.config-note {
  margin-top: 16px;
  font-size: 0.74rem;
  color: rgba(243, 234, 216, 0.55);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
}
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 3, 18, 0.75);
  backdrop-filter: blur(4px);
}
.modal__panel {
  position: relative;
  width: min(680px, 92vw);
  max-height: 86vh;
  overflow: auto;
  display: flex;
  gap: 24px;
  background:
    radial-gradient(140% 120% at 50% 0%, #241350 0%, #150a33 60%, #10082a 100%);
  border: 1px solid var(--gold-soft);
  border-radius: 18px;
  padding: 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.65);
  animation: configIn 0.35s ease both;
}
.modal__close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: rgba(243, 234, 216, 0.7);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
}
.modal__close:hover { color: var(--gold); }

.modal__art {
  flex: 0 0 auto;
  width: 150px;
  aspect-ratio: 1 / 1.68;
  border-radius: var(--radius);
  border: 2px solid var(--gold-soft);
  background: radial-gradient(140% 100% at 50% 0%, #2c1a58 0%, #191038 55%, #120a2a 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 16px 10px;
  position: relative;
}
.modal__numeral {
  font-family: Cinzel, serif;
  color: var(--gold);
  letter-spacing: 0.14em;
}
.modal__symbol {
  font-size: 3.4rem;
  filter: drop-shadow(0 0 14px rgba(232, 196, 106, 0.5));
}
.modal__revbadge {
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: #3d1030;
  border: 1px solid #ff7ab8;
  color: #ffd7ec;
  font-size: 0.75rem;
  padding: 3px 12px;
  border-radius: 999px;
}

.modal__info h3 {
  font-family: Cinzel, serif;
  color: var(--gold);
  font-size: 1.4rem;
  margin-bottom: 2px;
}
.modal__en {
  font-style: italic;
  color: rgba(243, 234, 216, 0.6);
  font-size: 0.85rem;
  margin-bottom: 14px;
}
.modal__meaning {
  margin-top: 10px;
  line-height: 1.55;
  font-size: 0.93rem;
}
.modal__meaning strong { color: var(--gold); font-weight: 600; }

@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 12px 14px;
  }
  .brand { flex: 1 1 auto; font-size: 1rem; }
  .toolbar {
    flex: 1 1 100%;
    justify-content: space-between;
    gap: 8px;
  }
  .progress { min-width: 0; }
  .btn { padding: 8px 14px; font-size: 0.82rem; }
  .modal__panel {
    flex-direction: column;
    align-items: center;
    text-align: left;
    padding: 20px 18px;
    gap: 16px;
  }
  .modal__art { width: 120px; }
  .config-card { padding: 26px 20px 22px; }
  .config-card h2 { font-size: 1.4rem; }
  .banner { top: auto; bottom: 72px; left: 50%; right: auto; transform: translateX(-50%); }
  .hintbar { font-size: 0.72rem; }
  :root { font-size: 14px; }
}

@media (max-width: 380px) {
  .topbar { padding: 10px 12px; }
  .brand { font-size: 0.92rem; }
  .btn { padding: 7px 11px; font-size: 0.78rem; }
  .config-card { padding: 22px 16px 18px; }
  .config-card h2 { font-size: 1.25rem; }
  .config-sub { font-size: 0.82rem; }
  :root { font-size: 13px; }
}

@media (max-height: 560px) and (max-width: 640px) {
  .config-card { padding: 18px 18px 16px; }
  .config-emblem { font-size: 1.7rem; }
  .count-row { margin-top: 16px; }
  .btn--big { margin-top: 14px; padding: 10px 20px; }
  .modal__panel { max-height: 92vh; }
}
