/* =========================
   Spelling Worksheet Generator – Modern UI + Print polish
   ========================= */

/* ---------- Theme ---------- */
:root {
  --bg: #f5f7fb;
  --fg: #0f172a;
  --muted: #475569;
  --panel: #ffffff;
  --border: #e5e7eb;
  --accent: #3a68ff;
  --accent-600: #2e55d1;
  --accent-50: #eef3ff;
  --ring: rgba(58, 104, 255, 0.35);

  /* Worksheet variables */
  --page-margin: 0.5in;
  --line-height: 26px;
  --line-thickness: 2px;
  --line-gap: 10px;
  --max-content-width: 1200px;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--fg);
  background: linear-gradient(180deg, #f7f9ff 0%, #f5f7fb 100%);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  line-height: 1.5;
}

/* ---------- Header ---------- */
header {
  position: relative;
  padding: 28px 16px;
  background: radial-gradient(1200px 400px at 20% -20%, #eaf0ff 0%, #ffffff 60%),
              linear-gradient(90deg, #ffffff 0%, #f8fbff 100%);
  border-bottom: 1px solid var(--border);
}
header h1 {
  margin: 0 0 6px 0;
  font-size: clamp(22px, 2.4vw, 30px);
  letter-spacing: -0.02em;
}
.subtitle { margin: 0; color: var(--muted); font-size: 14px; }

/* ---------- Layout ---------- */
main {
  max-width: var(--max-content_width, var(--max-content-width));
  margin: 0 auto;
  padding: 20px 16px 60px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow:
    0 1px 2px rgba(15, 23, 42, 0.04),
    0 6px 20px rgba(15, 23, 42, 0.06);
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.panel:hover {
  transform: translateY(-1px);
  box-shadow:
    0 2px 6px rgba(15, 23, 42, 0.05),
    0 12px 28px rgba(15, 23, 42, 0.08);
}
.panel h2 {
  margin: 2px 0 12px 0;
  font-size: 16px;
  letter-spacing: 0.02em;
  color: #0b1220;
}

/* Make preview span full width */
.preview-container {
  grid-column: 1 / -1;
}

/* ---------- Forms ---------- */
.form-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}
.form-row label {
  min-width: 220px;
  max-width: 45%;
  color: var(--muted);
  font-size: 14px;
}
input[type="number"],
input[type="text"],
textarea {
  flex: 1 1 auto;
  width: 100%;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}
textarea { resize: vertical; }
input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--ring);
}

/* Radio group */
.word-source {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 12px;
  margin: 14px 0;
}
.word-source legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 12px;
}
.word-source label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.word-source input[type="radio"] {
  appearance: none;
  width: 14px; height: 14px; border-radius: 999px;
  border: 2px solid var(--border);
  display: inline-block; position: relative;
}
.word-source input[type="radio"]:checked {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--ring);
}
.word-source input[type="radio"]:checked::after {
  content: "";
  position: absolute; inset: 3px;
  background: var(--accent);
  border-radius: 999px;
}

/* ---------- Lists / Library / Picked ---------- */
.list {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  min-height: 140px;
  max-height: 260px;
  overflow: auto;
  background: #fff;
}
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px;
  border-bottom: 1px dashed #eef1f6;
  transition: background 100ms ease;
}
.row:last-child { border-bottom: none; }
.row:hover { background: #fafcff; }
.row .word { font-weight: 600; letter-spacing: 0.01em; }

.picked { margin-top: 10px; }
.picked-header {
  display: flex; align-items: center; justify-content: space-between;
  margin: 10px 0 6px;
}
.picked-header h3 { margin: 0; font-size: 15px; }
.pill-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-50);
  border: 1px solid var(--accent);
  color: var(--accent-600);
  font-weight: 700;
}
.picked-actions {
  display: flex; justify-content: flex-end; margin-top: 8px;
}
.btn-secondary {
  background: #fff; color: var(--fg);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--accent-50);
  border-color: var(--accent);
  color: var(--accent-600);
}

.picked-list .row { background: #f8fbff; }

.bulk textarea { width: 100%; }

/* Importer button-like label */
.library-controls {
  display: flex; flex-wrap: wrap;
  gap: 10px; align-items: center; margin-top: 10px;
}
.library-controls .importer {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: border-color 120ms, box-shadow 120ms, transform 80ms;
}
.library-controls .importer:active { transform: translateY(1px); }
.library-controls .importer:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--ring);
}
.library-controls .importer input { display: none; }

/* ---------- Buttons ---------- */
button {
  appearance: none;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease, box-shadow 120ms ease;
}
button:hover { background: var(--accent-600); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--ring); }

/* Action row */
.actions {
  display: flex; flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}
.actions button:nth-child(1) {
  background: #fff; color: var(--fg);
  border: 1px solid var(--border);
}
.actions button:nth-child(1):hover {
  background: var(--accent-50);
  border-color: var(--accent);
  color: var(--accent-600);
}

/* ---------- Preview (Paper) ---------- */
.sheet {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  min-height: 420px;
  box-shadow:
    0 1px 2px rgba(15,23,42,0.03),
    0 10px 40px rgba(15,23,42,0.08);
}

/* Name/Date header that prints */
.sheet-header {
  display: none;
  margin: 6px 2px 14px;
}
.sheet-header.visible { display: block; }
.name-date {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--fg);
}
.line-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 42%;
}
.line-label { font-weight: 600; }
.line-blank {
  flex: 1 1 auto;
  border-bottom: 2px solid #0f172a;
  height: 1.4em;
}

/* Two-column content */
#preview { column-count: 2; column-gap: 28px; }
.ws-word {
  break-inside: avoid;
  margin: 0 0 18px 0;
  padding: 0 0 10px 0;
  border-bottom: 1px dotted #e6e9ef;
}
.ws-word .sample {
  font-size: clamp(18px, 2vw, 22px);
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: 0.01em;
}
.ws-word .lines { display: grid; gap: var(--line-gap); }
.ws-word .lines .line {
  height: var(--line-height);
  border-bottom: var(--line-thickness) solid #0f172a;
  border-radius: 2px;
}

/* Utility */
.hidden { display: none !important; }
.screen-only { display: block; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  main { grid-template-columns: 1fr; }
  .form-row label { min-width: 150px; }
}

/* ---------- Print styles ---------- */
@page {
  size: Letter;
  margin: var(--page-margin);
}
@media print {
  body { background: white; }
  header, footer,
  .panel:not(.preview-container) { display: none !important; }
  .preview-container h2 { display: none !important; } /* Hide "Print Preview" label */
  main { padding: 0; }
  .preview-container { grid-column: 1 / -1; border: none; box-shadow: none; }
  .sheet { border: none; box-shadow: none; padding: 0; }
  #preview { column-count: 2; column-gap: 24px; }
}
