/* ─── Passwords — Stylesheet ──────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,400&family=Syne:wght@400;500;600;700;800&display=swap');

/* ─── Design Tokens ──────────────────────────────────────────────────────── */
:root {
  --font-display: 'Syne', sans-serif;
  --font-mono: 'DM Mono', monospace;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);

  --strength-weak:      #ef4444;
  --strength-fair:      #f97316;
  --strength-good:      #eab308;
  --strength-strong:    #22c55e;
  --strength-excellent: #06b6d4;
}

/* ─── Light Theme ────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: light) {
  :root {
    --bg-base:     #f0ede8;
    --bg-surface:  #faf8f5;
    --bg-elevated: #ffffff;
    --bg-input:    #f5f2ee;
    --bg-muted:    #e8e4de;

    --border:      #d8d3cb;
    --border-focus: #1a1a1a;

    --text-primary:   #0f0f0f;
    --text-secondary: #5a5550;
    --text-muted:     #8a847c;
    --text-inverse:   #ffffff;

    --accent:         #1a1a1a;
    --accent-hover:   #333333;
    --accent-subtle:  #e8e6e2;

    --error:          #c0392b;
    --error-bg:       #fdf0ef;
    --success:        #16a34a;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.06);

    --output-bg: #0f0f0f;
    --output-text: #f0ede8;
    --output-border: #1a1a1a;
  }
}

/* ─── Dark Theme ─────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-base:     #0c0c0e;
    --bg-surface:  #141417;
    --bg-elevated: #1c1c21;
    --bg-input:    #1a1a1f;
    --bg-muted:    #242428;

    --border:      #2a2a30;
    --border-focus: #c8c4bc;

    --text-primary:   #f0ede8;
    --text-secondary: #9a968f;
    --text-muted:     #5a5650;
    --text-inverse:   #0f0f0f;

    --accent:         #e8e4dc;
    --accent-hover:   #ffffff;
    --accent-subtle:  #242428;

    --error:          #f87171;
    --error-bg:       #1f1010;
    --success:        #4ade80;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.4), 0 2px 6px rgba(0,0,0,0.2);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.5), 0 4px 12px rgba(0,0,0,0.3);

    --output-bg: #e8e4dc;
    --output-text: #0f0f0f;
    --output-border: #e8e4dc;
  }
}

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

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

body {
  font-family: var(--font-display);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  padding: 2rem 1rem 4rem;
  transition: background var(--transition), color var(--transition);
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.app-wrapper {
  max-width: 560px;
  margin: 0 auto;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 2.5rem;
  gap: 1rem;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-mark {
  width: 40px;
  height: 40px;
  background: var(--accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-mark svg {
  color: var(--text-inverse);
}

.app-title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1.2;
}

.app-subtitle {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  margin-top: 2px;
  font-family: var(--font-mono);
}

/* ─── Settings Toggle Button ─────────────────────────────────────────────── */
.settings-toggle-btn {
  border: none;
  background: transparent;
  padding: 0.5rem;
  color: var(--text-secondary);
  cursor: pointer;
}

/* ─── Settings Panel ─────────────────────────────────────────────────────── */
.settings-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  margin-bottom: 1.5rem;
  box-shadow: none;
}

.settings-panel.open {
  max-height: 400px;
  padding: 1.5rem;
  opacity: 1;
  box-shadow: var(--shadow-md);
  margin-bottom: 1.5rem;
}

.settings-title {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  font-family: var(--font-mono);
}

.settings-section {
  margin-bottom: 1.25rem;
}

.settings-section:last-of-type {
  margin-bottom: 0;
}

.settings-section-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.625rem;
  font-family: var(--font-mono);
}

/* Checkboxes */
.checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  transition: all var(--transition);
  user-select: none;
}

.checkbox-item:hover {
  border-color: var(--border-focus);
}

.checkbox-item input[type="checkbox"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  background: var(--bg-elevated);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all var(--transition);
}

.checkbox-item input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox-item input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1.5px;
  width: 5px;
  height: 9px;
  border: 1.5px solid var(--text-inverse);
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

.checkbox-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

/* Length control */
.length-control {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.length-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 1.125rem;
  font-weight: 400;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  line-height: 1;
  flex-shrink: 0;
}

.length-btn:hover:not(:disabled) {
  border-color: var(--border-focus);
  background: var(--bg-muted);
}

.length-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.length-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  min-width: 2.5rem;
  text-align: center;
}

/* Settings footer */
.settings-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  margin-top: 1.25rem;
}

.btn-reset {
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
}

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

/* ─── Form Card ──────────────────────────────────────────────────────────── */
.form-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 2rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem;
}

/* ─── Field Group ────────────────────────────────────────────────────────── */
.field-group {
  margin-bottom: 1.375rem;
}

