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

:root {
  --bg: #0f0a14;
  --surface: #1a1220;
  --gold: #d4a830;
  --gold-dim: #8a6e1e;
  --red: #c0392b;
  --blue: #2e5ca8;
  --yellow: #e8c840;
  --text: #e8dcc8;
  --text-dim: #8a7e6e;
  --font-display: 'Permanent Marker', cursive;
  --font-body: 'Noto Sans KR', sans-serif;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* Screens */
.screen {
  display: none;
  min-height: 100dvh;
  padding: 20px;
  padding-top: 60px;
  position: relative;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── INTRO ── */
.intro-content {
  text-align: center;
  width: 100%;
  max-width: 480px;
}

.glitch-title {
  font-family: var(--font-display);
  font-size: clamp(4rem, 15vw, 8rem);
  color: var(--yellow);
  letter-spacing: 0.15em;
  text-shadow:
    3px 3px 0 var(--red),
    -2px -2px 0 var(--blue),
    0 0 40px rgba(232, 200, 64, 0.3);
  line-height: 1;
  margin-bottom: 8px;
  position: relative;
}

.glitch-title::after {
  content: 'TARO';
  position: absolute;
  left: 2px;
  top: 2px;
  color: var(--red);
  opacity: 0.4;
  z-index: -1;
}

.subtitle {
  font-family: var(--font-display);
  font-size: clamp(0.7rem, 2.5vw, 1rem);
  color: var(--text-dim);
  letter-spacing: 0.3em;
  margin-bottom: 48px;
}

.spread-select {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 40px;
  flex-wrap: wrap;
}

.spread-btn {
  background: var(--surface);
  border: 2px solid var(--gold-dim);
  color: var(--text-dim);
  padding: 14px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 90px;
  font-family: var(--font-body);
}

.spread-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(212, 168, 48, 0.1);
  box-shadow: 0 0 20px rgba(212, 168, 48, 0.15);
}

.spread-num {
  font-family: var(--font-display);
  font-size: 1.8rem;
  line-height: 1;
}

.spread-label {
  font-size: 0.7rem;
  white-space: nowrap;
}

.btn-start {
  font-family: var(--font-display);
  font-size: 1.2rem;
  background: linear-gradient(135deg, var(--gold), var(--gold-dim));
  color: var(--bg);
  border: none;
  padding: 16px 48px;
  border-radius: 50px;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 24px rgba(212, 168, 48, 0.3);
}

.btn-start:active {
  transform: scale(0.96);
}

/* ── DRAW SCREEN ── */
#draw.active {
  justify-content: flex-start;
  padding-top: 20px;
}

.draw-header {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 600px;
  margin-bottom: 8px;
}

.draw-header h2 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--gold);
}

