:root {
  color-scheme: dark;
  --bg-top: #151119;
  --bg-bottom: #0d0a11;
  --surface: rgba(255, 248, 241, 0.08);
  --surface-border: rgba(255, 231, 214, 0.12);
  --text-main: #f8f0e9;
  --text-muted: #cdbfb5;
  --accent: #d27b52;
  --accent-strong: #f09a6d;
  --accent-soft: rgba(210, 123, 82, 0.16);
  --shadow-xl: 0 34px 90px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 46px rgba(0, 0, 0, 0.28);
  --shadow-sm: 0 10px 24px rgba(0, 0, 0, 0.16);
  --radius-xl: 30px;
  --radius-lg: 24px;
  --radius-md: 18px;
}

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

html {
  min-height: 100%;
  background:
    radial-gradient(circle at 20% 10%, rgba(223, 128, 84, 0.18), transparent 32%),
    radial-gradient(circle at 80% 18%, rgba(129, 86, 162, 0.14), transparent 24%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}

body {
  min-height: 100dvh;
  margin: 0;
  font-family: "Manrope", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at 12% 80%, rgba(210, 123, 82, 0.12), transparent 20%),
    radial-gradient(circle at 88% 76%, rgba(89, 69, 135, 0.16), transparent 20%);
}

body[data-deck="vin"] {
  --accent: #4d86c6;
  --accent-strong: #7fb2ea;
  --accent-soft: rgba(77, 134, 198, 0.16);
}

body[data-deck="tantsi"] {
  --accent: #b96a7a;
  --accent-strong: #e38f9e;
  --accent-soft: rgba(185, 106, 122, 0.16);
}

body[data-deck="allegory"] {
  --accent: #6e68c4;
  --accent-strong: #9c95ef;
  --accent-soft: rgba(110, 104, 196, 0.16);
}

button,
img {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

body.modal-open {
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 33rem);
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    clamp(18px, 4vw, 28px)
    clamp(16px, 4vw, 24px)
    calc(clamp(22px, 4vw, 30px) + env(safe-area-inset-bottom));
}

.welcome-view,
.reading-view {
  display: grid;
  gap: 18px;
}

.welcome-hero,
.hero {
  padding-top: max(8px, env(safe-area-inset-top));
}

.eyebrow,
.meta-label,
.metric-label {
  margin: 0;
  font-size: 0.76rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.welcome-hero h1,
.hero h1,
.deck-option h2,
.meta-title,
.history-title,
.fullscreen-title,
.card-placeholder h2,
.about-card h2 {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  line-height: 0.95;
  letter-spacing: -0.035em;
}

.welcome-hero h1,
.hero h1 {
  margin-top: 6px;
  font-size: clamp(2.8rem, 12vw, 4.9rem);
}

.hero-copy,
.deck-option-copy,
.about-copy,
.meta-note,
.history-empty,
.history-item span,
.about-list {
  color: var(--text-muted);
  line-height: 1.62;
}

.deck-grid {
  display: grid;
  gap: 14px;
}

.deck-option,
.metric-card,
.history-panel,
.about-card,
.fullscreen-sheet {
  background: linear-gradient(180deg, rgba(255, 248, 241, 0.12), rgba(255, 248, 241, 0.06));
  backdrop-filter: blur(20px);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow-sm);
}

.deck-option {
  overflow: hidden;
  border-radius: 28px;
}

.deck-preview {
  aspect-ratio: 16 / 10;
}

.deck-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.deck-option-body {
  padding: 18px;
}

.deck-option h2 {
  margin-top: 8px;
  font-size: clamp(2rem, 8vw, 3rem);
}

.deck-option-copy {
  margin: 12px 0 0;
}

.deck-option-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.deck-option-meta span {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 248, 241, 0.08);
  border: 1px solid rgba(255, 231, 214, 0.12);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.deck-enter-btn {
  width: 100%;
  margin-top: 16px;
}

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

.lang-switch-compact {
  margin-top: -6px;
}

.lang-btn {
  min-height: 44px;
  border: 1px solid rgba(255, 231, 214, 0.12);
  border-radius: 14px;
  background: rgba(255, 248, 241, 0.06);
  color: var(--text-muted);
  font-weight: 800;
  cursor: pointer;
}

.lang-btn.is-active {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: #fff6f0;
  border-color: transparent;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: max(8px, env(safe-area-inset-top));
}

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

.metric-card {
  padding: 16px 18px;
  border-radius: var(--radius-md);
}

.metric-value {
  display: block;
  margin-top: 10px;
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  line-height: 1;
}

.card-stage {
  display: grid;
  gap: 14px;
}

.card-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.meta-title {
  margin-top: 6px;
  font-size: clamp(2rem, 7vw, 2.8rem);
}

.icon-btn {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 237, 224, 0.18);
  border-radius: 16px;
  background: rgba(255, 248, 241, 0.08);
  color: var(--text-main);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.icon-btn span {
  font-size: 1.2rem;
  line-height: 1;
}

.card-scene {
  position: relative;
  perspective: 1600px;
  padding: 10px 4px 6px;
}

.card-shadow {
  position: absolute;
  left: 50%;
  width: calc(100% - 24px);
  aspect-ratio: 1038 / 1500;
  border-radius: 30px;
  transform: translateX(-50%);
  pointer-events: none;
}

