.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.app-shell {
  width: 100%;
  max-width: 460px;
  /* JS updates --app-height from visualViewport because standalone Android PWAs
     can report 100vh/100dvh taller than the touchable viewport. */
  height: 100vh;
  height: 100dvh;
  height: var(--app-height);
  display: flex;
  min-height: 0;
}

.workspace {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: var(--page);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  min-height: 58px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 14px 8px;
  border-bottom: 1px solid var(--line-soft);
  border-color: var(--line-soft);
  position: relative;
  z-index: 20;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--page) 86%, transparent);
  -webkit-backdrop-filter: saturate(150%) blur(18px);
  backdrop-filter: saturate(150%) blur(18px);
  transition: box-shadow var(--dur-fast) var(--ease-standard), border-color var(--dur-fast) var(--ease-standard);
}

.topbar.scrolled {
  box-shadow: 0 1px 0 var(--line), 0 6px 16px -12px rgba(0, 0, 0, 0.5);
  border-color: var(--line);
}

.mode-wrap {
  position: relative;
}
.account-wrap { position: relative; }
.account-button { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--line-soft); border-radius: 13px; background: var(--accent-soft); color: var(--accent-strong); font-size: 13px; font-weight: 900; }
.account-menu { position: absolute; z-index: 40; top: calc(100% + 9px); inset-inline-end: 0; width: 230px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-2); box-shadow: var(--elev-2); text-align: start; }
.account-menu[hidden] { display: none; }
.account-menu strong,.account-menu small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-menu small { margin-top: 4px; color: var(--muted); }
.account-menu button { width: 100%; min-height: 42px; margin-top: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-1); color: var(--text); font-weight: 750; }

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--accent-ink);
  background: var(--grad-accent);
  box-shadow: var(--accent-glow);
}

.brand-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-title {
  font-size: var(--fs-title);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}

.top-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}
.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.view[hidden] {
  display: none;
}

.overlay {
  position: absolute;
  inset: 0;
  background: var(--glass-scrim);
  -webkit-backdrop-filter: var(--scrim-blur);
  backdrop-filter: var(--scrim-blur);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-enter) var(--ease-out);
  z-index: 100;
}

.overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(160%) blur(28px);
  backdrop-filter: saturate(160%) blur(28px);
  border-top: 1px solid var(--line-soft);
  border-top-left-radius: var(--radius-xl);
  border-top-right-radius: var(--radius-xl);
  padding: 10px 18px max(28px, calc(env(safe-area-inset-bottom, 0px) + 22px));
  transform: translateY(100%);
  transition: transform var(--dur-sheet) var(--ease-spring);
  box-shadow: var(--shadow);
  z-index: 50;
  max-height: 86vh;
  max-height: 86dvh;
  max-height: min(88dvh, calc(var(--app-height) - 24px));
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
}

.overlay.open .sheet {
  transform: translateY(0);
}

.sheet-handle {
  width: 38px;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  margin: 6px auto 14px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 3;
  margin: 0 -18px 18px;
  padding: 2px 18px 12px;
  background: linear-gradient(var(--glass) 70%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.sheet-header h3 {
  margin: 0;
  font-size: var(--fs-title);
  font-weight: 800;
}

.sheet-section {
  margin-bottom: 18px;
}

/* Inline setting rows become contained iOS-style grouped cards. */
.sheet-section.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-m);
  padding: 13px 15px;
  margin-bottom: 12px;
}

/* Restore the wider between-group rhythm after a run of grouped cards. */
.sheet-section.row-between + .sheet-section:not(.row-between) {
  margin-top: 6px;
}

/* Sections stagger up as the sheet opens (reduced-motion guarded globally). */
.overlay.open .sheet-section {
  animation: rise-in 0.42s var(--ease-spring) both;
}

.overlay.open .sheet-section:nth-child(1) {
  animation-delay: 0.04s;
}

.overlay.open .sheet-section:nth-child(2) {
  animation-delay: 0.08s;
}

.overlay.open .sheet-section:nth-child(3) {
  animation-delay: 0.12s;
}

.overlay.open .sheet-section:nth-child(4) {
  animation-delay: 0.16s;
}

.overlay.open .sheet-section:nth-child(n + 5) {
  animation-delay: 0.2s;
}

/* Consolidated settings entry (e.g. "API & Providers") that opens a nested popup. */
.settings-row {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  text-align: start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 13px 15px;
  color: var(--text);
  transition: border-color var(--dur-fast) var(--ease-standard), background var(--dur-fast) var(--ease-standard), transform var(--dur-press) var(--ease-spring);
}

.settings-row:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: var(--surface-3);
}

.settings-row:active {
  transform: scale(0.99);
}

.settings-row-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-s);
  background: var(--accent-soft);
  color: var(--accent-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.settings-row-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.seg-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

@media (max-width: 460px) {
  .status-pill { width: 38px; min-width: 38px; padding: 0; justify-content: center; }
  .status-pill .status-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .top-right { gap: 6px; }
  .top-right > .icon-btn { width: 38px; height: 38px; border-radius: 13px; }
}

.settings-row-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.settings-row-title {
  font-size: var(--fs-base);
  font-weight: 700;
}

.settings-row-sub {
  font-size: var(--fs-small);
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-row-chev {
  color: var(--muted);
  font-size: var(--fs-lg);
  flex-shrink: 0;
  transition: transform var(--dur-fast) var(--ease-spring);
}

.settings-row:hover .settings-row-chev {
  transform: translateX(3px);
}

.settings-support {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 13px 15px 15px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-m);
  background: var(--surface-2);
}
.settings-support-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; color: var(--accent-strong); background: var(--accent-soft); }
.settings-support-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.settings-support strong,.settings-support small { display: block; }
.settings-support strong { color: var(--text); font-size: 14px; }
.settings-support small { margin-top: 3px; color: var(--muted); font-size: 10px; line-height: 1.35; }
.settings-support .feedback-link { grid-column: 2; width: fit-content; color: var(--accent-strong); font-size: 12px; font-weight: 750; overflow-wrap: anywhere; }

[dir="rtl"] .settings-row-chev {
  transform: scaleX(-1);
}

[dir="rtl"] .settings-row:hover .settings-row-chev {
  transform: scaleX(-1) translateX(3px);
}

.setting-label {
  display: block;
  font-size: var(--fs-small);
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.row-between .setting-label {
  margin-bottom: 0;
}

.lang-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang-row .select {
  flex: 1;
  min-width: 0;
}

@media (min-width: 480px) {
  .app-shell {
    padding: 20px 0;
    align-items: center;
  }

  .workspace {
    min-height: min(880px, calc(var(--app-height) - 40px));
    height: min(880px, calc(var(--app-height) - 40px));
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
  }
}
