:root {
  color-scheme: dark;
  --bg: #101111;
  --surface: #191a18;
  --surface-2: #23231f;
  --line: rgba(238, 230, 204, 0.14);
  --text: #f5efe0;
  --muted: #bcb39d;
  --accent: #e6b95d;
  --accent-2: #74c0a7;
  --danger: #d98672;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

:root.light {
  color-scheme: light;
  --bg: #f6f2e9;
  --surface: #fffaf0;
  --surface-2: #ece3d1;
  --line: rgba(48, 42, 31, 0.16);
  --text: #27231c;
  --muted: #746a5b;
  --accent: #9d6721;
  --accent-2: #26745f;
  --danger: #a64d3b;
  --shadow: 0 22px 56px rgba(94, 71, 41, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 8%, rgba(116, 192, 167, 0.16), transparent 32rem),
    linear-gradient(135deg, #101111 0%, var(--bg) 48%, #17130f 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: 24px;
  width: min(1420px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.oracle-stage,
.reading-panel {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: var(--shadow);
}

.oracle-stage {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: calc(100vh - 48px);
  padding: 24px;
}

.reading-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: calc(100vh - 48px);
  padding: 22px;
}

.topbar,
.reading-header,
.history-title,
.controls-row,
.camera-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 760px;
  margin-bottom: 0;
  font-size: clamp(2.15rem, 5vw, 5.6rem);
  line-height: 0.94;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.4rem;
}

h3 {
  margin-bottom: 0;
  font-size: 1rem;
}

.icon-button,
.primary-button,
.ghost-button,
.segment,
.text-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface-2);
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  place-items: center;
}

.primary-button,
.ghost-button {
  min-height: 44px;
  padding: 0 18px;
  font-weight: 800;
}

.primary-button {
  border-color: color-mix(in srgb, var(--accent) 62%, transparent);
  background: var(--accent);
  color: #18120b;
}

.ghost-button {
  background: transparent;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--muted);
}

.question-panel {
  display: grid;
  gap: 10px;
}

.question-panel label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 84px;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 14px;
  outline: none;
  background: var(--surface-2);
  color: var(--text);
}

textarea:focus {
  border-color: color-mix(in srgb, var(--accent) 70%, transparent);
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(2, 1fr);
  border: 1px solid var(--line);
}

.segment {
  min-width: 76px;
  min-height: 42px;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.segment.active {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.gesture-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.45fr);
  gap: 20px;
  flex: 1;
  min-height: 430px;
}

.camera-card,
.deck-zone {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
}

.camera-card {
  display: grid;
  grid-template-rows: 1fr auto;
}

.camera-frame {
  position: relative;
  overflow: hidden;
  min-height: 360px;
  background:
    linear-gradient(90deg, rgba(230, 185, 93, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(116, 192, 167, 0.08) 1px, transparent 1px),
    #0c0d0c;
  background-size: 36px 36px;
}

#cameraVideo,
#motionCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#cameraVideo {
  opacity: 0.42;
}

#motionCanvas {
  opacity: 0.62;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.camera-overlay p {
  position: absolute;
  bottom: 20px;
  width: min(88%, 560px);
  margin: 0;
  color: var(--muted);
  text-align: center;
}

.portal-ring {
  width: min(46vw, 360px);
  aspect-ratio: 1;
  border: 2px solid rgba(230, 185, 93, 0.56);
  border-radius: 50%;
  box-shadow:
    0 0 0 16px rgba(230, 185, 93, 0.045),
    0 0 70px rgba(116, 192, 167, 0.22),
    inset 0 0 42px rgba(230, 185, 93, 0.14);
}

.portal-ring.active {
  animation: pulse 0.7s ease-out;
}

@keyframes pulse {
  0% {
    transform: scale(0.92);
  }
  100% {
    transform: scale(1.08);
  }
}

.camera-actions {
  padding: 14px;
}

.meter {
  position: relative;
  flex: 1;
  height: 8px;
  overflow: hidden;
  background: var(--surface-2);
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 120ms ease;
}

.deck-zone {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 18px;
  padding: 24px;
}

.deck {
  position: relative;
  width: min(62vw, 220px);
  aspect-ratio: 0.66;
  outline: none;
}

.deck-card {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(230, 185, 93, 0.38);
  background:
    radial-gradient(circle at 50% 32%, rgba(230, 185, 93, 0.38), transparent 15%),
    repeating-linear-gradient(45deg, rgba(116, 192, 167, 0.25) 0 2px, transparent 2px 14px),
    linear-gradient(155deg, #25231e, #101111 68%);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.32);
  transition:
    transform 220ms ease,
    box-shadow 220ms ease;
}

.deck-card::after {
  content: "";
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(245, 239, 224, 0.24);
}

.card-a {
  transform: rotate(-7deg) translate(-12px, 8px);
}

.card-b {
  transform: rotate(4deg) translate(8px, 2px);
}

.card-c {
  transform: rotate(0);
}

.deck:hover .card-a,
.deck:focus-visible .card-a {
  transform: rotate(-12deg) translate(-28px, 10px);
}

.deck:hover .card-b,
.deck:focus-visible .card-b {
  transform: rotate(9deg) translate(24px, 0);
}

.deck-hint {
  margin-bottom: 0;
  color: var(--muted);
  text-align: center;
}

.cards-result {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 12px;
}

.empty-state {
  grid-column: 1 / -1;
  display: grid;
  min-height: 240px;
  place-items: center;
  border: 1px dashed var(--line);
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.mini-card,
.tarot-card {
  aspect-ratio: 0.68;
  border: 1px solid color-mix(in srgb, var(--accent) 42%, var(--line));
  background:
    radial-gradient(circle at 50% 30%, rgba(230, 185, 93, 0.24), transparent 28%),
    linear-gradient(160deg, color-mix(in srgb, var(--surface-2) 78%, #2f5e51), var(--surface));
}

.mini-card {
  width: 82px;
}

.tarot-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 212px;
  padding: 12px;
}

.tarot-card.reversed {
  background:
    radial-gradient(circle at 50% 70%, rgba(217, 134, 114, 0.2), transparent 29%),
    linear-gradient(25deg, color-mix(in srgb, var(--surface-2) 70%, #623d36), var(--surface));
}

.card-symbol {
  display: grid;
  flex: 1;
  place-items: center;
  font-size: clamp(2rem, 7vw, 3.8rem);
}

.card-name {
  font-weight: 900;
}

.card-role,
.card-orientation {
  color: var(--muted);
  font-size: 0.82rem;
}

.interpretation {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
  line-height: 1.72;
}

.interpretation p {
  margin-bottom: 0;
}

.history-panel {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: 220px;
  overflow: auto;
  margin-top: 12px;
}

.history-item {
  border: 1px solid var(--line);
  padding: 10px;
  background: rgba(255, 255, 255, 0.025);
}

.history-item button {
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.history-item small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .oracle-stage,
  .reading-panel {
    min-height: auto;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 12px;
  }

  .oracle-stage,
  .reading-panel {
    padding: 16px;
  }

  .gesture-grid {
    grid-template-columns: 1fr;
  }

  .camera-frame {
    min-height: 310px;
  }

  .controls-row,
  .camera-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented,
  .primary-button,
  .ghost-button {
    width: 100%;
  }
}
