:root {
  color-scheme: dark;
  --color-bg: var(--tg-theme-bg-color, #0b1016);
  --color-surface: var(--tg-theme-secondary-bg-color, #121a22);
  --color-surface-raised: #18232d;
  --color-surface-soft: rgba(255, 255, 255, 0.045);
  --color-text: var(--tg-theme-text-color, #edf3f5);
  --color-muted: var(--tg-theme-hint-color, #8d9ba5);
  --color-link: var(--tg-theme-link-color, #76c8b0);
  --color-accent: var(--tg-theme-button-color, #76c8b0);
  --color-on-accent: var(--tg-theme-button-text-color, #07130f);
  --color-success: #6fd1a9;
  --color-warning: #e2bb78;
  --color-danger: var(--tg-theme-destructive-text-color, #f18a8a);
  --color-border: rgba(203, 222, 229, 0.12);
  --color-focus: #a8e8d5;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.625rem;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --target-min: 44px;
  --page-max: 430px;
  --shadow-dialog: 0 24px 70px rgba(0, 0, 0, 0.48);
  --motion-fast: 150ms;
  --motion-base: 220ms;
}

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

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--color-bg);
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, summary { font: inherit; }
button { color: inherit; }
button, label, input { -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: wait; opacity: 0.62; }

button:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

h1, h2, h3, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; }

.button,
.icon-button {
  min-height: var(--target-min);
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.button {
  display: inline-flex;
  min-width: var(--target-min);
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1;
  transition: transform var(--motion-fast) ease, background-color var(--motion-fast) ease, opacity var(--motion-fast) ease;
}

.button:active:not(:disabled), .icon-button:active:not(:disabled) { transform: scale(0.97); }
.button--primary { background: var(--color-accent); color: var(--color-on-accent); }
.button--secondary { background: rgba(118, 200, 176, 0.12); color: var(--color-link); }
.button--ghost { background: var(--color-surface-soft); color: var(--color-text); }
.button--danger { background: rgba(241, 138, 138, 0.14); color: var(--color-danger); }
.button--compact { padding-inline: var(--space-3); }

.icon-button {
  display: inline-grid;
  min-width: var(--target-min);
  place-items: center;
  padding: 0;
  border-radius: var(--radius-pill);
  background: var(--color-surface-soft);
  transition: transform var(--motion-fast) ease, background-color var(--motion-fast) ease;
}

.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-soft);
  color: var(--color-text);
  padding: 0 var(--space-3);
  appearance: none;
}

.input::placeholder { color: var(--color-muted); opacity: 0.72; }
.input:focus { border-color: var(--color-accent); }

.field { display: grid; gap: var(--space-2); }
.field__label { color: var(--color-text); font-size: var(--text-sm); font-weight: 650; }
.field__hint { color: var(--color-muted); font-size: var(--text-xs); }
.toggle-row,
.check-row {
  position: relative;
  display: flex;
  min-height: var(--target-min);
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
}

.toggle-row > input,
.check-row > input {
  position: absolute;
  z-index: 1;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch {
  position: relative;
  width: 38px;
  height: 24px;
  flex: 0 0 auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface-raised);
  transition: background-color var(--motion-fast) ease, border-color var(--motion-fast) ease;
}

.switch > span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-muted);
  transition: transform var(--motion-fast) ease, background-color var(--motion-fast) ease;
}

.toggle-row > input:checked + .switch { border-color: var(--color-accent); background: rgba(118, 200, 176, 0.2); }
.toggle-row > input:checked + .switch > span { background: var(--color-accent); transform: translateX(14px); }
.toggle-row > input:focus-visible + .switch,
.check-row > input:focus-visible + .check-mark { outline: 2px solid var(--color-focus); outline-offset: 2px; }

.check-mark {
  display: grid;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--color-muted);
  border-radius: 6px;
  color: var(--color-on-accent);
}

.check-row > input:checked + .check-mark { border-color: var(--color-accent); background: var(--color-accent); }
.check-row > input:checked + .check-mark::after { width: 8px; height: 4px; border-bottom: 2px solid currentColor; border-left: 2px solid currentColor; content: ""; transform: translateY(-1px) rotate(-45deg); }

.dialog {
  width: min(calc(100% - 24px), 406px);
  max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
  margin: auto;
  padding: 0;
  overflow: visible;
  border: 0;
  background: transparent;
  color: var(--color-text);
}

.dialog::backdrop { background: rgba(2, 7, 11, 0.76); backdrop-filter: blur(8px); }
.dialog__surface {
  max-height: inherit;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-dialog);
  padding: var(--space-5);
}
.dialog__surface--compact { text-align: center; }
.dialog__header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.dialog__header h2, .dialog__surface--compact > h2 { font-size: var(--text-lg); }
.dialog__close { margin: calc(var(--space-2) * -1) calc(var(--space-2) * -1) 0 0; }
.dialog__actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
.form-stack { display: grid; gap: var(--space-5); }
.form-error { color: var(--color-danger); font-size: var(--text-sm); }

.eyebrow {
  margin-bottom: var(--space-1);
  color: var(--color-link);
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.spinner {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
