:root {
  color-scheme: dark;
  --bg: #071016;
  --surface: #101d26;
  --surface-2: #142936;
  --border: #28495b;
  --text: #f5fbff;
  --muted: #a7bbc8;
  --accent: #22d3ee;
  --accent-2: #34d399;
  --danger: #fb7185;
  --shadow: rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 8%, rgba(34, 211, 238, 0.16), transparent 32%),
    radial-gradient(circle at 86% 18%, rgba(52, 211, 153, 0.15), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.puzzle-app {
  display: grid;
  gap: 1rem;
  min-height: 100vh;
  padding: clamp(0.85rem, 2vw, 1.5rem);
}

.puzzle-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  justify-content: space-between;
}

.puzzle-title {
  margin: 0;
  font-size: clamp(2rem, 4.2vw, 3.6rem);
  line-height: 1;
}

.puzzle-subtitle {
  max-width: 62rem;
  margin: 0.55rem 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1fr);
}

.panel {
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: 0 20px 44px var(--shadow);
  padding: clamp(0.8rem, 2vw, 1rem);
}

.toolbar,
.actions,
.direction-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
}

.toolbar {
  justify-content: space-between;
}

.button,
.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 0.68rem;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 850;
  text-decoration: none;
}

.button { min-height: 2.65rem; padding: 0.62rem 0.9rem; }
.mini-button { min-height: 2.25rem; padding: 0.42rem 0.62rem; }
.button.primary, .mini-button.primary { border-color: transparent; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #061117; }
.button.danger, .mini-button.danger { border-color: color-mix(in srgb, var(--danger) 72%, var(--border)); color: #fecdd3; }

.muted { color: var(--muted); }

.field-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}

.field {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.field small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.field input, .field textarea, .field select {
  width: 100%;
  min-height: 2.55rem;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  background: var(--surface);
  color: var(--text);
  padding: 0.58rem 0.7rem;
  outline: none;
}

.field textarea {
  min-height: 5.5rem;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.button:focus-visible,
.mini-button:focus-visible,
.icon-button:focus-visible,
.entry-summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 42%, transparent);
  outline-offset: 2px;
}

.entry-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.7rem;
}

.entry-card {
  display: grid;
  gap: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 0.68rem;
  background: var(--surface-2);
  padding: 0.6rem;
}

.entry-card.compact {
  padding-block: 0.48rem;
}

.entry-head {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
}

.entry-summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.55rem;
  align-items: center;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  text-align: left;
}

.entry-index {
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font-weight: 900;
}

.entry-copy {
  display: grid;
  min-width: 0;
}

.entry-copy strong,
.entry-copy .muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-actions {
  flex: 0 0 auto;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  background: var(--surface);
  color: var(--text);
  font-weight: 900;
}

.print-icon-button {
  font-size: 1.25rem;
  min-width: 2.65rem;
}

.status {
  min-height: 1.4rem;
  color: var(--muted);
  font-weight: 750;
}
.status.error { color: var(--danger); }
.status.success { color: var(--accent-2); }

.grid-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface-2);
  padding: 0.75rem;
}

.live-print-app {
  align-content: start;
}

.print-sheet {
  display: grid;
  gap: 1rem;
  max-width: 64rem;
  width: 100%;
  justify-self: center;
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  background: var(--surface);
  padding: clamp(0.9rem, 2vw, 1.35rem);
  box-shadow: 0 20px 44px var(--shadow);
}

.print-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.print-heading h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
}

.print-heading p {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.print-grid {
  justify-self: start;
  max-width: 100%;
}

.print-clues h2 {
  margin: 0 0 0.55rem;
}

.print-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  padding-top: 0.8rem;
}

.print-footer img {
  width: 2.2rem;
  height: 2.2rem;
  object-fit: contain;
}

.print-footer a {
  color: var(--text);
  font-weight: 850;
  text-decoration: none;
}

.letter-grid {
  display: grid;
  gap: 0.16rem;
  width: max-content;
  min-width: 100%;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(1.8rem, 4vw, 2.5rem);
  height: clamp(1.8rem, 4vw, 2.5rem);
  border: 1px solid color-mix(in srgb, var(--border) 78%, #ffffff);
  border-radius: 0.28rem;
  background: #f8fafc;
  color: #0f172a;
  font-weight: 900;
  text-transform: uppercase;
}

button.cell {
  cursor: pointer;
}

.wordsearch-cell {
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.wordsearch-cell.marked {
  border-color: #16a34a;
  background: #bbf7d0;
  color: #052e16;
  transform: scale(0.98);
}

.wordsearch-cell:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent-2) 55%, transparent);
  outline-offset: 2px;
}

