/* ── Reset & Variables ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand: #7C3AED;
  --brand-dark: #5B21B6;
  --brand-light: #EDE9FE;
  --bg: #F5F3FF;
  --surface: #FFFFFF;
  --surface2: #F0EBFF;
  --border: #DDD6FE;
  --text: #1A1A1A;
  --text-muted: #6B7280;
  --purple-soft: #8B5CF6;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(124,58,237,.12);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.06);
  font-family: "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { background: var(--bg); color: var(--text); min-height: 100dvh; overflow-x: hidden; font-size: 16px; line-height: 1.6; }
button { cursor: pointer; border: none; font-family: inherit; background: none; }
a { text-decoration: none; color: inherit; }

/* ── Layout ────────────────────────────────────────────── */
.layout-container {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}
@media (max-width: 800px) {
  .layout-container { grid-template-columns: 1fr; padding: 16px 12px 40px; }
  .app-sidebar { display: none; }
}

/* 모바일 전용 */
@media (max-width: 520px) {
  .hero-title { font-size: 20px; }
  .hero-desc { font-size: 13px; }
  .hero-badges { gap: 6px; }
  .hero-badge { font-size: 11px; padding: 3px 10px; }
  .theme-grid { grid-template-columns: 1fr; }
  .how-to-steps { gap: 4px; padding: 12px; }
  .how-to-step:not(:last-child)::after { display: none; }
  .how-to-steps { flex-direction: row; justify-content: space-around; }
  .cards-row { gap: 8px; }
  .card-flip { width: 80px; height: 126px; }
  .header-logo h1 { font-size: 17px; }
  .header-logo p { display: none; }
}

