:root {
  --bg: #080b18;
  --surface: rgba(14, 19, 36, 0.78);
  --surface-strong: rgba(12, 16, 31, 0.92);
  --border: rgba(232, 198, 122, 0.24);
  --border-strong: rgba(232, 198, 122, 0.52);
  --gold: #e8c67a;
  --gold-soft: #f5dfb0;
  --text: #eef1f7;
  --muted: #a2acc4;
  --fire: #ff8f2e;
  --water: #47c7fa;
  --air: #c2b8ff;
  --earth: #5cdb94;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard Variable", "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#tarot-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#tarot-canvas:active {
  cursor: grabbing;
}

.hidden {
  display: none !important;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #141c35 0%, #070a14 100%);
  transition: opacity 0.4s ease;
}

.loading-card {
  text-align: center;
  padding: 28px 34px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.loading-sigil {
  font-size: 32px;
  color: var(--gold);
  margin-bottom: 8px;
  animation: pulse 2s ease-in-out infinite;
}

.loading-card h1 {
  font-size: 22px;
  letter-spacing: 0.08em;
  color: var(--gold-soft);
}

.loading-card p {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

@keyframes pulse {
  0%, 100% { opacity: 0.55; transform: scale(0.95); }
  50% { opacity: 1; transform: scale(1.08); }
}

/* Top Bar */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  pointer-events: none;
}

.top-bar > * {
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.brand-mark {
  color: var(--gold);
  font-size: 15px;
}

.brand-name {
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 14px;
  color: var(--gold-soft);
}

.badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 600;
}

.badge-muted {
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}

.badge-gpu {
  background: rgba(232, 198, 122, 0.16);
  color: var(--gold);
  border: 1px solid rgba(232, 198, 122, 0.3);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chip-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}

.chip-btn:hover {
  border-color: var(--border-strong);
  background: rgba(24, 32, 58, 0.88);
}

.chip-gold {
  border-color: var(--border-strong);
  color: var(--gold-soft);
  background: rgba(232, 198, 122, 0.14);
}

/* Phase Banner */
.phase-banner {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 18;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  max-width: calc(100vw - 32px);
  pointer-events: none;
}

.phase-pill {
  font-size: 11px;
  font-weight: 700;
  color: #121524;
  background: var(--gold);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.phase-hint {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Bottom Floating Ritual Bar */
.ritual-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  max-width: calc(100vw - 24px);
  flex-wrap: wrap;
  justify-content: center;
}

.pick-progress {
  font-size: 13px;
  font-weight: 700;
  color: var(--gold-soft);
  padding: 0 8px;
}

.action-btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 15px;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.2s, background 0.2s;
}

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

.action-btn.primary {
  background: linear-gradient(135deg, #e8c67a 0%, #c89a45 100%);
  color: #131624;
}

.action-btn.secondary {
  background: rgba(255, 255, 255, 0.10);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.action-btn.ghost {
  background: transparent;
  color: var(--muted);
}

.action-btn.ghost:hover {
  color: var(--text);
}

/* Setup & Crisis Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(5, 8, 18, 0.62);
  backdrop-filter: blur(8px);
}

.setup-panel {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 24px;
  border-radius: 22px;
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-head h2 {
  font-size: 20px;
  color: var(--gold-soft);
}

.panel-head .sub {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

.icon-close {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
}

.icon-close:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 7px;
  letter-spacing: 0.03em;
}

.text-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.text-input:focus {
  border-color: var(--gold);
  background: rgba(255, 255, 255, 0.08);
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.preset-chip {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.preset-chip:hover {
  color: var(--gold-soft);
  border-color: var(--border-strong);
}

.spread-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.spread-item {
  text-align: left;
  padding: 11px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.spread-item:hover {
  border-color: var(--border-strong);
}

.spread-item.selected {
  border-color: var(--gold);
  background: rgba(232, 198, 122, 0.13);
}

.spread-item .s-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.spread-item .s-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--gold-soft);
}

.spread-item .s-cnt {
  font-size: 11px;
  color: var(--gold);
  background: rgba(232, 198, 122, 0.16);
  padding: 1px 6px;
  border-radius: 999px;
}

.spread-item .s-sub {
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.35;
}

.setup-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  color: var(--text);
}

.deck-tag {
  font-size: 11.5px;
  color: var(--muted);
}

.start-btn {
  width: 100%;
  margin-top: 18px;
  padding: 13px 18px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, #eccd84 0%, #c4933b 100%);
  color: #131624;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(232, 198, 122, 0.28);
}

.start-btn:hover {
  filter: brightness(1.06);
}

/* Crisis Panel */
.crisis-panel {
  border-color: rgba(255, 166, 102, 0.6);
}

.crisis-msg {
  margin-top: 10px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}

.crisis-lines {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.crisis-line {
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 166, 102, 0.12);
  border: 1px solid rgba(255, 166, 102, 0.35);
}

.crisis-line strong {
  font-size: 15px;
  color: #ffd399;
}

.crisis-line span {
  display: block;
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--muted);
}

/* Result Summary Drawer */
.result-drawer {
  position: fixed;
  top: 64px;
  right: 16px;
  bottom: 84px;
  width: 340px;
  max-width: calc(100vw - 32px);
  z-index: 25;
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.drawer-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--gold-soft);
}

.drawer-question {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.drawer-body {
  padding: 12px 14px;
  overflow-y: auto;
  flex: 1;
}

.result-cards-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px 11px;
  border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.result-card-row:hover {
  border-color: var(--border-strong);
  background: rgba(232, 198, 122, 0.10);
}

.rc-pos {
  font-size: 11px;
  color: var(--gold);
  font-weight: 600;
}

.rc-name {
  font-size: 14px;
  font-weight: 700;
  margin-top: 2px;
}

.rc-en {
  font-size: 11px;
  color: var(--muted);
}

.rc-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.dir-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
}

.dir-up {
  background: rgba(92, 219, 148, 0.16);
  color: #8ceab6;
}

.dir-rev {
  background: rgba(255, 143, 122, 0.18);
  color: #ffb1a1;
}

.elem-dot {
  font-size: 11px;
  color: var(--muted);
}

.analysis-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
}

.analysis-section h3 {
  font-size: 13px;
  color: var(--gold);
  margin-bottom: 10px;
}

.element-bars {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.elem-chip {
  padding: 7px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.elem-chip .e-lbl {
  font-size: 11px;
  color: var(--muted);
}

.elem-chip .e-val {
  font-size: 15px;
  font-weight: 800;
  margin-top: 2px;
}

.analysis-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.analysis-summary {
  margin-top: 10px;
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  line-height: 1.5;
  color: #d7deee;
}

@media (max-width: 720px) {
  .spread-grid {
    grid-template-columns: 1fr;
  }
  .top-actions .chip-btn {
    font-size: 11px;
    padding: 6px 9px;
  }
  .result-drawer {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 74px;
    width: auto;
    max-width: none;
    max-height: 52vh;
  }
}
