:root {
  color-scheme: dark;
  --bg: #000;
  --text: #f6f6f4;
  --muted: #898989;
  --muted-2: #5f5f5f;
  --faint: #363636;
  --surface: #1a1a1a;
  --surface-2: #0a0a0a;
  --line: #252525;
  --accent: #c8ff00;
  --danger: #ff5e5e;
  --radius: 18px;
  --pill: 999px;
  --nav-height: 68px;
  --tg-content-top: 0px;
  --tg-safe-bottom: 0px;
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-bottom));
  --app-height: 100vh;
  --shell-top: max(env(safe-area-inset-top, 0px), calc(var(--tg-content-top) + 12px), 24px);
  --studio-bottom-space: 176px;
  --settings-menu-left: 0px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100vh;
  height: -webkit-fill-available;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
}

body {
  position: fixed;
  inset: 0;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.25 "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.studio-active,
body.result-active,
body.balance-active {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  appearance: none;
  border: 0;
  cursor: pointer;
}

button:disabled,
input:disabled,
textarea:disabled {
  cursor: default;
  opacity: .6;
}

svg {
  display: block;
}

svg path,
svg circle {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.hidden,
.visually-hidden {
  display: none !important;
}

.app-shell {
  position: relative;
  width: min(100%, 430px);
  height: var(--app-height);
  min-height: var(--app-height);
  margin: 0 auto;
  overflow: hidden;
  padding: var(--shell-top) 15px var(--safe-bottom);
  background: #000;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

body.result-active .result-view.active,
body.balance-active .balance-view.active {
  position: relative;
  display: flex;
  flex-direction: column;
  height: calc(var(--app-height) - var(--shell-top) - var(--nav-height) - 12px - var(--safe-bottom));
  padding-bottom: 12px;
}

body.result-active .result-view.active {
  overflow: auto;
}

body.balance-active .balance-view.active {
  overflow: hidden;
}

body.studio-active .studio-view.active {
  display: flex;
  flex-direction: column;
  height: calc(var(--app-height) - var(--shell-top) - var(--studio-bottom-space) - var(--safe-bottom));
  overflow: hidden;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 7px;
  color: var(--accent);
}

.logo-mark {
  display: block;
  width: 31px;
  height: 31px;
  flex: 0 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 32%, #fff 0 8%, transparent 9%),
    linear-gradient(135deg, #ff6f91, #7f5cff 55%, #00d9a6);
}

.brand {
  color: var(--accent);
  font-size: 26px;
  line-height: 1;
  font-weight: 700;
  white-space: nowrap;
}

.balance-wrap {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 11px;
}

.balance-label {
  color: var(--muted);
  font-size: 17px;
  white-space: nowrap;
}

.balance-pill {
  display: inline-flex;
  align-items: center;
  min-width: 118px;
  height: 38px;
  padding: 2px 2px 2px 18px;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  background: #050505;
  color: var(--text);
}

.balance-pill span:first-child {
  min-width: 58px;
  color: var(--text);
  font-size: 17px;
  text-align: center;
  white-space: nowrap;
}

.plus-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-left: 8px;
  border-radius: 50%;
  background: #1b1b1b;
  color: var(--accent);
  font-size: 34px;
  font-weight: 400;
  line-height: .82;
}

.control-block {
  margin-bottom: 12px;
}

.generation-selector {
  display: grid;
  grid-template-columns: 122px minmax(0, 1fr);
  gap: 7px;
  margin-bottom: 12px;
}

.model-balance-pill,
.model-select-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  background: #020202;
}

.model-select-wrap {
  position: relative;
  min-width: 0;
}

.model-balance-pill {
  width: 100%;
  min-width: 0;
  height: 46px;
  padding-left: 14px;
  justify-content: space-between;
}

.model-balance-pill span:first-child {
  min-width: 0;
  flex: 1 1 auto;
}

.model-balance-pill .plus-mark {
  margin-left: 10px;
}

.model-select-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  width: 100%;
  padding: 0 16px;
  color: var(--text);
  text-align: left;
}

.model-select-button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-select-button small {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.mode-block {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-height: 46px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  background: #020202;
  margin-bottom: 14px;
}

.mode-tab {
  border-radius: var(--pill);
  background: transparent;
  color: var(--muted);
}

.mode-tab.active {
  background: var(--surface);
  color: var(--text);
}

.media-panel {
  margin-bottom: 20px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #0a0a0a;
}

.reference-status-row {
  display: grid;
  grid-template-columns: auto auto auto 34px;
  align-items: center;
  gap: 15px;
  min-height: 28px;
  padding: 0 15px;
  margin-bottom: 20px;
}

.keyframe-label-row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.reference-status {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted-2);
  font-size: 13px;
  white-space: nowrap;
}

.reference-status.active {
  color: var(--accent);
}

.reference-status svg,
.icon-button svg,
.swap-button svg,
.expand-prompt-button svg,
.clear-prompt-button svg,
.round-button svg,
.result-info-button svg,
.video-fullscreen-button svg,
.nav-button svg {
  width: 20px;
  height: 20px;
}

.reference-status svg {
  width: 23px;
  height: 23px;
  flex: 0 0 auto;
}

.swap-button,
.round-button,
.result-info-button,
.video-fullscreen-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #050505;
  color: var(--text);
}

