:root {
  --bg: #070914;
  --panel: rgba(255,255,255,.09);
  --panel-2: rgba(255,255,255,.14);
  --text: #f7f9ff;
  --muted: #b8c1df;
  --gold: #ffd64d;
  --orange: #ff8a1c;
  --blue: #42d6ff;
  --red: #ff465f;
  --green: #76ff8f;
  --radius: 24px;
  --shadow: 0 18px 46px rgba(0,0,0,.38);
}

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

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 5%, rgba(66,214,255,.22), transparent 28%),
    radial-gradient(circle at 90% 8%, rgba(255,214,77,.20), transparent 25%),
    radial-gradient(circle at 50% 90%, rgba(255,70,95,.18), transparent 34%),
    linear-gradient(160deg, #070914, #121a3f 52%, #070914);
  overflow-x: hidden;
}

.stars {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .7;
  background-image:
    radial-gradient(circle, rgba(255,255,255,.9) 1px, transparent 1.7px),
    radial-gradient(circle, rgba(255,255,255,.35) 1px, transparent 1.9px);
  background-size: 44px 44px, 82px 82px;
  animation: drift 22s linear infinite;
}

@keyframes drift {
  from { transform: translateY(0); }
  to { transform: translateY(90px); }
}

@keyframes pop {
  from { transform: scale(.96); opacity: .4; }
  to { transform: scale(1); opacity: 1; }
}

.app {
  position: relative;
  z-index: 1;
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 18px 14px 30px;
  min-height: 100vh;
}

header {
  padding-top: env(safe-area-inset-top);
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.orb {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff5b7, var(--gold) 34%, #ff8a1c 70%, #bd4300);
  display: grid;
  place-items: center;
  color: #562000;
  font-weight: 950;
  box-shadow: 0 0 26px rgba(255,214,77,.54), inset -8px -10px 18px rgba(90,32,0,.32);
  flex: 0 0 auto;
}

h1 {
  margin: 0;
  font-size: 1.22rem;
  letter-spacing: .2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subtitle {
  margin: 2px 0 0;
  font-size: .78rem;
  color: var(--muted);
}

.chip {
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.08);
  border-radius: 999px;
  padding: 8px 11px;
  color: var(--muted);
  font-size: .76rem;
  backdrop-filter: blur(14px);
  white-space: nowrap;
}

.search-box {
  position: sticky;
  top: 0;
  z-index: 4;
  padding: 8px 0 12px;
  background: linear-gradient(to bottom, rgba(7,9,20,.95), rgba(7,9,20,.65), transparent);
  backdrop-filter: blur(8px);
}

.search {
  width: 100%;
  padding: 15px 16px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,.16);
  outline: none;
  color: var(--text);
  background: rgba(255,255,255,.10);
  font: inherit;
  box-shadow: 0 10px 24px rgba(0,0,0,.16);
}

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

.card {
  min-height: 188px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(255,255,255,.13), rgba(255,255,255,.055));
  box-shadow: 0 12px 32px rgba(0,0,0,.22);
  overflow: hidden;
  position: relative;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  padding: 0;
}

.card:active { transform: scale(.985); }

.thumb {
  height: 118px;
  background:
    radial-gradient(circle at 50% 45%, rgba(255,214,77,.22), transparent 38%),
    linear-gradient(135deg, rgba(66,214,255,.18), rgba(255,138,28,.12));
  display: grid;
  place-items: center;
  overflow: hidden;
}

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

.placeholder {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2.1rem;
  font-weight: 950;
  color: #4a2100;
  background: radial-gradient(circle at 35% 30%, #fff5b7, var(--gold) 40%, #ff8a1c);
  box-shadow: 0 0 30px rgba(255,214,77,.35);
}

.card-content { padding: 12px; }
.card h2 { margin: 0; font-size: 1rem; }

.meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.3;
}

