/* ---------- Fonts (bundled for offline use) ---------- */
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 300 600;
  font-display: swap;
  src: url(fonts/montserrat-latin.woff2) format('woff2');
}

/* ---------- Theme tokens ---------- */
:root {
  --brand: #4D41F7;
  --bg: #F2F1F7; /* softly dimmed, slightly lavender – pure white was too glaring */
  --text: #000000;
  --text-2: #526165;
  --card: #4D41F7;
  --card-solid: #4D41F7; /* opaque version of --card for overlays */
  --input: #FFFFFF;
  --result: #4D41F7;
  --toggle-bg: rgba(157, 152, 221, 0.3);
  --toggle-off-text: #000000;
  --drawer: #F2F1F7;
  --snack: #4D41F7;
  --switch-off: #E5E5E5;
  --scrim: rgba(0, 0, 0, 0.54);
  --danger: #FB3936;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  /* dark-mode card colour (rgba(157,152,221,.4) on black), used as a solid colour in both themes */
  --clear-muted: #3F3D58;
  --radius: 17px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --text: #FFFFFF;
    --card: rgba(157, 152, 221, 0.4);
    --card-solid: #3F3D58;
    --input: rgba(255, 255, 255, 0.945);
    --result: #FFFFFF;
    --toggle-bg: rgba(157, 152, 221, 0.3);
    --toggle-off-text: #9D98DD;
    --drawer: #1C1C1E;
    --snack: #3F3D58;
    --switch-off: #39393D;
    --shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --text: #FFFFFF;
  --card: rgba(157, 152, 221, 0.4);
  --card-solid: #3F3D58;
  --input: rgba(255, 255, 255, 0.945);
  --result: #FFFFFF;
  --toggle-bg: rgba(157, 152, 221, 0.3);
  --toggle-off-text: #9D98DD;
  --drawer: #1C1C1E;
  --snack: #3F3D58;
  --switch-off: #39393D;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-weight: 600;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }
svg { fill: currentColor; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- Splash ---------- */
.splash {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: var(--bg); color: var(--text);
  transition: opacity 0.4s ease;
}
.splash-logo { width: min(80vw, 420px); aspect-ratio: 1011 / 364; }
.splash.gone { opacity: 0; pointer-events: none; }

/* ---------- Pages ---------- */
.page {
  min-height: 100%;
  background: var(--bg);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.page.sub {
  position: fixed; inset: 0; z-index: 20;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.2, 0.7, 0.2, 1), visibility 0s linear 0.3s;
  visibility: hidden;
}
.page.sub.open {
  transform: none;
  visibility: visible;
  transition: transform 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.appbar, .content, .subbar, .sub-content {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

/* ---------- Home ---------- */
.appbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 64px;
  padding: 0 10px 0 16px;
}
.appbar-logo { width: 116px; height: 42px; color: var(--brand); }
.icon-btn {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 50%;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { background: rgba(127, 127, 127, 0.15); }
.menu-btn { width: 52px; height: 52px; }
.menu-btn svg { width: 32px; height: 26px; color: var(--text); }
.appbar-actions { display: flex; align-items: center; gap: 2px; }
.appbar-btn { width: 40px; height: 40px; color: var(--text); }
.appbar-btn svg { width: 22px; height: 22px; }
.lang-btn { font-size: 14px; font-weight: 600; letter-spacing: 0.04em; }

/* Home is laid out compactly so it fits small phones (e.g. 375×667) without scrolling.
   On taller screens the content (everything below the header) is centred vertically. The offset is
   computed from a fixed base height instead of using flexbox centring, so the content does not jump
   when the result or the suggestion list appears – it only grows downwards.
   --home-fixed: content height without the dynamic gaps (update when the home layout changes);
   a reserve is added for the session salt field (the services dropdown overlays and needs none). */
.home {
  --appbar-h: 64px;
  /* Vertical spacing grows with the screen height (small phones stay scroll-free) */
  --gap-block: clamp(14px, 3.4vh, 36px);  /* segment, card and Generate row from the element above */
  --gap-seg: clamp(10px, 2vh, 20px);      /* between the two segments */
  --pad-card: clamp(20px, 4vh, 40px);     /* card padding top/bottom */
  --gap-field: clamp(16px, 3.6vh, 34px);  /* between the input fields */
  /* Height of the content = fixed part (measured with all gaps above at 0) + the dynamic gaps */
  --home-fixed: 335px;
  --home-base: calc(var(--home-fixed) + 3 * var(--gap-block) + var(--gap-seg) + 2 * var(--pad-card) + var(--gap-field));
  --home-reserve: 0px;
}
.home.with-session-salt { --home-reserve: calc(52px + var(--gap-field)); }
.content {
  padding: max(0px, calc((100vh - var(--appbar-h) - var(--home-base) - var(--home-reserve) - 8px
    - env(safe-area-inset-top) - env(safe-area-inset-bottom)) / 2)) 0 8px;
}
@supports (height: 100dvh) {
  .content {
    padding-top: max(0px, calc((100dvh - var(--appbar-h) - var(--home-base) - var(--home-reserve) - 8px
      - env(safe-area-inset-top) - env(safe-area-inset-bottom)) / 2));
  }
}
.headline {
  margin: 6px 20px 0;
  font-size: 18px; font-weight: 600;
}

/* Segmented slider (length, special characters) */
.segment {
  position: relative;
  display: grid; grid-template-columns: 1fr 1fr;
  width: 90%; height: 50px;
  margin: var(--gap-block) auto 0;
  background: var(--toggle-bg);
  border-radius: 14px;
}
.segment + .segment { margin-top: var(--gap-seg); }
.segment-knob {
  position: absolute; top: 0; left: 0;
  width: 50%; height: 100%;
  background: var(--brand);
  border-radius: 14px;
  box-shadow: 0 3px 10px rgba(77, 65, 247, 0.35);
  transition: transform 0.3s ease;
}
.segment.on .segment-knob { transform: translateX(100%); }
.segment button {
  position: relative;
  padding: 0 6px;
  font-size: 14px; font-weight: 600;
  color: var(--toggle-off-text);
  transition: color 0.3s ease;
}
.segment button[aria-checked="true"] { color: #FFFFFF; }

.card {
  width: 90%;
  margin: var(--gap-block) auto 0;
  padding: var(--pad-card) 18px;
  display: flex; flex-direction: column; gap: var(--gap-field);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.field {
  display: flex; align-items: center;
  height: 52px;
  padding: 0 12px 0 14px;
  background: var(--input);
  border-radius: var(--radius);
  cursor: text;
}
.field-icon { width: 22px; height: 22px; flex: none; color: #526165; }
.field input {
  flex: 1; min-width: 0; height: 100%;
  margin: 0 10px;
  border: 0; outline: 0; background: transparent;
  font: inherit; font-size: 17px; font-weight: 300;
  color: #526165;
}
.field input::placeholder { color: #526165; opacity: 1; }
.field-clear {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  color: #526165;
  visibility: hidden; /* keeps its space so the eye icon does not jump */
}
.field-clear.visible { visibility: visible; }
.field-clear svg { width: 18px; height: 18px; }
.field-clear:active { background: rgba(82, 97, 101, 0.12); }
.field-eye { width: 36px; height: 36px; display: grid; place-items: center; flex: none; color: #526165; border-radius: 50%; }
.field-eye svg { width: 22px; height: 22px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 60px;
  border-radius: var(--radius);
  font-size: 16px; font-weight: 400;
  transition: transform 0.1s ease, filter 0.2s ease;
}
.btn:active { transform: scale(0.98); filter: brightness(1.15); }
.btn-brand { background: var(--brand); color: #FFFFFF; box-shadow: 0 3px 8px rgba(77, 65, 247, 0.3); }

.result {
  display: block;
  width: 90%; min-height: 40px;
  margin: 8px auto 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 15px; font-weight: 300;
  color: var(--result);
  text-align: center;
  word-break: break-all;
  user-select: all;
  -webkit-user-select: all;
}
.result.mono { font-size: 17px; letter-spacing: 0.04em; font-weight: 400; }

/* ---------- Drawer ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 30;
  background: var(--scrim);
  opacity: 0; visibility: hidden;
  transition: opacity 0.25s ease, visibility 0s linear 0.25s;
}
.scrim.open { opacity: 1; visibility: visible; transition: opacity 0.25s ease; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31;
  width: min(70vw, 340px);
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 90px) 0 env(safe-area-inset-bottom);
  background: var(--drawer);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.2);
  transform: translateX(105%);
  transition: transform 0.25s ease;
  overflow-y: auto;
}
.drawer.open { transform: none; }
.drawer-head { padding: 0 20px; color: var(--text); }
.drawer-logo { display: block; width: 100%; max-width: 230px; aspect-ratio: 1011 / 364; }
.drawer-nav { margin-top: 40px; padding: 0 5px; }
.tile {
  display: flex; align-items: center; gap: 16px;
  width: 100%; min-height: 56px;
  padding: 8px 16px;
  text-align: left;
  border-radius: 12px;
}
.tile:active { background: rgba(127, 127, 127, 0.12); }
.tile > span { flex: 1; font-size: 20px; font-weight: 400; }
.tile-lead { width: 20px; height: 20px; flex: none; }
.tile-trail { width: 18px; height: 18px; flex: none; }
.drawer-foot { margin-top: auto; padding: 24px 10px 40px; }
.btn-clear { width: 100%; font-weight: 600; }
.clear-icon { width: 15px; height: 15px; fill: currentColor; } /* red had too little contrast on the purple button */
.hint { margin: 10px 0 0; font-size: 14px; font-weight: 300; color: var(--text-2); text-align: center; }

/* ---------- Sub pages ---------- */
.subbar {
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
  height: 64px; padding: 0 8px;
  border-bottom: 1px solid rgba(127, 127, 127, 0.18);
}
.subbar h2 { margin: 0; text-align: center; font-size: 22px; font-weight: 400; }
.sub-content { padding: 12px 0 48px; }

.switch-tile {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px;
  cursor: pointer;
}
.switch-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.switch-text strong { font-size: 18px; font-weight: 500; }
.switch-text small, .tile-two small { font-size: 13px; font-weight: 300; color: var(--text-2); }

.switch {
  appearance: none; -webkit-appearance: none;
  position: relative; flex: none;
  width: 51px; height: 31px; margin: 0;
  border-radius: 31px;
  background: var(--switch-off);
  cursor: pointer;
  transition: background 0.2s ease;
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}
.switch:checked { background: var(--brand); }
.switch:checked::after { transform: translateX(20px); }

.divider { margin: 10px 25px; border: 0; border-top: 1px solid var(--brand); }

.tile-special { margin-top: 20px; padding: 8px 24px 8px 16px; }
.tile-two { flex: 1; display: flex; flex-direction: column; gap: 2px; padding-left: 8px; }
.tile-two strong { font-size: 18px; font-weight: 500; }
.muted { color: var(--text-2); }

.btn-wide { display: flex; width: calc(100% - 32px); margin: 50px auto 0; font-weight: 500; }

.section-title { margin: 16px 16px 0; font-size: 20px; font-weight: 600; }
.muted-text { margin: 4px 16px 0; font-size: 14px; font-weight: 300; color: var(--text-2); }
.card-salt { width: calc(100% - 32px); margin-top: 50px; padding: 30px 16px; gap: 24px; }
.salt-actions { display: flex; gap: 12px; }
.btn-soft {
  flex: 1; height: 48px;
  background: rgba(255, 255, 255, 0.18);
  color: #FFFFFF;
  font-size: 15px; font-weight: 500;
}
.btn-soft svg { width: 18px; height: 18px; }
.generate[aria-busy="true"] { opacity: 0.7; pointer-events: none; }
.caution { margin: 32px 16px 0; color: var(--danger); font-size: 14px; font-weight: 600; }

.prose p { margin: 16px 20px 0; font-size: 16px; font-weight: 400; line-height: 1.5; color: var(--text-2); }
.prose .section-title { margin: 24px 20px 0; }

/* ---------- Snackbar ---------- */
.snackbar {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 50;
  width: min(calc(100% - 32px), 520px);
  padding: 16px;
  background: var(--snack);
  color: #FFFFFF;
  font-size: 16px; font-weight: 300;
  text-align: center;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  transform: translate(-50%, calc(100% + 40px));
  transition: transform 0.25s ease;
}
.snackbar.show { transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
#personalSalt { font-size: 15px; font-weight: 400; }

/* ---------- Salt hints ---------- */
.notice {
  margin: 20px 16px 0;
  padding: 12px 14px;
  border-left: 3px solid var(--brand);
  border-radius: 8px;
  background: rgba(157, 152, 221, 0.15);
  font-size: 14px; font-weight: 400; line-height: 1.45;
  color: var(--text);
}
.link-btn {
  color: var(--brand);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- Backup dialog ---------- */
.dialog {
  width: min(calc(100% - 32px), 400px);
  max-height: calc(100% - 32px);
  padding: 24px 20px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
.dialog::backdrop { background: var(--scrim); }
.dialog-title { margin: 0; font-size: 20px; font-weight: 600; }
.dialog-text { margin: 8px 0 0; font-size: 14px; font-weight: 300; line-height: 1.45; color: var(--text-2); }
.qr { width: 200px; margin: 20px auto 0; }
.qr svg { display: block; width: 100%; height: auto; border-radius: 8px; }
.salt-display {
  margin: 16px 0 0;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 18px; font-weight: 500;
  letter-spacing: 0.04em;
  text-align: center;
  word-break: break-all;
  user-select: all;
  -webkit-user-select: all;
}
.dialog-actions { display: flex; gap: 12px; margin-top: 20px; }
.btn-outline {
  flex: 1; height: 48px;
  border: 1px solid rgba(127, 127, 127, 0.35);
  font-size: 15px; font-weight: 500;
}
.btn-outline svg { width: 18px; height: 18px; }
.dialog-done { display: flex; width: 100%; margin-top: 12px; font-weight: 500; }
.dialog-later { display: block; margin: 14px auto 0; font-weight: 400; }

/* ---------- Print: only the salt backup ---------- */
@media print {
  body.print-salt > *:not(#backupDialog) { display: none !important; }
  body.print-salt #backupDialog {
    position: static; display: block;
    width: auto; max-height: none;
    box-shadow: none;
    background: #FFFFFF; color: #000000;
  }
  body.print-salt .dialog-actions,
  body.print-salt .dialog-done,
  body.print-salt .dialog-later { display: none !important; }
  body.print-salt .dialog-text { color: #000000; }
}

/* ---------- Language select ---------- */
.select {
  flex: none;
  height: 36px;
  padding: 0 32px 0 12px;
  border: 1px solid rgba(127, 127, 127, 0.35);
  border-radius: 10px;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%237f7f7f' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E") no-repeat right 6px center / 20px;
  color: var(--text);
  font: inherit; font-size: 15px; font-weight: 500;
  appearance: none; -webkit-appearance: none;
  cursor: pointer;
}

/* ---------- Imprint ---------- */
.imprint {
  margin: 12px 20px 0;
  font-style: normal;
  font-size: 16px; font-weight: 400; line-height: 1.6;
  color: var(--text-2);
}
.imprint a { color: var(--brand); }

/* ---------- Service list ---------- */
.field-wrap { position: relative; }
.field-drop {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  color: #526165;
}
.field-drop svg { width: 24px; height: 24px; transition: transform 0.2s ease; }
.field-wrap.open .field-drop svg { transform: rotate(180deg); }

/* Dropdown with saved services: a separate card directly below the input card, same width and colour.
   It is part of the layout, so it never covers Generate or the result. */
.suggest {
  width: 90%;
  margin: 8px auto 0;
  max-height: 252px; overflow-y: auto; /* about 6 rows; longer lists scroll inside the card */
  padding: 6px;
  background: var(--card-solid);
  border-radius: var(--radius);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.3);
}
.suggest-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; height: 40px;
  padding: 0 12px;
  border-radius: 11px;
  text-align: left;
  color: #FFFFFF;
  font-size: 15px; font-weight: 500;
}
.suggest-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-item small { flex: none; font-size: 12px; font-weight: 400; opacity: 0.75; }
.suggest-item:hover, .suggest-item.active { background: rgba(255, 255, 255, 0.16); }

.tile-sub { margin-top: 0; }

.services-intro { margin-top: 16px; }
.services-empty { margin-top: 24px; text-align: center; }
.service-list { list-style: none; margin: 16px 16px 0; padding: 0; }
.service-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(127, 127, 127, 0.18);
}
.service-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.service-text strong { font-size: 16px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.service-text small { font-size: 13px; font-weight: 300; color: var(--text-2); }
.service-delete { flex: none; width: 40px; height: 40px; color: var(--text-2); }
.service-delete svg { width: 22px; height: 22px; }

.list-actions { display: flex; gap: 12px; margin: 28px 16px 0; }
.danger-link { display: block; margin: 24px auto 0; color: var(--danger); font-weight: 500; }

/* ---------- Clear clipboard (home, next to Generate) ---------- */
.generate-row {
  display: flex; justify-content: center; align-items: center; gap: 12px;
  margin: var(--gap-block) auto 0;
}
.generate { width: 200px; height: 54px; flex: 0 1 200px; }
.clear-square {
  flex: none;
  width: 54px; height: 54px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--danger);
  transition: opacity 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.clear-square svg { width: 24px; height: 24px; }
/* Disabled: outline and icon in the dark-mode card colour */
.clear-square:disabled {
  border-color: var(--clear-muted);
  color: var(--clear-muted);
  cursor: default;
}
/* A password or salt from CODES is on the clipboard */
.clear-square:not(:disabled) {
  border-color: rgba(251, 57, 54, 0.45);
  background: rgba(251, 57, 54, 0.06);
}
.clear-square:not(:disabled):active { transform: scale(0.96); }