.icon-button,
.trash-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  color: #bdbdbd;
}

.reference-rail {
  display: flex;
  gap: 13px;
  width: calc(100% + 15px);
  margin-right: -15px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.reference-rail::-webkit-scrollbar,
.chip-options::-webkit-scrollbar {
  display: none;
}

.reference-preview-grid {
  display: flex;
  flex: 0 0 auto;
  gap: 13px;
}

.reference-preview-card,
.reference-add-card,
.reference-empty-card,
.frame-card {
  position: relative;
  flex: 0 0 auto;
  width: 130px;
  height: 94px;
  border-radius: 18px;
  overflow: hidden;
}

.reference-preview-card,
.reference-add-card {
  border: 1px solid var(--line);
  background: #050505;
}

.reference-empty-card {
  border: 1px dashed rgba(255, 255, 255, .08);
  background: rgba(255, 255, 255, .02);
}

.reference-preview-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reference-preview-meta {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 10px;
}

.reference-preview-meta strong {
  display: block;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-preview-meta span {
  color: var(--muted);
  font-size: 11px;
}

.reference-kind {
  color: var(--accent);
  font-size: 11px;
  text-transform: uppercase;
}

.reference-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .72);
  color: #fff;
  font-size: 18px;
  line-height: 1;
}

.reference-add-card {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 38px;
}

.keyframe-label-row span {
  color: var(--muted);
  font-size: 13px;
}

.keyframe-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.frame-card {
  border: 1px solid var(--line);
  background: #050505;
}

.frame-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
}

.frame-card.has-preview .frame-thumb {
  opacity: 1;
}

.frame-add {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 42px;
}

.frame-card.has-preview .frame-add {
  display: none;
}

.prompt-card {
  position: relative;
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: #0a0a0a;
}

.prompt-input {
  width: 100%;
  min-height: 160px;
  padding: 0 40px 0 0;
  border: 0;
  resize: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  line-height: 1.45;
}

.prompt-input::placeholder {
  color: var(--muted-2);
}

.expand-prompt-button {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .04);
  color: var(--muted);
}

.generation-dock {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 17px + var(--safe-bottom));
  z-index: 30;
  width: min(calc(100vw - 30px), 400px);
  transform: translateX(-50%);
  display: grid;
  gap: 12px;
  padding-top: 76px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0), #000 42px, #000 100%);
  pointer-events: none;
}

.generation-dock > * {
  pointer-events: auto;
}

.settings-block {
  position: relative;
}

.settings-row {
  position: absolute;
  left: var(--settings-menu-left);
  bottom: 50px;
  display: none;
  width: 96px;
  align-items: end;
}

.settings-block.expanded .settings-row {
  display: block;
}

.settings-cell {
  display: none;
  overflow: hidden;
  border-radius: 18px;
  background: var(--surface);
}

.settings-cell.active {
  display: block;
}

.chip-options {
  display: grid;
  max-height: min(440px, calc(var(--app-height) - 285px));
  overflow-y: auto;
  padding: 6px 0;
}

.option-button {
  min-height: 36px;
  padding: 6px 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 400;
}

.option-button.active {
  color: var(--accent);
  font-weight: 400;
}

.settings-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) max-content 30px;
  align-items: center;
  gap: 4px;
}

.setting-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 42px;
  min-height: 38px;
  padding-inline: 8px;
  border-radius: var(--pill);
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prompt-counter {
  justify-self: end;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.clear-prompt-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: transparent;
  color: #cfcfcf;
}

