@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/ibm-plex-sans-arabic-400-ar.bin") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/ibm-plex-sans-arabic-400-latin.bin") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/ibm-plex-sans-arabic-500-ar.bin") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/ibm-plex-sans-arabic-500-latin.bin") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/ibm-plex-sans-arabic-600-ar.bin") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/ibm-plex-sans-arabic-600-latin.bin") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/ibm-plex-sans-arabic-700-ar.bin") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/ibm-plex-sans-arabic-700-latin.bin") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}

html,
body,
button,
input,
textarea,
select {
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
}
body {
  font-weight: 400;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
[lang="ar"],
[dir="rtl"] {
  direction: rtl;
  text-align: right;
}
[lang="en"],
[dir="ltr"] {
  direction: ltr;
  text-align: left;
}
html[lang="en"] [lang="ar"],
html[lang="ar"] [lang="en"] {
  display: none !important;
}
html[dir="rtl"] .nav-item,
html[dir="rtl"] .quiet-button,
html[dir="rtl"] .form-card label,
html[dir="rtl"] .settings-card > label {
  text-align: right;
}
html[dir="ltr"] .nav-item,
html[dir="ltr"] .quiet-button,
html[dir="ltr"] .form-card label,
html[dir="ltr"] .settings-card > label {
  text-align: left;
}
html[dir="rtl"] .topbar,
html[dir="rtl"] .drawer-head,
html[dir="rtl"] .composer-row,
html[dir="rtl"] .result-actions,
html[dir="rtl"] .settings-actions {
  direction: rtl;
}
html[dir="ltr"] .topbar,
html[dir="ltr"] .drawer-head,
html[dir="ltr"] .composer-row,
html[dir="ltr"] .result-actions,
html[dir="ltr"] .settings-actions {
  direction: ltr;
}
.language-toggle { min-width: 64px; }
@media (min-width: 841px) {
  html[dir="rtl"] .sidebar { border-right: 0; border-left: 1px solid var(--line); }
  html[dir="rtl"] .nav-item.active::after { right: auto; left: 8px; }
}
textarea[dir="auto"],
input[dir="auto"],
.message[dir="auto"] {
  text-align: start;
  unicode-bidi: plaintext;
}
h1, h2, h3, strong, button { font-weight: 600; }
.message { line-height: 1.75; }
.topbar h1,
.welcome-card h2,
.card-heading h2 { font-weight: 700; }
.topbar h1 { letter-spacing: -.02em; }
.topbar #section-title {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 .28em;
}
.title-ar { letter-spacing: 0; }
.title-divider { color: var(--muted); font-weight: 400; }
.send-button,
.primary { font-weight: 700; }

.field-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.advanced {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(7, 11, 20, .4);
  margin: 4px 0 16px;
  overflow: hidden;
}