.tag {
  position: absolute;
  top: 10px;
  right: 10px;
  border-radius: 999px;
  padding: 6px 8px;
  font-size: .68rem;
  font-weight: 850;
  color: #160b00;
  background: linear-gradient(135deg, #ffe06a, #ff8a1c);
  box-shadow: 0 8px 18px rgba(0,0,0,.22);
}

.detail {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  background: rgba(3,5,13,.74);
  backdrop-filter: blur(16px);
  padding: 14px;
  overflow: auto;
}

.detail.show { display: block; animation: pop .18s ease-out; }

.detail-card {
  width: min(100%, 720px);
  margin: 0 auto;
  border-radius: 32px;
  border: 1px solid rgba(255,255,255,.17);
  background:
    radial-gradient(circle at 25% 8%, rgba(66,214,255,.18), transparent 30%),
    linear-gradient(145deg, rgba(18,26,63,.98), rgba(7,9,20,.98));
  box-shadow: var(--shadow);
  overflow: hidden;
}

.detail-hero {
  min-height: 340px;
  background:
    radial-gradient(circle at 50% 40%, rgba(255,214,77,.22), transparent 35%),
    linear-gradient(135deg, rgba(66,214,255,.14), rgba(255,138,28,.12));
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.image-stage {
  width: 100%;
  height: 390px;
  overflow: hidden;
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: grab;
  background:
    radial-gradient(circle at 50% 40%, rgba(255,214,77,.14), transparent 35%),
    rgba(0,0,0,.12);
}

.image-stage:active { cursor: grabbing; }

.detail-hero img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transform-origin: center center;
  transition: transform .08s linear;
  user-select: none;
  -webkit-user-drag: none;
}

.close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 14px);
  left: 14px;
  z-index: 3;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.38);
  color: white;
  border-radius: 999px;
  padding: 10px 13px;
  font-weight: 900;
  backdrop-filter: blur(14px);
  cursor: pointer;
}

.carousel-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 14px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 14px;
  pointer-events: none;
}

.carousel-btn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.2);
  background: rgba(0,0,0,.42);
  color: white;
  font-size: 1.35rem;
  font-weight: 950;
  backdrop-filter: blur(14px);
  cursor: pointer;
}

.carousel-counter {
  pointer-events: auto;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  padding: 9px 12px;
  background: rgba(0,0,0,.42);
  color: white;
  font-size: .78rem;
  font-weight: 800;
  backdrop-filter: blur(14px);
}

.zoom-controls {
  position: absolute;
  right: 14px;
  bottom: 70px;
  z-index: 3;
  display: grid;
  gap: 8px;
}

.zoom-btn {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.2);
  background: rgba(0,0,0,.42);
  color: white;
  font-size: 1.1rem;
  font-weight: 950;
  backdrop-filter: blur(14px);
  cursor: pointer;
}

.main-badge {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 14px);
  right: 14px;
  z-index: 3;
  border-radius: 999px;
  padding: 9px 12px;
  color: #160b00;
  background: linear-gradient(135deg, #ffe06a, #ff8a1c);
  font-size: .75rem;
  font-weight: 950;
  box-shadow: 0 8px 18px rgba(0,0,0,.25);
}

.detail-body { padding: 18px; }

.detail-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.detail h2 {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: -.5px;
}

.power {
  color: var(--blue);
  font-size: .82rem;
  font-weight: 900;
  text-align: right;
  white-space: nowrap;
}

.bio {
  color: var(--muted);
  line-height: 1.5;
  margin: 10px 0 14px;
}

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.fact {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px;
  padding: 12px;
}

.fact strong {
  display: block;
  font-size: .75rem;
  color: var(--muted);
  margin-bottom: 3px;
}

.fact span {
  font-weight: 850;
  font-size: .94rem;
}

.tools {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.input {
  width: 100%;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.16);
  padding: 14px;
  outline: none;
  color: var(--text);
  background: rgba(255,255,255,.09);
  font: inherit;
}

.btn {
  border: 0;
  border-radius: 18px;
  padding: 14px;
  font-weight: 950;
  color: #160b00;
  background: linear-gradient(135deg, #ffe06a, #ff8a1c 65%, #ff465f);
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(0,0,0,.28);
}

.btn.alt {
  color: var(--text);
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.15);
  backdrop-filter: blur(14px);
}

.btn.danger {
  color: white;
  background: rgba(255,70,95,.22);
  border: 1px solid rgba(255,70,95,.45);
}

.btn:active { transform: scale(.985); }