.btn-back {
  background: none;
  border: 2px solid var(--gold-dim);
  color: var(--gold);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.instruction {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 24px;
  text-align: center;
}

/* Card Spread Layout */
.card-spread {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
  max-width: 600px;
  flex: 1;
  padding: 10px 0;
}

/* Single card */
.card-spread[data-count="1"] {
  align-items: center;
}

/* 3-card spread */
.card-spread[data-count="3"] .card-slot {
  flex: 0 0 28%;
}

/* 5-card cross spread */
.card-spread[data-count="5"] {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: auto auto auto;
  gap: 12px;
  max-width: 380px;
}

.card-spread[data-count="5"] .card-slot:nth-child(1) { grid-column: 2; grid-row: 1; }
.card-spread[data-count="5"] .card-slot:nth-child(2) { grid-column: 1; grid-row: 2; }
.card-spread[data-count="5"] .card-slot:nth-child(3) { grid-column: 2; grid-row: 2; }
.card-spread[data-count="5"] .card-slot:nth-child(4) { grid-column: 3; grid-row: 2; }
.card-spread[data-count="5"] .card-slot:nth-child(5) { grid-column: 2; grid-row: 3; }

/* Card Slot */
.card-slot {
  perspective: 800px;
  cursor: pointer;
  position: relative;
}

.card-slot .label {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 6px;
  font-family: var(--font-display);
  letter-spacing: 0.1em;
}

/* Card */
.card {
  width: 120px;
  height: 208px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s ease;
  margin: 0 auto;
}

.card.flipped {
  transform: rotateY(180deg);
}

.card.reversed.flipped {
  transform: rotateY(180deg) rotate(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.card-face img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.card-front {
  transform: rotateY(180deg);
}

.card-back {
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-back-pattern {
  width: 100%;
  height: 100%;
  background:
    repeating-linear-gradient(45deg, transparent, transparent 8px, rgba(212,168,48,0.06) 8px, rgba(212,168,48,0.06) 9px),
    repeating-linear-gradient(-45deg, transparent, transparent 8px, rgba(212,168,48,0.06) 8px, rgba(212,168,48,0.06) 9px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-back-pattern::after {
  content: '?';
  font-family: var(--font-display);
  font-size: 3rem;
  color: var(--gold-dim);
  text-shadow: 0 0 20px rgba(212,168,48,0.3);
}

/* Hover / tap effect on unflipped cards */
.card-slot:not(.revealed) .card {
  animation: float 3s ease-in-out infinite;
}

.card-slot:not(.revealed):nth-child(2) .card { animation-delay: 0.3s; }
.card-slot:not(.revealed):nth-child(3) .card { animation-delay: 0.6s; }
.card-slot:not(.revealed):nth-child(4) .card { animation-delay: 0.9s; }
.card-slot:not(.revealed):nth-child(5) .card { animation-delay: 1.2s; }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.card-slot.revealed .card {
  animation: none;
}

.btn-reading {
  font-family: var(--font-display);
  font-size: 1rem;
  background: linear-gradient(135deg, var(--gold), var(--gold-dim));
  color: var(--bg);
  border: none;
  padding: 14px 40px;
  border-radius: 50px;
  cursor: pointer;
  margin: 20px 0;
  letter-spacing: 0.05em;
  box-shadow: 0 4px 24px rgba(212, 168, 48, 0.3);
  transition: transform 0.2s;
  animation: fadeIn 0.4s ease;
}

.btn-reading:active {
  transform: scale(0.96);
}

/* ── READING SCREEN ── */
#reading.active {
  justify-content: flex-start;
  padding-top: 20px;
}

.reading-header {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 600px;
  margin-bottom: 24px;
}

.reading-header h2 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--gold);
}

.reading-content {
  width: 100%;
  max-width: 600px;
  flex: 1;
  overflow-y: auto;
  padding-bottom: 20px;
}

.reading-card {
  background: var(--surface);
  border: 1px solid var(--gold-dim);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  animation: fadeIn 0.5s ease backwards;
}

.reading-card:nth-child(2) { animation-delay: 0.15s; }
.reading-card:nth-child(3) { animation-delay: 0.3s; }
.reading-card:nth-child(4) { animation-delay: 0.45s; }
.reading-card:nth-child(5) { animation-delay: 0.6s; }

.reading-card-header {
  display: flex;
  gap: 16px;
  margin-bottom: 14px;
  align-items: center;
}

.reading-card-header img {
  width: 70px;
  height: 120px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--gold-dim);
}

.reading-card-header img.reversed-img {
  transform: rotate(180deg);
}

.reading-card-info h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--yellow);
  margin-bottom: 4px;
}

.reading-card-info .position {
  font-size: 0.75rem;
  color: var(--gold-dim);
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

.reading-card-info .reversed-tag {
  display: inline-block;
  background: var(--red);
  color: white;
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 4px;
  margin-top: 4px;
}

.reading-card .meaning {
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
}

.reading-card .keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.reading-card .keyword {
  background: rgba(212, 168, 48, 0.1);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  font-size: 0.7rem;
  padding: 3px 10px;
  border-radius: 20px;
}

.reading-actions {
  display: flex;
  gap: 12px;
  padding: 16px 0;
  width: 100%;
  max-width: 600px;
  justify-content: center;
}

.btn-retry, .btn-share {
  font-family: var(--font-display);
  font-size: 0.9rem;
  padding: 12px 28px;
  border-radius: 50px;
  cursor: pointer;
  border: 2px solid var(--gold-dim);
  transition: transform 0.2s;
  letter-spacing: 0.05em;
}

.btn-retry {
  background: var(--surface);
  color: var(--gold);
}

.btn-share {
  background: linear-gradient(135deg, var(--gold), var(--gold-dim));
  color: var(--bg);
  border: none;
}

.btn-retry:active, .btn-share:active {
  transform: scale(0.96);
}

/* ── HIDDEN ── */
.hidden {
  display: none !important;
}

/* ── Responsive ── */
@media (max-width: 380px) {
  .card {
    width: 100px;
    height: 173px;
  }

  .spread-btn {
    min-width: 80px;
    padding: 10px 12px;
  }
}

@media (min-width: 768px) {
  .card {
    width: 150px;
    height: 260px;
  }
}
