:root {
  color-scheme: dark;
  --bg: #101314;
  --surface: #171b1c;
  --surface-2: #202526;
  --line: #303738;
  --text: #f4f6f4;
  --muted: #9da6a4;
  --teal: #41c9b4;
  --coral: #ff7868;
  --gold: #e4bd62;
  --blue: #76a9ff;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-shell {
  min-height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 18px calc(88px + var(--safe-bottom));
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(16px);
}

h1, h2, p { margin: 0; }
h1 { font-size: 20px; line-height: 1.2; }
h2 { font-size: 22px; line-height: 1.25; }
.eyebrow { color: var(--teal); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.muted { color: var(--muted); font-size: 13px; }

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
}
.icon-button svg { width: 19px; height: 19px; }

.view { display: none; }
.view.active { display: block; }

.workspace-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 18px;
}

.workspace-summary h2 { margin-top: 4px; }
.balance-box {
  display: flex;
  gap: 9px;
  align-items: center;
  min-width: 104px;
  padding: 10px 12px;
  border: 1px solid #3d4545;
  border-radius: 8px;
  background: var(--surface);
}
.balance-box svg { width: 20px; color: var(--gold); }
.balance-box strong, .balance-box span { display: block; }
.balance-box strong { font-size: 18px; }
.balance-box span { color: var(--muted); font-size: 11px; }

.studio-banner {
  position: relative;
  height: 174px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.studio-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: .86;
}
.studio-banner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(9, 12, 13, .88), rgba(9, 12, 13, .12));
}
.banner-copy {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 2;
}
.banner-copy span { display: block; color: #d9dfdd; font-size: 12px; margin-bottom: 5px; }
.banner-copy strong { display: block; max-width: 210px; font-size: 25px; line-height: 1.08; }

.section { margin-top: 26px; }
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 13px;
}
.section-heading h2 { font-size: 17px; }
.text-button { border: 0; color: var(--teal); background: transparent; font-size: 13px; }

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

.studio-card {
  min-height: 142px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-align: left;
  background-color: var(--surface);
  background-image: var(--card-image);
  background-size: 330%;
  background-position: var(--card-position);
  overflow: hidden;
  position: relative;
}
.studio-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(16, 19, 20, .25), rgba(16, 19, 20, .94));
}
.studio-card > * { position: relative; z-index: 1; }
.studio-card .studio-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 8px;
  background: rgba(12, 15, 16, .76);
}
.studio-card svg { width: 19px; }
.studio-card strong { display: block; font-size: 16px; }
.studio-card span { display: block; color: #c5ccca; font-size: 11px; margin-top: 3px; }
.studio-card.coming { opacity: .76; }

.page-heading { padding: 18px 0 20px; }
.page-heading h2 { margin-top: 5px; font-size: 26px; }

.studio-list { display: grid; gap: 10px; }
.studio-row {
  width: 100%;
  min-height: 90px;
  display: grid;
  grid-template-columns: 48px 1fr 28px;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-align: left;
  background: var(--surface);
}
.studio-row .studio-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--accent);
}
.studio-row strong, .studio-row span { display: block; }
.studio-row span { color: var(--muted); font-size: 12px; margin-top: 4px; }
.studio-row > svg { width: 17px; color: var(--muted); }

.filter-tabs {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 12px;
  scrollbar-width: none;
}
.filter-tabs button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  white-space: nowrap;
  background: var(--surface);
}
.filter-tabs button.active { color: #071312; border-color: var(--teal); background: var(--teal); }

.project-list { display: grid; gap: 8px; }
.project-list.compact .project-item:nth-child(n+4) { display: none; }
.project-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 70px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.project-type {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--accent);
  background: var(--surface-2);
}
.project-thumbnail { object-fit: cover; padding: 0; }
.project-item strong, .project-item span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-item span { color: var(--muted); font-size: 11px; margin-top: 4px; }
.project-status { color: var(--teal); font-size: 11px; }
.empty-state { padding: 28px 12px; color: var(--muted); text-align: center; border: 1px dashed var(--line); border-radius: 8px; }

