:root {
  --bg: #f7f3ec;
  --surface: #ffffff;
  --ink: #26222f;
  --muted: #8a8494;
  --brand: #4f32d3;
  --brand-dark: #4328b8;
  --gold: #d9a441;
  --gold-soft: #f6e7c8;
  --danger: #d6455d;
  --ok: #2e9b68;
  --shadow: 0 10px 30px rgba(38, 34, 47, 0.12);
  --radius: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16141c;
    --surface: #211e2a;
    --ink: #f2eef8;
    --muted: #9d96ab;
    --gold-soft: #3a2f18;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 18px 10px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, var(--bg) 60%, transparent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  font-size: 30px;
  filter: drop-shadow(0 4px 8px rgba(79, 50, 211, 0.35));
}

.brand-name {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-tagline {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted);
}

.credits-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid rgba(217, 164, 65, 0.45);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow);
  cursor: default;
}

.credits-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f2c14e, #d9a441);
}

.app-main {
  flex: 1;
  padding: 6px 18px calc(86px + env(safe-area-inset-bottom));
}

.view {
  animation: view-in 0.22s ease-out;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.card-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  position: relative;
}

.card-fan {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 8px;
  transition: opacity 0.25s ease;
}

.card-fan.faded {
  opacity: 0;
}

.card-back {
  width: 104px;
  height: 156px;
  border-radius: 14px;
  background: linear-gradient(150deg, #6b4ef0, #4f32d3 55%, #3d259f);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transform-origin: 50% 100%;
}

.card-back::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  border-radius: 9px;
}

.card-back-1 {
  transform: rotate(-14deg) translateY(4px);
}

.card-back-2 {
  transform: rotate(14deg) translateY(4px);
}

.card-back-3 {
  transform: rotate(0deg) translateY(-2px) scale(1.06);
  z-index: 2;
}

.result-card {
  position: absolute;
  width: 216px;
  height: 320px;
  perspective: 900px;
}

.result-card.card-in {
  animation: card-in 0.45s cubic-bezier(0.34, 1.3, 0.4, 1);
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: scale(0.92) rotate(-4deg);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.result-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.34, 1.3, 0.4, 1);
}

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

.result-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 22px;
  text-align: center;
  overflow: hidden;
}

.result-front {
  background: linear-gradient(160deg, #fffdf7, #f8efdb);
  color: #26222f;
  box-shadow: var(--shadow);
  border: 1px solid rgba(217, 164, 65, 0.4);
}

.result-front::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(217, 164, 65, 0.35);
  border-radius: 12px;
  pointer-events: none;
}

.result-back {
  background: linear-gradient(150deg, #6b4ef0, #4f32d3 55%, #3d259f);
  transform: rotateY(180deg);
}

.result-back-mark {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.18), 0 0 40px rgba(242, 193, 78, 0.5);
}

.result-emoji {
  font-size: 46px;
  filter: drop-shadow(0 4px 10px rgba(217, 164, 65, 0.45));
}

.result-name {
  margin: 12px 0 8px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.result-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: #5b5468;
  max-height: 118px;
  overflow-y: auto;
}

.draw-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  border: none;
  border-radius: 16px;
  padding: 16px 18px;
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #5b3df0, #4f32d3 60%, #4328b8);
  box-shadow: 0 12px 26px rgba(79, 50, 211, 0.4);
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.draw-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.draw-btn:disabled {
  opacity: 0.6;
  box-shadow: none;
  cursor: progress;
}

.draw-icon {
  font-size: 20px;
}

.draw-cost {
  font-size: 11px;
  font-weight: 700;
  opacity: 0.85;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 3px 9px;
}

.draw-hint {
  margin: 12px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.status-box {
  margin: 14px 0 10px;
  border-radius: 14px;
  padding: 13px 15px;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid;
}

.status-box.error {
  border-color: rgba(214, 69, 93, 0.35);
  background: rgba(214, 69, 93, 0.08);
  color: var(--danger);
}

.status-box.error .status-title {
  font-weight: 800;
}

.status-box .btn-link {
  margin-top: 10px;
}

.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: var(--brand);
  cursor: pointer;
  text-decoration: none;
}

.btn-link:hover {
  background: var(--brand-dark);
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.section-title {
  margin: 8px 0 14px;
  font-size: 20px;
  font-weight: 800;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.history-emoji {
  font-size: 24px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gold-soft);
  border-radius: 12px;
  flex-shrink: 0;
}

.history-body {
  flex: 1;
  min-width: 0;
}

.history-name {
  font-size: 14px;
  font-weight: 800;
}

.history-time {
  font-size: 11px;
  color: var(--muted);
}

.history-cost {
  font-size: 12px;
  font-weight: 700;
  color: var(--ok);
  background: rgba(46, 155, 104, 0.12);
  border-radius: 999px;
  padding: 3px 8px;
  white-space: nowrap;
}

.history-empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-top: 48px;
  padding: 0 24px;
  line-height: 1.6;
}

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--surface);
  border-top: 1px solid rgba(128, 128, 160, 0.18);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 0 8px;
  border: none;
  background: none;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease;
}

.tab-btn.active {
  color: var(--brand);
}

.tab-icon {
  font-size: 18px;
}

.tab-btn.active .tab-icon {
  animation: view-in 0.2s ease-out;
}

.toast {
  position: fixed;
  bottom: calc(96px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 40px);
  max-width: 420px;
  background: #26222f;
  color: #f7f3ec;
  font-size: 13px;
  font-weight: 600;
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  z-index: 40;
  animation: toast-in 0.25s ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

[hidden] {
  display: none !important;
}

/* ─── Exit consent modal ─────────────────────────────────────────────── */

.exit-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(20, 16, 30, 0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  z-index: 60;
  animation: modal-fade 0.2s ease-out;
}

.exit-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  color: var(--ink);
  border-radius: 20px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  animation: modal-in 0.25s cubic-bezier(0.34, 1.3, 0.4, 1);
}

.exit-mark {
  font-size: 32px;
  filter: drop-shadow(0 4px 8px rgba(79, 50, 211, 0.35));
}

.exit-title {
  margin: 10px 0 6px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.exit-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
}

.exit-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.exit-btn {
  flex: 1;
  border: none;
  border-radius: 14px;
  padding: 13px 10px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease;
}

.exit-btn:active {
  transform: scale(0.97);
}

.exit-btn-ghost {
  background: rgba(128, 128, 160, 0.14);
  color: var(--ink);
}

.exit-btn-danger {
  background: linear-gradient(135deg, #d6455d, #b8384e);
  color: #fff;
}

@keyframes modal-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}