.advanced summary {
  padding: 12px 14px;
  color: #b6c1d2;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::after { content: "+"; font-size: 18px; color: var(--accent); font-weight: 400; }
.advanced[open] summary { border-bottom: 1px solid var(--line); }
.advanced[open] summary::after { content: "−"; }
.advanced > div,
.advanced > label,
.advanced > .help { margin-left: 14px; margin-right: 14px; }
.advanced > div:first-of-type,
.advanced > label:first-of-type { margin-top: 14px; }
.advanced > .help { display: block; margin-bottom: 14px; }

.composer-advanced {
  margin: 2px 0 8px;
  border-color: var(--line-soft);
  background: transparent;
}

.composer-advanced .field-grid { padding: 12px 12px 0; }
.composer-advanced label { color: var(--muted); font-size: 11px; }
.option-row { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.help { color: #6f7d91; font-size: 11px; }
.switch span { flex: 0 0 auto; }

.composer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mic-button,
.live-button {
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--panel-2);
  padding: 9px 12px;
  font-weight: 800;
}

.mic-button {
  display: flex;
  align-items: center;
  gap: 7px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.mic-button span { color: var(--danger); font-size: 11px; }
.mic-button b { font-size: 11px; white-space: nowrap; }
.mic-button.listening {
  border-color: var(--danger);
  background: rgba(255, 113, 133, .12);
  box-shadow: 0 0 0 4px rgba(255, 113, 133, .08);
}
.mic-button.listening span { animation: voice-pulse .75s infinite alternate; }

.live-button { color: var(--muted); }
.live-button i {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: #667085;
}
.live-button.active { color: #071008; background: var(--accent); border-color: var(--accent); }
.live-button.active i { background: #071008; animation: voice-pulse .75s infinite alternate; }

@keyframes voice-pulse {
  to { transform: scale(1.45); opacity: .5; }
}

.live-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: -2px -2px 8px;
  padding: 8px 10px;
  border-radius: 11px;
  color: var(--accent);
  background: rgba(156, 255, 87, .07);
  font-size: 12px;
  font-weight: 750;
}
.live-bar i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: voice-pulse .8s infinite alternate; }
.live-bar span { flex: 1; }
.live-bar button { border: 0; color: var(--danger); background: transparent; font-weight: 800; }

.voice-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 12px;
  padding-bottom: 12px;
}
.voice-options label { display: block; color: var(--muted); font-size: 11px; font-weight: 700; }
.voice-options label input,
.voice-options label select { margin-top: 6px; }
.voice-options .switch { margin: 8px 0 2px; }
.voice-player { width: 100%; height: 38px; margin-top: 9px; }
.voice-preview-button { margin: 2px 0 12px; }

.music-presets {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 16px;
  scrollbar-width: none;
}
.music-presets::-webkit-scrollbar { display: none; }
.music-presets button {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: #c9d4e4;
  background: var(--panel-2);
  font-size: 12px;
  font-weight: 800;
}
.music-presets button:hover { border-color: rgba(156, 255, 87, .45); color: var(--accent); }
#music-lyrics[dir="rtl"] { text-align: right; font-family: inherit; line-height: 1.9; }

.upload-card {
  margin: 0 0 16px;
  padding: 15px;
  border: 1px dashed rgba(156, 255, 87, .4);
  border-radius: 14px;
  background: rgba(156, 255, 87, .045);
}
.upload-card p {
  margin: 10px 0 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}
.upload-card input[type="file"] {
  padding: 10px;
  border-style: dashed;
  cursor: pointer;
}
.upload-card input[type="file"]::file-selector-button {
  margin-inline-end: 10px;
  padding: 8px 11px;
  border: 0;
  border-radius: 9px;
  color: #071008;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

.form-field > label { margin-bottom: 7px; }
.tag-combobox { position: relative; margin-bottom: 14px; }
.tag-entry {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 46px;
  padding: 5px 6px 5px 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #080e19;
  transition: border .2s, box-shadow .2s;
}
.tag-combobox:focus-within .tag-entry {
  border-color: #536581;
  box-shadow: 0 0 0 3px rgba(104, 215, 255, .08);
}
.tag-entry input {
  min-width: 0;
  margin: 0 !important;
  padding: 7px 4px;
  border: 0;
  box-shadow: none !important;
  background: transparent;
}
.tag-entry button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid rgba(156, 255, 87, .3);
  border-radius: 9px;
  color: var(--accent);
  background: rgba(156, 255, 87, .08);
  font-size: 11px;
  font-weight: 850;
}
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 7px; }
.tag-list:empty { display: none; }
.instrument-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 6px 8px 6px 10px;
  border: 1px solid rgba(104, 215, 255, .25);
  border-radius: 999px;
  color: #dce9f7;
  background: rgba(104, 215, 255, .08);
  font-size: 11px;
  font-weight: 750;
}
.instrument-tag span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.instrument-tag button {
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: rgba(255, 255, 255, .07);
  line-height: 1;
}
.instrument-tag button:hover { color: var(--danger); }
.tag-options {
  position: absolute;
  z-index: 20;
  inset: calc(100% + 6px) 0 auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  max-height: 220px;
  overflow: auto;
  padding: 8px;
  border: 1px solid #33435a;
  border-radius: 13px;
  background: #0b1220;
  box-shadow: 0 20px 45px rgba(0, 0, 0, .45);
}
.tag-options button {
  overflow: hidden;
  padding: 9px 10px;
  border: 0;
  border-radius: 9px;
  color: #c9d4e4;
  background: transparent;
  text-align: start;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}
.tag-options button:hover,
.tag-options button:focus { color: var(--text); background: var(--panel-2); outline: none; }
.tag-options .empty-option { grid-column: 1 / -1; padding: 10px; color: var(--muted); font-size: 11px; }

