:root,
[data-theme="light"] {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-subtle: #f1f4f0;
  --border: #dfe4dd;
  --border-strong: #c6d0c3;
  --text: #151c17;
  --text-muted: #5a665d;
  --accent: #15803d;
  --accent-hover: #166534;
  --accent-soft: rgba(22, 163, 74, 0.1);
  --accent-ring: rgba(22, 163, 74, 0.28);
  --warn-bg: rgba(180, 83, 9, 0.08);
  --warn-text: #92400e;
  --error-bg: rgba(185, 28, 28, 0.08);
  --error-text: #b91c1c;
  --shadow: 0 8px 30px rgba(15, 23, 18, 0.06);
}

[data-theme="dark"] {
  --bg: #0b0f0c;
  --surface: #121814;
  --surface-subtle: #18211b;
  --border: #253129;
  --border-strong: #334439;
  --text: #edf2ee;
  --text-muted: #98a69c;
  --accent: #22c55e;
  --accent-hover: #16a34a;
  --accent-soft: rgba(34, 197, 94, 0.12);
  --accent-ring: rgba(34, 197, 94, 0.3);
  --warn-bg: rgba(245, 158, 11, 0.12);
  --warn-text: #fcd34d;
  --error-bg: rgba(239, 68, 68, 0.12);
  --error-text: #fca5a5;
  --shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Naskh Arabic", "Geeza Pro", "Segoe UI", Tahoma, system-ui, -apple-system, sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

.page-shell {
  min-height: 100dvh;
  max-width: 580px;
  margin-inline: auto;
  padding: 1rem 1.125rem 1.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.01em;
}

.brand-logo {
  width: 24px;
  height: 25px;
  flex-shrink: 0;
  display: block;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.ghost-btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  height: 36px;
  padding-inline: 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.icon-btn {
  width: 36px;
  padding-inline: 0;
}

.ghost-btn:hover,
.icon-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.install-btn {
  color: var(--accent);
  border-color: var(--accent-soft);
  background: var(--accent-soft);
}

.icon-sm {
  width: 17px;
  height: 17px;
}

.ios-popover {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
}

.ios-popover p {
  margin: 0;
}

.close-x {
  background: transparent;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.1rem 0.25rem;
}

.main-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.4rem 1.35rem;
  box-shadow: var(--shadow);
}

.view-panel {
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.view-centered {
  align-items: center;
  text-align: center;
  padding-block: 1rem;
}

.hero {
  text-align: center;
}

.hero-title {
  margin: 0 0 0.35rem;
  font-size: clamp(1.34rem, 4vw, 1.65rem);
  font-weight: 700;
  line-height: 1.32;
}

.hero-subtitle {
  margin: 0 auto;
  max-width: 46ch;
  color: var(--text-muted);
  font-size: 0.91rem;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
}

.mode-tab {
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.89rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.mode-tab:hover:not(.is-active) {
  color: var(--text);
}

.mode-tab.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 1.45rem 1.15rem;
  border: 1.5px dashed var(--border-strong);
  border-radius: 16px;
  background: var(--surface-subtle);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.18s ease, background-color 0.18s ease;
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone-icon {
  width: 34px;
  height: 34px;
  color: var(--accent);
  margin-bottom: 0.15rem;
}

.dropzone-cta {
  font-size: 1.03rem;
  font-weight: 700;
  color: var(--text);
}

.dropzone-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.selected-file-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.95rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
}

.selected-file-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.selected-file-name {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selected-file-size {
  font-size: 0.78rem;
  color: var(--text-muted);
  unicode-bidi: isolate;
  align-self: flex-start;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-align: start;
}

.field label {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-muted);
}

.select-control,
.field input,
.field textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.select-control {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.select-control:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.select-control:focus,
.field input:focus,
.field textarea:focus,
.dropzone:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.micro-note {
  margin: -0.45rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.trim-panel {
  padding: 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.trim-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.ranges-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.55rem;
  align-items: end;
}

.range-row input {
  padding: 0.5rem 0.65rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.88rem;
  direction: ltr;
  text-align: center;
}

.range-remove-btn {
  height: 38px;
  padding-inline: 0.65rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.82rem;
}

.range-remove-btn:hover {
  color: var(--error-text);
  border-color: var(--error-text);
}

.secondary-sm-btn {
  align-self: flex-start;
  padding: 0.42rem 0.8rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.inline-error {
  margin: 0;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: var(--error-bg);
  color: var(--error-text);
  font-size: 0.86rem;
}

.primary-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.82rem 1.25rem;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #ffffff;
  font-size: 1rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

[data-theme="dark"] .primary-btn {
  color: #062110;
}

.primary-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.secondary-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.78rem 1.2rem;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.secondary-btn:hover {
  background: var(--surface-subtle);
}

.link-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.link-btn:hover {
  color: var(--text);
}

.processing-emblem {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
}

.crescent-pulse {
  width: 48px;
  height: 48px;
  animation: gentle-pulse 2s ease-in-out infinite;
}

@keyframes gentle-pulse {
  0%, 100% {
    opacity: 0.65;
    transform: scale(0.96);
  }
  50% {
    opacity: 1;
    transform: scale(1.04);
  }
}

.processing-filename {
  margin: 0;
  font-weight: 600;
  font-size: 0.94rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.processing-stage {
  margin: -0.6rem 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.progress-wrap {
  width: 100%;
  height: 9px;
  border-radius: 999px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.progress-pct {
  margin: -0.75rem 0 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.soft-tip {
  margin: 0;
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.84rem;
}

.status-badge {
  width: 52px;
  height: 52px;
  border-radius: 999px;
  display: grid;
  place-items: center;
}

.status-badge svg {
  width: 26px;
  height: 26px;
}

.status-success {
  background: var(--accent-soft);
  color: var(--accent);
}

.status-guard {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.panel-heading {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.result-summary {
  margin: -0.35rem 0 0.25rem;
  font-size: 1.04rem;
  font-weight: 600;
  color: var(--text);
}

.guard-body {
  margin: 0 0 0.5rem;
  max-width: 44ch;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.result-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.another-btn {
  margin-top: 0.25rem;
}

.footer-line {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding-top: 0.5rem;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.footer-link {
  background: transparent;
  border: none;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
  padding: 0.15rem 0.25rem;
}

.footer-link:hover {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.modal-dialog {
  border: none;
  padding: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  width: min(92vw, 440px);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.modal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.modal-card {
  padding: 1.35rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.feedback-status {
  margin: 0;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  font-size: 0.86rem;
  background: var(--surface-subtle);
}

.feedback-status.is-success {
  background: var(--accent-soft);
  color: var(--accent);
}

.feedback-status.is-error {
  background: var(--error-bg);
  color: var(--error-text);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 999;
}

@media (max-width: 520px) {
  .main-card {
    padding: 1.35rem 1.1rem;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }
}