.wordsearch-live-app .letter-grid {
  min-width: 0;
}

.live-wordsearch-layout {
  grid-template-columns: minmax(0, 1fr);
}

.cell.block {
  background: #0b1118;
  border-color: #0b1118;
  color: transparent;
}

.cell-number {
  position: absolute;
  top: 0.12rem;
  left: 0.16rem;
  font-size: 0.58rem;
  color: #334155;
  font-weight: 900;
}

.clue-list,
.word-list {
  display: grid;
  gap: 0.5rem;
  color: var(--muted);
  line-height: 1.45;
}

.word-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 800;
  padding: 0.35rem 0.7rem;
}

.direction-option {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  background: var(--surface-2);
  padding: 0.55rem 0.7rem;
  color: var(--text);
  font-weight: 800;
}

@media (min-width: 780px) {
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1180px) {
  .layout { grid-template-columns: minmax(26rem, 0.48fr) minmax(0, 1fr); }
}

@media (max-width: 759px) {
  .puzzle-app {
    padding: 0.65rem;
  }

  .puzzle-title {
    font-size: 2rem;
  }

  .puzzle-subtitle {
    font-size: 0.92rem;
  }

  .panel {
    padding: 0.7rem;
  }

  .button, .toolbar { width: 100%; }

  .button {
    min-height: 2.45rem;
  }

  .mini-button {
    min-height: 2.1rem;
    padding-inline: 0.52rem;
    font-size: 0.9rem;
  }

  .entry-head {
    align-items: flex-start;
  }

  .entry-summary {
    flex: 1 1 12rem;
  }

  .compact-actions {
    flex: 1 1 100%;
  }

  .direction-option {
    padding: 0.48rem 0.58rem;
  }
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  :root {
    color-scheme: light;
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #ffffff;
    --border: #000000;
    --text: #000000;
    --muted: #000000;
    --shadow: transparent;
  }

  body {
    background: #ffffff;
    color: #000000;
  }

  .puzzle-app {
    min-height: auto;
    padding: 0;
  }

  .print-hidden,
  .button,
  .mini-button,
  .icon-button {
    display: none !important;
  }

  .print-sheet,
  .grid-wrap {
    border: 0;
    box-shadow: none;
    padding: 0;
    background: #ffffff;
  }

  .print-sheet {
    max-width: none;
    gap: 8mm;
  }

  .print-heading h1 {
    font-size: 22pt;
  }

  .print-heading p,
  .clue-list {
    color: #000000;
  }

  .letter-grid {
    gap: 0;
    width: max-content;
    min-width: 0;
  }

  .cell {
    width: 8mm;
    height: 8mm;
    border: 1px solid #000000;
    border-radius: 0;
    background: #ffffff;
    color: #000000;
  }

  .cell.block {
    background: #000000;
    border-color: #000000;
  }

  .cell-number {
    color: #000000;
    font-size: 6pt;
  }

  .print-footer {
    border-top: 1px solid #000000;
    break-inside: avoid;
  }

  .print-footer img {
    filter: grayscale(1) contrast(1.3);
  }

  .print-footer a {
    color: #000000;
  }

  .wordsearch-live-app .layout,
  .live-wordsearch-layout {
    display: grid;
    gap: 8mm;
    grid-template-columns: 1fr;
  }

  .wordsearch-live-app .panel {
    border: 0;
    box-shadow: none;
    padding: 0;
    background: #ffffff;
  }

  .wordsearch-live-app .grid-wrap {
    overflow: visible;
  }

  .wordsearch-live-app .cell {
    width: 7.5mm;
    height: 7.5mm;
    border: 1px solid #000000;
    background: #ffffff !important;
    color: #000000 !important;
    transform: none !important;
  }

  .wordsearch-live-app .cell.marked {
    background: #ffffff !important;
  }

  .wordsearch-live-app .word-pill {
    border: 1px solid #000000;
    background: #ffffff;
    color: #000000;
  }
}