.card-shadow-a {
  top: 18px;
  background: linear-gradient(180deg, var(--accent), rgba(255, 255, 255, 0.03));
  opacity: 0.18;
  transform: translateX(-50%) rotate(-4deg) scale(0.97);
}

.card-shadow-b {
  top: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.03));
  opacity: 0.35;
  transform: translateX(-50%) rotate(3deg) scale(0.985);
}

.card-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1038 / 1500;
  background: transparent;
  cursor: pointer;
  perspective: 1600px;
}

.card-frame.is-shuffling .card-3d {
  animation: shufflePulse 650ms ease;
}

.card-3d {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-xl);
  transform-style: preserve-3d;
  transition: transform 720ms cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: var(--shadow-xl);
}

.card-frame.is-flipped .card-3d {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: var(--radius-xl);
  backface-visibility: hidden;
}

.card-face-front {
  background: linear-gradient(180deg, #f2e4d8, #ceb59c);
  transform: rotateY(180deg);
}

.card-face-back {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 235, 220, 0.12);
}

.card-back-image,
#card-image,
.card-placeholder {
  width: 100%;
  height: 100%;
}

.card-back-image,
#card-image {
  display: block;
  object-fit: cover;
}

#card-image {
  background: #f4ede4;
}

.card-placeholder {
  display: grid;
  place-content: center;
  gap: 14px;
  padding: 30px;
  text-align: center;
  color: #2d201a;
}

.placeholder-badge {
  justify-self: center;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(91, 55, 37, 0.08);
  font-size: 0.78rem;
  color: #71574e;
}

.card-placeholder h2 {
  font-size: clamp(2rem, 7vw, 2.8rem);
}

.card-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.meta-note {
  margin: 0;
  max-width: 36ch;
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.btn {
  min-height: 58px;
  border: 0;
  border-radius: 18px;
  padding: 16px 14px;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn-primary {
  color: #fff5ef;
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.16);
}

.btn-primary:disabled {
  cursor: not-allowed;
  background: linear-gradient(180deg, rgba(181, 157, 143, 0.6), rgba(149, 132, 123, 0.6));
  box-shadow: none;
}

.btn-secondary,
.btn-ghost {
  color: var(--text-main);
  background: rgba(255, 248, 241, 0.08);
  border: 1px solid rgba(255, 231, 214, 0.12);
}

.btn-ghost {
  background: var(--accent-soft);
}

.about-deck {
  display: grid;
  gap: 12px;
}

.about-card {
  padding: 18px;
  border-radius: var(--radius-lg);
}

.about-card h2 {
  margin-top: 8px;
  font-size: clamp(1.9rem, 7vw, 2.5rem);
}

.about-copy {
  margin: 14px 0 0;
}

.about-list {
  margin: 14px 0 0;
  padding-left: 18px;
}

.about-list li + li {
  margin-top: 10px;
}

.history-panel {
  padding: 16px;
  border-radius: var(--radius-lg);
}

.history-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.history-title,
.fullscreen-title {
  margin-top: 6px;
  font-size: 1.9rem;
}

.history-clear {
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font-weight: 800;
  cursor: pointer;
  padding: 8px 0;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.history-empty {
  margin: 0;
  grid-column: 1 / -1;
  padding: 16px;
  border-radius: 16px;
  background: rgba(255, 248, 241, 0.06);
}

.history-item {
  display: block;
  width: 100%;
  padding: 8px;
  border: 1px solid rgba(255, 231, 214, 0.08);
  border-radius: 18px;
  background: rgba(255, 248, 241, 0.08);
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.history-item img {
  display: block;
  width: 100%;
  aspect-ratio: 1038 / 1500;
  object-fit: cover;
  border-radius: 14px;
}

.history-item strong {
  display: block;
  margin-top: 10px;
  font-size: 0.94rem;
}

.fullscreen-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
}

.fullscreen-modal[hidden] {
  display: none !important;
}

.fullscreen-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 8, 12, 0.78);
  backdrop-filter: blur(14px);
}

.fullscreen-sheet {
  position: relative;
  width: min(100%, 33rem);
  max-height: min(100dvh - 36px, 56rem);
  padding: 16px;
  border-radius: 28px;
}

.fullscreen-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.fullscreen-card-wrap {
  margin-top: 16px;
}

.fullscreen-card {
  display: block;
  width: 100%;
  max-height: calc(100dvh - 180px);
  object-fit: contain;
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
}

.btn:focus-visible,
.history-clear:focus-visible,
.history-item:focus-visible,
.icon-btn:focus-visible,
.card-frame:focus-visible,
.lang-btn:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.28);
  outline-offset: 2px;
}

@keyframes shufflePulse {
  0% { transform: rotateY(0deg) rotateZ(0deg) scale(1); }
  25% { transform: rotateY(0deg) rotateZ(-2deg) scale(0.99); }
  50% { transform: rotateY(0deg) rotateZ(2deg) scale(1.014); }
  100% { transform: rotateY(0deg) rotateZ(0deg) scale(1); }
}

@media (max-width: 400px) {
  .controls {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 430px) {
  .history-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
