/* Password Hasher NG — UI styles.
   Light/dark via prefers-color-scheme; tokens as custom properties. */

:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #16181d;
  --muted: #5d6674;
  --border: #d7dae0;
  --border-strong: #b6bcc8;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --on-accent: #ffffff;
  --ring: rgba(79, 70, 229, 0.35);
  --field-bg: #ffffff;
  --hash-bg: #f8f9fb;
  --chip-bg: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.08);
}

/* Dark tokens exist twice — system preference (unless forced light) and forced
   dark via data-theme. Keep both blocks in sync. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116;
    --card: #171b22;
    --text: #e8eaf0;
    --muted: #98a1b3;
    --border: #2a303c;
    --border-strong: #3a4250;
    --accent: #818cf8;
    --accent-hover: #a5b0fc;
    --on-accent: #0e1116;
    --ring: rgba(129, 140, 248, 0.4);
    --field-bg: #10131a;
    --hash-bg: #10131a;
    --chip-bg: #10131a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1116;
  --card: #171b22;
  --text: #e8eaf0;
  --muted: #98a1b3;
  --border: #2a303c;
  --border-strong: #3a4250;
  --accent: #818cf8;
  --accent-hover: #a5b0fc;
  --on-accent: #0e1116;
  --ring: rgba(129, 140, 248, 0.4);
  --field-bg: #10131a;
  --hash-bg: #10131a;
  --chip-bg: #10131a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
}

:root[data-theme="light"] {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 16px 40px;
}

.app {
  width: 100%;
  max-width: 560px;
}

/* ---------- Header ---------- */

.app-header {
  text-align: center;
  margin: 8px 0 20px;
}

.app-header h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}

.app-header .ng {
  color: var(--accent);
}

.tagline {
  color: var(--muted);
  margin: 0 0 10px;
  font-size: 14px;
}

.offline-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  background: var(--card);
}

.offline-badge .icon {
  width: 13px;
  height: 13px;
  color: var(--accent);
}

/* ---------- Card / fields ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 22px 22px 18px;
  margin: 0;
}

.field {
  margin-bottom: 16px;
}

.field > label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.control {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.control input[type="text"],
.control input[type="password"] {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  font-size: 15px;
  color: var(--text);
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

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

.control input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

/* Hashword output */

.hashword {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 16px !important;
  letter-spacing: 0.06em;
  background: var(--hash-bg) !important;
  cursor: text;
}

/* Subtle pulse while PBKDF2 runs; delayed so fast derivations don't flicker */
.hashword.deriving {
  animation: deriving-pulse 1s ease-in-out 0.15s infinite;
}

@keyframes deriving-pulse {
  0%, 100% { border-color: var(--border); }
  50% { border-color: var(--accent); }
}

@media (prefers-reduced-motion: reduce) {
  .hashword.deriving {
    animation: none;
  }
}

/* ---------- Master key extras ---------- */

.keywrap {
  position: relative;
}

.keywrap #key {
  padding-right: 44px;
}

/* Widen when the hint badge is visible (progressive: minor overlap without :has) */
.keywrap:has(.key-hint:not(.hidden)) #key {
  padding-right: 92px;
}

.key-hint {
  position: absolute;
  right: 46px;
  top: 50%;
  transform: translateY(-50%);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--accent);
  background: var(--hash-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  pointer-events: none;
}

.unmask-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.unmask-toggle:hover {
  color: var(--text);
  background: var(--hash-bg);
}

.unmask-toggle .icon {
  width: 18px;
  height: 18px;
}

.unmask-toggle .eye-closed {
  display: none;
}

#unmask:checked ~ .unmask-toggle .eye-open {
  display: none;
}

#unmask:checked ~ .unmask-toggle .eye-closed {
  display: block;
}

#unmask:focus-visible ~ .unmask-toggle {
  box-shadow: 0 0 0 3px var(--ring);
  color: var(--text);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 44px;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}

.btn:hover {
  border-color: var(--border-strong);
}

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

.btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.btn .icon {
  width: 15px;
  height: 15px;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

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

.btn.ghost {
  color: var(--muted);
}

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

/* ---------- Options disclosure ---------- */

.options-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin: 4px 0 0;
  padding: 10px 2px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: color 0.15s;
}

.options-toggle:hover {
  color: var(--text);
}

.options-toggle:focus-visible {
  outline: none;
  color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
  border-radius: 8px;
}

.options-toggle .chevron {
  width: 15px;
  height: 15px;
  transition: transform 0.2s;
}

.options-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

/* ---------- Settings groups ---------- */

#settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 24px;
  padding-top: 8px;
}

#settings.hidden {
  display: none;
}

.form-group {
  margin-bottom: 12px;
}

.form-group h2 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 8px;
}

.form-group ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.form-group li {
  padding: 0;
  margin: 0;
}

.checkboxes li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 6px;
  margin: 0 -6px;
  border-radius: 8px;
}

.checkboxes li:hover {
  background: var(--hash-bg);
}

.checkboxes input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  margin: 3px 0 0;
  flex-shrink: 0;
  cursor: pointer;
}

.checkboxes label {
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
}

.algorithm select {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.algorithm select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.group-note {
  font-size: 12px;
  color: var(--muted);
  margin: 6px 0 0;
}

/* Size: segmented chips */

.size-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.size-grid input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.size-grid label {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.size-grid label:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.size-grid input:checked + label {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.size-grid input:focus-visible + label {
  box-shadow: 0 0 0 3px var(--ring);
}

/* ---------- Theme switch ---------- */

.theme-switch {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 20;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 999px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.theme-btn:hover {
  color: var(--text);
}

.theme-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

.theme-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

.theme-btn .icon {
  width: 15px;
  height: 15px;
}

/* ---------- Footer ---------- */

.app-footer {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
  font-size: 13px;
  color: var(--muted);
}

.app-footer a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.app-footer a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------- Utilities ---------- */

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 480px) {
  body {
    padding: 12px 10px 28px;
  }

  /* Scrolls with the page: a fixed pill would cover the Hashword row and
     steal its taps once the card scrolls under it. */
  .theme-switch {
    position: absolute;
  }

  .card {
    padding: 16px 14px 12px;
    border-radius: 14px;
  }

  #settings {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .size-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .control {
    flex-wrap: wrap;
  }

  .control .btn {
    flex: 1;
  }

  .control input[type="text"],
  .control input[type="password"] {
    flex-basis: 100%;
  }
}
