.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 9, 0.62);
  z-index: 55;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-slow) var(--ease-out);
}
.settings-overlay.open { opacity: 1; pointer-events: auto; }
@media (hover: hover) and (pointer: fine) and (min-width: 641px) {
  .settings-overlay {
    background: rgba(3, 5, 9, 0.5);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
  }
}

.settings-sheet {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  max-width: 100%;
  background: var(--panel);
  border-left: 1px solid var(--line);
  z-index: 60;
  transform: translateX(100%);
  transition: transform var(--dur-slow) var(--ease-out);
  overflow: hidden;
  box-shadow: -30px 0 60px -30px rgba(0, 0, 0, 0.9);
  outline: none;
}
.settings-sheet::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -1px;
  width: 1px;
  z-index: 3;
  background: linear-gradient(180deg, rgba(201, 161, 92, 0.5), rgba(201, 161, 92, 0.05) 40%, transparent 75%);
  pointer-events: none;
}
[dir="rtl"] .settings-sheet {
  right: auto;
  left: 0;
  border-left: none;
  border-right: 1px solid var(--line);
  transform: translateX(-100%);
  box-shadow: 30px 0 60px -30px rgba(0, 0, 0, 0.9);
}
[dir="rtl"] .settings-sheet::before { left: auto; right: -1px; }
.settings-sheet.open { transform: translateX(0); }
.settings-overlay.no-anim,
.settings-sheet.no-anim,
.settings-page.no-anim { transition: none !important; }

.settings-stack {
  position: relative;
  height: 100%;
  overflow: hidden;
}

.settings-page {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel);
  transform: translateX(100%);
  transition: transform var(--dur-slow) var(--ease-out), opacity var(--dur-slow) var(--ease-out);
}
[dir="rtl"] .settings-page { transform: translateX(-100%); }
.settings-page.entered { transform: translateX(0); }
.settings-page.entered.is-covered {
  transform: translateX(-28%);
  opacity: 0.35;
}
[dir="rtl"] .settings-page.entered.is-covered { transform: translateX(28%); }
.settings-page.leaving,
.settings-page.entered.leaving { transform: translateX(100%); }
[dir="rtl"] .settings-page.leaving,
[dir="rtl"] .settings-page.entered.leaving { transform: translateX(-100%); }
.settings-root.entered { transform: translateX(0); }
.settings-root.entered.is-covered { transform: translateX(-28%); }
[dir="rtl"] .settings-root.entered.is-covered { transform: translateX(28%); }
.settings-page:not(.settings-root) {
  box-shadow: -24px 0 40px -28px rgba(0, 0, 0, 0.9);
}
[dir="rtl"] .settings-page:not(.settings-root) {
  box-shadow: 24px 0 40px -28px rgba(0, 0, 0, 0.9);
}

