:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --input-bg: #f8fafc;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --danger: #dc2626;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

[data-theme="dark"] {
  --bg: #0b1120;
  --card: #151e32;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #25314d;
  --input-bg: #0f172a;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --danger: #f87171;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  transition: background 0.25s, color 0.25s;
}

.card {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
  transition: background 0.25s, border-color 0.25s;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

h1 { font-size: 1.25rem; font-weight: 650; }

/* Icons & icon buttons */
.icon {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex-shrink: 0;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:active { transform: scale(0.95); }

.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* Output */
.output { display: flex; gap: 8px; }

#password {
  flex: 1; min-width: 0;
  height: 40px;
  padding: 0 12px;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 1rem;
  letter-spacing: 0.5px;
  text-overflow: ellipsis;
}
#password:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Strength */
.strength { margin: 12px 0 20px; min-height: 28px; }
.strength-bar { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }
#strengthFill { display: block; height: 100%; width: 0; border-radius: 99px; transition: width 0.3s, background 0.3s; }
#strengthText { display: block; margin-top: 6px; color: var(--muted); font-size: 0.78rem; }

/* Options */
.options { display: flex; flex-direction: column; gap: 4px; }

.length-row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.95rem; font-weight: 500;
  margin-bottom: 8px;
}
.length-row output {
  min-width: 40px; text-align: center;
  padding: 2px 10px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-weight: 600;
}

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px;
  background: var(--border);
  border-radius: 99px;
  outline: none;
  margin-bottom: 14px;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  background: var(--accent);
  border: 3px solid var(--card);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  background: var(--accent);
  border: 3px solid var(--card);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

/* Custom checkboxes */
.check {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 4px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}
.check:last-child { border-bottom: none; }
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check .box {
  width: 20px; height: 20px; flex-shrink: 0;
  border: 2px solid var(--muted);
  border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.check .box::after {
  content: "";
  width: 5px; height: 10px;
  border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  margin-top: -2px;
  transition: transform 0.15s;
}
.check input:checked + .box { background: var(--accent); border-color: var(--accent); }
.check input:checked + .box::after { transform: rotate(45deg) scale(1); }
.check input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }
.check .text { flex: 1; }
.check .hint { color: var(--muted); font-size: 0.8rem; font-family: ui-monospace, Consolas, monospace; }

/* Error */
.error { margin-top: 12px; color: var(--danger); font-size: 0.85rem; font-weight: 500; }

/* Generate button */
.primary-btn {
  width: 100%;
  margin-top: 20px;
  padding: 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}
.primary-btn:hover { background: var(--accent-hover); box-shadow: 0 6px 16px rgba(79, 70, 229, 0.3); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

/* Toast */
.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 12px 20px;
  background: #16a34a;
  color: #fff;
  border-radius: 10px;
  font-size: 0.9rem; font-weight: 500;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error-toast { background: var(--danger); }

/* Responsive */
@media (max-width: 480px) {
  body { padding: 12px; align-items: flex-start; }
  .card { padding: 18px; border-radius: 14px; margin-top: 8px; }
  h1 { font-size: 1.1rem; }
  #password { font-size: 0.9rem; }
  .check { padding: 12px 2px; }
}

@media (max-width: 340px) {
  .check .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
