/* ================================================================
   Chomsky — Grammatical Passphrase Generator
   Dark-only theme with warm amber accent
   ================================================================ */

/* --- Custom Properties ----------------------------------------- */
:root {
  /* Palette */
  --bg-base:       #0b0d12;
  --bg-surface:    #14171f;
  --bg-elevated:   #1c2030;
  --bg-input:      #0e1017;
  --border:        #262b38;
  --border-hover:  #3a4058;
  --text-primary:  #e2dfd8;
  --text-secondary:#9094a0;
  --text-muted:    #505468;
  --accent:        #d4a03c;
  --accent-hover:  #e0b04c;
  --accent-subtle: rgba(212, 160, 60, 0.10);
  --danger:        #cc4444;
  --success:       #3ca860;

  /* Typography */
  --font-display: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  --font-body:    'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono:    'Fira Code', 'SF Mono', 'Menlo', 'Consolas', monospace;

  /* Spacing */
  --space-xs: 0.375rem;
  --space-sm: 0.75rem;
  --space-md: 1.25rem;
  --space-lg: 2rem;
  --space-xl: 3rem;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  /* Transitions */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* Subtle grain overlay for atmosphere */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px;
  z-index: 9999;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s var(--ease-out);
}
a:hover {
  color: var(--accent-hover);
}

/* --- Layout ---------------------------------------------------- */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-md);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* --- Header ---------------------------------------------------- */
header {
  text-align: center;
  padding: 0 0 var(--space-md);
}

header h1 {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 4vw, 1.7rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--text-primary);
}

header p {
  margin-top: var(--space-sm);
  color: var(--text-secondary);
  font-size: 0.95rem;
}
header p a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* --- Card ------------------------------------------------------ */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  transition: border-color 0.3s var(--ease-out);
}
.card:hover {
  border-color: var(--border-hover);
}

.card h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-md);
  color: var(--text-primary);
}

/* --- Output Area ----------------------------------------------- */
#passphrase-output {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font-family: var(--font-mono);
  font-size: 1.24rem;
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: 0.015em;
  margin-bottom: var(--space-sm);
  color: var(--accent);
  user-select: all;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#passphrase-output:focus-within,
#passphrase-output:not(.placeholder) {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

#passphrase-output.placeholder {
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 400;
  font-style: italic;
  letter-spacing: 0;
  user-select: none;
}

/* --- Notes ----------------------------------------------------- */
.note {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
  line-height: 1.6;
}

.note-value {
  color: var(--accent);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.82rem;
}

/* --- Buttons --------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  white-space: nowrap;
  line-height: 1;
  user-select: none;
}
.btn:active {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  color: #0b0d12;
  border-color: var(--accent);
  font-weight: 600;
  margin-top: var(--space-md);
  width: 100%;
  padding: 0.75rem 1.2rem;
  font-size: 0.95rem;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: rgba(212, 160, 60, 0.25);
}
.btn-secondary:hover:not(:disabled) {
  color: var(--accent);
  border-color: rgba(212, 160, 60, 0.4);
  background: rgba(212, 160, 60, 0.18);
}

/* Copy button feedback */
#copy-btn {
  min-width: 5rem;
}
#copy-btn.copy-feedback {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

/* --- Controls Header ------------------------------------------- */
.controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}
.controls-header h2 {
  margin-bottom: 0;
}

#controls-toggle {
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
}

/* Output card header — mirrors the Settings card header (h2 left, button right) */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.card-header h2 {
  margin-bottom: 0;
}

#copy-btn {
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
}

/* --- Controls Body --------------------------------------------- */
.controls-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.45s var(--ease-out),
              opacity 0.35s var(--ease-out);
  opacity: 1;
}

.controls-body-inner {
  overflow: hidden;
  min-height: 0;
}

.controls-body.collapsed {
  grid-template-rows: 0fr;
  opacity: 0;
  pointer-events: none;
}

/* The controls grid */
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-md);
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border);
}

/* --- Control Groups -------------------------------------------- */
.control-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.control-group-full {
  grid-column: 1 / -1;
  margin-top: var(--space-sm);
}

