/*
  Crossword Maker. Plain CSS, not built by Tailwind; colours come from the site's
  theme tokens so dark mode just works, except the sheets, which are always ink on
  white like paper. Sheet sizes are CSS pixels (96 to the inch), the same on screen
  and in print, so the preview is the printed page scaled down.
*/

.cw {
  --cw-line: var(--color-base-300);
  --cw-accent: var(--color-primary);
  display: grid;
  gap: 1.25rem;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}
.cw [hidden] { display: none !important; }
@media (min-width: 60rem) {
  .cw { grid-template-columns: minmax(20rem, 25rem) minmax(0, 1fr); }
  .cw-view { position: sticky; top: 5.5rem; }
  .cw-preview { max-height: calc(100vh - 14rem); overflow-y: auto; padding-right: 0.25rem; }
}

.cw-alert {
  padding: 0.85rem 1rem;
  border: 1px solid var(--cw-line, var(--color-base-300));
  border-radius: 0.75rem;
  background: var(--color-base-200);
}

.cw-panel {
  min-width: 0;
  padding: 1rem;
  border: 1px solid var(--cw-line);
  border-radius: 0.875rem;
  background: var(--color-base-100);
}
@media (min-width: 40rem) { .cw-panel { padding: 1.25rem; } }

/* ---- Form ---- */
.cw-form { display: flex; flex-direction: column; gap: 1.1rem; }
.cw-field { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; margin: 0; padding: 0; border: 0; }
.cw-label { padding: 0; font-size: 0.875rem; font-weight: 600; }
.cw-hint { font-size: 0.8125rem; line-height: 1.45; color: var(--muted); }
.cw-hint:empty { display: none; }
.cw-words { width: 100%; min-height: 15rem; resize: vertical; font-size: 0.875rem; line-height: 1.55; tab-size: 4; }
.cw-input { width: 100%; }
.cw-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.4rem 0.75rem; margin-top: 0.25rem; }
.cw-row-controls { display: flex; align-items: center; gap: 0.4rem; }
.cw-select { min-width: 10rem; }

.cw-warnings {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: color-mix(in oklab, var(--color-warning) 55%, var(--color-base-content));
}
.cw-warnings:empty { display: none; }

.cw-undo { font-size: 0.8125rem; color: var(--muted); }
.cw-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-base-content);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 0.18em;
  cursor: pointer;
}
.cw-link:focus-visible { outline: 2px solid var(--cw-accent); outline-offset: 2px; border-radius: 2px; }

.cw-section {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
  margin: 0;
  padding: 1rem 0 0;
  border: 0;
  border-top: 1px solid var(--cw-line);
}
.cw-legend { float: left; width: 100%; padding: 0; font-size: 0.9375rem; font-weight: 650; }
.cw-legend + * { clear: both; }

.cw-check { display: flex; align-items: center; gap: 0.55rem; font-size: 0.9375rem; cursor: pointer; }

/* Segmented choice */
.cw-seg {
  display: flex;
  flex-wrap: wrap;
  border: 1px solid var(--cw-line);
  border-radius: 0.625rem;
  overflow: hidden;
  background: var(--color-base-100);
}
.cw-seg label { flex: 1 1 auto; position: relative; cursor: pointer; }
.cw-seg input { position: absolute; opacity: 0; pointer-events: none; }
.cw-seg span { display: block; padding: 0.4rem 0.75rem; text-align: center; font-size: 0.8125rem; white-space: nowrap; }
.cw-seg label + label span { border-left: 1px solid var(--cw-line); }
.cw-seg input:checked + span { background: var(--color-base-content); color: var(--color-base-100); font-weight: 600; }
.cw-seg input:focus-visible + span { outline: 2px solid var(--cw-accent); outline-offset: -2px; }
.cw-seg-sm span { padding: 0.25rem 0.7rem; }

/* ---- Preview ---- */
.cw-view { display: flex; flex-direction: column; gap: 0.75rem; }
.cw-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.cw-status { font-size: 0.9375rem; line-height: 1.5; }
.cw-view.is-busy .cw-status::before {
  content: "";
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  margin-right: 0.45rem;
  vertical-align: -0.1rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: cw-spin 0.7s linear infinite;
}
@keyframes cw-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .cw-view.is-busy .cw-status::before { animation: none; } }
.cw-view.is-busy .cw-preview { opacity: 0.55; }

.cw-unplaced {
  padding: 0.7rem 0.85rem;
  border: 1px solid color-mix(in oklab, var(--color-warning) 55%, var(--cw-line));
  border-radius: 0.625rem;
  background: color-mix(in oklab, var(--color-warning) 9%, var(--color-base-100));
  font-size: 0.875rem;
  line-height: 1.5;
}
.cw-copy { display: flex; gap: 0.4rem; }
.cw-copy input { flex: 1; min-width: 0; }

