/* Andika (SIL OFL 1.1, see /fonts/OFL.txt): clear letterforms for early and dyslexic readers. */
@font-face {
  font-family: 'Andika';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/andika-400-cyrillic-ext.woff2') format('woff2');
  unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}

@font-face {
  font-family: 'Andika';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/andika-400-cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: 'Andika';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/andika-400-vietnamese.woff2') format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: 'Andika';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/andika-400-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Andika';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/andika-400-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Andika';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/andika-700-cyrillic-ext.woff2') format('woff2');
  unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}

@font-face {
  font-family: 'Andika';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/andika-700-cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: 'Andika';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/andika-700-vietnamese.woff2') format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: 'Andika';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/andika-700-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Andika';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/andika-700-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Light theme in Fairfield Public Schools colours (navy, blue and red from
   the district shield). */
:root {
  --bg: #f3f6fa;
  --panel: #ffffff;
  --ink: #1b2536;
  --muted: #5d687a;
  --faint: #8a94a6;
  --line: #e2e7ef;
  --line-strong: #cfd6e2;
  --navy: #003479;
  --blue: #008cd2;
  --red: #9d2f21;
  --accent: var(--navy);
  --accent-ink: #ffffff;
  --accent-soft: #e8f1fb;
  --warn-bg: #fff6e6;
  --warn-ink: #7a4a00;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 32 64 / 5%), 0 4px 16px rgb(16 32 64 / 6%);
  --shadow-sheet: 0 1px 3px rgb(16 32 64 / 10%), 0 12px 32px rgb(16 32 64 / 10%);
  font-family: Andika, system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  line-height: 1.4;
}

main {
  flex: 1;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--navy);
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

.loading {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
}

.offscreen {
  position: fixed;
  left: -9999px;
  top: 0;
}

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* ---------- Top bar & footer ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  border-top: 4px solid var(--navy);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--ink);
}

.brand img {
  display: block;
  height: 38px;
  width: auto;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-text strong {
  font-size: 19px;
  color: var(--navy);
}

.brand-text small {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

#topnav {
  display: flex;
  gap: 4px;
}

#topnav a {
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--navy);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}

#topnav a:hover {
  background: var(--accent-soft);
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px 16px 24px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.site-footer img {
  flex: none;
}

/* ---------- Buttons & controls ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  color: var(--ink);
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  border-color: var(--navy);
  background: #f8fafd;
}

.btn.primary {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--accent-ink);
}

.btn.primary:hover {
  background: #0a428f;
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn.ghost:hover {
  background: var(--accent-soft);
  color: var(--navy);
}

.btn.small {
  padding: 6px 12px;
  font-size: 13px;
}

.btn[disabled] {
  opacity: 0.6;
  cursor: progress;
}

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 10px;
  background: #edf1f6;
}

.seg button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}

.seg button:hover {
  color: var(--ink);
}

.seg button[aria-pressed='true'] {
  background: var(--panel);
  color: var(--navy);
  font-weight: 700;
  box-shadow: 0 1px 2px rgb(16 32 64 / 12%);
}

.linkish {
  border: 0;
  background: none;
  color: var(--navy);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 0;
}

/* ---------- Editor ---------- */
.editor {
  display: grid;
  grid-template-columns: minmax(360px, 480px) 1fr;
  gap: 28px;
  padding: 24px;
  max-width: 1480px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.editor > .panel {
  padding: 24px 24px 0;
}

.panel-head h1 {
  font-size: 24px;
  color: var(--navy);
}

.panel-head .lede {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.group {
  padding: 20px 0;
  border-top: 1px solid var(--line);
}

.panel-head + .group {
  margin-top: 20px;
}

.group h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  margin-bottom: 14px;
}

.step {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--navy);
  font-size: 12px;
  font-weight: 700;
}

.type-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.type-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  text-align: left;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.type-card:hover {
  border-color: var(--line-strong);
  background: #fafbfd;
}

.type-card .icon {
  font-size: 20px;
  line-height: 1;
}

.type-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.type-card strong {
  font-size: 14px;
}

.type-card small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.type-card[aria-checked='true'] {
  border-color: var(--navy);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--navy);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field > label,
.field > .label,
.pairs-top .label {
  font-size: 13px;
  font-weight: 700;
}

.field .help,
.check .help {
  font-size: 12px;
  color: var(--muted);
}

.field input[type='text'],
.field select,
.field textarea,
.pairs input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  font-size: 15px;
}

.field textarea {
  resize: vertical;
  line-height: 1.45;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.pairs input:focus {
  outline: 2px solid var(--blue);
  outline-offset: -1px;
  border-color: transparent;
}

.field ::placeholder,
.pairs ::placeholder {
  color: var(--faint);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  margin-bottom: 12px;
  cursor: pointer;
}

.check > span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.check input {
  margin-top: 3px;
  width: 16px;
  height: 16px;
  accent-color: var(--navy);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0 16px;
}

.row > .field {
  flex: 1 1 160px;
}

details.more > summary {
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  list-style: none;
}

details.more > summary::-webkit-details-marker {
  display: none;
}

details.more > summary h2 {
  margin: 0;
}

details.more > summary h2::after {
  content: '▸';
  margin-left: auto;
  color: var(--faint);
  transition: transform 0.15s;
}

details.more[open] > summary h2::after {
  transform: rotate(90deg);
}

details.more > summary .summary-hint {
  font-size: 12px;
  color: var(--muted);
}

details.more[open] > summary {
  margin-bottom: 14px;
}

/* Answer + clue rows */
.pairs-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pairs-count {
  font-size: 12px;
  color: var(--muted);
  margin-right: auto;
}

.pairs-count.over {
  color: var(--red);
  font-weight: 700;
}

.pairs-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pairs-head,
.pairs-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) minmax(0, 1.8fr) 28px;
  gap: 6px;
  align-items: center;
}