.field-group:last-child {
  margin-bottom: 0;
}

.field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.field-label-text {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.field-optional {
  font-size: 0.6875rem;
  font-weight: 400;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ─── Input Wrapper ──────────────────────────────────────────────────────── */
.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.field-input {
  width: 100%;
  padding: 0.6875rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 400;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

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

.field-input:focus {
  border-color: var(--border-focus);
  background: var(--bg-elevated);
  box-shadow: 0 0 0 3px rgba(128,128,128,0.08);
}

.field-input.valid {
  border-color: var(--success);
}

.field-input.invalid {
  border-color: var(--error);
  background: var(--error-bg);
}

/* Input with toggle button */
.input-wrapper .field-input.has-toggle {
  padding-right: 2.75rem;
}

.input-toggle-btn {
  position: absolute;
  right: 0.75rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  display: flex;
  align-items: center;
  transition: color var(--transition);
  line-height: 0;
}

.input-toggle-btn:hover {
  color: var(--text-primary);
}

/* ─── Error Messages ─────────────────────────────────────────────────────── */
.field-error {
  font-size: 0.6875rem;
  color: var(--error);
  font-family: var(--font-mono);
  margin-top: 0.375rem;
  display: none;
  align-items: center;
  gap: 0.25rem;
  min-height: 1rem;
}

.field-error.visible {
  display: flex;
}

.field-error::before {
  content: '✕';
  font-size: 0.625rem;
  font-weight: 700;
}

/* ─── Field Hint ─────────────────────────────────────────────────────────── */
.field-hint {
  font-size: 0.6875rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 0.375rem;
  line-height: 1.5;
}

/* ─── Divider ────────────────────────────────────────────────────────────── */
.form-divider {
  height: 1px;
  background: var(--border);
  margin: 1.5rem 0;
}

/* ─── Output Section ─────────────────────────────────────────────────────── */
.output-section {
  background: var(--bg-surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  margin-bottom: 1rem;
  transition: all var(--transition);
}

.output-section.has-result {
  border-color: var(--output-border);
  box-shadow: var(--shadow-md);
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.output-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.btn-copy {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.875rem;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--text-inverse);
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0.01em;
}

.btn-copy:hover:not(:disabled) {
  opacity: 0.85;
  transform: translateY(-1px);
}

.btn-copy:active:not(:disabled) {
  transform: translateY(0);
}

.btn-copy:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

/* Output area */
.output-area {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.output-password {
  font-family: var(--font-mono);
  font-size: 1.125rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  word-break: break-all;
  color: var(--output-text);
  background: var(--output-bg);
  padding: 0.875rem 1rem;
  border-radius: var(--radius-md);
  width: 100%;
  text-align: center;
  display: none;
  line-height: 1.5;
  user-select: all;
}

.output-password.visible {
  display: block;
  animation: fadeInUp 200ms ease;
}

.output-placeholder {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  display: none;
  padding: 0.5rem;
}

.output-placeholder.visible {
  display: block;
}

/* Loading state */
.output-loading {
  display: none;
  align-items: center;
  gap: 0.625rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: var(--font-mono);
}

.output-loading.visible {
  display: flex;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--text-primary);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

/* ─── Strength Bar ───────────────────────────────────────────────────────── */
.strength-section {
  margin-top: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.strength-track {
  flex: 1;
  height: 4px;
  background: var(--bg-muted);
  border-radius: 2px;
  overflow: hidden;
}

.strength-bar {
  height: 100%;
  width: 0;
  border-radius: 2px;
  transition: width 400ms cubic-bezier(0.4,0,0.2,1), background 400ms ease;
}

.strength-label {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  min-width: 4.5rem;
  text-align: right;
  transition: color 300ms ease;
}

/* ─── Copy Feedback ──────────────────────────────────────────────────────── */
.copy-feedback {
  font-size: 0.6875rem;
  color: var(--success);
  font-family: var(--font-mono);
  font-weight: 500;
  margin-top: 0.5rem;
  text-align: center;
  opacity: 0;
  transition: opacity var(--transition);
  min-height: 1.25rem;
}

.copy-feedback.visible {
  opacity: 1;
}

/* ─── Footer ─────────────────────────────────────────────────────────────── */
.app-footer {
  text-align: center;
  font-size: 0.6875rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  padding-top: 0.5rem;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  body { padding: 1.5rem 0.875rem 3rem; }
  .form-card { padding: 1.5rem; }
  .checkbox-grid { grid-template-columns: 1fr 1fr; }
  .output-password { font-size: 1rem; letter-spacing: 0.06em; }
}

@media (max-width: 360px) {
  .checkbox-grid { grid-template-columns: 1fr; }
}

/* ─── Accessibility ──────────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

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