:root {
  --bg-0: #07080f;
  --bg-1: #12122a;
  --ink: #e9e8f6;
  --ink-dim: #a9a8c6;
  --line: rgba(196, 190, 255, 0.22);
  --pill: rgba(34, 33, 66, 0.62);
  --pill-hover: rgba(58, 55, 104, 0.78);
  --accent: #cfc4ff;
  --gold: #f1dfae;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-0);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 280px;
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  touch-action: none;            /* gestures are handled only inside the card area */
  cursor: grab;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
  background: radial-gradient(120% 90% at 50% 42%, var(--bg-1) 0%, var(--bg-0) 72%);
}
.stage.dragging { cursor: grabbing; }
.stage:focus-visible::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 2px solid var(--accent);
  border-radius: 14px;
  pointer-events: none;
  box-shadow: 0 0 0 3px rgba(12, 12, 28, 0.7) inset;
}

#view { display: block; width: 100%; height: 100%; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  text-align: center;
  color: var(--ink-dim);
  font-size: 14px;
  letter-spacing: 0.04em;
  transition: opacity 0.5s ease;
}
.overlay[hidden] { display: none; }
.overlay.done { opacity: 0; pointer-events: none; }
.overlay p { margin: 0; max-width: 32ch; line-height: 1.6; }

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.fallback { background: var(--bg-0); cursor: default; }
.fallback img {
  max-height: 78%;
  max-width: 86%;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
}

.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  flex-wrap: wrap;
  padding: 10px max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: linear-gradient(180deg, rgba(7, 8, 15, 0) 0%, var(--bg-0) 55%);
  margin-top: -18px;
  padding-top: 26px;
  position: relative;
  pointer-events: none;
}
.bar > * { pointer-events: auto; }

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--ink-dim);
  letter-spacing: 0.05em;
}

.controls { display: flex; gap: 10px; margin-left: auto; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  font: inherit;
  font-size: 14px;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: var(--pill);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
}
.btn:hover { background: var(--pill-hover); border-color: rgba(214, 206, 255, 0.45); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.toggle .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(190, 188, 220, 0.35);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.toggle[aria-pressed="true"] { border-color: rgba(241, 223, 174, 0.55); }
.toggle[aria-pressed="true"] .dot { background: var(--gold); box-shadow: 0 0 10px rgba(241, 223, 174, 0.8); }

@media (max-width: 520px) {
  .bar { justify-content: center; }
  .hint { width: 100%; text-align: center; font-size: 12px; }
  .controls { margin: 0 auto; }
  .btn { padding: 0 16px; }
}
@media (max-height: 480px) {
  .hint { display: none; }
  .bar { padding-top: 20px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .btn { min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}

/* card picker */
.cards { display: flex; gap: 8px; align-items: center; }
.cards[hidden] { display: none; }
.thumb {
  padding: 0;
  width: 36px;
  height: 52px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--pill);
  overflow: hidden;
  cursor: pointer;
  opacity: 0.62;
  transition: opacity 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb:hover { opacity: 0.9; }
.thumb[aria-pressed="true"] { opacity: 1; border-color: var(--gold); box-shadow: 0 0 10px rgba(241, 223, 174, 0.45); transform: translateY(-2px); }
.thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.overlay.veil { background: rgba(7, 8, 15, 0.55); }

@media (max-width: 520px) {
  .cards { width: 100%; justify-content: center; }
}
@media (max-height: 480px) {
  .thumb { width: 28px; height: 40px; }
}

.btn[hidden] { display: none; }
@media (max-width: 520px) { .controls { flex-wrap: wrap; justify-content: center; } .btn { padding: 0 13px; font-size: 13px; } }

.back {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); z-index: 5;
  padding: 7px 12px; font-size: 13px; letter-spacing: 0.06em; color: var(--ink-dim); text-decoration: none;
  background: var(--pill); border: 1px solid var(--line); border-radius: 999px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.back:hover { color: var(--ink); background: var(--pill-hover); }
.back:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.app { position: relative; }
