:root {
  color-scheme: dark;
  --bg: #0a0a0c;
  --bg-elevated: #0f0f12;
  --panel: rgba(18, 18, 22, 0.92);
  --panel-2: #141418;
  --panel-solid: #121216;
  --text: #ececf1;
  --muted: #7a7d85;
  --muted-2: #555860;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.10);
  --accent: #9e2a3b;
  --accent-2: #7a1f2d;
  --accent-glow: rgba(158, 42, 59, 0.30);
  --danger: #c0392b;
  --danger-soft: rgba(192, 57, 43, 0.10);
  --success: #27ae60;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
  --radius: 18px;
  --radius-sm: 12px;
  --transition: 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

/* Ambient background — RED orbs */
.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.40;
  animation: float 20s ease-in-out infinite;
}

.orb-1 {
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, rgba(160, 30, 30, 0.50), transparent 70%);
  top: -6%;
  left: 50%;
  transform: translateX(-50%);
}

.orb-2 {
  width: 240px;
  height: 240px;
  background: radial-gradient(circle, rgba(140, 20, 20, 0.35), transparent 70%);
  bottom: 12%;
  left: -8%;
  animation-delay: -7s;
}

.orb-3 {
  width: 180px;
  height: 180px;
  background: radial-gradient(circle, rgba(120, 25, 25, 0.25), transparent 70%);
  bottom: 22%;
  right: -4%;
  animation-delay: -14s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(10px, -14px) scale(1.03); }
  66% { transform: translate(-8px, 8px) scale(0.98); }
}

html[data-reduce-motion="true"] .orb {
  animation: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  background: none;
}

