/* ═══════════════════════════════════════════════════════════════════════════
   Starpass v2.2 — Design System
   Approach: Deep-dark with electric-violet accent, DM Mono + Outfit typography
   Mobile-first, fit-to-viewport, smooth animations, no layout overflow
═══════════════════════════════════════════════════════════════════════════ */

/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  /* Palette */
  --bg:          #0a0a0f;
  --bg-1:        #111118;
  --bg-2:        #18181f;
  --bg-3:        #22222c;
  --border:      rgba(255,255,255,0.07);
  --border-md:   rgba(255,255,255,0.12);

  --accent:      #7c6cfa;
  --accent-dim:  rgba(124,108,250,0.15);
  --accent-glow: rgba(124,108,250,0.35);

  --txt:         #f0f0f5;
  --txt-2:       #9898a8;
  --txt-3:       #5c5c70;

  --success:     #34d399;
  --danger:      #f87171;
  --warn:        #fbbf24;

  /* Strength colours */
  --s0: #f87171;
  --s1: #fb923c;
  --s2: #fbbf24;
  --s3: #a3e635;
  --s4: #34d399;

  /* Spacing */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-2xl: 28px;

  /* Motion */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --fast: 140ms;
  --mid:  260ms;
  --slow: 400ms;

  /* Layout */
  --header-h: 56px;
  --gap: clamp(12px, 2vw, 24px);
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  font-family: 'Outfit', system-ui, sans-serif;
  background: var(--bg);
  color: var(--txt);
  min-height: 100dvh;
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img, svg { display: block; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* ── Skip link ──────────────────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--r-md);
  font-weight: 600;
  z-index: 9999;
  transition: top var(--fast);
}
.skip-link:focus { top: 16px; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: rgba(10,10,15,0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  height: 100%;
  padding: 0 clamp(16px, 4vw, 32px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--txt);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Pill buttons */
.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--txt-2);
  background: var(--bg-2);
  border: 1px solid var(--border);
  transition: color var(--fast), background var(--fast), border-color var(--fast), transform var(--fast);
  white-space: nowrap;
}
.pill-btn:hover  { color: var(--txt); background: var(--bg-3); border-color: var(--border-md); }
.pill-btn:active { transform: scale(0.96); }
.pill-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.pill-btn.accent { background: var(--accent-dim); color: var(--accent); border-color: rgba(124,108,250,0.3); }
.pill-btn.accent:hover { background: rgba(124,108,250,0.25); }

/* On very small screens, hide text labels */
@media (max-width: 400px) {
  .pill-btn span { display: none; }
  .pill-btn { padding: 7px 10px; }
}

/* ── Main layout ─────────────────────────────────────────────────────────── */
.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--gap) clamp(12px, 4vw, 32px);
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
  /* On desktop: side by side, fill remaining viewport height */
  align-items: start;
}

@media (min-width: 900px) {
  .main {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
    min-height: calc(100dvh - var(--header-h));
    min-height: calc(100vh  - var(--header-h));
  }
}

/* ── Panel ──────────────────────────────────────────────────────────────── */
.panel {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-2xl);
  overflow: hidden;
}

/* Generator panel inner scroll on desktop so it never overflows viewport */
@media (min-width: 900px) {
  .generator-panel {
    position: sticky;
    top: calc(var(--header-h) + var(--gap));
    max-height: calc(100dvh - var(--header-h) - var(--gap)*2);
    max-height: calc(100vh  - var(--header-h) - var(--gap)*2);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--border-md) transparent;
  }
}

/* ── Tabs ───────────────────────────────────────────────────────────────── */
.tab-rail {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  padding: 4px;
  gap: 3px;
}

.tab-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 6px;
  border-radius: var(--r-md);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--txt-3);
  transition: color var(--fast), background var(--fast);
  white-space: nowrap;
}
.tab-btn:hover  { color: var(--txt-2); background: var(--bg-3); }
.tab-btn.active { color: var(--txt);   background: var(--bg-1); box-shadow: 0 1px 3px rgba(0,0,0,0.4); }
.tab-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ── Tab content ────────────────────────────────────────────────────────── */
.tab-content { display: none; padding: 20px; }
.tab-content.active { display: block; }

form { display: flex; flex-direction: column; gap: 18px; }

/* ── Field row (label + slider) ──────────────────────────────────────────── */
.field-row { display: flex; flex-direction: column; gap: 8px; }

.field-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--txt-2);
}

.field-value {
  background: var(--bg-3);
  padding: 2px 10px;
  border-radius: 999px;
  font-family: 'DM Mono', monospace;
  font-size: 0.8125rem;
  color: var(--accent);
  min-width: 3ch;
  text-align: center;
}

.slider-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--txt-3);
  padding: 0 2px;
}