.account-panel {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.account-avatar {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--teal);
  background: var(--surface-2);
}
.account-panel strong, .account-panel span { display: block; }
.account-panel span { color: var(--muted); font-size: 12px; margin-top: 4px; }

.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.metric { padding: 15px 8px; text-align: center; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.metric strong, .metric span { display: block; }
.metric strong { font-size: 21px; }
.metric span { color: var(--muted); font-size: 11px; margin-top: 4px; }

.primary-button {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 0;
  border-radius: 8px;
  color: #071312;
  font-weight: 750;
  background: var(--teal);
}
.primary-button svg { width: 18px; }
.primary-button.full { width: 100%; }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  width: min(760px, 100%);
  min-height: calc(68px + var(--safe-bottom));
  padding: 8px 12px var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  transform: translateX(-50%);
  background: #121617;
}
.bottom-nav button {
  min-height: 52px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  border: 0;
  color: var(--muted);
  background: transparent;
}
.bottom-nav svg { width: 20px; height: 20px; }
.bottom-nav span { font-size: 10px; }
.bottom-nav button.active { color: var(--teal); }

dialog {
  width: min(430px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
}
dialog::backdrop { background: rgba(2, 5, 5, .76); backdrop-filter: blur(4px); }
.dialog-panel { max-height: calc(100dvh - 30px); padding: 24px; position: relative; overflow-y: auto; }
.dialog-close { position: absolute; right: 14px; top: 14px; }
.dialog-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: 8px;
  color: var(--teal);
  background: var(--surface-2);
}
.dialog-panel h2 { margin: 5px 0 8px; }
.dialog-description { color: var(--muted); font-size: 13px; line-height: 1.55; }
.field { display: grid; gap: 7px; margin: 20px 0 12px; color: var(--muted); font-size: 12px; }
.field input {
  width: 100%;
  height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  color: var(--text);
  background: #111516;
}
.field textarea,
.field select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  color: var(--text);
  background: #111516;
}
.field textarea { resize: vertical; line-height: 1.45; }
.field select { height: 46px; padding: 0 11px; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--teal); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.segmented-field { display: grid; gap: 7px; margin: 14px 0; color: var(--muted); font-size: 12px; }
.segmented-control {
  min-height: 42px;
  padding: 3px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111516;
}
.segmented-control button {
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
}
.segmented-control button.active { color: #071312; font-weight: 700; background: var(--teal); }
.generation-progress { padding: 26px 6px; text-align: center; }
.generation-progress strong, .generation-progress p { display: block; }
.generation-progress p { margin-top: 8px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.progress-spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 14px;
  display: block;
  border: 3px solid var(--line);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.generation-result { display: grid; gap: 12px; margin: 18px 0; }
.audio-variant { padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #111516; }
.audio-variant strong { display: block; margin-bottom: 9px; font-size: 13px; }
.audio-variant audio { width: 100%; height: 38px; }
.generation-result details { border-top: 1px solid var(--line); padding-top: 13px; }
.generation-result summary { color: var(--teal); cursor: pointer; font-size: 13px; font-weight: 700; }
.generation-result pre { white-space: pre-wrap; color: #d8dedd; font-family: inherit; font-size: 12px; line-height: 1.55; }
.image-generation-result { margin: 18px 0; }
.image-result-grid { display: grid; gap: 12px; }
.image-result {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111516;
}
.image-result img {
  width: 100%;
  height: auto;
  max-height: 480px;
  display: block;
  object-fit: contain;
  background: #0c0f10;
}
.image-result-actions { padding: 10px; display: flex; justify-content: flex-end; }
.download-button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-2);
}
.download-button svg { width: 17px; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(82px + var(--safe-bottom));
  z-index: 50;
  max-width: calc(100% - 32px);
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #252b2c;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 620px) {
  .app-shell { padding-left: 28px; padding-right: 28px; }
  .studio-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .studio-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .image-result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