.primary-button,
.download-button,
.result-upscale-button,
.payment-check button {
  min-height: 54px;
  border-radius: var(--pill);
  background: var(--accent);
  color: #101010;
  font-size: 16px;
  font-weight: 700;
}

.primary-button:disabled,
.download-button:disabled,
.result-upscale-button:disabled,
.payment-check button:disabled {
  background: #232323;
  color: #6f6f6f;
}

.result-view,
.balance-view {
  gap: 14px;
}

.result-header,
.balance-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.result-header h2,
.balance-title-row h2 {
  flex: 1 1 auto;
  font-size: 26px;
  font-weight: 700;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: var(--pill);
  background: rgba(200, 255, 0, .14);
  color: var(--accent);
  font-size: 13px;
}

.video-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: #0a0a0a;
  aspect-ratio: 9 / 16;
}

.video-frame video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-placeholder,
.result-link {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.video-placeholder {
  color: var(--muted);
  background: linear-gradient(180deg, rgba(255, 255, 255, .02), rgba(255, 255, 255, .01));
}

.play-button {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .06);
  font-size: 28px;
}

.result-link {
  color: var(--text);
  text-decoration: none;
  background: rgba(0, 0, 0, .38);
}

.video-time {
  position: absolute;
  right: 14px;
  bottom: 14px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: var(--pill);
  background: rgba(0, 0, 0, .65);
  font-size: 12px;
  line-height: 28px;
}

.video-fullscreen-button {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  background: rgba(0, 0, 0, .55);
}

.result-details,
.glass-card,
.topup-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #0a0a0a;
}

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

.result-details span,
.glass-card span,
.topup-card label,
.topup-card small,
.payment-warning,
#minTopupText {
  color: var(--muted);
}

.result-details strong,
.glass-card strong {
  display: block;
  margin-top: 6px;
}

.wide-detail {
  grid-column: 1 / -1;
}

.result-action-bar {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 10px;
}

.result-action-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  background: #0a0a0a;
}

.balance-title-row {
  justify-content: space-between;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2e2e2e, #111);
}

.balance-hero strong {
  display: block;
  margin: 5px 0 4px;
  font-size: 31px;
  line-height: 1;
}

.balance-hero p {
  margin-top: 0;
  color: var(--muted);
}

.cost-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.bolt {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(200, 255, 0, .12);
  color: var(--accent);
  font-weight: 700;
}

.topup-card {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: 18px;
}

.amount-input,
.payment-check input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  background: #050505;
  color: var(--text);
}

.payment-methods {
  display: grid;
  gap: 10px;
}

.method-card {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #050505;
  color: var(--text);
  text-align: left;
}

.method-card.active {
  border-color: rgba(200, 255, 0, .45);
  box-shadow: inset 0 0 0 1px rgba(200, 255, 0, .15);
}

.method-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: rgba(200, 255, 0, .12);
  color: var(--accent);
}

.method-card strong,
.method-card small {
  display: block;
}

.payment-warning {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.35;
}

.payment-check {
  display: grid;
  gap: 10px;
}

.payment-check.hidden {
  display: none !important;
}

.bottom-nav {
  position: absolute;
  right: 15px;
  bottom: var(--safe-bottom);
  left: 15px;
  z-index: 18;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(10, 10, 10, .96);
  backdrop-filter: blur(18px);
}

.nav-button {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-height: 52px;
  padding: 7px 4px 6px;
  border-radius: 20px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
}

.nav-button.active {
  background: #171717;
  color: var(--text);
}

.nav-button svg {
  width: 20px;
  height: 20px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: calc(var(--safe-bottom) + var(--nav-height) + 120px);
  left: 18px;
  z-index: 60;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(18, 18, 18, .96);
  color: var(--text);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
}

.studio-view.prompt-focus .control-block,
.studio-view.prompt-focus .mode-block,
.studio-view.prompt-focus .media-panel {
  display: none;
}

.studio-view.prompt-focus .prompt-card {
  margin-top: 0;
  padding-top: 8px;
}

.studio-view.prompt-focus .prompt-input {
  min-height: calc(var(--app-height) - 245px);
  padding: 8px 40px 0 17px;
}

.studio-view.prompt-focus .expand-prompt-button {
  top: 8px;
  right: 13px;
  z-index: 50;
}

@media (max-width: 360px) {
  .settings-summary {
    grid-template-columns: repeat(4, minmax(0, 1fr)) max-content 30px;
  }
}