.app-shell {
  min-height: 100dvh;
  padding:
    max(22px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(22px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  position: relative;
  z-index: 1;
}

/* ========== MAIN MENU ========== */
.main-menu {
  width: min(420px, 100%);
  min-height: calc(100dvh - 44px);
  margin: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 26px;
  position: relative;
}

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

.brand-mark {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: transparent;
  border: none;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-text .eyebrow {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.18em;
  font-weight: 800;
}

.brand-text h1 {
  margin: 2px 0 0;
  font-size: 28px;
  letter-spacing: -0.04em;
  font-weight: 900;
  line-height: 1.1;
}

.tagline {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

/* Menu card */
.menu-card {
  display: grid;
  gap: 6px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.menu-button {
  width: 100%;
  min-height: 54px;
  padding: 0 16px 0 12px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 15px;
  transition:
    transform var(--transition),
    background var(--transition),
    border-color var(--transition);
}

.menu-button:active {
  transform: scale(0.98);
}

.menu-button:hover {
  background: #18181d;
  border-color: var(--border-strong);
}

.btn-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-icon-wrap {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.04);
  font-size: 14px;
  color: var(--muted);
  flex-shrink: 0;
}

.menu-button.primary {
  background: var(--accent);
  border-color: transparent;
  color: white;
}

.menu-button.primary:hover {
  background: #b03045;
}

.menu-button.primary .btn-icon-wrap {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.menu-button.danger {
  color: var(--danger);
}

.menu-button.danger .btn-icon-wrap {
  background: var(--danger-soft);
  color: var(--danger);
}

.button-arrow {
  font-size: 17px;
  opacity: 0.35;
  font-weight: 500;
}

/* Status */
.status-line {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 10px rgba(39, 174, 96, 0.45);
  animation: blink 2.4s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

html[data-reduce-motion="true"] .status-dot {
  animation: none;
}

.version-badge {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--muted-2);
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* ========== SCREENS ========== */
.screen {
  width: min(480px, 100%);
  min-height: calc(100dvh - 44px);
  margin: auto;
  padding-top: 4px;
  position: relative;
  animation: screenIn 0.24s var(--transition);
}

@keyframes screenIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

html[data-reduce-motion="true"] .screen {
  animation: none;
}

.hidden {
  display: none !important;
}

.back-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  padding: 10px 4px;
  font-weight: 700;
  font-size: 14px;
  transition: color var(--transition);
}

.back-button:hover {
  color: var(--text);
}

.back-arrow {
  font-size: 16px;
}

/* Coming soon */
.coming-soon {
  min-height: calc(100dvh - 110px);
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  gap: 10px;
  padding: 20px 0;
}

.coming-icon {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
}

.coming-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.coming-soon .eyebrow {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.16em;
  font-weight: 800;
}

.coming-soon h2 {
  margin: 0;
  font-size: 32px;
  letter-spacing: -0.03em;
  font-weight: 900;
}

.coming-soon p {
  margin: 0;
  color: var(--muted);
  max-width: 300px;
  line-height: 1.55;
  font-size: 14px;
}

.progress-bar {
  width: 160px;
  height: 4px;
  background: var(--panel-2);
  border-radius: 99px;
  margin-top: 18px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 38%;
  background: var(--accent);
  border-radius: 99px;
  animation: progressPulse 2.2s ease-in-out infinite;
}

@keyframes progressPulse {
  0%, 100% { width: 32%; opacity: 0.85; }
  50% { width: 48%; opacity: 1; }
}

html[data-reduce-motion="true"] .progress-fill {
  animation: none;
  width: 40%;
}

.progress-label {
  font-size: 12px !important;
  color: var(--muted-2) !important;
  margin-top: 6px !important;
}

/* ========== SETTINGS ========== */
.settings-panel {
  margin-top: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.panel-header .eyebrow {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.16em;
  font-weight: 800;
}

.panel-header h2 {
  margin: 4px 0 0;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.panel-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(158, 42, 59, 0.12);
  font-size: 18px;
  color: var(--accent);
}

/* Settings tabs */
.settings-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-top: 16px;
  margin-bottom: 8px;
}

.tab-btn {
  min-height: 36px;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  transition: all 0.16s ease;
}

.tab-btn.active {
  background: var(--accent);
  color: white;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.setting-group {
  padding-top: 18px;
}

.setting-title {
  font-weight: 800;
  font-size: 14px;
  margin-bottom: 4px;
}

.setting-desc {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.4;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* Segmented controls */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  margin-top: 10px;
}

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

.segmented button {
  min-height: 38px;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  transition: all 0.16s ease;
}

.segmented button.active {
  background: var(--accent);
  color: white;
}

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.toggle-track::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 2px;
  top: 2px;
  background: #6b6f78;
  border-radius: 50%;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), background 0.2s ease;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
}

.toggle input:checked + .toggle-track {
  background: var(--accent);
  border-color: transparent;
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(20px);
  background: white;
}

.toggle input:disabled + .toggle-track {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Danger action */
.danger-action {
  width: 100%;
  min-height: 46px;
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 700;
  font-size: 14px;
  border: 1px solid rgba(192, 57, 43, 0.15);
  transition: background 0.18s ease, transform 0.15s ease;
}

.danger-action:active {
  transform: scale(0.98);
}

.danger-action:hover {
  background: rgba(192, 57, 43, 0.16);
}

/* ========== AI TAB COMPONENTS ========== */
.select-wrap {
  margin-top: 8px;
}

.styled-select {
  width: 100%;
  height: 44px;
  padding: 0 32px 0 12px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%237a7d85' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
}

.styled-input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  margin-top: 8px;
  outline: none;
  transition: border-color 0.2s ease;
}

.styled-input:focus {
  border-color: var(--accent);
}

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

.input-with-btn {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.input-with-btn .styled-input {
  flex: 1;
  margin-top: 0;
}

.scan-btn {
  height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.18s ease, transform 0.15s ease;
}

.scan-btn:active {
  transform: scale(0.97);
}

.scan-btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Model grid with vertical scroll + right slider */
.model-search-wrap {
  margin-top: 10px;
}

.model-grid-wrap {
  margin-top: 10px;
  height: 320px;
  overflow: hidden;
  border-radius: 16px;
}

.model-scroll-container {
  height: 100%;
  overflow-y: auto;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) var(--panel-2);
  padding-right: 4px;
}

.model-scroll-container::-webkit-scrollbar {
  width: 4px;
}

.model-scroll-container::-webkit-scrollbar-track {
  background: var(--panel-2);
  border-radius: 99px;
}

.model-scroll-container::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 99px;
}



/* Model card — redesigned */
.model-card {
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.2s ease;
  flex-shrink: 0;
}

.model-card.selected {
  border-color: var(--accent);
}

.model-card-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.provider-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 800;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--panel-2);
}

.provider-logo img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.provider-logo .logo-fallback {
  font-size: 14px;
  font-weight: 800;
}

.model-card-header .model-name-block {
  flex: 1;
  min-width: 0;
}

.model-card-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.25;
  word-break: break-word;
}