.note {
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.45;
  margin: 8px 0 0;
}

.saved-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 800;
}

.saved {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.saved-item {
  position: relative;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px;
  overflow: hidden;
  padding: 0;
  height: 82px;
  background: rgba(255,255,255,.07);
  cursor: pointer;
}

.saved-item.active {
  border-color: rgba(66,214,255,.9);
  box-shadow: 0 0 0 2px rgba(66,214,255,.22);
}

.saved-item.main {
  border-color: rgba(255,214,77,.95);
  box-shadow: 0 0 0 2px rgba(255,214,77,.22);
}

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

.mini-star {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffe06a, #ff8a1c);
  color: #160b00;
  font-size: .8rem;
  font-weight: 950;
}

.video-section,
.movie-section {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.12);
}

.video-stage {
  margin-top: 10px;
  border-radius: 22px;
  overflow: hidden;
  background: rgba(0,0,0,.34);
  border: 1px solid rgba(255,255,255,.14);
  min-height: 220px;
  display: grid;
  place-items: center;
  position: relative;
}

.video-stage video {
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  background: black;
  display: block;
}

.video-empty {
  color: var(--muted);
  text-align: center;
  padding: 34px 18px;
  line-height: 1.4;
  font-size: .9rem;
}

.video-controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.video-counter {
  margin-top: 8px;
  color: var(--muted);
  text-align: center;
  font-size: .8rem;
  font-weight: 800;
}

.media-label {
  display: block;
  text-align: center;
  border-radius: 18px;
  padding: 14px;
  font-weight: 950;
  color: #160b00;
  background: linear-gradient(135deg, #ffe06a, #ff8a1c 65%, #ff465f);
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(0,0,0,.28);
}

.file-input { display: none; }

.music-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.music-status {
  color: var(--muted);
  font-size: .78rem;
  text-align: center;
  min-height: 1rem;
}

.movie-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.movie-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.movie-item {
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 16px;
  padding: 11px;
  background: rgba(255,255,255,.08);
  color: var(--text);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.movie-item strong {
  display: block;
  font-size: .86rem;
}

.movie-item span {
  display: block;
  color: var(--muted);
  font-size: .72rem;
  margin-top: 2px;
}

.movie-actions {
  display: flex;
  gap: 6px;
}

.movie-mini-btn {
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  padding: 8px 9px;
  background: rgba(255,255,255,.10);
  color: var(--text);
  font-size: .76rem;
  font-weight: 900;
  cursor: pointer;
}

.recording-badge {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 58px);
  right: 14px;
  z-index: 3;
  display: none;
  border-radius: 999px;
  padding: 8px 11px;
  color: white;
  background: rgba(255,70,95,.72);
  font-size: .72rem;
  font-weight: 950;
  box-shadow: 0 8px 18px rgba(0,0,0,.25);
  backdrop-filter: blur(14px);
}

.recording-badge.show { display: block; }

.storyboard-editor,
.movie-player,
.slideshow {
  position: fixed;
  inset: 0;
  color: white;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 10%, rgba(255,211,77,.16), transparent 32%),
    radial-gradient(circle at 80% 8%, rgba(55,215,255,.14), transparent 30%),
    rgba(2,4,12,.97);
}

.slideshow {
  z-index: 40;
}

.movie-player {
  z-index: 60;
}

.storyboard-editor {
  z-index: 55;
}

.storyboard-editor,
.movie-player,
.slideshow {
  display: none;
}

.storyboard-editor.show,
.movie-player.show,
.slideshow.show {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.storyboard-editor.show {
  display: block;
}

.storyboard-top,
.movie-player-top,
.slideshow-top {
  padding: calc(env(safe-area-inset-top) + 14px) 14px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  z-index: 2;
}

.storyboard-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
}

.storyboard-title strong,
.movie-player-title strong,
.slideshow-title strong {
  display: block;
  font-size: 1rem;
}

.storyboard-title span,
.movie-player-title span,
.slideshow-title span {
  display: block;
  color: rgba(255,255,255,.68);
  font-size: .78rem;
  margin-top: 2px;
}

.slideshow-title {
  min-width: 0;
}