.message { position: relative; }
.message-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  opacity: .55;
  transition: opacity .2s;
}
.message:hover .message-actions,
.message:focus-within .message-actions { opacity: 1; }
.message-actions button {
  border: 0;
  border-radius: 8px;
  padding: 5px 8px;
  background: rgba(255, 255, 255, .06);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}
.message-actions button:hover { color: var(--text); background: rgba(255, 255, 255, .1); }

.history-new { margin-top: 22px; }
.history-item {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 14px;
  padding: 13px;
  cursor: pointer;
}
.history-item:hover { border-color: #3b4a61; }
.history-item.active { border-color: rgba(156, 255, 87, .45); background: rgba(156, 255, 87, .05); }
.history-item strong { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.history-item small { color: var(--muted); }
.history-item p { color: #a6b1c3; margin: 6px 0 0; font-size: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.history-actions { display: flex; gap: 5px; margin-top: 9px; }
.history-actions button { border: 0; border-radius: 8px; padding: 5px 8px; background: var(--panel-2); color: var(--muted); font-size: 10px; }
.history-actions button.danger { color: var(--danger); }

@media (max-width: 760px) {
  .field-grid.three { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 540px) {
  .language-toggle { min-width: 37px; }
  .language-toggle[data-mobile-icon]::before { font-size: 9px; font-weight: 800; letter-spacing: 0; }
  .field-grid.three { grid-template-columns: 1fr; }
  .advanced summary { padding: 11px 12px; }
  .voice-options { grid-template-columns: 1fr; }
  .message-actions { opacity: .8; }
  .composer-row { align-items: flex-end; gap: 8px; }
  .composer-actions { gap: 5px; }
  .mic-button { width: 42px; height: 42px; justify-content: center; padding: 0; border-radius: 50%; }
  .mic-button b { display: none; }
  .live-button { padding: 9px 10px; }
  .send-button { padding: 10px 13px; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  #new-chat { display: none; }
  .tag-options { grid-template-columns: 1fr; max-height: 250px; }
  button[data-mobile-icon] {
    min-width: 42px;
    min-height: 42px;
    font-size: 0 !important;
  }
  button[data-mobile-icon]::before {
    content: attr(data-mobile-icon);
    display: inline-grid;
    place-items: center;
    font-size: 20px;
    line-height: 1;
  }
  .nav-item[data-mobile-icon] { display: grid; place-items: center; padding: 8px 3px; }
  .nav-item[data-mobile-icon] span { display: none; }
  .top-actions button[data-mobile-icon] { position: relative; }
  .top-actions button[data-mobile-icon] span {
    position: absolute;
    display: grid;
    place-items: center;
    top: -5px;
    right: -5px;
    min-width: 16px;
    height: 16px;
    margin: 0;
    font-size: 9px;
  }
  .live-button[data-mobile-icon] i { display: none; }
  .tag-entry button[data-mobile-icon] { min-width: 38px; min-height: 34px; }
  .primary.wide[data-mobile-icon],
  .quiet-button.wide[data-mobile-icon],
  .voice-preview-button.wide[data-mobile-icon] { width: 100%; }
}

/* Refined desktop navigation */
.app-shell { grid-template-columns: 276px minmax(0, 1fr); }
.sidebar {
  padding: 20px 16px;
  border-right-color: var(--line);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
}
.brand {
  gap: 13px;
  margin-bottom: 22px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .07);
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  box-shadow: 0 8px 22px rgba(108, 223, 45, .25);
}
.sidebar nav { gap: 8px; }
.nav-item {
  position: relative;
  gap: 11px;
  min-height: 52px;
  padding: 8px 11px;
  border: 1px solid transparent;
  border-radius: 15px;
  font-size: 13px;
}
.nav-item::before {
  content: attr(data-mobile-icon);
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted);
  background: var(--panel);
  font-size: 16px;
  transition: .2s ease;
}
.nav-item span { display: none; }
.nav-item:hover { border-color: var(--line); background: var(--panel); }
.nav-item.active {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
  box-shadow: 0 8px 22px rgba(0, 0, 0, .07);
}
.nav-item.active::before {
  border-color: var(--accent);
  color: #123406;
  background: var(--accent);
  box-shadow: 0 6px 16px rgba(108, 223, 45, .22);
}
.nav-item.active::after {
  content: "";
  position: absolute;
  right: 8px;
  width: 4px;
  height: 18px;
  border-radius: 999px;
  background: var(--accent);
}
.sidebar-foot {
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}
.sidebar-foot .quiet-button {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-2);
}
.sidebar-foot .quiet-button::before { content: "⚙"; margin-right: 8px; }
.connection {
  padding: 4px 6px;
  font-size: 11px;
}

/* Light theme */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-2: #edf2f7;
  --line: #d9e2ec;
  --line-soft: #e7edf4;
  --text: #172033;
  --muted: #68768a;
  --accent: #78e83f;
  --accent-2: #168fc7;
  --danger: #dc5268;
  --shadow: 0 22px 60px rgba(35, 53, 78, .11);
  background: var(--bg);
}
html[data-theme="light"] body {
  background: radial-gradient(circle at 78% -18%, rgba(80, 151, 255, .12), transparent 31%), radial-gradient(circle at 10% 105%, rgba(120, 232, 63, .11), transparent 32%), var(--bg);
}
html[data-theme="light"] .sidebar { background: rgba(244, 247, 251, .86); }
html[data-theme="light"] .form-card,
html[data-theme="light"] .preview-card { background: rgba(255, 255, 255, .9); }
html[data-theme="light"] .ghost {
  border-color: var(--line);
  color: #526176;
  background: rgba(255, 255, 255, .86);
}
html[data-theme="light"] .ghost:hover { color: var(--text); background: #fff; }
html[data-theme="light"] .composer {
  border-color: #cad5e2;
  background: rgba(255, 255, 255, .94);
}
html[data-theme="light"] textarea,
html[data-theme="light"] input,
html[data-theme="light"] select,
html[data-theme="light"] .tag-entry { background: #fff; color: var(--text); }
html[data-theme="light"] .advanced { background: #f8fafc; }
html[data-theme="light"] .advanced summary { color: #40506a; }
html[data-theme="light"] .tag-options,
html[data-theme="light"] .drawer,
html[data-theme="light"] .settings-card { background: #fff; }
html[data-theme="light"] .tag-options button,
html[data-theme="light"] .music-presets button { color: #40506a; }
html[data-theme="light"] .instrument-tag {
  color: #24516b;
  background: #edf8ff;
}
html[data-theme="light"] .message.user {
  border-color: #c7d9e8;
  background: #e8f3fb;
}
html[data-theme="light"] .message.assistant { background: #fff; }
html[data-theme="light"] .message-actions button { background: #eef2f6; }
html[data-theme="light"] .message-actions button:hover { background: #e3e9f0; }
html[data-theme="light"] .history-item p { color: #68768a; }
html[data-theme="light"] .upload-card { background: rgba(120, 232, 63, .07); }
html[data-theme="light"] .empty-preview span { color: #8fa0b5; }
html[data-theme="light"] .scrim { background: rgba(23, 32, 51, .35); }
body,
.sidebar,
.form-card,
.preview-card,
.composer,
.drawer,
.settings-card { transition: background-color .22s ease, border-color .22s ease, color .22s ease; }

@media (max-width: 840px) {
  .app-shell { display: block; }
  .sidebar {
    background: color-mix(in srgb, var(--bg) 91%, transparent);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, .08);
  }
  .sidebar nav { gap: 5px; }
  .nav-item {
    min-height: 48px;
    padding: 5px 3px;
    border-radius: 13px;
  }
  .nav-item::before {
    width: 34px;
    height: 34px;
    border: 0;
    background: transparent;
  }
  .nav-item.active::before { background: var(--accent); }
  .nav-item.active::after { display: none; }
  html[data-theme="light"] .sidebar { background: rgba(255, 255, 255, .94); }
}

/* App installation surface */
.install-banner {
  position: fixed;
  z-index: 65;
  right: 22px;
  bottom: 22px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: min(460px, calc(100vw - 28px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--text);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: 0 22px 60px rgba(16, 27, 45, .24);
  backdrop-filter: blur(22px);
  animation: install-rise .3s ease both;
}
@keyframes install-rise { from { opacity: 0; transform: translateY(18px); } }
.install-app-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  color: #071008;
  background: linear-gradient(145deg, #b6ff75, var(--accent));
  box-shadow: 0 10px 25px rgba(108, 223, 45, .28);
  font-size: 23px;
  font-weight: 950;
}
.install-copy { min-width: 0; }
.install-copy strong { display: block; font-size: 14px; }
.install-copy p { margin: 3px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.install-banner .primary { min-width: 48px; min-height: 42px; }
.install-dismiss {
  position: absolute;
  top: -8px;
  right: -8px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: var(--panel);
  box-shadow: 0 5px 15px rgba(0, 0, 0, .12);
}
.standalone-app .install-banner,
.standalone-app #install-app { display: none !important; }

@media (max-width: 840px) {
  body { min-height: 100dvh; overflow-x: hidden; overscroll-behavior-y: contain; -webkit-tap-highlight-color: transparent; }
  button, input, select, textarea { touch-action: manipulation; }
  .workspace {
    width: 100%;
    padding: max(14px, env(safe-area-inset-top)) 12px calc(118px + env(safe-area-inset-bottom));
  }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 18;
    min-height: 66px;
    margin: -14px -4px 18px;
    padding: calc(12px + env(safe-area-inset-top)) 5px 10px;
    border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: blur(22px);
  }
  .topbar h1 { font-size: 22px; }
  .topbar .eyebrow { font-size: 8px; }
  .top-actions { gap: 5px; flex-wrap: nowrap; }
  .top-actions button[data-mobile-icon] {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0;
    border-radius: 13px;
  }
  #install-app:not(.hidden) { display: inline-grid !important; }
  .tool-grid { gap: 14px; }
  .form-card,
  .preview-card {
    padding: 17px;
    border-radius: 23px;
    box-shadow: 0 12px 35px rgba(30, 47, 72, .09);
  }
  .card-heading { margin-bottom: 19px; }
  .card-heading h2 { font-size: clamp(25px, 8vw, 34px); }
  .advanced { border-radius: 17px; }
  .primary.wide { min-height: 50px; border-radius: 15px; }
  .composer {
    bottom: calc(91px + env(safe-area-inset-bottom));
    border-radius: 20px;
    box-shadow: 0 16px 42px rgba(16, 27, 45, .17);
  }
  .sidebar {
    inset: auto 10px calc(9px + env(safe-area-inset-bottom)) 10px;
    width: auto;
    padding: 7px;
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: 0 14px 40px rgba(16, 27, 45, .2);
  }
  .sidebar nav { gap: 4px; }
  .nav-item { min-height: 50px; border-radius: 16px; }
  .nav-item.active { transform: translateY(-2px); }
  .nav-item::before { font-size: 18px; }
  .drawer {
    width: 100vw;
    max-width: none;
    padding: calc(22px + env(safe-area-inset-top)) 18px calc(22px + env(safe-area-inset-bottom));
    border-left: 0;
  }
  .install-banner {
    right: 12px;
    bottom: calc(91px + env(safe-area-inset-bottom));
    grid-template-columns: auto minmax(0, 1fr) auto;
    width: calc(100vw - 24px);
    padding: 12px;
    border-radius: 20px;
  }
  .install-app-icon { width: 46px; height: 46px; border-radius: 14px; }
  .install-banner .primary { width: 44px; min-width: 44px; padding: 0; }
}

@media (display-mode: standalone) {
  .workspace { padding-top: max(16px, env(safe-area-inset-top)); }
  .topbar { padding-top: 10px; }
}

/* Compact phone tuning based on real-device captures */
@media (max-width: 540px) {
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { font-size: 14px; }
  html[data-theme="light"] body { background: #f7f9fc; }
  html[data-theme="light"] {
    --bg: #f7f9fc;
    --panel: #ffffff;
    --panel-2: #f0f4f8;
    --line: #dbe4ed;
    --text: #172235;
    --muted: #6d7b8e;
    --accent: #72df3a;
  }
  .workspace { padding-left: 8px; padding-right: 8px; padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  .topbar {
    min-height: 56px;
    margin-left: 0;
    margin-right: 0;
    margin-bottom: 12px;
    padding-left: 2px;
    padding-right: 2px;
  }
  .topbar h1 { font-size: 19px; }
  .top-actions button[data-mobile-icon] {
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
    border-radius: 11px;
  }
  .top-actions button[data-mobile-icon]::before { font-size: 16px; }
  .chat-stream {
    min-height: calc(100dvh - 205px);
    gap: 10px;
    padding: 6px 0 132px;
  }
  .message {
    max-width: 90%;
    padding: 10px 12px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.65;
    unicode-bidi: plaintext;
    box-shadow: 0 5px 16px rgba(30, 47, 72, .045);
  }
  .message.user { max-width: 82%; border-bottom-right-radius: 5px; }
  .message.assistant { border-bottom-left-radius: 5px; }
  .message small { margin-bottom: 4px; font-size: 8px; letter-spacing: .1em; }
  html[data-theme="light"] .message.user { border-color: #c6dbe9; background: #e7f2fa; }
  html[data-theme="light"] .message.assistant { border-color: #dbe4ed; background: #fff; }
  .message-actions { gap: 4px; margin-top: 7px; }
  .message-actions button[data-mobile-icon] {
    width: 31px;
    min-width: 31px;
    height: 31px;
    min-height: 31px;
    padding: 0;
    border-radius: 9px;
  }
  .message-actions button[data-mobile-icon]::before { font-size: 14px; }
  .composer {
    bottom: calc(63px + env(safe-area-inset-bottom));
    padding: 8px;
    border-radius: 16px;
    box-shadow: 0 10px 28px rgba(16, 27, 45, .13);
  }
  .composer textarea {
    min-height: 34px;
    max-height: 105px;
    padding: 4px 5px;
    font-size: 14px;
  }
  .composer-advanced { margin: 1px 0 5px; border-radius: 13px; }
  .composer-advanced summary { min-height: 38px; padding: 8px 10px; font-size: 10px; }
  .composer-advanced summary::after { font-size: 15px; }
  .composer-row { margin-top: 2px; gap: 5px; }
  .composer-row select { max-width: 48vw; padding: 6px 4px; font-size: 12px; }
  .composer-actions { gap: 4px; }
  .mic-button,
  .live-button,
  .send-button {
    width: 37px;
    min-width: 37px;
    height: 37px;
    min-height: 37px;
    padding: 0;
    border-radius: 11px;
  }
  .send-button[data-mobile-icon]::before,
  .live-button[data-mobile-icon]::before { font-size: 16px; }
  .sidebar {
    inset: auto 6px calc(6px + env(safe-area-inset-bottom)) 6px;
    padding: 4px;
    border-radius: 17px;
    box-shadow: 0 9px 25px rgba(16, 27, 45, .14);
  }
  .sidebar nav { gap: 2px; }
  .nav-item {
    min-height: 42px;
    padding: 2px;
    border: 0;
    border-radius: 13px;
  }
  .nav-item::before {
    width: 29px;
    height: 29px;
    flex-basis: 29px;
    border-radius: 10px;
    font-size: 15px;
  }
  .nav-item.active {
    transform: none;
    border-color: transparent;
    background: transparent;
    box-shadow: none;
  }
  .nav-item.active::before { box-shadow: 0 5px 12px rgba(78, 170, 30, .2); }
  .form-card,
  .preview-card {
    padding: 14px;
    border-radius: 18px;
    box-shadow: 0 7px 22px rgba(30, 47, 72, .065);
  }
  .tool-grid { gap: 10px; }
  .card-heading { margin-bottom: 15px; }
  .card-heading h2 { margin-top: 5px; font-size: 25px; }
  .form-card label { margin-bottom: 11px; font-size: 11px; }
  textarea, input, select { padding: 10px 11px; border-radius: 11px; }
  .large-input { min-height: 120px; }
  .advanced { margin-bottom: 12px; border-radius: 14px; }
  .advanced summary { padding: 9px 11px; font-size: 11px; }
  .primary.wide { min-height: 44px; border-radius: 13px; }
  .preview-card { min-height: 230px; }
  .empty-preview span { font-size: 34px; }
  .install-banner {
    right: 8px;
    bottom: calc(61px + env(safe-area-inset-bottom));
    width: calc(100vw - 16px);
    padding: 10px;
    border-radius: 16px;
  }
  .install-app-icon { width: 40px; height: 40px; border-radius: 12px; font-size: 18px; }
  .install-copy strong { font-size: 12px; }
  .install-copy p { font-size: 10px; }
}

/* Closed off-canvas drawers must not cast shadows into the viewport. */
.drawer {
  visibility: hidden;
  pointer-events: none;
  box-shadow: none;
  transition: transform .25s ease, visibility 0s linear .25s;
}
.drawer.open {
  visibility: visible;
  pointer-events: auto;
  box-shadow: -16px 0 42px rgba(16, 27, 45, .18);
  transition: transform .25s ease, visibility 0s;
}
@media (max-width: 840px) {
  .drawer.open { box-shadow: none; }
}

/* Studio identity and bilingual finishing layer. */
body[data-section="chat"] { --accent: #72df3a; }
body[data-section="speech"] { --accent: #27b6d6; }
body[data-section="music"] { --accent: #9a72ee; }
body[data-section="images"] { --accent: #e96a98; }
body[data-section="video"] { --accent: #f4933e; }

.brand-mark,
.install-app-icon {
  background: linear-gradient(145deg, #b6ff75, #72df3a);
}

.title-stack { min-width: 0; }
.title-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}
.mobile-health { display: none; }

.topbar h1,
.eyebrow,
.card-heading span,
.nav-item,
.primary,
.send-button,
.spark {
  transition: color .22s ease, background-color .22s ease, border-color .22s ease, box-shadow .22s ease;
}

.welcome-card {
  position: relative;
  isolation: isolate;
  width: min(100%, 680px);
  padding: 24px 18px;
}
.welcome-card::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 10% 12%;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 10%, transparent), transparent 68%);
  filter: blur(18px);
  pointer-events: none;
}
.spark {
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  animation: spark-float 3.6s ease-in-out infinite;
}
.welcome-card h2 span,
.welcome-card h2 small { display: block; }
.welcome-card h2 small {
  margin-top: 9px;
  color: color-mix(in srgb, var(--text) 76%, var(--accent));
  font-size: .48em;
  font-weight: 750;
  letter-spacing: 0;
}
.welcome-card > p { margin-bottom: 14px; }
.welcome-meta {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}
.welcome-meta span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 78%, transparent);
}
.welcome-meta i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #72df3a;
}
.suggestions button {
  position: relative;
  display: grid;
  grid-template-columns: 22px auto;
  grid-template-rows: auto auto;
  column-gap: 8px;
  min-width: 142px;
  padding: 9px 12px;
  text-align: left;
}
.suggestions button::before {
  content: attr(data-suggest-icon);
  grid-row: 1 / 3;
  align-self: center;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 8px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  font-size: 12px;
}
.suggestions button span { color: var(--text); font-weight: 750; line-height: 1.2; }
.suggestions button small { color: var(--muted); font-size: 9px; line-height: 1.25; }
.suggestions button:hover {
  border-color: color-mix(in srgb, var(--accent) 38%, var(--line));
  transform: translateY(-1px);
}

.form-card,
.preview-card { position: relative; }
.form-card::before,
.preview-card::before {
  content: "";
  position: absolute;
  inset: 0 18px auto;
  height: 2px;
  border-radius: 0 0 999px 999px;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 80%, transparent), transparent);
  opacity: .6;
}
.composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 7%, transparent), 0 12px 34px rgba(16, 27, 45, .1);
}

@keyframes spark-float {
  0%, 100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(-4px) rotate(4deg); }
}

@media (max-width: 840px) {
  .mobile-health {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 7px;
    border: 1px solid color-mix(in srgb, #72df3a 28%, var(--line));
    border-radius: 999px;
    color: var(--muted);
    background: color-mix(in srgb, var(--panel) 78%, transparent);
    font-size: 8px;
  }
  .mobile-health i {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #8b96a8;
  }
  .mobile-health i.online { background: #72df3a; }
  .mobile-health i.offline { background: var(--danger); }
  .mobile-health.is-offline { border-color: color-mix(in srgb, var(--danger) 25%, var(--line)); }
  .mobile-health b { font-weight: 750; }
}

@media (max-width: 540px) {
  .welcome-card { padding: 18px 4px 22px; }
  .welcome-card h2 { font-size: clamp(29px, 9vw, 34px); }
  .welcome-card h2 small { margin-top: 7px; }
  .welcome-card > p { margin: 12px auto 10px; max-width: 300px; font-size: 12px; }
  .welcome-meta { margin-bottom: 17px; gap: 5px; }
  .welcome-meta span { padding: 4px 7px; font-size: 8px; }
  .suggestions { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .suggestions button { min-width: 0; padding: 8px; grid-template-columns: 20px minmax(0, 1fr); column-gap: 6px; }
  .suggestions button:nth-child(3) { grid-column: 1 / -1; }
  .suggestions button::before { width: 20px; height: 20px; }
  .suggestions button span { font-size: 10px; }
  .suggestions button small { font-size: 8px; }
  .composer:focus-within { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 8%, transparent); }
}

@media (prefers-reduced-motion: reduce) {
  .spark { animation: none; }
  .panel.active { animation: none; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

/* Dynamic desktop rail and mobile active-section tracker. */
body[data-section="chat"] { --nav-index: 0; }
body[data-section="speech"] { --nav-index: 1; }
body[data-section="music"] { --nav-index: 2; }
body[data-section="images"] { --nav-index: 3; }
body[data-section="video"] { --nav-index: 4; }

.app-shell { transition: grid-template-columns .24s ease; }
.sidebar { transition: padding .24s ease, background-color .22s ease, border-color .22s ease; }
.workspace { transition: width .24s ease; }
.brand { position: relative; }
.sidebar-toggle {
  position: absolute;
  inset-inline-end: -29px;
  top: 50%;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 27px;
  height: 34px;
  padding: 0;
  transform: translateY(-50%);
  border: 1px solid var(--line);
  border-radius: 0 11px 11px 0;
  color: var(--muted);
  background: var(--panel);
  font-size: 19px;
  line-height: 1;
}
html[dir="rtl"] .sidebar-toggle { border-radius: 11px 0 0 11px; }
.sidebar-toggle:hover { color: var(--text); background: var(--panel-2); }

@media (min-width: 841px) {
  body.sidebar-collapsed .app-shell { grid-template-columns: 82px minmax(0, 1fr); }
  body.sidebar-collapsed .sidebar { padding-inline: 11px; }
  body.sidebar-collapsed .brand {
    justify-content: center;
    margin-bottom: 22px;
    padding: 10px 4px;
  }
  body.sidebar-collapsed .brand > div { display: none; }
  body.sidebar-collapsed .brand-mark { width: 39px; height: 39px; }
  body.sidebar-collapsed .sidebar-toggle { inset-inline-end: -23px; }
  body.sidebar-collapsed .nav-item {
    justify-content: center;
    gap: 0;
    padding-inline: 4px;
    font-size: 0;
  }
  body.sidebar-collapsed .nav-item::before { flex-basis: 36px; width: 36px; height: 36px; }
  body.sidebar-collapsed .nav-item::after {
    content: attr(aria-label);
    position: absolute;
    left: calc(100% + 10px);
    right: auto;
    width: max-content;
    height: auto;
    padding: 7px 9px;
    transform: translateX(-4px);
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--text);
    background: var(--panel);
    box-shadow: 0 8px 20px rgba(16, 27, 45, .1);
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity .16s ease, transform .16s ease;
  }
  body.sidebar-collapsed .nav-item:hover::after,
  body.sidebar-collapsed .nav-item:focus-visible::after { opacity: 1; transform: none; }
  html[dir="rtl"] body.sidebar-collapsed .nav-item::after {
    right: calc(100% + 10px);
    left: auto;
  }
  body.sidebar-collapsed .sidebar-foot { align-items: center; padding: 8px 4px; }
  body.sidebar-collapsed .sidebar-foot .quiet-button {
    display: grid;
    place-items: center;
    width: 42px;
    height: 40px;
    padding: 0;
    font-size: 0;
  }
  body.sidebar-collapsed .sidebar-foot .quiet-button::before { margin: 0; font-size: 15px; }
  body.sidebar-collapsed .connection { justify-content: center; padding: 6px 0; }
  body.sidebar-collapsed .connection span { display: none; }
}

@media (max-width: 840px) {
  .sidebar-toggle { display: none; }
  .sidebar nav { position: relative; }
  .sidebar nav::after {
    content: "";
    position: absolute;
    inset-inline-start: calc((var(--nav-index) * 20%) + 10% - 14px);
    bottom: -2px;
    width: 28px;
    height: 3px;
    border-radius: 999px;
    background: var(--accent);
    transition: inset-inline-start .25s ease, background-color .22s ease;
    pointer-events: none;
  }
}
