/* Crossword page only. It follows the vocabulary page: one rounded card,
   square controls whose grey rule turns white, and no accent colour.
   Interface text is bold and uppercase; clues and German keep their case. */
.crossword-page {
  --background: #000;
  --card: #101010;
  --panel: #191919;
  --foreground: #fff;
  --muted: #9a9a9a;
  --rule: #3a3a3a;
  --wrong: #ff5a4f;

  margin: 0;
  padding: 14px;
  background: var(--background);
  color: var(--foreground);
  font-family: "Inter", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color-scheme: dark;
  -webkit-tap-highlight-color: transparent;
}

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

.crossword-page [hidden] {
  display: none !important;
}

.crossword-page :where(button, input, select) {
  font: inherit;
  color: inherit;
}

.crossword-page button {
  cursor: pointer;
}

.crossword-page button:disabled {
  cursor: default;
  opacity: 0.35;
}

.crossword-page :where(button, select, summary, a):focus-visible {
  outline: 3px solid #fff;
  outline-offset: 4px;
}

/* The page sits inside one rounded card */
.crossword-card {
  min-height: calc(100dvh - 28px);
  padding: 30px 40px 48px;
  border-radius: 30px;
  background: var(--card);
}

.crossword-page .site-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin: 0 0 34px;
  font-size: clamp(0.75rem, 3.4vw, 3.25rem);
}

.crossword-page .site-header h1 {
  margin: clamp(36px, 8vh, 96px) 0 0;
  font-family: inherit;
  font-size: 2em;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.045em;
  text-transform: uppercase;
}

.crossword-page .home-link {
  flex-shrink: 0;
  color: var(--foreground);
  font-family: inherit;
  font-size: 1em;
  font-weight: 900;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

/* Buttons, as on the vocabulary page: a grey square rule that turns white
   on hover and fills white while it is on. */
.outline-button,
.solid-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 54px;
  padding: 0 22px;
  border: 2px solid var(--rule);
  border-radius: 0;
  background: transparent;
  color: var(--foreground);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.outline-button:hover:not(:disabled) {
  border-color: #fff;
}

.outline-button[aria-pressed="true"],
.solid-button {
  border-color: #fff;
  background: #fff;
  color: #000;
}

.solid-button:hover:not(:disabled) {
  background: transparent;
  color: #fff;
}

/* A square icon button, filling on hover. Icons are drawn, never typed. */
.icon-button {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 2px solid var(--rule);
  border-radius: 0;
  background: transparent;
  color: var(--foreground);
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.icon-button:hover:not(:disabled) {
  border-color: #fff;
  background: #fff;
  color: #000;
}

.icon-button svg {
  display: block;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.text-button {
  min-height: 40px;
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: color 0.2s ease;
}

.text-button:hover:not(:disabled) {
  color: var(--foreground);
}

.page-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.load-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
}

/* Hint language on the left, New puzzle on the right */
.puzzle-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.language-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.toolbar-label {
  margin-right: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* The board on the left, the clues on the right */
.puzzle-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 24rem);
  gap: 48px;
  margin-top: 36px;
  align-items: start;
}

.board-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 4px 20px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.board-stats {
  display: flex;
  align-items: center;
  gap: 18px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#word-count {
  color: var(--foreground);
}

#pause {
  min-height: 32px;
  padding: 0;
}

.board-stage {
  position: relative;
  margin-top: 14px;
}

.grid-scroll {
  overflow: auto;
  padding: 4px;
}

/* The grid. A square is ruled grey, its word is ruled white, and the square
   you are typing in fills white, as the filters do when they are on. */
#crossword-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  max-width: calc(var(--cols) * 44px);
  min-width: calc(var(--cols) * 26px);
  margin: 0 auto;
}

.crossword-row {
  display: contents;
}

.crossword-cell,
.crossword-block {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
}

