
.modal, .toast {
  --bg: var(--ink-850);
  --fg: #f3f6fc;
  --fg-2: #a9b4ca;
  --fg-3: #8b96ad;
  --surface: var(--ink-800);
  --surface-2: var(--ink-700);
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.22);
  --accent-text: var(--blue-sky);
  --ok-text: var(--ok-on-dark);
  --warn-text: var(--warn-on-dark);
  --danger-text: var(--danger-on-dark);
  color-scheme: dark;
}

html:has(.modal:not([hidden])) { overflow: hidden; }
@media (min-width: 601px) {
  html:has(.modal:not([hidden])) { scrollbar-gutter: stable; }
}

.modal {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 24px;
  color: var(--fg);
}

.modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(3, 6, 13, 0.72);
  animation: modal-fade 200ms var(--ease);
}

.modal__box {
  position: relative;
  width: 100%; max-width: 440px;
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
  padding: 0 32px 32px;
  border-radius: var(--r-xl);
  background: var(--bg);
  box-shadow: var(--shadow-modal);
  color: var(--fg);
  font-size: var(--fs-small);
  line-height: 1.5;
  animation: modal-in 220ms var(--ease);
}

@keyframes modal-fade { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px); } }

.modal :focus-visible { outline-color: var(--blue-sky); }

.modal__x {
  --x: 36px;
  position: sticky; top: 30px; z-index: 2;
  display: grid; place-items: center;
  width: var(--x); height: var(--x);
  margin: 30px -8px -34px auto;
  border-radius: 50%;
  background: var(--surface);
  color: var(--fg-2);
  font-size: 22px; line-height: 1; font-weight: 400;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.modal__x:hover { background: var(--surface-2); color: var(--fg); }

.modal__head { margin-bottom: 24px; }
.modal__head h3 {
  padding-right: 44px;
  font-family: var(--font-display);
  font-size: clamp(1.375rem, 1.2rem + 0.55vw, 1.625rem);
  line-height: 1.2; font-weight: 600; letter-spacing: -0.015em;
  color: var(--fg);
  text-wrap: balance;
}
.modal__head p {
  margin-top: 6px;
  font-size: 1rem; line-height: 1.45;
  color: var(--fg-2);
  text-wrap: pretty;
  overflow-wrap: anywhere;
}

.modal .field { margin-bottom: 16px; }
.modal .field input {
  min-height: 52px;
  font-size: 1rem;
  scroll-margin-bottom: 96px;
}
.modal .field input:hover { border-color: var(--line-strong); }
.modal .field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.38);
}
.modal .field input:user-invalid { border-color: var(--danger-text); }

.modal .field input:-webkit-autofill,
.modal .field input:-webkit-autofill:hover {
  -webkit-text-fill-color: var(--fg);
  caret-color: var(--fg);
  box-shadow: 0 0 0 40px var(--surface) inset;
}
.modal .field input:-webkit-autofill:focus {
  box-shadow: 0 0 0 40px var(--surface) inset, 0 0 0 3px rgba(37, 99, 235, 0.38);
}

.modal .note { margin-bottom: 16px; }

.modal a:not([href]) { cursor: pointer; }

.modal .btn--block { min-height: 52px; padding-block: 14px; font-size: 1.0625rem; }

.modal__forgot {
  margin: -6px 0 20px;
  text-align: right;
  font-size: var(--fs-small);
}
.modal__forgot a,
.modal__switch a {
  color: var(--accent-text); font-weight: 600;
  border-radius: 4px;
}
.modal__forgot a:hover,
.modal__switch a:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }

.authsep {
  display: flex; align-items: center; gap: 14px;
  margin: 20px 0;
  font-size: var(--fs-fine); color: var(--fg-3);
}
.authsep::before, .authsep::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.modal .btn--google, .modal .btn--apple { gap: 10px; }
.modal .btn--google { --btn-bd: #fff; }
.modal .btn--google:hover { --btn-bg: #e9edf4; --btn-bd: #e9edf4; }
.modal .btn--apple { --btn-bg: #000; --btn-fg: #fff; --btn-bd: rgba(255, 255, 255, 0.28); margin-top: 12px; }
.modal .btn--apple:hover { --btn-bg: #000; --btn-bd: rgba(255, 255, 255, 0.5); }
.modal .btn--apple svg { margin-top: -2px; }

.modal__switch {
  margin-top: 24px;
  text-align: center;
  font-size: var(--fs-small); color: var(--fg-2);
}
.modal__fineprint {
  margin-top: 12px;
  text-align: center;
  font-size: var(--fs-fine); line-height: 1.5; color: var(--fg-3);
  text-wrap: balance;
}
.modal__fineprint a {
  white-space: nowrap;
  color: var(--fg-2);
  text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
}
.modal__fineprint a:hover { color: var(--fg); text-decoration-color: currentColor; }

.prof__section { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); }
.prof__section--first { margin-top: 0; padding-top: 0; border-top: 0; }
.prof__title {
  margin-bottom: 14px;
  font-family: var(--font-display);
  font-size: var(--fs-body); line-height: 1.3; font-weight: 600; letter-spacing: -0.005em;
  color: var(--fg);
}
.prof__sub {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px;
  margin-bottom: 16px;
}
.prof__subinfo { font-size: var(--fs-small); color: var(--fg-2); }
.prof__subnote { margin-top: 12px; font-size: var(--fs-fine); line-height: 1.5; color: var(--fg-3); }
#profCancelBtn { margin-top: 10px; }
.prof__hint { margin-bottom: 16px; font-size: var(--fs-small); color: var(--fg-2); }

#profileModal .nav__pill {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 28px; padding: 4px 10px;
  border-radius: var(--r-sm);
  font-size: 0.875rem; font-weight: 600; line-height: 1.3;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--fg-2); background: var(--surface);
}
#profileModal .nav__pill--ok { color: var(--ok-on-dark); background: rgba(74, 222, 128, 0.12); }
#profileModal .nav__pill--off { color: var(--warn-on-dark); background: rgba(251, 191, 36, 0.12); }

.prof__tokens { display: flex; align-items: center; gap: 14px; }
.prof__tokens .tokenic { flex: none; }
.prof__tokens-count {
  font-family: var(--font-display);
  font-size: 1.375rem; line-height: 1.2; font-weight: 600; letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}
.prof__tokens-hint { margin-top: 2px; font-size: var(--fs-small); line-height: 1.45; color: var(--fg-2); }

.order {
  margin: 0 0 20px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.order__row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 6px 16px;
  padding: 10px 0;
  font-size: 1rem; line-height: 1.4; color: var(--fg);
}
.order__row > span { min-width: 0; }
.order__row > strong {
  flex: none;
  text-align: right; white-space: nowrap;
  font-weight: 600; font-size: 1.0625rem;
  font-variant-numeric: tabular-nums;
}
.order__row > span strong { font-weight: 600; }
.order__row--sub { padding: 4px 0 6px; font-size: var(--fs-small); color: var(--fg-2); }
.order__row--sub > strong { font-size: var(--fs-small); font-weight: 500; color: var(--fg-2); }
.order__row--sub:last-child { padding-bottom: 10px; }
.order__row--sub .order__discount { color: var(--ok-text); }
.order__was {
  margin-right: 4px;
  font-weight: 400; color: var(--fg-3);
  text-decoration-thickness: 1px;
}
.order__row--promo { flex-wrap: wrap; }
.order__row--promo > strong { margin-left: auto; }

#payDiscountCode { color: var(--fg); letter-spacing: 0.02em; }
.promo__remove {
  margin: -8px -6px -8px 4px; padding: 8px 6px;
  font-size: var(--fs-fine); font-weight: 500; color: var(--fg-3);
  text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px;
  border-radius: 6px;
}
.promo__remove:hover { color: var(--fg); }

.promo { margin: -8px 0 20px; }
.promo__toggle {
  margin: -8px 0; padding: 8px 0;
  font-size: var(--fs-small); font-weight: 600; color: var(--accent-text);
  border-radius: 4px;
}
.promo__toggle:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.promo__form { display: flex; gap: 8px; }
.promo__input {
  flex: 1; min-width: 0; min-height: 48px;
  padding: 0 14px;
  border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--surface); color: var(--fg);
  font-size: 1rem; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.promo__input::placeholder { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--fg-3); }
.promo__input:hover { border-color: var(--line-strong); }
.promo__input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.38); }
.promo__apply { flex: none; min-height: 48px; padding-inline: 20px; }
.promo__msg { margin-top: 10px; font-size: 0.875rem; font-weight: 500; line-height: 1.45; color: var(--fg-2); }
.promo__msg--ok { color: var(--ok-text); }
.promo__msg--err { color: var(--danger-text); }

@media (max-width: 600px) {
  .modal { place-items: end stretch; padding: 12px 0 0; }
  .modal__box {
    max-width: none;
    max-height: calc(100vh - 12px);
    max-height: calc(100dvh - 12px);
    padding: 24px 20px max(24px, calc(16px + env(safe-area-inset-bottom)));
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    animation-name: modal-sheet;
  }
  .modal__box { padding-top: 0; }
  .modal__x { top: 20px; margin: 20px -4px -32px auto; }
  .modal__head { margin-bottom: 20px; }
  .modal__head h3 { font-size: 1.375rem; }
}
@keyframes modal-sheet { from { opacity: 0; transform: translateY(40px); } }

.toast {
  position: fixed; z-index: 120;
  left: 50%; bottom: max(24px, calc(12px + env(safe-area-inset-bottom)));
  display: flex; align-items: center; gap: 12px;
  width: max-content; max-width: min(30rem, calc(100vw - 32px));
  padding: 13px 20px 13px 14px;
  border-radius: var(--r-lg);
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #1a2644;
  color: var(--fg);
  font-family: var(--font-text); font-size: var(--fs-small); font-weight: 500; line-height: 1.4;
  text-align: left;
  opacity: 0; transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

.toast__ic { flex: none; display: grid; place-items: center; width: 22px; height: 22px; }
.toast__ic svg { width: 22px; height: 22px; }
.toast__ic .checkic { width: 22px; height: 22px; vertical-align: 0; }
.toast--warn .toast__ic { color: var(--warn-on-dark); }

.toast--info .toast__ic svg,
.toast--err .toast__ic svg { display: none; }
.toast--info .toast__ic::before,
.toast--err .toast__ic::before {
  display: grid; place-items: center;
  width: 20px; height: 20px; border-radius: 6px;
  font-family: var(--font-display); font-size: 0.8125rem; font-weight: 700; line-height: 1;
  color: #fff;
}
.toast--info .toast__ic::before { content: "i"; content: "i" / ""; background: var(--blue); }
.toast--err .toast__ic::before { content: "!"; content: "!" / ""; background: var(--danger); }

@media (max-width: 600px) {
  .toast { left: 16px; right: 16px; width: auto; max-width: none; transform: translateY(12px); }
  .toast.is-show { transform: none; }
}