.settings-page-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 16px 20px;
  background: var(--panel);
  flex-shrink: 0;
}
[dir="rtl"] .settings-page-head { padding: 18px 20px 16px 16px; }
.settings-page-head::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, var(--line), var(--line) 60%, transparent);
}
[dir="rtl"] .settings-page-head::after { background: linear-gradient(270deg, var(--line), var(--line) 60%, transparent); }
.settings-page-head h2 {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.2rem;
  letter-spacing: 0.01em;
  color: var(--bone);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.settings-back, .settings-close {
  flex: none;
  width: 34px;
  height: 34px;
  background: transparent;
  border: none;
  color: var(--ash);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  transition: color var(--dur-quick) var(--ease-out), background-color var(--dur-quick) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.settings-back { margin-inline-start: -8px; }
.settings-back svg, .settings-close svg {
  transition: transform var(--dur-base) var(--ease-spring);
}
[dir="rtl"] .settings-back svg { transform: scaleX(-1); }
@media (hover: hover) {
  .settings-back:hover, .settings-close:hover { color: var(--brass); background-color: rgba(255, 255, 255, 0.03); }
  .settings-close:hover svg { transform: rotate(90deg); }
  .settings-back:hover svg { transform: translateX(-2px); }
  [dir="rtl"] .settings-back:hover svg { transform: scaleX(-1) translateX(-2px); }
}
.settings-back:active, .settings-close:active { transform: scale(0.9); }

.settings-list {
  padding: 8px 10px 22px;
}
.settings-row {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 10px 10px;
  background: transparent;
  border: none;
  border-radius: 12px;
  color: var(--bone);
  cursor: pointer;
  text-align: left;
  font-size: 0.95rem;
  touch-action: manipulation;
  transition: background-color var(--dur-quick) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
[dir="rtl"] .settings-row { text-align: right; }
.settings-row + .settings-row::after {
  content: '';
  position: absolute;
  top: -0.5px;
  inset-inline-start: 52px;
  inset-inline-end: 10px;
  height: 1px;
  background: var(--line-soft);
}
.lang-row + .lang-row::after,
.settings-toggle-row + .settings-toggle-row::after { inset-inline-start: 50px; }
@media (hover: hover) {
  .settings-row:hover { background-color: rgba(255, 255, 255, 0.025); }
  .settings-row:hover .settings-row-chevron { color: var(--brass); transform: translateX(calc(3px * var(--dir))); }
  .settings-row:hover .settings-row-icon { color: var(--brass); box-shadow: inset 0 0 0 1px var(--brass-a28); }
}
.settings-row:active { transform: scale(0.985); background-color: var(--brass-a06); }
.settings-row-label { flex: 1; min-width: 0; }
.settings-row-meta { color: var(--ash); font-size: 0.84rem; }
.settings-row-meta .numeral { font-size: 0.92rem; color: var(--ash-hi); }
.settings-row-chevron {
  color: var(--ash-lo);
  display: flex;
  transition: color var(--dur-quick) var(--ease-out), transform var(--dur-base) var(--ease-spring);
}
[dir="rtl"] .settings-row-chevron svg { transform: scaleX(-1); }

.settings-row-icon {
  flex: none;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  color: var(--brass-dim);
  background: var(--mat-panel-2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), inset 0 0 0 1px rgba(255, 255, 255, 0.025);
  transition: color var(--dur-quick) var(--ease-out), box-shadow var(--dur-quick) var(--ease-out);
}

.settings-colophon {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 26px 20px calc(26px + env(safe-area-inset-bottom, 0px));
  color: var(--ash-lo);
  font-size: 0.78rem;
  animation: gm-fade var(--dur-epic) var(--ease-out) 500ms backwards;
}
.colophon-name {
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  color: var(--ash);
}
:root[lang="ar"] .colophon-name,
:root[lang="aii"] .colophon-name { letter-spacing: 0; }
.colophon-version::before { content: '· '; color: var(--ash-lo); }

.lang-code {
  flex: none;
  width: 28px;
  font-size: 0.62rem;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ash-lo);
  text-align: center;
  transition: color var(--dur-quick) var(--ease-out);
}
.lang-row.is-current .lang-code { color: var(--brass); }
.lang-row.is-current .settings-row-label { color: var(--brass-hi); }
.lang-row[data-lang="aii"] .settings-row-label {
  font-family: 'Noto Sans Syriac Eastern', 'Estrangelo Edessa', 'East Syriac Adiabene', var(--font-ui);
  line-height: 1.75;
  direction: rtl;
  text-align: right;
}
.settings-check { color: var(--brass); display: flex; }
.check-path {
  stroke-dasharray: 22;
  stroke-dashoffset: 22;
  animation: gm-draw var(--dur-slow) var(--ease-out) 260ms forwards;
}

.settings-toggle-row { cursor: pointer; }
.settings-toggle-row .system-index { width: 28px; text-align: center; min-width: 0; }
.switch { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.switch input {
  position: absolute;
  inset: 0;
  z-index: 1;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--mat-well);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.6), inset 0 0 0 1px var(--line);
  overflow: hidden;
}
.switch-track::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--mat-brass);
  box-shadow: var(--bevel-brass);
  opacity: 0;
  transform: scaleX(0.4);
  transform-origin: left center;
  transition: opacity var(--dur-quick) var(--ease-out), transform var(--dur-base) var(--ease-out);
}
[dir="rtl"] .switch-track::before { transform-origin: right center; }
.switch-thumb {
  position: absolute;
  z-index: 1;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff 0%, #dfe4ec 100%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.55), inset 0 -1px 0 rgba(0, 0, 0, 0.08);
  transform-origin: left center;
  transition: transform var(--dur-base) var(--ease-spring-lively), background var(--dur-quick) var(--ease-out);
}
.switch input:active ~ .switch-track .switch-thumb { transform: scaleX(1.18); }
.switch input:checked ~ .switch-track::before { opacity: 1; transform: none; }
.switch input:checked ~ .switch-track .switch-thumb {
  transform: translateX(18px);
  background: linear-gradient(180deg, #fffaf0 0%, #f1e6cf 100%);
}
.switch input:checked:active ~ .switch-track .switch-thumb {
  transform: translateX(14.4px) scaleX(1.18);
}
[dir="rtl"] .switch-thumb { left: auto; right: 3px; transform-origin: right center; }
[dir="rtl"] .switch input:checked ~ .switch-track .switch-thumb { transform: translateX(-18px); }
[dir="rtl"] .switch input:checked:active ~ .switch-track .switch-thumb { transform: translateX(-14.4px) scaleX(1.18); }
.switch input:focus-visible ~ .switch-track { outline: 1.5px solid var(--brass); outline-offset: 3px; }
.settings-toggle-row:has(input:checked) .settings-row-label { color: var(--bone); }
.settings-toggle-row:has(input:not(:checked)) .settings-row-label { color: var(--ash-hi); }

.settings-subtitle {
  padding: 16px 20px 0;
  color: var(--ash);
  font-size: 0.85rem;
  line-height: 1.55;
}

.settings-prose {
  padding: 22px 22px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.settings-prose p {
  color: var(--ash-hi);
  font-size: 0.9rem;
  line-height: 1.7;
}
.settings-prose p:first-child:not(.prose-lede) {
  color: var(--bone-dim);
}
.settings-prose .prose-lede {
  font-family: var(--font-display);
  font-size: 1.12rem;
  line-height: 1.5;
  color: var(--bone);
  text-align: center;
  padding: 0 6px 6px;
}
.about-version {
  margin-top: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}
.settings-prose .about-version .numeral { color: var(--brass); font-size: 0.95rem; }

.update-body {
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.update-version-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--mat-well);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5), inset 0 0 0 1px var(--line-soft);
  font-size: 0.88rem;
  color: var(--ash);
}
.update-version-value {
  color: var(--brass);
  font-size: 1.05rem;
}
.update-check-button {
  height: 46px;
  padding: 0 16px;
  border-radius: 12px;
  font-size: 0.95rem;
}