.slideshow-title strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slideshow-close {
  border: 1px solid rgba(255,255,255,.22);
  background: rgba(255,255,255,.12);
  color: white;
  border-radius: 999px;
  padding: 10px 13px;
  font-weight: 900;
  backdrop-filter: blur(14px);
  cursor: pointer;
}

.storyboard-stage,
.movie-player-stage,
.slideshow-stage {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 0;
}

.storyboard-stage {
  position: absolute;
  inset: 0;
  touch-action: none;
  background: rgba(0,0,0,.25);
}

.storyboard-stage img,
.movie-player-stage img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}

.slideshow-stage {
  padding: 8px 14px;
}

.slideshow-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 22px;
  box-shadow: 0 24px 80px rgba(0,0,0,.55);
  opacity: 0;
  transform: scale(.985);
  transition: opacity .7s ease, transform .7s ease;
}

.slideshow-stage img.visible {
  opacity: 1;
  transform: scale(1);
}

.storyboard-bottom,
.movie-player-bottom,
.slideshow-bottom {
  padding: 12px 14px calc(env(safe-area-inset-bottom) + 14px);
  display: grid;
  gap: 10px;
  background: linear-gradient(to top, rgba(0,0,0,.62), transparent);
}

.storyboard-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  max-height: min(48vh, 380px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.storyboard-bottom::-webkit-scrollbar {
  width: 6px;
}

.storyboard-bottom::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.24);
  border-radius: 999px;
}

.storyboard-controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.storyboard-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.storyboard-single-action {
  display: grid;
  grid-template-columns: 1fr;
}

.storyboard-fields {
  display: grid;
  grid-template-columns: 1fr 130px;
  gap: 8px;
}

.storyboard-add-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.storyboard-thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.storyboard-thumbs::-webkit-scrollbar { display: none; }

.storyboard-thumb {
  width: 74px;
  height: 58px;
  flex: 0 0 auto;
  border-radius: 13px;
  border: 1px solid rgba(255,255,255,.18);
  overflow: hidden;
  background: rgba(255,255,255,.08);
  position: relative;
  cursor: pointer;
}

.storyboard-thumb.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(255,211,77,.28);
}

.storyboard-thumb.dragging {
  opacity: .45;
}

.storyboard-thumb.drag-target {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(66,214,255,.36);
}

.storyboard-thumb.saved::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: #06210a;
  font-size: .72rem;
  font-weight: 950;
}

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

.storyboard-note {
  color: rgba(255,255,255,.70);
  font-size: .76rem;
  line-height: 1.35;
  text-align: center;
}

.movie-progress,
.slideshow-progress {
  height: 5px;
  border-radius: 999px;
  background: rgba(255,255,255,.18);
  overflow: hidden;
}

.movie-progress-bar,
.slideshow-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--orange), var(--gold), var(--blue));
}

.slideshow-progress-bar {
  transition: width .2s linear;
}

.slideshow-controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 9px;
}

.slideshow-btn,
.slideshow-music-label {
  border: 1px solid rgba(255,255,255,.20);
  background: rgba(255,255,255,.13);
  color: white;
  border-radius: 18px;
  padding: 12px 10px;
  font-weight: 900;
  text-align: center;
  backdrop-filter: blur(14px);
  cursor: pointer;
  font: inherit;
}

.slideshow-music-label { display: block; }

.slideshow-settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  align-items: center;
}

.slideshow-select {
  width: 100%;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.20);
  padding: 12px 10px;
  color: white;
  background: rgba(255,255,255,.13);
  outline: none;
  font: inherit;
  backdrop-filter: blur(14px);
}

.slideshow-select option { color: #222; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 20;
  width: min(calc(100% - 28px), 460px);
  border-radius: 18px;
  padding: 13px 14px;
  background: rgba(0,0,0,.72);
  border: 1px solid rgba(255,255,255,.16);
  color: var(--text);
  box-shadow: var(--shadow);
  display: none;
  text-align: center;
  backdrop-filter: blur(16px);
}

.toast.show { display: block; }

@media (min-width: 680px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
  .row { grid-template-columns: 1fr auto; }
  .saved { grid-template-columns: repeat(6, 1fr); }
}