.pairs-head {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--faint);
}

.pairs-num {
  font-size: 12px;
  color: var(--faint);
  text-align: right;
}

.pairs input {
  padding: 7px 9px;
  font-size: 14px;
}

.pairs-remove {
  border: 0;
  background: none;
  color: var(--faint);
  cursor: pointer;
  border-radius: 6px;
  height: 28px;
}

.pairs-remove:hover {
  background: #fdecea;
  color: var(--red);
}

.pairs-body > .btn {
  align-self: flex-start;
  margin-top: 4px;
}

.pairs-body textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
}

.pairs-quick-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

/* Sticky footer: warnings, special characters, actions */
.panel-foot {
  position: sticky;
  bottom: 0;
  margin: 0 -24px;
  padding: 12px 24px 16px;
  background: rgb(255 255 255 / 96%);
  border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 -6px 16px rgb(16 32 64 / 5%);
  backdrop-filter: blur(6px);
}

.warnings {
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
}

.warnings:empty {
  display: none;
}

.warnings li {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 6px;
}

.palette {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-bottom: 12px;
}

.palette .label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.palette .chars {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.palette .chars:empty {
  display: none;
}

.palette button.ch {
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 15px;
}

.palette button.ch:hover {
  border-color: var(--navy);
  background: var(--accent-soft);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.actions .grow {
  flex: 1;
}

.recent-note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Preview / sheet ---------- */
.preview {
  position: sticky;
  top: 86px;
}

.preview-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.preview-bar .title {
  font-weight: 700;
  margin-right: auto;
  color: var(--ink);
}

.preview-bar .title small {
  font-weight: 400;
  color: var(--muted);
}

.sheet-wrap {
  display: flex;
  justify-content: center;
}

.sheet {
  position: relative;
  width: 100%;
  background: #fff;
  box-shadow: var(--shadow-sheet);
  border-radius: 4px;
  line-height: 0;
}

.sheet.portrait {
  max-width: min(816px, calc((100vh - 150px) * 8.5 / 11));
}

.sheet.landscape {
  max-width: 1056px;
}

.viewer .sheet.portrait {
  max-width: 816px;
}

.sheet svg {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-select: none;
}

.sheet .hit {
  cursor: pointer;
  touch-action: none;
}

.sheet .cw-clue {
  cursor: pointer;
}

.key-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  font-size: 16px; /* stops iOS zooming on focus */
  caret-color: transparent;
}

/* ---------- Viewer ---------- */
.viewer {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: sticky;
  top: 74px;
  z-index: 5;
}

.toolbar .spacer {
  flex: 1;
}

.print-opts {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 14px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}

.print-opts .inline {
  display: flex;
  align-items: center;
  gap: 6px;
}

.print-opts select {
  padding: 5px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
}

.print-opts .check {
  margin: 0;
  font-size: 13px;
  align-items: center;
}

.print-opts .check input {
  margin: 0;
}

/* Download menu */
.menu {
  position: relative;
}

.menu > summary {
  list-style: none;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  min-width: 240px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-sheet);
}

.menu-list button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  text-align: left;
}

.menu-list button:hover {
  background: var(--accent-soft);
}

.menu-list small {
  color: var(--muted);
  font-size: 12px;
}

.status {
  min-height: 22px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.error-box {
  max-width: 560px;
  margin: 60px auto;
  padding: 28px;
  text-align: center;
}

/* ---------- Recent puzzles ---------- */
.recent-wrap {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
}

.recent {
  padding: 24px;
}

.recent h1 {
  font-size: 22px;
  color: var(--navy);
}

.recent .notice {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.5;
}

.recent-list {
  list-style: none;
  margin: 16px 0;
  padding: 0;
}

.recent-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.recent-list li.empty {
  display: block;
  color: var(--muted);
  border: 0;
}

.recent-list .icon {
  font-size: 22px;
}

.recent-list .meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.recent-list .title {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-list small {
  color: var(--muted);
}

.recent-list .row-actions {
  display: flex;
  gap: 6px;
}

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-sheet);
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#print-root {
  display: none;
}

/* ---------- Small screens ---------- */
@media (max-width: 960px) {
  .editor {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 20px;
  }

  .editor > .panel {
    padding: 20px 16px 0;
  }

  .panel-foot {
    margin: 0 -16px;
    padding: 12px 16px 14px;
  }

  .preview {
    position: static;
  }

  .sheet.portrait {
    max-width: 100%;
  }

  .viewer,
  .recent-wrap {
    padding: 16px;
  }

  .toolbar {
    position: static;
  }

  .topbar {
    padding: 8px 16px;
  }
}

@media (max-width: 600px) {
  .type-picker {
    grid-template-columns: 1fr;
  }

  .type-card {
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }

  .brand-text small {
    display: none;
  }

  .recent-list li {
    flex-wrap: wrap;
  }

  .pairs-head,
  .pairs-row {
    grid-template-columns: 18px minmax(0, 1fr) minmax(0, 1.4fr) 24px;
  }
}

/* ---------- Print: only the prepared pages ---------- */
@media print {
  body > *:not(#print-root) {
    display: none !important;
  }

  body {
    background: #fff;
    display: block;
  }

  #print-root {
    display: block;
  }

  .print-page {
    width: 8.5in;
    height: 10.95in;
    overflow: hidden;
    break-after: page;
  }

  .print-page.landscape {
    width: 11in;
    height: 8.45in;
  }

  .print-page:last-child {
    break-after: auto;
  }

  .print-page svg {
    display: block;
    width: 100%;
    height: 100%;
  }
}