/* ── Slider ──────────────────────────────────────────────────────────────── */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--bg-3);
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  cursor: pointer;
  transition: box-shadow var(--fast), transform var(--fast);
}
.slider::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}
.slider:hover::-webkit-slider-thumb  { box-shadow: 0 0 0 5px var(--accent-glow); }
.slider:active::-webkit-slider-thumb { transform: scale(1.15); }
.slider:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

/* ── Count grid ──────────────────────────────────────────────────────────── */
.count-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.count-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.count-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--txt-3);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.count-input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  color: var(--txt);
  font-size: 0.9375rem;
  font-family: 'DM Mono', monospace;
  transition: border-color var(--fast), box-shadow var(--fast);
  width: 100%;
  -moz-appearance: textfield;
}
.count-input::-webkit-inner-spin-button,
.count-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.count-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

/* ── Select ──────────────────────────────────────────────────────────────── */
.select-input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  color: var(--txt);
  font-size: 0.9375rem;
  width: 100%;
  cursor: pointer;
  transition: border-color var(--fast);
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L6 7L11 1' stroke='%239898a8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
.select-input:focus { outline: none; border-color: var(--accent); }

/* ── Toggle row ──────────────────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}

.toggle-input { position: absolute; opacity: 0; width: 0; height: 0; }

.toggle-track {
  flex-shrink: 0;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--bg-3);
  border: 1px solid var(--border-md);
  position: relative;
  transition: background var(--fast), border-color var(--fast);
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--txt-3);
  transition: transform var(--mid) var(--ease), background var(--fast);
}
.toggle-input:checked ~ .toggle-track { background: var(--accent-dim); border-color: var(--accent); }
.toggle-input:checked ~ .toggle-track::after { transform: translateX(16px); background: var(--accent); }
.toggle-row:focus-within .toggle-track { box-shadow: 0 0 0 3px var(--accent-dim); }

.toggle-text {
  font-size: 0.875rem;
  color: var(--txt-2);
  line-height: 1.4;
}
.toggle-text em { color: var(--txt-3); font-style: normal; }

/* ── Generate button ─────────────────────────────────────────────────────── */
.generate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  border-radius: var(--r-lg);
  font-size: 0.9375rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent-glow);
  transition: transform var(--fast) var(--ease), box-shadow var(--fast), filter var(--fast);
  position: relative;
  overflow: hidden;
}
.generate-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 60%);
}
.generate-btn:hover  { filter: brightness(1.12); box-shadow: 0 0 24px var(--accent-glow); transform: translateY(-1px); }
.generate-btn:active { transform: scale(0.97) translateY(0); }
.generate-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ── Output ──────────────────────────────────────────────────────────────── */
.output {
  border-top: 1px solid var(--border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: fadeSlideUp var(--mid) var(--ease) both;
}
.output.hidden { display: none; }

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.output-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.output-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--txt-3);
}

.icon-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  color: var(--txt-2);
  background: var(--bg-2);
  border: 1px solid var(--border);
  transition: color var(--fast), background var(--fast);
  flex-shrink: 0;
}
.icon-btn:hover { color: var(--accent); background: var(--accent-dim); border-color: rgba(124,108,250,0.3); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.result-text {
  font-family: 'DM Mono', monospace;
  font-size: clamp(0.875rem, 2.5vw, 1.05rem);
  font-weight: 400;
  color: var(--txt);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  word-break: break-all;
  min-height: 54px;
  line-height: 1.6;
  letter-spacing: 0.02em;
}

.save-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--r-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--txt-2);
  background: var(--bg-2);
  border: 1px solid var(--border);
  width: 100%;
  justify-content: center;
  transition: color var(--fast), background var(--fast), border-color var(--fast);
}
.save-btn:hover { color: var(--accent); background: var(--accent-dim); border-color: rgba(124,108,250,0.3); }
.save-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Strength ────────────────────────────────────────────────────────────── */
.strength-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.strength-block.hidden { display: none; }

.strength-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.strength-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--txt-3);
}

.strength-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--txt-2);
  transition: color var(--mid);
}

.strength-track {
  height: 6px;
  background: var(--bg-3);
  border-radius: 999px;
  overflow: hidden;
}

.strength-fill {
  height: 100%;
  border-radius: 999px;
  width: 0%;
  background: var(--s0);
  transition: width var(--slow) var(--ease), background var(--mid);
}

.crack-info {
  font-size: 0.8rem;
  color: var(--txt-3);
  font-family: 'DM Mono', monospace;
}
.crack-info .crack-time-label { color: var(--txt-3); }
.crack-info .crack-time-value { color: var(--txt-2); margin-left: 4px; }
.crack-time-note {
  display: block;
  margin-top: 5px;
  font-size: 0.78rem;
  color: var(--txt-2);
  line-height: 1.45;
  font-family: 'Outfit', sans-serif;
  font-style: italic;
}