.crossword-cell {
  border: 2px solid var(--rule);
  background: transparent;
  color: var(--foreground);
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.crossword-cell.is-solved {
  border-color: #333;
  background: #333;
}

.crossword-cell.is-word {
  border-color: #fff;
}

.crossword-cell.is-active {
  z-index: 1;
  border-color: #fff;
  background: #fff;
  color: #000;
}

/* A wrong letter is struck through, so it never depends on colour alone. */
.crossword-cell.is-wrong::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top right, transparent calc(50% - 1.5px), var(--wrong) calc(50% - 1.5px), var(--wrong) calc(50% + 1.5px), transparent calc(50% + 1.5px));
  pointer-events: none;
}

/* A revealed letter carries a small corner mark. */
.crossword-cell.is-revealed::after {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 5px;
  height: 5px;
  background: currentColor;
  pointer-events: none;
}

.cell-number {
  position: absolute;
  top: 1px;
  left: 3px;
  font-size: clamp(8px, 0.7vw, 10px);
  font-weight: 800;
  line-height: 1.2;
  pointer-events: none;
}

.crossword-cell input {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 5px 0 0;
  border: 0;
  border-radius: 0;
  outline: none !important;
  background: transparent;
  color: inherit;
  caret-color: transparent;
  font-size: clamp(15px, 1.6vw, 22px);
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
  -webkit-appearance: none;
  appearance: none;
}

.crossword-cell input::selection {
  background: transparent;
}

.pause-panel {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 20px;
  padding: 16px;
  background: var(--card);
}

.pause-panel h2,
.completion h2,
.dialog-heading h2 {
  margin: 0;
  font-size: clamp(1.6rem, 2.6vw, 2.25rem);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.035em;
  text-transform: uppercase;
}

/* The clue being answered, in the panel the word details use. */
.active-clue {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 24px;
  padding: 22px 24px;
  background: var(--panel);
}

.active-clue-text {
  flex: 1;
  min-width: 0;
}

.active-direction {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* The clue is the language being taught, so it keeps its own case. */
#active-clue {
  margin: 6px 0 0;
  font-size: clamp(1.1rem, 1.5vw, 1.35rem);
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.board-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.board-actions .outline-button {
  height: 44px;
  padding: 0 18px;
  font-size: 0.75rem;
}

.feedback {
  min-height: 1.5em;
  margin: 16px 0 0;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.spelling-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px 20px;
  margin-top: 12px;
}

#spelling-note {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.spelling-rule {
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

#special-keys {
  display: flex;
  gap: 8px;
}

/* Clues, under headings ruled like the letters on the vocabulary page */
.clue-group + .clue-group {
  margin-top: 30px;
}

.clue-heading {
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid #2b2b2b;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.clue-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.clue-button {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--foreground);
  text-align: left;
  transition: opacity 0.15s ease;
}

/* The number is a square of its own: it takes you to that square. */
.clue-number {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 2px solid var(--rule);
  font-size: 0.85rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.clue-text {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.clue-length {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.clue-button:hover:not(:disabled) .clue-number {
  border-color: #fff;
}

.clue-button[aria-current="true"] .clue-number {
  border-color: #fff;
  background: #fff;
  color: #000;
}

.clue-button[aria-current="true"] .clue-text,
.clue-button:hover:not(:disabled) .clue-text {
  text-decoration: underline;
  text-underline-offset: 5px;
  text-decoration-thickness: 2px;
}

.clue-list:hover .clue-button:not(:hover, [aria-current="true"]) {
  opacity: 0.55;
}

.clue-button.is-solved .clue-text {
  color: var(--muted);
}

/* Solved: the length gives way to a drawn tick. */
.clue-button.is-solved .clue-length {
  width: 14px;
  height: 8px;
  margin-right: 4px;
  border-left: 3px solid var(--muted);
  border-bottom: 3px solid var(--muted);
  transform: translateY(-2px) rotate(-45deg);
}

/* The finish, in the same panel as the active clue */
.completion {
  margin-top: 36px;
  padding: 28px;
  background: var(--panel);
  animation: completion-in 500ms ease both;
}

.completion:focus {
  outline: none;
}

.completion-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: end;
  gap: 20px 24px;
}

.completion h2 {
  font-size: clamp(2.5rem, 5vw, 4rem);
  line-height: 1;
  letter-spacing: -0.045em;
}

#completion-message {
  margin: 12px 0 0;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.completion-review summary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  list-style: none;
  cursor: pointer;
}

.completion-review summary::-webkit-details-marker {
  display: none;
}

.completion-review summary::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2.5px solid currentColor;
  border-bottom: 2.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.2s ease;
}