/* ── Ad containers ─────────────────────────────────────── */
.ad-container { display: block; width: 100%; text-align: center; }
.top-ad { background: #f9f9f9; padding: 8px 0; border-bottom: 1px solid var(--border); }
.middle-ad { margin: 16px 0; }
.bottom-ad { margin-top: 24px; padding: 16px 0; border-top: 1px solid var(--border); }

/* ── Header ────────────────────────────────────────────── */
.main-header {
  background: linear-gradient(135deg, #4C1D95 0%, #7C3AED 60%, #A855F7 100%);
  padding: 16px 16px 28px;
  position: relative;
  overflow: hidden;
}
.main-header::before {
  content: '';
  position: absolute; top: -40px; right: -40px;
  width: 160px; height: 160px; border-radius: 50%;
  background: rgba(255,255,255,.08);
}
.main-header::after {
  content: '';
  position: absolute; bottom: -30px; left: 20px;
  width: 100px; height: 100px; border-radius: 50%;
  background: rgba(255,255,255,.06);
}
.header-inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  position: relative; z-index: 1;
}
.header-logo { display: flex; align-items: center; gap: 12px; }
.header-logo-icon {
  font-size: 28px;
  background: rgba(255,255,255,.2);
  border-radius: 12px;
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
}
.header-logo h1 { font-size: 22px; font-weight: 800; color: #fff; letter-spacing: -.5px; }
.header-logo h1 a { color: #fff; }
.header-logo p { font-size: 13px; color: rgba(255,255,255,.8); margin-top: 2px; }
.btn-share {
  font-size: 13px; color: rgba(255,255,255,.9);
  padding: 7px 14px; border-radius: 20px;
  background: rgba(255,255,255,.2); border: 1.5px solid rgba(255,255,255,.4);
  font-weight: 600; position: relative; z-index: 1;
  cursor: pointer; transition: background .15s;
}
.btn-share:hover { background: rgba(255,255,255,.3); }

.header-hero {
  max-width: 1100px; margin: 16px auto 0;
  position: relative; z-index: 1;
}
.hero-title { font-size: 28px; font-weight: 900; color: #fff; letter-spacing: -.5px; }
.hero-desc { font-size: 15px; color: rgba(255,255,255,.85); margin-top: 4px; }
.hero-badges {
  display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap;
}
.hero-badge {
  font-size: 12px; font-weight: 700;
  background: rgba(255,255,255,.15); color: rgba(255,255,255,.95);
  border: 1px solid rgba(255,255,255,.3); border-radius: 20px;
  padding: 4px 12px;
}

/* ── App Card ──────────────────────────────────────────── */
.app-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 16px;
}
.card-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.card-header-icon { font-size: 18px; }
.card-header-title { font-size: 15px; font-weight: 700; color: var(--text); }
.card-header-sub { font-size: 13px; color: var(--text-muted); margin-left: auto; }

/* ── Screen visibility ─────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

/* ── Theme Grid (홈 화면) ────────────────────────────────── */
.theme-section { padding: 20px; }
.theme-section-title {
  font-size: 14px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 14px;
}
.theme-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.theme-btn {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
  color: var(--text); transition: all .15s; text-align: left;
}
.theme-btn:hover {
  border-color: var(--brand); background: var(--brand-light);
  box-shadow: 0 2px 10px rgba(124,58,237,.15); transform: translateY(-1px);
}
.theme-btn:last-child:nth-child(odd) { grid-column: 1 / -1; }
.theme-emoji { font-size: 26px; flex-shrink: 0; }
.theme-info {}
.theme-name { font-size: 14px; font-weight: 700; color: var(--text); }
.theme-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.how-to-section {
  padding: 0 20px 20px;
}
.how-to-steps {
  display: flex; gap: 0;
  background: var(--surface2); border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.how-to-step {
  flex: 1; text-align: center; position: relative;
}
.how-to-step:not(:last-child)::after {
  content: '→';
  position: absolute; right: -8px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 14px;
}
.step-num {
  font-size: 20px; display: block; margin-bottom: 4px;
}
.step-text { font-size: 11px; color: var(--text-muted); font-weight: 600; }

/* ── Reveal Screen (카드 뒤집기) ────────────────────────── */
.reveal-section {
  padding: 20px;
}
.reveal-theme-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--brand-light); color: var(--brand);
  font-size: 13px; font-weight: 700;
  border-radius: 20px; padding: 5px 14px; margin-bottom: 12px;
}
.reveal-guide {
  font-size: 14px; color: var(--text-muted); margin-bottom: 20px;
}
.cards-row {
  display: flex; gap: 12px; justify-content: center;
  margin-bottom: 24px; flex-wrap: wrap;
}
.card-slot {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  flex: 1; min-width: 90px; max-width: 130px;
}
.position-label {
  font-size: 11px; font-weight: 700; color: var(--brand);
  background: var(--brand-light); border-radius: 20px; padding: 3px 10px;
  text-align: center;
}

/* 카드 플립 */
.card-flip { width: 90px; height: 140px; perspective: 600px; flex-shrink: 0; cursor: pointer; }
.card-inner {
  width: 100%; height: 100%; position: relative;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.45, 0.05, 0.55, 0.95);
  border-radius: 12px;
}
.card-flip.flipped .card-inner { transform: rotateY(180deg); }
.card-flip.revealed { cursor: default; }
.card-back, .card-front {
  position: absolute; inset: 0; border-radius: 12px;
  backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.card-back {
  background: linear-gradient(135deg, #4C1D95 0%, #7C3AED 100%);
  border: 1.5px solid #A855F7;
  box-shadow: 0 4px 16px rgba(124,58,237,.35);
}
.card-back-pattern {
  font-size: 26px; color: rgba(255,255,255,.5);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.card-back-pattern span { font-size: 10px; color: rgba(255,255,255,.3); letter-spacing: 3px; }
.card-front {
  background: linear-gradient(135deg, #1E0A3A 0%, #2D1F4A 100%);
  border: 1.5px solid #A855F7;
  transform: rotateY(180deg);
  padding: 8px 6px; text-align: center;
  box-shadow: 0 4px 16px rgba(124,58,237,.3);
}
.card-front.reversed { transform: rotateY(180deg) rotate(180deg); }
.card-emoji { font-size: 24px; line-height: 1; }
.card-name { font-size: 10px; font-weight: 700; color: #E9D5FF; line-height: 1.3; }
.reversed-badge { font-size: 8px; background: rgba(168,85,247,.3); color: #C4B5FD; border-radius: 4px; padding: 2px 5px; }
.card-keywords { font-size: 10px; color: #C4B5FD; text-align: center; }

.progress-indicator {
  display: flex; gap: 6px; justify-content: center; margin-bottom: 16px;
}
.progress-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--border); transition: background .3s;
}
.progress-dot.done { background: var(--brand); }

.cta-btn {
  display: block; width: 100%;
  padding: 16px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #7C3AED, #A855F7);
  color: #fff; font-size: 16px; font-weight: 800;
  box-shadow: 0 4px 20px rgba(124,58,237,.4);
  transition: opacity .15s, transform .1s;
}
.cta-btn:hover { opacity: .92; transform: translateY(-1px); }
.cta-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

/* ── Reading Screen (결과) ──────────────────────────────── */
.reading-section { padding: 20px; }
.reading-theme-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--brand-light); color: var(--brand);
  font-size: 13px; font-weight: 700;
  border-radius: 20px; padding: 5px 14px; margin-bottom: 16px;
}
.overall-card {
  background: linear-gradient(135deg, #4C1D95 0%, #7C3AED 100%);
  border-radius: var(--radius-sm); padding: 16px 18px; margin-bottom: 16px;
  box-shadow: 0 4px 16px rgba(124,58,237,.25);
}
.overall-label {
  font-size: 11px; font-weight: 700; color: rgba(255,255,255,.7);
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px;
}
.overall-text { font-size: 14px; color: #fff; line-height: 1.7; font-weight: 500; }

.reading-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 16px; margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.reading-card-top { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.reading-card-emoji {
  font-size: 28px; flex-shrink: 0;
  background: var(--brand-light); border-radius: 10px;
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
}
.reading-card-info { flex: 1; }
.reading-position {
  font-size: 11px; font-weight: 700; color: var(--brand);
  background: var(--brand-light); border-radius: 6px; padding: 3px 8px;
  display: inline-block; margin-bottom: 4px;
}
.reading-card-name { font-size: 16px; font-weight: 800; color: var(--text); }
.reading-reversed { font-size: 11px; color: #EF4444; font-weight: 600; margin-left: 6px; }
.reading-keywords { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.keyword-chip {
  font-size: 11px; font-weight: 600; background: var(--brand-light);
  color: var(--brand); border-radius: 6px; padding: 3px 9px;
}
.reading-full { font-size: 14px; color: #374151; line-height: 1.75; }

.result-btns { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.restart-btn {
  display: block; width: 100%; padding: 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--brand); color: var(--brand);
  font-size: 15px; font-weight: 700;
  background: var(--surface); transition: background .15s;
}
.restart-btn:hover { background: var(--brand-light); }
.btn-share-result {
  display: block; width: 100%; padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--brand); color: #fff;
  font-size: 15px; font-weight: 700;
  transition: background .15s;
}
.btn-share-result:hover { background: var(--brand-dark); }
.disclaimer {
  font-size: 11px; color: var(--text-muted);
  text-align: center; line-height: 1.7; margin-top: 12px;
  padding: 0 8px;
}

/* ── Info Cards (하단) ─────────────────────────────────── */
.info-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px;
}
.info-card h2 { font-size: 16px; font-weight: 800; color: var(--text); margin-bottom: 12px; }
.info-card p { font-size: 14px; color: #374151; line-height: 1.75; margin-bottom: 8px; }
.info-card ul { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.info-card ul li {
  font-size: 13px; color: #374151; padding-left: 16px; position: relative; line-height: 1.6;
}
.info-card ul li::before { content: '•'; position: absolute; left: 0; color: var(--brand); }

/* ── Sidebar ────────────────────────────────────────────── */
.app-sidebar {
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.app-sidebar::-webkit-scrollbar { display: none; }

.sidebar-card { background: var(--surface); border-radius: var(--radius-sm); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.sidebar-card h3 { font-size: 14px; font-weight: 700; margin-bottom: 12px; padding-left: 8px; border-left: 3px solid var(--brand); color: var(--text); }
.sidebar-list { list-style: none; padding: 0; margin: 0; }
.sidebar-list li { margin-bottom: 6px; }
.sidebar-list a { display: flex; align-items: flex-start; text-decoration: none; color: var(--text); padding: 7px 8px; border-radius: 8px; transition: background .15s; }
.sidebar-list a:hover { background: var(--brand-light); }
.link-icon { margin-right: 8px; font-size: 15px; flex-shrink: 0; margin-top: 1px; }
.link-content { flex: 1; min-width: 0; }
.link-title { display: block; font-size: 13px; font-weight: 600; color: var(--brand); margin-bottom: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-desc { display: block; font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Footer ────────────────────────────────────────────── */
.main-footer {
  border-top: 1px solid var(--border); padding: 20px;
  text-align: center; font-size: 12px; color: var(--text-muted);
}

/* ── Share Toast ────────────────────────────────────────── */
.share-toast {
  position: fixed; bottom: 80px; left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #1A1F36; color: #fff;
  padding: 12px 22px; border-radius: 99px;
  font-size: 14px; font-weight: 600; white-space: nowrap;
  opacity: 0; transition: opacity .2s, transform .2s;
  z-index: 9999; box-shadow: 0 4px 20px rgba(0,0,0,.25);
  pointer-events: none;
}
.share-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