/* History spinner */
.history-spinner {
  padding: 12px 8px;
  font-size: 0.8125rem;
  color: var(--txt-3);
  text-align: center;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50%       { opacity: 1; }
}

/* ── History panel ───────────────────────────────────────────────────────── */
.history-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.history-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.history-heading {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--txt);
}

.ghost-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--txt-3);
  background: transparent;
  border: 1px solid transparent;
  transition: color var(--fast), background var(--fast), border-color var(--fast);
}
.ghost-btn:hover { background: var(--bg-3); border-color: var(--border); }
.ghost-btn.danger:hover { color: var(--danger); background: rgba(248,113,113,0.1); border-color: rgba(248,113,113,0.2); }
.ghost-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.search-wrap {
  position: relative;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

.search-icon {
  position: absolute;
  left: 34px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--txt-3);
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 9px 12px 9px 34px;
  color: var(--txt);
  font-size: 0.875rem;
  transition: border-color var(--fast), box-shadow var(--fast);
  -webkit-appearance: none;
}
.search-input::placeholder { color: var(--txt-3); }
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }

.history-caption {
  padding: 6px 20px;
  font-size: 0.75rem;
  color: var(--txt-3);
  font-family: 'DM Mono', monospace;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-md) transparent;
  padding: 8px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 80px;
}

.history-empty {
  padding: 24px 8px;
  font-size: 0.875rem;
  color: var(--txt-3);
  text-align: center;
}

/* ── History item ────────────────────────────────────────────────────────── */
.history-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 2px;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: border-color var(--fast);
}
.history-item:hover { border-color: var(--border-md); }

.history-badge {
  grid-row: 1 / 3;
  grid-column: 1;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  white-space: nowrap;
  align-self: center;
}

.history-value {
  grid-row: 1;
  grid-column: 2;
  font-family: 'DM Mono', monospace;
  font-size: 0.875rem;
  color: var(--txt);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-date {
  grid-row: 2;
  grid-column: 2;
  font-size: 0.7rem;
  color: var(--txt-3);
}

.history-action {
  grid-row: 1 / 3;
  align-self: center;
  width: 36px; height: 36px;
  min-width: 36px; min-height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  font-size: 0.85rem;
  color: var(--txt-3);
  transition: color var(--fast), background var(--fast);
}
.view-btn   { grid-column: 3; }
.delete-btn { grid-column: 4; }
.history-action:hover { color: var(--txt); background: var(--bg-3); }
.delete-btn:hover { color: var(--danger); background: rgba(248,113,113,0.1); }
.history-action:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Footer ─────────────────────────────────────────────────────────────── */
.footer {
  margin-top: auto;
  padding: 40px 0 24px;
  border-top: 1px solid var(--border); 
  background: var(--bg); 
}

.footer-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 32px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.footer-info {
  font-size: 0.8125rem;
  color: var(--txt-3);
  text-align: center;
}

.footer-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px; 
}

.footer-link {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--txt-2);
  transition: color var(--fast), background var(--fast);
  padding: 4px 8px;
  border-radius: var(--r-sm);
}

.footer-link:hover {
  color: var(--accent); 
  background: var(--accent-dim); 
}

.footer-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.footer-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--txt-3);
  opacity: 0.5;
}

@media (min-width: 640px) {
  .footer-inner {
    flex-direction: row;
    justify-content: space-between;
  }
  .footer-links {
    gap: 12px;
  }
}

/* ── Modals ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0,0,0,0);
  display: flex;
  align-items: flex-end;   /* mobile: bottom sheet */
  justify-content: center;
  transition: background var(--mid);
  /* Pointer events off when hidden (set via JS) */
}
.modal-overlay.hidden { display: none; }
.modal-overlay.show   { background: rgba(0,0,0,0.7); }

/* On desktop: centered card */
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
}

.modal-sheet {
  background: var(--bg-1);
  border: 1px solid var(--border-md);
  border-radius: var(--r-2xl) var(--r-2xl) 0 0;
  width: 100%;
  max-width: 540px;
  max-height: 88dvh;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(100%);
  transition: transform var(--slow) var(--ease);
  /* Pull up safely on iPhones */
  padding-bottom: env(safe-area-inset-bottom);
}

@media (min-width: 640px) {
  .modal-sheet {
    border-radius: var(--r-2xl);
    transform: translateY(16px) scale(0.97);
    transition: transform var(--mid) var(--ease), opacity var(--mid);
    opacity: 0;
    max-height: 90vh;
  }
}

.modal-overlay.show .modal-sheet {
  transform: translateY(0);
}

