:root {
  --bg: #fbf7f6;
  --bg-soft: #fffaf8;
  --panel: rgba(255, 255, 255, .88);
  --panel-solid: #ffffff;
  --text: #2b2530;
  --muted: #8c7e86;
  --line: #eadde2;
  --line-strong: #dbc6cf;
  --rose: #b56a7c;
  --rose-dark: #844857;
  --mauve: #7d667a;
  --gold: #b88a4a;
  --pearl: #fff5f1;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(102, 65, 80, .14);
  --shadow-soft: 0 10px 28px rgba(102, 65, 80, .10);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  background:
    linear-gradient(145deg, #fffaf8 0%, #f9eff3 45%, #f8f4ee 100%);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  letter-spacing: 0;
}
button, input, textarea, select { font: inherit; }
button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 13px;
  background: rgba(255, 255, 255, .82);
  color: var(--text);
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease, background .16s ease;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .58; cursor: not-allowed; }
.primary {
  border-color: rgba(132, 72, 87, .35);
  background: linear-gradient(135deg, #be7485, #8f5262);
  color: #fff;
  box-shadow: 0 12px 28px rgba(181, 106, 124, .26);
}
.wide { width: 100%; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .86);
  color: var(--text);
  padding: 12px 13px;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .72);
}
input:focus, textarea:focus, select:focus {
  border-color: rgba(181, 106, 124, .58);
  box-shadow: 0 0 0 4px rgba(181, 106, 124, .10);
}
textarea { resize: vertical; }
label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.app-shell { min-height: 100dvh; }
.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--rose-dark);
  font-weight: 800;
  font-size: 13px;
}
.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 10px;
  display: inline-block;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .86), rgba(255, 255, 255, .12)),
    linear-gradient(135deg, #d9a0aa, #b88a4a);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .64), 0 8px 18px rgba(181, 106, 124, .22);
}
.brand-mark.small {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
}
.auth-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
}
.auth-panel {
  width: min(430px, 100%);
  border: 1px solid rgba(234, 221, 226, .82);
  border-radius: 24px;
  background: var(--panel);
  padding: 22px;
  display: grid;
  gap: 13px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 5px;
  border-radius: 16px;
  background: #f7ebeF;
  border: 1px solid rgba(234, 221, 226, .82);
}
.auth-tab {
  min-height: 38px;
  border: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}