.model-card-header .model-id {
  margin: 3px 0 0;
  font-size: 11px;
  color: var(--muted-2);
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.model-specs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.spec-item {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.spec-label {
  font-size: 10px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.spec-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.model-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2px;
}

.model-developer {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

.model-select-btn {
  min-height: 32px;
  padding: 0 16px;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  font-size: 13px;
  transition: all 0.18s ease;
}

.model-select-btn.selected {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  pointer-events: none;
}

.model-select-btn:active {
  transform: scale(0.97);
}

/* Loading & error */
/* Model fallback notice */
.model-fallback-notice {
  padding: 10px 12px;
  background: rgba(158, 42, 59, 0.10);
  border: 1px solid var(--accent);
  border-radius: 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 8px;
  flex-shrink: 0;
}

html[data-theme="light"] .model-fallback-notice,
@media (prefers-color-scheme: light) {
  html[data-theme="system"] .model-fallback-notice {
    background: rgba(158, 42, 59, 0.06);
  }
}

.model-grid-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  justify-content: center;
}

.loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.model-error {
  padding: 16px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  background: var(--danger-soft);
  border-radius: 12px;
}

/* ========== ABOUT ========== */
.about-panel {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: screenIn 0.24s var(--transition);
}

.about-hero {
  text-align: center;
  padding: 24px 16px 10px;
}

.about-logo {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  overflow: hidden;
  margin: 0 auto 14px;
  background: transparent;
  border: none;
}

.about-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.about-hero h2 {
  margin: 0;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.about-version {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.about-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px 18px;
}

.about-card p {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}

.about-meta {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 4px 16px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.meta-row:last-child {
  border-bottom: none;
}

.meta-label {
  color: var(--muted);
  font-weight: 600;
}

.meta-value {
  font-weight: 700;
}

.status-ok {
  color: var(--success);
}

.about-footer {
  text-align: center;
  font-size: 12px;
  color: var(--muted-2);
  margin: 6px 0 0;
}

/* ========== COMPACT MODE ========== */
html[data-compact="true"] .main-menu {
  gap: 16px;
}

html[data-compact="true"] .menu-button {
  min-height: 48px;
}

html[data-compact="true"] .brand-mark {
  width: 52px;
  height: 52px;
}

html[data-compact="true"] .brand-text h1 {
  font-size: 24px;
}

html[data-compact="true"] .setting-group {
  padding-top: 12px;
}

/* ========== NO ANIMATIONS ========== */
html[data-no-anim="true"] * {
  animation: none !important;
  transition-duration: 0.01ms !important;
}

/* ========== LIGHT THEME ========== */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #eaecef;
  --bg-elevated: #f0f1f4;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-2: #e2e4e8;
  --panel-solid: #ffffff;
  --text: #111114;
  --muted: #5c5f66;
  --muted-2: #8a8f96;
  --border: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.10);
  --shadow: 0 16px 40px rgba(20, 25, 35, 0.08);
  --accent-glow: rgba(158, 42, 59, 0.18);
}

html[data-theme="light"] .orb {
  opacity: 0.30;
}

html[data-theme="light"] .menu-button:hover {
  background: #f2f3f5;
}

html[data-theme="light"] .btn-icon-wrap {
  background: rgba(0, 0, 0, 0.03);
}

html[data-theme="light"] .toggle-track::after {
  background: #8a8f96;
}

html[data-theme="light"] .toggle input:checked + .toggle-track::after {
  background: white;
}

html[data-theme="light"] .spec-item {
  background: rgba(0,0,0,0.02);
}

/* System theme → light when OS prefers light */
@media (prefers-color-scheme: light) {
  html[data-theme="system"] {
    color-scheme: light;
    --bg: #eaecef;
    --bg-elevated: #f0f1f4;
    --panel: rgba(255, 255, 255, 0.92);
    --panel-2: #e2e4e8;
    --panel-solid: #ffffff;
    --text: #111114;
    --muted: #5c5f66;
    --muted-2: #8a8f96;
    --border: rgba(0, 0, 0, 0.06);
    --border-strong: rgba(0, 0, 0, 0.10);
    --shadow: 0 16px 40px rgba(20, 25, 35, 0.08);
    --accent-glow: rgba(158, 42, 59, 0.18);
  }

  html[data-theme="system"] .orb {
    opacity: 0.30;
  }

  html[data-theme="system"] .menu-button:hover {
    background: #f2f3f5;
  }

  html[data-theme="system"] .btn-icon-wrap {
    background: rgba(0, 0, 0, 0.03);
  }

  html[data-theme="system"] .spec-item {
    background: rgba(0,0,0,0.02);
  }
}