@media (min-width: 640px) {
  .modal-overlay.show .modal-sheet {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.modal-sheet--sm { max-width: 420px; }

.modal-drag-handle {
  width: 40px; height: 4px;
  background: var(--border-md);
  border-radius: 999px;
  margin: 10px auto 0;
  flex-shrink: 0;
}
@media (min-width: 640px) { .modal-drag-handle { display: none; } }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-head h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--txt);
}

.modal-close-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  color: var(--txt-3);
  background: var(--bg-2);
  border: 1px solid var(--border);
  transition: color var(--fast), background var(--fast);
  flex-shrink: 0;
}
.modal-close-btn:hover { color: var(--txt); background: var(--bg-3); }
.modal-close-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.modal-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-md) transparent;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

/* ── Help cards ──────────────────────────────────────────────────────────── */
.help-card {
  display: flex;
  gap: 14px;
  padding: 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.help-icon { font-size: 1.25rem; flex-shrink: 0; line-height: 1; padding-top: 2px; }
.help-card h3 { font-size: 0.875rem; font-weight: 600; color: var(--txt); margin-bottom: 4px; }
.help-card p  { font-size: 0.8125rem; color: var(--txt-2); line-height: 1.5; }
.help-card kbd {
  background: var(--bg-3);
  border: 1px solid var(--border-md);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.75rem;
  font-family: 'DM Mono', monospace;
  color: var(--txt);
}

/* ── Changelog ───────────────────────────────────────────────────────────── */
.changelog-version {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.version-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: 'DM Mono', monospace;
  background: var(--bg-3);
  color: var(--txt-2);
  border: 1px solid var(--border);
  width: fit-content;
}
.version-tag.current { background: var(--accent-dim); color: var(--accent); border-color: rgba(124,108,250,0.3); }
.changelog-version ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.changelog-version li {
  font-size: 0.8125rem;
  color: var(--txt-2);
  padding-left: 16px;
  position: relative;
  line-height: 1.4;
}
.changelog-version li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--accent);
  font-size: 0.75rem;
}

/* ── Share modal ─────────────────────────────────────────────────────────── */
.share-desc { font-size: 0.875rem; color: var(--txt-2); margin-bottom: 4px; }

.share-btns {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.share-action {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--txt);
  transition: background var(--fast), border-color var(--fast), color var(--fast);
  text-align: left;
}
.share-action:hover { background: var(--bg-3); border-color: var(--border-md); color: var(--accent); }
.share-action:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Passphrase modal extras ─────────────────────────────────────────────── */
.modal-desc { font-size: 0.8125rem; color: var(--txt-2); line-height: 1.5; margin-bottom: 4px; }

.pass-field-wrap {
  position: relative;
}

.pass-input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 44px 12px 16px;
  color: var(--txt);
  font-size: 1rem;
  font-family: 'DM Mono', monospace;
  letter-spacing: 0.1em;
  transition: border-color var(--fast), box-shadow var(--fast);
}
.pass-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.pass-input::placeholder { letter-spacing: normal; font-family: 'Outfit', sans-serif; color: var(--txt-3); }

.pass-clear-btn {
  position: absolute;
  right: 10px; top: 50%;
  transform: translateY(-50%);
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  color: var(--txt-3);
  transition: color var(--fast), background var(--fast);
}
.pass-clear-btn:hover { color: var(--txt); background: var(--bg-3); }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom));
  right: 16px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}

.toast {
  padding: 11px 16px;
  border-radius: var(--r-lg);
  font-size: 0.875rem;
  font-weight: 500;
  color: #fff;
  pointer-events: auto;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: toastIn var(--mid) var(--ease) both,
             toastOut var(--fast) var(--ease) both var(--dismiss, 2.7s);
}
.toast.success { background: #065f46; border: 1px solid rgba(52,211,153,0.3); }
.toast.error   { background: #7f1d1d; border: 1px solid rgba(248,113,113,0.3); }

@keyframes toastIn  { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:translateX(0); } }
@keyframes toastOut { from { opacity:1; } to   { opacity:0; } }

/* ── Reduced motion ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Scrollbar (webkit) ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-md); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--txt-3); }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive tweaks ───────────────────────────────────────────────────── */
@media (max-width: 899px) {
  /* On mobile, history panel shows below generator */
  .history-panel {
    min-height: 320px;
  }
  .history-list {
    max-height: 340px;
  }
}

@media (max-width: 480px) {
  .tab-btn { font-size: 0.75rem; gap: 4px; padding: 8px 4px; }
  .tab-btn svg { width: 12px; height: 12px; }
  .count-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
}

/* SVGs inside buttons must not capture clicks */
button svg { pointer-events: none; }
