/* Design tokens, reset, and shared shell (nav, footer, buttons). */

:root {
  --bg: #ffffff;
  --surface: #f7f7f8;
  --surface-alt: #f1f1f3;
  --border: #e6e6ea;
  --border-strong: #d6d6dd;

  --text: #16161a;
  --text-secondary: #5b5b68;
  --text-muted: #8b8b98;

  --accent: #1e8289;
  --accent-hover: #186b71;
  --accent-soft: #e8f2f2;
  --nav-bg: rgba(255, 255, 255, 0.85);
  --primary-hover: #2c2c33;
  --on-strong: #ffffff;
  --overlay: rgba(22, 22, 26, 0.35);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(22, 22, 26, 0.05);
  --shadow: 0 10px 34px rgba(22, 22, 26, 0.07);

  --page-max: 1080px;
  --nav-height: 64px;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #111315;
  --surface: #191c1f;
  --surface-alt: #22262a;
  --border: #2b3035;
  --border-strong: #3c434a;

  --text: #f1f3f4;
  --text-secondary: #b5bac1;
  --text-muted: #858b94;

  --accent: #62bcc2;
  --accent-hover: #75c9ce;
  --accent-soft: #173033;
  --nav-bg: rgba(17, 19, 21, 0.88);
  --primary-hover: #d9dde0;
  --on-strong: #111315;
  --overlay: rgba(0, 0, 0, 0.58);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.22);
  --shadow: 0 12px 38px rgba(0, 0, 0, 0.3);
}

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

/*
 * The browser hides [hidden] with `display: none`, but that is a plain element
 * rule, so any class here that sets a display wins and the element stays on
 * screen with its hidden attribute set. Anything toggled from JS needs this.
 */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
}

p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

img,
svg {
  display: block;
  max-width: 100%;
}

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Layout helpers */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.container {
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 24px;
}

.section {
  padding: 88px 0;
}

.section--tight {
  padding: 64px 0;
}

.section--surface {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.section-head {
  max-width: 620px;
  margin-bottom: 44px;
}

.section-label {
  display: block;
  margin-bottom: 12px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.section-title {
  font-size: clamp(26px, 3.4vw, 34px);
}

.section-sub {
  margin-top: 14px;
  color: var(--text-secondary);
  font-size: 17px;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn--primary {
  background: var(--text);
  color: var(--on-strong);
}

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

.btn--secondary {
  background: var(--bg);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn--secondary:hover {
  background: var(--surface);
  border-color: var(--text-muted);
}

.btn--ghost {
  height: 38px;
  padding: 0 14px;
  color: var(--text-secondary);
}

.btn--ghost:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.btn--sm {
  height: 36px;
  padding: 0 16px;
  font-size: 14px;
}

.btn--block {
  width: 100%;
}

/* Navigation */

.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--nav-height);
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}

.nav.is-scrolled {
  border-bottom-color: var(--border);
}

.nav__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.nav__brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.nav__mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--text);
  color: var(--on-strong);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
}

.nav__links {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Only ever seen on a narrow screen, where the links live behind it. */

.nav__toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-right: -8px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  cursor: pointer;
}

.nav__toggle:hover {
  background: var(--surface-alt);
}

.nav__burger,
.nav__burger::before,
.nav__burger::after {
  display: block;
  width: 18px;
  height: 1.5px;
  border-radius: 2px;
  background: currentColor;
  transition: transform 0.18s ease, opacity 0.12s ease;
}

.nav__burger::before,
.nav__burger::after {
  content: "";
  position: relative;
}

.nav__burger::before {
  top: -6px;
}

.nav__burger::after {
  top: 4.5px;
}

.nav.is-open .nav__burger {
  background: transparent;
}

.nav.is-open .nav__burger::before {
  transform: translateY(6px) rotate(45deg);
}

.nav.is-open .nav__burger::after {
  transform: translateY(-4.5px) rotate(-45deg);
}