.cw-preview-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; }
.cw-preview-bar .cw-legend { float: none; width: auto; }
.cw-preview { display: flex; flex-direction: column; gap: 1rem; transition: opacity 0.15s; }
.cw-empty {
  display: grid;
  place-items: center;
  min-height: 14rem;
  padding: 2rem 1rem;
  border: 2px dashed var(--cw-line);
  border-radius: 0.75rem;
  color: var(--muted);
  text-align: center;
}
.cw-page-wrap { margin: 0; }
.cw-page-label { margin-bottom: 0.35rem; font-size: 0.8125rem; color: var(--muted); }
.cw-page {
  position: relative;
  width: 100%;
  overflow: hidden;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 0 0 1px var(--cw-line), 0 2px 10px rgb(0 0 0 / 0.08);
}
.cw-page > .cw-sheet { position: absolute; top: 0; left: 0; transform-origin: 0 0; }

/* ---- Sheets (preview and print) ---- */
.cw-sheet {
  position: relative;
  box-sizing: border-box;
  background: #fff;
  color: #1d1b22;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  line-height: 1.35;
  overflow: hidden;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.cw-head { padding-bottom: 16px; }
.cw-head-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px 28px; }
.cw-title { margin: 0; font-size: 26px; font-weight: 700; line-height: 1.15; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.cw-of { font-size: 13px; color: #555; overflow-wrap: anywhere; }
.cw-lines { display: flex; align-items: flex-end; gap: 8px; padding-bottom: 3px; font-size: 12px; white-space: nowrap; }
.cw-lines i { display: inline-block; width: 160px; height: 1em; border-bottom: 1px solid #1d1b22; }
.cw-lines i + span { margin-left: 10px; }
.cw-lines i.cw-short { width: 96px; }
.cw-instr { margin: 6px 0 0; font-size: 13px; color: #444; overflow-wrap: anywhere; }
.cw-head-more { padding-bottom: 14px; font-size: 15px; font-weight: 600; color: #444; overflow-wrap: anywhere; }

.cw-body { position: relative; }
.cw-grid { position: absolute; display: block; overflow: visible; }
.cw-grid rect { fill: #fff; stroke: #1d1b22; stroke-width: 1.4px; }
.cw-grid text { fill: #1d1b22; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }
.cw-grid .cw-n { font-size: 27px; font-weight: 700; }
.cw-grid .cw-l { font-size: 58px; font-weight: 500; text-anchor: middle; }

.cw-region { position: absolute; }
.cw-dir { margin: 0; padding: 2px 0 6px; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
/* Each item is measured alone, so spacing never depends on its neighbours. */
.cw-dir.cw-dir-gap { padding-top: 12px; }
.cw-clue { display: grid; grid-template-columns: 26px minmax(0, 1fr); padding: 0 0 5px; font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.cw-clue b { font-weight: 700; }
.cw-enum { color: #555; white-space: nowrap; }
.cw-blank { display: inline-block; width: 70%; height: 1em; border-bottom: 1px solid #999; }
.cw-answer span { letter-spacing: 0.04em; }
.cw-foot { position: absolute; right: 0; bottom: 0; left: 0; display: flex; justify-content: flex-end; height: 18px; font-size: 10px; line-height: 18px; color: #666; }

/* Off-screen box for measuring headers and clues before laying out a page. */
.cw-measure { position: absolute; top: 0; left: -10000px; visibility: hidden; pointer-events: none; }
.cw-measure .cw-region { position: static; }

/* ---- Printing: only the sheets ---- */
.cw-print { display: none; }
@media print {
  body > *:not(.cw-print) { display: none !important; }
  html, body { background: #fff !important; }
  .cw-print { display: block; }
  .cw-print .cw-sheet { break-after: page; page-break-after: always; }
  .cw-print .cw-sheet:last-child { break-after: auto; page-break-after: auto; }
}

/* ---- Below the tool ---- */
.cw-tips { display: grid; gap: 0.9rem; margin: 1.25rem 0 0; padding: 0; list-style: none; font-size: 0.9375rem; line-height: 1.55; }
.cw-tips li { padding-left: 0.9rem; border-left: 3px solid var(--color-base-300); }
.cw-examples { display: grid; gap: 0.9rem; margin: 1.25rem 0 0; padding: 0; list-style: none; }
.cw-examples li { display: flex; flex-direction: column; gap: 0.15rem; font-size: 0.9375rem; line-height: 1.5; }
.cw-example-link { font-weight: 600; text-decoration: underline; text-underline-offset: 0.18em; }
