/* Mrs. Mandeville Crossword Builder - classroom palette */
:root {
  --purple: #581c64;
  --purple-deep: #461650;
  --purple-ink: #35113c;
  --green: #027538;
  --green-soft: #e8f5ee;
  --blue: #174b7d;
  --gold: #f8ba47;
  --ink: #242424;
  --muted: #474747;
  --soft: #737373;
  --line: #e5e5e5;
  --cream: #faf8f6;
  --white: #ffffff;
  --shadow: 0 14px 32px rgba(53, 17, 60, 0.1);
  --radius: 16px;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Source Sans 3", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --cell: 28px;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.site-header {
  background: rgba(250, 248, 246, 0.95);
  border-bottom: 1px solid rgba(88, 28, 100, 0.1);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand { display: flex; flex-direction: column; gap: 0.1rem; }
.brand-kicker {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--green);
  font-weight: 700;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--purple);
}
.header-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem;
  display: grid;
  gap: 1.25rem;
}
@media (min-width: 980px) {
  .layout {
    grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
    align-items: start;
  }
}

.panel {
  background: var(--white);
  border: 1px solid rgba(88, 28, 100, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.panel h1 {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: 1.55rem;
  color: var(--purple);
}

.panel h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--blue);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 1rem 0 0.65rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}
.field span {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--purple-ink);
}