.nav__link {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 15px;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.nav__link:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.nav__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Compact night-view switch; the text is available through its accessible name. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.theme-toggle:hover {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

.theme-toggle__moon {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle__label {
  display: none;
}

.theme-toggle__track {
  position: relative;
  width: 27px;
  height: 16px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  transition: background-color 0.16s ease;
}

.theme-toggle__track span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease, background-color 0.16s ease;
}

.theme-toggle[aria-pressed="true"] .theme-toggle__track {
  background: var(--accent);
}

.theme-toggle[aria-pressed="true"] .theme-toggle__track span {
  transform: translateX(11px);
}

/* Account: a way in when signed out, a way out when signed in */

.account {
  position: relative;
  margin-left: 4px;
}

.account__toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 5px;
  border: 0;
  border-radius: var(--radius-pill);
  background: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.account__toggle:hover,
.account__toggle[aria-expanded="true"] {
  background: var(--surface-alt);
  color: var(--text);
}

.account__avatar {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  font-size: 12.5px;
  font-weight: 600;
}

.account__caret {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.account__toggle[aria-expanded="true"] .account__caret {
  transform: rotate(180deg);
}

.account__menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  min-width: 200px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  box-shadow: var(--shadow);
}

.account__who {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.account__email {
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account__plan {
  color: var(--text-muted);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.account__item {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.account__item:hover {
  background: var(--surface-alt);
  color: var(--text);
}

/* Text input */

.input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.input::placeholder {
  color: var(--text-muted);
}

.input:focus {
  outline: none;
  border-color: var(--text-muted);
  box-shadow: 0 0 0 4px rgba(22, 22, 26, 0.04);
}

/* Dialog used for warnings that need an answer */

.modal {
  width: min(430px, calc(100vw - 32px));
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(2px);
}

.modal__title {
  font-size: 20px;
  letter-spacing: -0.02em;
}

.modal__text {
  margin-top: 10px;
  color: var(--text-secondary);
  font-size: 14.5px;
  line-height: 1.6;
}

.modal__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 22px;
}

/* Footer */

.footer {
  padding: 40px 0;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 14px;
}

.footer__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

.footer__links a:hover {
  color: var(--text);
}

@media (max-width: 720px) {
  :root {
    --nav-height: 56px;
  }

  body {
    font-size: 16px;
  }

  .container {
    padding: 0 18px;
  }

  .section {
    padding: 64px 0;
  }

  .nav__brand {
    font-size: 18px;
  }

  .nav__toggle {
    display: inline-flex;
  }

  /* The links drop out of the bar and become a sheet under it. */
  .nav__links {
    position: absolute;
    top: var(--nav-height);
    left: 0;
    right: 0;
    display: grid;
    gap: 2px;
    padding: 8px 18px calc(12px + env(safe-area-inset-bottom, 0px));
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    box-shadow: var(--shadow);
  }

  .nav:not(.is-open) .nav__links {
    display: none;
  }

  .nav__link {
    padding: 12px 10px;
    font-size: 16px;
  }

  .nav__link.is-active {
    background: var(--surface);
    color: var(--text);
  }

  .nav__links .theme-toggle {
    justify-content: flex-start;
    width: 100%;
    height: 44px;
    padding: 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    font-size: 16px;
  }

  .nav__links .theme-toggle__label {
    display: inline;
  }

  .nav__links .theme-toggle__track {
    margin-left: auto;
  }

  /* In the sheet there is nothing to float a menu over, so it opens as rows. */
  .nav__account {
    margin-top: 4px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
  }

  .account__toggle {
    width: 100%;
    padding: 10px;
    font-size: 16px;
  }

  .account__caret {
    margin-left: auto;
  }

  .account__menu {
    position: static;
    min-width: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .account__item {
    padding: 12px 10px;
    font-size: 16px;
  }

  .nav__actions {
    gap: 6px;
  }

  /*
   * A phone bar has no room for "3 of 3 left today", so the script also writes
   * the short form and we show that one instead.
   */
  .usage[data-short] {
    font-size: 0;
  }

  .usage[data-short]::after {
    content: attr(data-short);
    font-size: 13px;
    white-space: nowrap;
  }

  /* Anything typed into stays at 16px, or iOS zooms the page on focus. */
  .input,
  .textarea,
  select,
  textarea {
    font-size: 16px;
  }

  .modal {
    max-height: calc(100vh - 32px);
    padding: 24px;
    overflow-y: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
