.app-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.app-title-row h1 {
  margin: 0;
}

.settings-trigger {
  display: inline-flex;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 92%, var(--accent-soft));
  color: var(--accent);
  box-shadow: 0 6px 18px var(--shadow);
  cursor: pointer;
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.settings-trigger > span {
  display: block;
  width: 20px;
  height: 20px;
  overflow: hidden;
  color: transparent;
  font-size: 0;
}

.settings-trigger > span::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  background: var(--accent);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M19.14 12.94c.04-.31.06-.63.06-.94s-.02-.63-.07-.94l2.03-1.58a.5.5 0 0 0 .12-.64l-1.92-3.32a.5.5 0 0 0-.61-.22l-2.39.96a7.05 7.05 0 0 0-1.62-.94l-.36-2.54A.49.49 0 0 0 13.89 2h-3.84a.49.49 0 0 0-.49.41L9.2 4.95c-.58.24-1.12.56-1.62.94l-2.39-.96a.5.5 0 0 0-.61.22L2.66 8.47a.5.5 0 0 0 .12.64l2.03 1.58c-.05.31-.08.65-.08.97s.03.64.08.94l-2.03 1.58a.5.5 0 0 0-.12.64l1.92 3.32c.13.23.39.31.61.22l2.39-.96c.5.39 1.04.71 1.62.95l.36 2.53c.04.24.24.41.49.41h3.84c.25 0 .46-.17.49-.41l.36-2.53c.58-.24 1.12-.57 1.62-.95l2.39.96c.22.08.48 0 .61-.22l1.92-3.32a.5.5 0 0 0-.12-.64l-2.02-1.58ZM12 15.5A3.5 3.5 0 1 1 12 8a3.5 3.5 0 0 1 0 7.5Z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M19.14 12.94c.04-.31.06-.63.06-.94s-.02-.63-.07-.94l2.03-1.58a.5.5 0 0 0 .12-.64l-1.92-3.32a.5.5 0 0 0-.61-.22l-2.39.96a7.05 7.05 0 0 0-1.62-.94l-.36-2.54A.49.49 0 0 0 13.89 2h-3.84a.49.49 0 0 0-.49.41L9.2 4.95c-.58.24-1.12.56-1.62.94l-2.39-.96a.5.5 0 0 0-.61.22L2.66 8.47a.5.5 0 0 0 .12.64l2.03 1.58c-.05.31-.08.65-.08.97s.03.64.08.94l-2.03 1.58a.5.5 0 0 0-.12.64l1.92 3.32c.13.23.39.31.61.22l2.39-.96c.5.39 1.04.71 1.62.95l.36 2.53c.04.24.24.41.49.41h3.84c.25 0 .46-.17.49-.41l.36-2.53c.58-.24 1.12-.57 1.62-.95l2.39.96c.22.08.48 0 .61-.22l1.92-3.32a.5.5 0 0 0-.12-.64l-2.02-1.58ZM12 15.5A3.5 3.5 0 1 1 12 8a3.5 3.5 0 0 1 0 7.5Z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.settings-trigger:active {
  transform: scale(0.97);
}

.settings-dialog {
  box-sizing: border-box;
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: hidden;
}

.settings-dialog::backdrop {
  background: color-mix(in srgb, #000 46%, transparent);
  backdrop-filter: blur(2px);
}

.settings-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: default;
}

.settings-sheet {
  position: absolute;
  right: 50%;
  bottom: 20px;
  z-index: 1;
  box-sizing: border-box;
  width: min(620px, calc(100vw - 32px));
  max-height: min(760px, calc(100dvh - 40px));
  transform: translateX(50%);
  border: 1px solid var(--border-soft);
  border-radius: 24px;
  background: color-mix(in srgb, var(--surface) 98%, var(--accent-soft));
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.22);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.settings-sheet-handle {
  display: none;
}

.settings-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--divider);
}

.settings-kicker,
.settings-sheet-header h2 {
  margin: 0;
}

.settings-kicker {
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.settings-sheet-header h2 {
  margin-top: 3px;
  font-size: 1.25rem;
}

.settings-close {
  display: inline-flex;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--soft-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 1.35rem;
  line-height: 1;
  touch-action: manipulation;
}

.settings-content {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.settings-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--divider);
  border-radius: 14px;
  background: var(--soft-2);
}

.settings-section-copy h3,
.settings-section-copy p {
  margin: 0;
}

.settings-section-copy h3 {
  font-size: 0.95rem;
}

.settings-section-copy p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
}

.settings-theme-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border));
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  touch-action: manipulation;
}

.settings-content > .backup-panel,
.settings-content > .data-safety {
  margin: 0;
  box-shadow: none;
}

@media (prefers-reduced-motion: no-preference) {
  .settings-dialog[open] .settings-sheet {
    animation: settings-sheet-in 180ms ease-out both;
  }

  .settings-trigger,
  .settings-close,
  .settings-theme-button {
    transition: transform 120ms ease, border-color 160ms ease, background 160ms ease;
  }

  @keyframes settings-sheet-in {
    from {
      opacity: 0;
      transform: translateX(50%) translateY(14px) scale(0.985);
    }
    to {
      opacity: 1;
      transform: translateX(50%) translateY(0) scale(1);
    }
  }
}

@media (max-width: 640px) {
  .settings-dialog::backdrop {
    background: color-mix(in srgb, #000 38%, transparent);
    backdrop-filter: blur(1.5px);
  }

  .settings-sheet {
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: calc(100dvh - max(44px, env(safe-area-inset-top)));
    transform: none;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 24px 24px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .settings-sheet-handle {
    display: block;
    width: 42px;
    height: 5px;
    margin: 9px auto 0;
    border-radius: 999px;
    background: var(--border);
  }

  .settings-sheet-header {
    padding-top: 12px;
  }

  @media (prefers-reduced-motion: no-preference) {
    .settings-dialog[open] .settings-sheet {
      animation: settings-sheet-mobile-in 180ms ease-out both;
    }

    @keyframes settings-sheet-mobile-in {
      from {
        opacity: 0;
        transform: translateY(24px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }
  }
}

@media (max-width: 430px) {
  .settings-trigger {
    width: 42px;
    height: 42px;
    border-radius: 13px;
  }

  .settings-sheet-header {
    padding-right: 14px;
    padding-left: 14px;
  }

  .settings-content {
    padding: 12px;
  }

  .settings-section {
    gap: 10px;
    padding: 12px;
  }

  .settings-theme-button {
    flex: 0 0 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .settings-trigger:active {
    transform: none;
  }
}