.completion-review[open] summary::after {
  transform: translateY(2px) rotate(-135deg);
}

.completion-review summary:hover {
  color: var(--foreground);
}

/* German first, its meaning beneath, as in the word details */
#word-review {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 40px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

#word-review li {
  padding: 10px 0;
  border-top: 1px solid #2b2b2b;
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

#word-review strong {
  display: block;
  color: var(--foreground);
  font-size: 1.05rem;
  font-weight: 800;
}

/* Settings */
.crossword-page dialog {
  width: min(500px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 28px;
  border: 0;
  border-radius: 0;
  background: var(--panel);
  color: var(--foreground);
}

.crossword-page dialog::backdrop {
  background: rgb(0 0 0 / 80%);
}

.dialog-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 26px;
}

.field-label,
.crossword-page dialog legend {
  display: block;
  margin: 0 0 12px;
  padding: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* White, like the search field, with the Filters chevron drawn in black */
.crossword-page dialog select {
  width: 100%;
  height: 54px;
  padding: 0 50px 0 18px;
  border: 0;
  border-radius: 0;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 18px center / 18px;
  appearance: none;
  color: #000;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color-scheme: light;
}

.crossword-page dialog fieldset {
  min-width: 0;
  margin: 24px 0 0;
  padding: 0;
  border: 0;
}

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

/* The vocabulary filters' toggles: a ticked square beside its label. */
.option-toggle {
  position: relative;
  display: inline-grid;
  grid-template-columns: 40px auto;
  align-items: stretch;
  height: 40px;
  cursor: pointer;
}

.option-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  border: 0;
}

.option-filter {
  position: relative;
  border: 2px solid var(--rule);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.option-filter::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 7px;
  border-left: 3px solid #000;
  border-bottom: 3px solid #000;
  opacity: 0;
  transform: translate(-50%, -65%) rotate(-45deg);
  transition: opacity 0.2s ease;
}

.option-body {
  display: flex;
  align-items: center;
  padding: 0 16px;
  border: 2px solid var(--rule);
  border-left: 0;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.option-toggle input:checked ~ .option-filter,
.option-toggle input:checked ~ .option-body {
  border-color: #fff;
  background: #fff;
  color: #000;
}

.option-toggle input:checked ~ .option-filter::after {
  opacity: 1;
}

.option-toggle:hover .option-filter,
.option-toggle:hover .option-body {
  border-color: #fff;
}

.option-toggle input:focus-visible ~ .option-filter {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.dialog-note,
.dialog-error {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.dialog-note + .dialog-note {
  margin-top: 8px;
}

.dialog-error {
  color: var(--wrong);
}

.dialog-error:empty {
  display: none;
}

#start-puzzle {
  width: 100%;
  margin-top: 24px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@keyframes completion-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Narrow: the clues drop beneath the board. */
@media (max-width: 900px) {
  .puzzle-body {
    grid-template-columns: minmax(0, 1fr);
    gap: 32px;
  }
}

@media (max-width: 860px) {
  .crossword-page {
    padding: 10px;
  }

  .crossword-card {
    min-height: calc(100dvh - 20px);
    padding: 22px 20px 40px;
    border-radius: 22px;
  }
}

@media (max-width: 480px) {
  .outline-button,
  .solid-button {
    height: 44px;
    padding: 0 14px;
    font-size: 0.72rem;
  }

  .board-actions .outline-button {
    padding: 0 12px;
    font-size: 0.68rem;
  }

  .active-clue {
    gap: 10px;
    padding: 16px;
  }

  .crossword-cell input {
    font-size: 17px;
  }

  .cell-number {
    font-size: 8px;
  }

  .completion {
    padding: 22px;
  }

  #word-review {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  .crossword-page *,
  .crossword-page *::before,
  .crossword-page *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
