:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111318;
  color: #f4f0e8;
  --panel: #1c2027;
  --panel-strong: #252b33;
  --line: rgba(255, 255, 255, 0.12);
  --text-soft: #b9bec7;
  --accent: #f4b35f;
  --accent-strong: #ffcf7a;
  --ok: #6ad7b7;
  --danger: #ff7b86;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(145deg, rgba(244, 179, 95, 0.14), transparent 28%),
    radial-gradient(circle at 82% 12%, rgba(106, 215, 183, 0.12), transparent 24%),
    #111318;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.shell {
  display: grid;
  place-items: start center;
  min-height: 100vh;
  padding: 24px;
}

.card {
  width: min(760px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(18, 21, 27, 0.88);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.28);
}

.card p {
  color: var(--text-soft);
  line-height: 1.65;
}

.card h2 {
  margin-top: 24px;
}

.stage,
.control-panel {
  border: 1px solid var(--line);
  background: rgba(18, 21, 27, 0.82);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.35);
}

.stage {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: calc(100vh - 36px);
  border-radius: 8px;
}

.top-bar,
.result-header {
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.2rem, 3vw, 2rem);
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
}

.credit-pill {
  flex: 0 0 auto;
  padding: 9px 12px;
  border: 1px solid rgba(244, 179, 95, 0.45);
  border-radius: 999px;
  background: rgba(244, 179, 95, 0.1);
  color: #ffe0ab;
  font-weight: 700;
}

.camera-view,
.processing-view,
.result-view {
  position: relative;
  min-height: 0;
}

.camera-view {
  overflow: hidden;
  margin: 0 18px 18px;
  border-radius: 8px;
  background: #07080b;
}

#cameraFeed,
#uploadPreview {
  width: 100%;
  height: 100%;
  min-height: 620px;
  object-fit: cover;
  display: block;
}

#uploadPreview {
  position: absolute;
  inset: 0;
}

.preview-overlay {
  pointer-events: none;
  position: absolute;
  inset: 0;
  mix-blend-mode: screen;
  opacity: 0.68;
}

.preview-overlay::before,
.preview-overlay::after {
  content: "";
  position: absolute;
  inset: 0;
}

.preview-overlay::before {
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.16), transparent);
  transform: translateX(-100%);
  animation: scan 7s linear infinite;
}

.preview-overlay::after {
  border: 2px solid rgba(255, 255, 255, 0.26);
  border-radius: 45% 45% 38% 38%;
  width: min(34vw, 260px);
  height: min(44vw, 340px);
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 36px rgba(255, 255, 255, 0.12);
}

@keyframes scan {
  to {
    transform: translateX(100%);
  }
}

.warm-animation {
  background: radial-gradient(circle at 52% 36%, rgba(255, 209, 134, 0.18), transparent 28%), linear-gradient(135deg, rgba(242, 143, 91, 0.34), rgba(91, 183, 198, 0.12));
}

.fantasy-portrait {
  background: radial-gradient(circle at 50% 35%, rgba(163, 124, 255, 0.22), transparent 28%), linear-gradient(145deg, rgba(82, 198, 170, 0.16), rgba(244, 209, 123, 0.28));
}

.space-explorer {
  background: radial-gradient(circle at 68% 18%, rgba(255, 255, 255, 0.24), transparent 8%), linear-gradient(145deg, rgba(56, 92, 170, 0.35), rgba(28, 26, 44, 0.1));
}

.cyberpunk-character {
  background: repeating-linear-gradient(90deg, rgba(255, 49, 138, 0.16) 0 2px, transparent 2px 12px), linear-gradient(135deg, rgba(0, 224, 255, 0.26), rgba(255, 49, 138, 0.22));
}

.storybook-illustration {
  background: radial-gradient(circle at 35% 28%, rgba(255, 238, 172, 0.22), transparent 30%), linear-gradient(145deg, rgba(132, 203, 151, 0.2), rgba(237, 165, 122, 0.18));
}

.classic-comic {
  background: radial-gradient(circle, rgba(255, 244, 128, 0.2) 1px, transparent 2px), linear-gradient(135deg, rgba(231, 68, 68, 0.26), rgba(47, 119, 209, 0.18));
  background-size: 12px 12px, auto;
}

.movie-poster {
  background: linear-gradient(180deg, rgba(255, 214, 128, 0.2), rgba(47, 78, 112, 0.22) 50%, rgba(0, 0, 0, 0.22));
}

.cute-mascot {
  background: radial-gradient(circle at 24% 22%, rgba(255, 163, 204, 0.25), transparent 22%), radial-gradient(circle at 78% 18%, rgba(126, 223, 194, 0.2), transparent 20%);
}

.watercolor {
  background: radial-gradient(circle at 44% 40%, rgba(123, 197, 225, 0.24), transparent 30%), radial-gradient(circle at 62% 55%, rgba(255, 190, 151, 0.2), transparent 28%);
  filter: blur(0.2px);
}

.future-hero {
  background: linear-gradient(135deg, rgba(98, 255, 203, 0.25), transparent 34%), linear-gradient(315deg, rgba(255, 203, 98, 0.2), transparent 40%);
}