input[type="text"],
select,
textarea {
  font: inherit;
  padding: 0.6rem 0.75rem;
  border: 1px solid #d5d0d7;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
input[type="text"]:focus,
select:focus {
  outline: 2px solid rgba(88, 28, 100, 0.35);
  border-color: var(--purple);
}

.word-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.word-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.word-table th,
.word-table td {
  padding: 0.4rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.word-table th {
  text-align: left;
  background: var(--green-soft);
  color: var(--green);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.word-table input {
  width: 100%;
  min-width: 0;
  padding: 0.45rem 0.5rem;
  border: 1px solid #e0dbe3;
  border-radius: 8px;
  font: inherit;
}
.word-table .col-actions { width: 2.5rem; }
.word-table .remove-btn {
  border: none;
  background: transparent;
  color: #a33;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
}
.word-table .remove-btn:hover { background: #fdeaea; }

.hint {
  margin: 0.55rem 0 0;
  color: var(--soft);
  font-size: 0.88rem;
}

.actions-row {
  display: flex;
  gap: 0.55rem;
  margin-top: 0.9rem;
  flex-wrap: nowrap;
}
.actions-row.wrap { flex-wrap: wrap; }

.btn {
  appearance: none;
  border: 1px solid rgba(88, 28, 100, 0.18);
  background: #fff;
  color: var(--purple);
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}
.btn:hover { background: rgba(88, 28, 100, 0.06); }
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--purple);
  border-color: var(--purple);
  color: #fff;
}
.btn-primary:hover { background: var(--purple-deep); }
.btn-danger {
  color: #8b1e1e;
  border-color: rgba(139, 30, 30, 0.25);
}
.btn-danger:hover { background: #fdeaea; }
.btn-small {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}
.file-btn { cursor: pointer; }

.status {
  margin-top: 0.9rem;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 0.92rem;
  min-height: 1.2em;
}
.status.warn {
  background: #fff6e5;
  color: #8a5a00;
}
.status.error {
  background: #fdeaea;
  color: #8b1e1e;
}
.status:empty { display: none; }

.persist {
  margin-top: 1.4rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
}

.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.empty-preview {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
  background: repeating-linear-gradient(
    -45deg,
    #faf8f6,
    #faf8f6 10px,
    #f3efe8 10px,
    #f3efe8 20px
  );
  border-radius: 12px;
  border: 1px dashed rgba(88, 28, 100, 0.2);
}

.hidden { display: none !important; }

.print-header {
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.print-header-main { min-width: 0; flex: 1; }
.print-kicker {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--green);
}
.print-title {
  margin: 0.2rem 0 0.35rem;
  font-size: 1.45rem;
  color: var(--purple);
}
.print-mode-label {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}
.print-name-line {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  min-width: 11rem;
  padding-top: 0.15rem;
}
.print-name-label {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
}
.print-name-underline {
  display: inline-block;
  flex: 1;
  min-width: 8rem;
  border-bottom: 1.5px solid #222;
  height: 1.1em;
}
.print-class-footer {
  display: none;
  margin: 1.25rem 0 0;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
}
.answer-only { display: none; }
body.print-answer .blank-only { display: none; }
body.print-answer .answer-only { display: block; }
body.print-blank .answer-only { display: none; }
body.print-blank .blank-only { display: block; }

.grid-scroll { overflow-x: auto; }

.xword-grid {
  border-collapse: collapse;
  margin: 0 auto;
  background: transparent;
}
.xword-grid td {
  width: var(--cell);
  height: var(--cell);
  min-width: var(--cell);
  padding: 0;
  border: none;
  background: transparent;
  position: relative;
  vertical-align: middle;
  text-align: center;
}
/* Only letter squares show a grid */
.xword-grid td.cell {
  background: #fff;
  border: 1.5px solid #222;
}
.xword-grid td.void {
  border: none;
  background: transparent;
}
.xword-grid .num {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 8px;
  line-height: 1;
  font-weight: 700;
  color: #111;
  pointer-events: none;
}
.xword-grid .letter {
  font-weight: 700;
  font-size: 14px;
  color: transparent;
  line-height: 1;
  user-select: none;
}
body.print-answer .xword-grid .letter,
body.show-answers .xword-grid .letter {
  color: var(--ink);
}

.clues-block {
  display: grid;
  gap: 1rem;
  margin-top: 1.25rem;
}
@media (min-width: 700px) {
  .clues-block { grid-template-columns: 1fr 1fr; }
}
.clue-col h3 {
  margin: 0 0 0.45rem;
  color: var(--purple);
  font-size: 1.05rem;
}
.clue-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
  font-size: 0.95rem;
}
.clue-list li { margin-bottom: 0.35rem; }
.clue-list .clue-num { font-weight: 700; }

.word-bank-block {
  margin-top: 1.1rem;
}
.word-bank-heading {
  margin: 0 0 0.45rem;
  color: var(--purple);
  font-size: 1.05rem;
}
.word-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.word-bank li { white-space: nowrap; }

.used-block {
  margin-top: 1rem;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: #f4f1f6;
  font-size: 0.9rem;
  color: var(--muted);
}
.used-block strong { color: var(--ink); }

.site-footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.5rem 1.25rem 2rem;
  color: var(--soft);
  font-size: 0.88rem;
}

/* Screen: optionally show answer letters when printing answer mode only */
@media screen {
  body:not(.print-answer):not(.show-answers) .xword-grid .letter {
    color: transparent;
  }
}

@media print {
  @page { margin: 0.55in; }
  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }
  .no-print { display: none !important; }
  .panel {
    box-shadow: none;
    border: none;
    padding: 0;
    background: transparent;
  }
  .layout {
    display: block;
    max-width: none;
    padding: 0;
  }
  .preview { display: block !important; }
  .puzzle-preview { display: block !important; }
  .empty-preview { display: none !important; }
  .xword-grid {
    background: transparent !important;
  }
  .xword-grid td {
    width: 22px;
    height: 22px;
    min-width: 22px;
    border: none !important;
    background: transparent !important;
  }
  .xword-grid td.cell {
    border: 1.5px solid #000 !important;
    background: #fff !important;
  }
  .xword-grid td.void {
    border: none !important;
    background: transparent !important;
  }
  .xword-grid .num { font-size: 7px; }
  .xword-grid .letter { font-size: 12px; }
  body.print-blank .xword-grid .letter { color: transparent !important; }
  body.print-answer .xword-grid .letter { color: #000 !important; }
  .word-bank-block { break-inside: avoid; margin-top: 0.85rem; }
  .word-bank-heading { color: #000; font-size: 11pt; }
  .word-bank { font-size: 10pt; gap: 0.25rem 0.85rem; }
  .clues-block { break-inside: auto; page-break-inside: auto; }
  .print-header-main {
    display: none !important;
  }
  .print-header {
    margin-bottom: 0.75rem;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 0.75rem;
  }
  .print-name-line {
    min-width: 12rem;
  }
  .print-name-label {
    color: #000;
    font-size: 11pt;
  }
  .print-name-underline {
    border-bottom: 1.5px solid #000;
    min-width: 9rem;
  }
  .print-class-footer {
    display: block !important;
    position: running(classfooter);
    margin: 1.4rem 0 0;
    text-align: center;
    font-size: 10pt;
    font-weight: 600;
    color: #000;
  }
  .puzzle-preview {
    min-height: auto;
  }
  .clues-block {
    margin-bottom: 0.5rem;
  }
  .clue-col h3 { color: #000; }
  .clue-list { font-size: 10pt; }
}