.update-progress {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 14px 0 4px;
}
.update-progress.is-active {
  display: flex;
  animation: gm-rise var(--dur-base) var(--ease-out) backwards;
}
.update-progress[hidden] {
  display: none !important;
}
.update-dial {
  position: relative;
  width: 88px;
  height: 88px;
  display: grid;
  place-items: center;
}
.update-dial > svg { position: absolute; }
.update-dial-ticks {
  inset: 0;
  color: var(--brass-dim);
  animation: gm-spin 14s linear infinite;
}
.update-dial-ticks path { stroke: currentColor; stroke-width: 0.6; opacity: 0.6; }
.update-dial-ring { transform: rotate(-90deg); }
.update-dial-track { stroke: var(--line); }
.update-dial-sweep {
  stroke: var(--brass);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s var(--ease-out);
}
.update-dial-value {
  position: relative;
  font-size: 1.05rem;
  color: var(--bone);
  transition: opacity var(--dur-quick) var(--ease-out), transform var(--dur-base) var(--ease-out);
}
.update-dial-value::after {
  content: '%';
  font-size: 0.62em;
  color: var(--ash);
  margin-inline-start: 1px;
}
.update-dial-check {
  position: absolute;
  color: var(--brass);
  opacity: 0;
}
.update-dial-check path { stroke-dasharray: 24; stroke-dashoffset: 24; }
.update-progress.is-done .update-dial-value { opacity: 0; transform: scale(0.7); }
.update-progress.is-done .update-dial-check { opacity: 1; }
.update-progress.is-done .update-dial-check path { animation: gm-draw 420ms var(--ease-out) forwards; }
.update-progress.is-done .update-dial-ticks { animation-play-state: paused; }
.update-stage-label {
  color: var(--ash-hi);
  font-size: 0.85rem;
}
.update-result-note {
  color: var(--ash);
  font-size: 0.85rem;
  min-height: 1.2em;
  text-align: center;
}
.update-result-note.is-error {
  color: var(--danger);
}

.agreement-screen {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(90% 60% at 50% -10%, rgba(24, 36, 58, 0.6), transparent 70%),
    var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}
.agreement-card {
  max-width: 460px;
  width: 100%;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 34px 30px 28px;
  border-radius: 24px;
  text-align: center;
  background: var(--mat-panel) padding-box, var(--edge-lit) border-box;
  box-shadow: var(--bevel), var(--depth-2);
  animation: gm-rise var(--dur-epic) var(--ease-out) 80ms backwards;
}
.agreement-card h1 {
  font-family: var(--font-display);
  font-weight: 400;
  margin-bottom: 16px;
  font-size: 1.75rem;
  line-height: 1.2;
  color: var(--bone);
  overflow: hidden;
  padding-bottom: 0.08em;
}
.agreement-card h1 .ch {
  display: inline-block;
  white-space: pre;
  animation: gm-letter 0.9s var(--ease-out) backwards;
  animation-delay: calc(300ms + var(--i, 0) * 26ms);
}
.agreement-card p {
  color: var(--ash-hi);
  margin-bottom: 24px;
  font-size: 0.9rem;
  line-height: 1.65;
  animation: gm-rise var(--dur-epic) var(--ease-out) 700ms backwards;
}
.agreement-policy-link,
.agreement-policy-back {
  display: block;
  margin: 0 auto 18px;
  padding: 8px 12px;
  color: var(--brass);
  text-decoration: underline;
  text-underline-offset: 3px;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.agreement-policy[hidden],
.agreement-summary[hidden] { display: none; }
.agreement-policy {
  display: flex;
  flex-direction: column;
  max-height: min(75vh, 640px);
  text-align: start;
}
.agreement-policy h1 { flex: 0 0 auto; text-align: center; }
.agreement-policy-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-inline-end: 4px;
}
.agreement-policy-body p { margin-bottom: 14px; }
.agreement-policy-back { flex: 0 0 auto; margin: 8px auto 0; }
.agreement-accept {
  width: 100%;
  height: 50px;
  padding: 0 32px;
  border-radius: 14px;
  font-size: 1rem;
  animation: gm-rise var(--dur-epic) var(--ease-out) 850ms backwards;
}

@media (max-width: 640px) {
  .settings-sheet { width: 100%; }
  .agreement-card { padding: 30px 22px 22px; }
}