.preview-note {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(8, 10, 14, 0.72);
  color: #e9edf2;
  font-size: 0.84rem;
}

.camera-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--text-soft);
  background: linear-gradient(145deg, #171a22, #090a0d);
}

.camera-fallback strong {
  color: #fff;
  font-size: 1.2rem;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  max-height: calc(100vh - 36px);
  padding: 16px;
  border-radius: 8px;
}

.panel-section {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.panel-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-heading span {
  color: var(--text-soft);
  font-size: 0.8rem;
}

.style-rail {
  display: grid;
  gap: 8px;
}

.style-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.style-card[aria-selected="true"] {
  border-color: rgba(244, 179, 95, 0.7);
  background: rgba(244, 179, 95, 0.12);
}

.style-swatch {
  width: 42px;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.style-card strong {
  display: block;
  font-size: 0.93rem;
}

.style-card span {
  display: block;
  margin-top: 3px;
  color: var(--text-soft);
  font-size: 0.78rem;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  grid-column: span 2;
  background: var(--accent);
  color: #17110a;
}

.test-credit-button {
  grid-column: span 2;
}

.secondary-button,
.icon-button {
  background: var(--panel-strong);
  color: #fff;
  border: 1px solid var(--line);
}

.icon-button {
  width: 44px;
  flex: 0 0 44px;
}

.status-card {
  color: var(--text-soft);
  font-size: 0.9rem;
  line-height: 1.5;
}

.processing-view {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  padding: 36px;
  text-align: center;
}

.progress-ring {
  width: 78px;
  aspect-ratio: 1;
  border: 7px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.progress-track {
  overflow: hidden;
  width: min(420px, 72vw);
  height: 10px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--ok));
  transition: width 0.25s ease;
}

.result-view {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding-bottom: 18px;
}

.compare-frame {
  position: relative;
  overflow: hidden;
  width: min(720px, calc(100% - 36px));
  height: min(72vh, 760px);
  justify-self: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #050608;
  touch-action: none;
}

.compare-frame img,
.after-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.compare-frame img {
  object-fit: cover;
}

.after-layer {
  overflow: hidden;
  clip-path: inset(0 0 0 52%);
}

.after-layer img {
  filter: saturate(1.18) contrast(1.08);
}

.compare-slider {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: ew-resize;
}

.compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 52%;
  width: 2px;
  background: #fff;
  transform: translateX(-1px);
  pointer-events: none;
}

.compare-handle span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  aspect-ratio: 1;
  border: 2px solid #fff;
  border-radius: 50%;
  background: rgba(17, 19, 24, 0.74);
  transform: translate(-50%, -50%);
}

.compare-handle span::before {
  content: "↔";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 900;
}

.compare-label {
  position: absolute;
  top: 12px;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 800;
}

.compare-label.before {
  left: 12px;
}

.compare-label.after {
  right: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 20;
  max-width: min(520px, calc(100vw - 28px));
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(28, 32, 39, 0.94);
  color: #fff;
  transform: translate(-50%, 80px);
  opacity: 0;
  transition: 0.2s ease;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mode-pill {
  flex: 0 0 auto;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-soft);
  font-size: 0.8rem;
  font-weight: 800;
}

.camera-tools {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 5;
  display: flex;
  gap: 8px;
}

.tool-button {
  display: grid;
  place-items: center;
  width: 42px;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(8, 10, 14, 0.68);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 900;
  cursor: pointer;
  backdrop-filter: blur(12px);
}

.text-button {
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  color: var(--text-soft);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.consent-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 9px;
  margin-bottom: 10px;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.35;
}

.consent-row input {
  margin-top: 2px;
  accent-color: var(--accent);
}

.result-header {
  justify-content: flex-start;
}

.result-meta {
  display: block;
  margin-top: 4px;
  color: var(--text-soft);
  font-size: 0.82rem;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-empty {
  padding: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  color: var(--text-soft);
  font-size: 0.85rem;
  text-align: center;
}

.history-item {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.history-item img {
  width: 52px;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 7px;
}

.history-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.88rem;
}

.history-item span {
  display: block;
  margin-top: 2px;
  color: var(--text-soft);
  font-size: 0.76rem;
}

.history-item b {
  color: var(--accent-strong);
  font-size: 0.72rem;
  text-transform: uppercase;
}

@media (max-width: 920px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 0;
  }

  .stage {
    min-height: 64vh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .top-bar {
    padding: 14px;
  }

  h1 {
    font-size: 1.08rem;
  }

  .camera-view {
    margin: 0 10px 10px;
  }

  #cameraFeed,
  #uploadPreview {
    min-height: 52vh;
  }

  .control-panel {
    max-height: none;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .style-rail {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
    scroll-snap-type: x mandatory;
  }

  .style-card {
    min-width: 218px;
    scroll-snap-align: start;
  }

  .compare-frame {
    width: calc(100% - 20px);
    height: 56vh;
  }
}

@media (max-width: 520px) {
  .credit-pill {
    padding: 7px 9px;
    font-size: 0.78rem;
  }

  .action-grid {
    grid-template-columns: 1fr;
  }

  .primary-button {
    grid-column: span 1;
  }

  .test-credit-button {
    grid-column: span 1;
  }
}