.control-group label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.control-group input[type="number"],
.control-group input[type="text"],
.control-group select {
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: 0.55rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
  width: 100%;
}
.control-group input:focus,
.control-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.control-group select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239094a0' d='M2.5 4.5L6 8l3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
  cursor: pointer;
}

/* --- Template Spinners ----------------------------------------- */
.template-spinners {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
}

.template-spinners .template-spinner {
  display: inline-block;
  flex: 0 0 auto;
  width: auto;
  max-width: none;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.35rem 1.6rem 0.35rem 0.75rem;
  background: var(--accent-subtle);
  border: 1px solid rgba(212, 160, 60, 0.25);
  border-radius: 999px;
  color: var(--accent);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath fill='%23d4a03c' d='M1.5 3.5L5 7l3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  transition: all 0.2s var(--ease-out);
  outline: none;
}
.template-spinner:hover {
  background-color: rgba(212, 160, 60, 0.18);
  border-color: rgba(212, 160, 60, 0.4);
}
.template-spinner:focus {
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

/* --- Word List Textareas --------------------------------------- */
.wordlist-textarea {
  width: 100%;
  min-height: 100px;
  max-height: 260px;
  padding: var(--space-sm);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  resize: vertical;
  outline: none;
  transition: border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}
.wordlist-textarea::placeholder {
  color: var(--text-muted);
  font-family: var(--font-body);
  font-style: italic;
}
.wordlist-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.wordlist-actions {
  margin-top: var(--space-xs);
  display: flex;
  gap: var(--space-sm);
}
.wordlist-actions .btn {
  font-size: 0.78rem;
  padding: 0.4rem 0.85rem;
}

/* --- Validation Message ---------------------------------------- */
#validation-msg {
  grid-column: 1 / -1;
  font-size: 0.85rem;
  color: var(--danger);
  min-height: 0;
}
#validation-msg:empty {
  display: none;
}

/* --- Documentation Card ---------------------------------------- */
.doc-card h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: var(--space-xs);
  letter-spacing: -0.005em;
}

.doc-card p {
  color: var(--text-primary);
  font-size: 0.92rem;
  margin-bottom: var(--space-md);
  line-height: 1.7;
}
.doc-card p:last-child {
  margin-bottom: 0;
}

.doc-card ol {
  color: var(--text-primary);
  font-size: 0.92rem;
  line-height: 1.7;
  margin: 0 0 var(--space-md);
  padding-left: 2rem;
}
.doc-card ol li {
  margin-bottom: var(--space-xs);
}
.doc-card ol li::marker {
  color: var(--accent);
  font-weight: 600;
}

.doc-card ul {
  color: var(--text-primary);
  font-size: 0.92rem;
  line-height: 1.7;
  margin: 0 0 var(--space-md);
  padding-left: 2rem;
}
.doc-card ul li {
  margin-bottom: var(--space-xs);
}
.doc-card ul li::marker {
  color: var(--accent);
  font-weight: 600;
}

.doc-section {
  margin-bottom: var(--space-lg);
}
.doc-section:last-child {
  margin-bottom: 0;
}

/* --- Footer ---------------------------------------------------- */
.footer {
  text-align: center;
  padding: var(--space-md) 0;
  font-size: 0.85rem;
}
.footer a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s var(--ease-out);
}
.footer a:hover {
  color: var(--accent-hover);
}

/* --- Responsive ------------------------------------------------ */
@media (max-width: 640px) {
  .container {
    padding: var(--space-md) var(--space-sm);
    gap: var(--space-md);
  }

  .card {
    padding: var(--space-md);
  }

  .controls {
    grid-template-columns: 1fr;
    gap: var(--space-sm);
  }

  #passphrase-output {
    font-size: 1.1rem;
  }

  .output-area {
    flex-direction: column;
  }

  #copy-btn {
    align-self: flex-end;
  }
}

/* --- Selection ------------------------------------------------- */
::selection {
  background: var(--accent);
  color: #0b0d12;
}