.auth-tab.is-active {
  background: #fff;
  color: var(--rose-dark);
  box-shadow: 0 8px 20px rgba(102, 65, 80, .11);
}
.auth-panel h1 {
  margin: 8px 0 0;
  font-size: 31px;
  line-height: 1.1;
  color: #332832;
}
.auth-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}
.code-row {
  display: grid;
  grid-template-columns: 1fr 94px;
  gap: 8px;
}
.hint {
  min-height: 22px;
  color: var(--gold);
  font-size: 13px;
  line-height: 1.5;
}
.work-view {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto auto auto auto 1fr auto;
  background:
    linear-gradient(180deg, rgba(255, 250, 248, .96) 0%, rgba(250, 241, 244, .82) 55%, rgba(255, 250, 248, .98) 100%);
}
.topbar {
  min-height: 70px;
  padding: 12px max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(234, 221, 226, .72);
  background: rgba(255, 250, 248, .86);
  backdrop-filter: blur(16px);
}
.topbar-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-title span:not(.brand-mark) {
  display: block;
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}
.topbar-title h1 {
  margin: 2px 0 0;
  font-size: 18px;
  line-height: 1.15;
}
.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.balance-pill {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid rgba(184, 138, 74, .28);
  background: rgba(255, 249, 238, .82);
  color: #8f6630;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.topbar-actions button {
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 999px;
}
.studio-head {
  padding: 16px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
}
.studio-head h1 {
  margin: 0;
  font-size: clamp(25px, 7vw, 38px);
  line-height: 1.05;
}
.studio-head p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}
.controls {
  margin: 0 max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  border: 1px solid rgba(234, 221, 226, .82);
  border-radius: 20px;
  background: rgba(255, 255, 255, .74);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
}
.controls select {
  min-height: 40px;
  padding: 9px 10px;
  border-radius: 12px;
  background: #fff;
}
.model-row {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.model-row label {
  display: inline-flex;
  grid-auto-flow: column;
  align-items: center;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid rgba(234, 221, 226, .86);
  border-radius: 999px;
  background: #fff;
  color: #473a45;
  font-size: 13px;
}
.model-row input {
  width: auto;
  margin: 0;
  accent-color: var(--rose);
}
.memory-bar {
  margin: 0 max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  padding: 10px 12px;
  border: 1px solid rgba(221, 199, 211, .76);
  border-radius: 16px;
  background: rgba(255, 246, 249, .82);
  color: #7e5262;
  font-size: 13px;
  line-height: 1.5;
}
.selected-bar {
  margin: 0 max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  padding: 9px 10px;
  border: 1px solid rgba(184, 138, 74, .32);
  border-radius: 18px;
  background: rgba(255, 248, 236, .88);
  color: #7b5a2e;
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 13px;
  box-shadow: var(--shadow-soft);
}
.selected-bar[hidden] { display: none; }
.selected-bar img {
  width: 44px;
  height: 60px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid rgba(184, 138, 74, .32);
}
.selected-bar button {
  min-height: 34px;
  margin-left: auto;
  border-color: rgba(184, 138, 74, .36);
  color: #7b5a2e;
}
.message-list {
  min-height: 0;
  overflow-y: auto;
  padding: 2px max(12px, env(safe-area-inset-right)) 14px max(12px, env(safe-area-inset-left));
  display: grid;
  align-content: start;
  gap: 13px;
}
.empty {
  min-height: 150px;
  display: grid;
  place-items: center;
  padding: 24px 18px;
  border: 1px dashed rgba(219, 198, 207, .95);
  border-radius: 22px;
  background: rgba(255, 255, 255, .62);
  color: var(--muted);
  text-align: center;
  box-shadow: var(--shadow-soft);
}
.message {
  display: grid;
  gap: 10px;
}
.message.user {
  justify-self: end;
  max-width: 88%;
}
.bubble {
  padding: 11px 13px;
  border-radius: 18px;
  border: 1px solid rgba(234, 221, 226, .9);
  background: rgba(255, 255, 255, .9);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.58;
  box-shadow: 0 8px 22px rgba(102, 65, 80, .08);
}
.message.user .bubble {
  border-color: rgba(132, 72, 87, .42);
  background: linear-gradient(135deg, #9c5e70, #70485e);
  color: #fff;
}
.results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.result {
  margin: 0;
  border: 1px solid rgba(234, 221, 226, .88);
  border-radius: 18px;
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow-soft);
}
.result img {
  width: 100%;
  aspect-ratio: 9 / 16;
  display: block;
  object-fit: cover;
  background: linear-gradient(135deg, #f4e3e7, #f7efe8);
}
.result figcaption {
  display: grid;
  gap: 8px;
  padding: 9px;
  color: var(--muted);
  font-size: 12px;
}
.result-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.result-actions a,
.result-actions button {
  min-height: 32px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid rgba(234, 221, 226, .9);
  background: #fffaf8;
  color: #6d5261;
  text-decoration: none;
  font-size: 12px;
  text-align: center;
}
.composer {
  padding: 10px max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: grid;
  gap: 9px;
  border-top: 1px solid rgba(234, 221, 226, .72);
  background: rgba(255, 250, 248, .9);
  backdrop-filter: blur(16px);
}
.composer textarea {
  min-height: 78px;
  max-height: 180px;
  border-radius: 18px;
  background: rgba(255, 255, 255, .9);
}
.composer button {
  border-radius: 18px;
}
@media (max-width: 374px) {
  .controls { grid-template-columns: 1fr 1fr; }
  .controls label:nth-child(3) { grid-column: 1 / -1; }
  .results { grid-template-columns: 1fr; }
}
@media (min-width: 760px) {
  body {
    background: linear-gradient(145deg, #fffaf8 0%, #f8eef2 42%, #fbf4ee 100%);
  }
  .work-view {
    width: min(1040px, 100%);
    margin: 0 auto;
    border-left: 1px solid rgba(234, 221, 226, .72);
    border-right: 1px solid rgba(234, 221, 226, .72);
  }
  .results {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .composer {
    grid-template-columns: 1fr 126px;
    align-items: stretch;
  }
  .composer button {
    min-height: 78px;
  }
}
