@charset "utf-8";

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #20242a;
  --muted: #6f7782;
  --line: #d9dee6;
  --accent: #0f7b6c;
  --accent-strong: #095e52;
  --accent-soft: #d9f2ed;
  --block: #4b535c;
  --danger: #a23b3b;
  --cell: clamp(18px, 1.85vw, 28px);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  padding: 0 14px;
}

button:hover {
  border-color: var(--accent);
}

button:disabled,
button:disabled:hover {
  border-color: var(--line);
  color: #8a929c;
  cursor: wait;
  opacity: 0.72;
}

.app-shell {
  width: min(1380px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.license-note {
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
}

.license-note a {
  color: inherit;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.preview-panel {
  min-width: 0;
  overflow: hidden;
}

body.embedded .app-shell {
  width: 100%;
  padding: 12px;
}

body.embedded .panel {
  padding: 14px;
}

body.embedded .panel-header {
  margin-bottom: 14px;
}

body.embedded h1 {
  font-size: 24px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-header.compact {
  margin-bottom: 12px;
}

h1,
h2 {
  margin: 0 0 6px;
  line-height: 1.15;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 22px;
}

p {
  margin: 0;
  color: var(--muted);
}

.field-row {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

label {
  color: var(--ink);
  font-weight: 650;
}

input[type="text"],
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
}

.grid-size-select {
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 18px) 50% / 7px 7px no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 13px) 50% / 7px 7px no-repeat,
    #fff;
  font-weight: 700;
  padding-right: 38px;
}

.grid-size-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 123, 108, 0.14);
  outline: none;
}

.file-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 1px minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
  margin-bottom: 12px;
}

.file-actions > button,
.file-actions > .file-button {
  width: 100%;
  min-width: 0;
}

.primary-actions {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr;
  gap: 10px;
  margin: 4px 0 12px;
}

.primary-actions > button {
  width: 100%;
  min-width: 0;
  white-space: nowrap;
}

.button-separator {
  align-self: stretch;
  width: 1px;
  min-height: 40px;
  margin: 0 8px;
  background: var(--line);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 14px;
  font-weight: 600;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.export-toggle-row {
  margin-bottom: 10px;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  padding: 0 14px;
  font-weight: 500;
  text-align: center;
}

.file-button:hover {
  border-color: var(--accent);
}

.file-button input {
  display: none;
}

.block-image-button {
  margin: -4px 0 14px;
}

.format-note {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
}

.bulk-import {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.bulk-import textarea {
  width: 100%;
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  resize: vertical;
  color: var(--ink);
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.table-footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: -2px 0 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.table-search {
  display: grid;
  gap: 7px;
  margin-bottom: 10px;
}

.table-search input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
}

.table-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 123, 108, 0.14);
  outline: none;
}

.table-search-count {
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
}

code {
  background: #eef1f4;
  border-radius: 4px;
  padding: 2px 5px;
}

.table-wrap {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 14px;
}

.word-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.word-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f1f4f7;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
}

.word-table th,
.word-table td {
  border-bottom: 1px solid var(--line);
  padding: 7px;
  vertical-align: top;
}

.word-table th:first-child,
.word-table td:first-child {
  width: 31%;
}

.word-table th:last-child,
.word-table td:last-child {
  width: 52px;
  text-align: center;
}

.word-table input,
.word-table textarea {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  padding: 7px;
}

.word-table textarea {
  min-height: 38px;
  resize: vertical;
}

.word-table input:focus,
.word-table textarea:focus {
  border-color: var(--accent);
  outline: none;
}

.delete-row {
  width: 34px;
  min-height: 34px;
  padding: 0;
  color: var(--danger);
}

.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.example-button {
  background: #4f46e5;
  border-color: #4f46e5;
  color: #fff;
  font-weight: 700;
}

.example-button:hover {
  background: #4338ca;
  border-color: #4338ca;
}

.danger-button {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-weight: 700;
}

.danger-button:hover {
  background: #872f2f;
  border-color: #872f2f;
}

.status-message {
  min-height: 22px;
  color: var(--muted);
}

.status-message.busy {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.status-message.busy::before {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(15, 123, 108, 0.22);
  border-top-color: var(--accent);
  border-radius: 999px;
  content: "";
  animation: status-spin 0.8s linear infinite;
}

.status-message.error {
  color: var(--danger);
}

.status-message.success {
  color: var(--accent-strong);
  font-weight: 750;
}

.status-message.success::before {
  content: "✓ ";
}

@keyframes status-spin {
  to {
    transform: rotate(360deg);
  }
}

.puzzle-output.empty {
  min-height: 280px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
}

.puzzle-output.generating {
  position: relative;
}

.puzzle-output.generating::before {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: rgba(246, 247, 249, 0.78);
  border-radius: 8px;
  color: var(--accent-strong);
  font-weight: 800;
  content: "Generálás folyamatban...";
}

.puzzle-output.generating::after {
  position: absolute;
  top: calc(50% + 28px);
  left: calc(50% - 18px);
  z-index: 6;
  width: 36px;
  height: 36px;
  border: 4px solid rgba(15, 123, 108, 0.2);
  border-top-color: var(--accent);
  border-radius: 999px;
  content: "";
  animation: status-spin 0.8s linear infinite;
}

.puzzle-title {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 16px;
}

.puzzle-title h3 {
  margin: 0;
  font-size: 20px;
}

.grid-scroll {
  overflow: auto;
  padding-bottom: 8px;
  max-width: 100%;
  scrollbar-gutter: stable;
}

.crossword-grid {
  border-collapse: collapse;
  margin: 0 auto 18px;
}

.crossword-grid td {
  width: var(--cell);
  height: var(--cell);
  min-width: var(--cell);
  border: 1px solid #20242a;
  text-align: center;
  vertical-align: middle;
  background: #fff;
  font-size: clamp(10px, 1.15vw, 16px);
  font-weight: 750;
  line-height: 1;
  position: relative;
}

.crossword-grid td.blank {
  border-color: var(--block);
  background: var(--block);
}

.crossword-grid td.solution {
  background: var(--accent-soft);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.crossword-grid td.solution-start {
  box-shadow: inset 3px 0 0 var(--accent-strong), inset 0 3px 0 var(--accent-strong);
}

.crossword-grid td.solution-end {
  box-shadow: inset -3px 0 0 var(--accent-strong), inset 0 -3px 0 var(--accent-strong);
}

.crossword-grid td.solution-start.solution-end {
  box-shadow: inset 0 0 0 3px var(--accent-strong);
}

.crossword-grid td .letter {
  color: #424a54;
}

.crossword-grid td .number {
  position: absolute;
  left: 3px;
  top: 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.crossword-grid td .part-number {
  position: absolute;
  right: 3px;
  bottom: 2px;
  font-size: 9px;
  font-weight: 800;
  color: var(--accent-strong);
}

.scandinavian-grid {
  --sk-cell: clamp(34px, 4vw, 48px);
  --block-fill: var(--block);
  --block-image: none;
  display: grid;
  grid-template-columns: repeat(var(--grid-size), var(--sk-cell));
  grid-template-rows: repeat(var(--grid-size), var(--sk-cell));
  width: max-content;
  min-width: 100%;
  justify-content: start;
  margin: 0 0 18px;
}

.scandinavian-grid.block-dots {
  --block-fill: radial-gradient(circle at 50% 50%, #66707a 0 18%, #4b535c 19% 100%);
}

.scandinavian-grid.block-diagonal {
  --block-fill: repeating-linear-gradient(135deg, #4b535c 0 7px, #626c76 7px 9px);
}

.scandinavian-grid.block-grid {
  --block-fill:
    linear-gradient(rgba(255, 255, 255, 0.13) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.13) 1px, transparent 1px),
    #4b535c;
}

.scandinavian-grid.block-image {
  background-image: var(--block-image);
  background-position: center;
  background-size: cover;
}

.sk-cell {
  position: relative;
  border: 1px solid #20242a;
  overflow: hidden;
}

.sk-block {
  background: var(--block-fill);
  background-size: 13px 13px;
  border-color: rgba(32, 36, 42, 0.42);
}

.block-image .sk-block {
  background: transparent;
}

.sk-letter {
  display: grid;
  place-items: center;
  background: #fff;
  color: #424a54;
  font-size: clamp(15px, 2.4vw, 24px);
  font-weight: 800;
}

.sk-clue {
  display: flex;
  background: #f8fafc;
  color: #20242a;
  font-size: clamp(5px, 0.62vw, 8px);
  line-height: 1;
  text-align: center;
  z-index: 1;
}

.sk-clue-part {
  position: relative;
  display: grid;
  align-items: start;
  justify-items: center;
  width: 100%;
  height: 100%;
  padding: 3px 16px 13px 2px;
}

.sk-clue-text {
  display: -webkit-box;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  hyphens: manual;
  overflow-wrap: anywhere;
  word-break: normal;
  max-height: calc(100% - 8px);
}

.sk-clue-text.tight {
  font-size: 0.9em;
}

.sk-clue-text.very-tight {
  font-size: 0.8em;
}

.sk-clue-text.ultra-tight {
  font-size: 0.7em;
  line-height: 0.95;
}

.sk-arrow {
  position: absolute;
  right: 1px;
  bottom: 0;
  width: 10px;
  color: var(--accent-strong);
  font-size: 1.45em;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  pointer-events: none;
}

.sk-clue.dual {
  display: grid;
  grid-template-rows: 1fr 1fr;
}

.sk-clue.dual::after {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  border-top: 1px solid #78818c;
  content: "";
}

.sk-clue.dual .sk-clue-part {
  min-height: 0;
  padding: 1px 14px 8px 2px;
}

.sk-clue.dual .sk-clue-text {
  -webkit-line-clamp: 2;
  max-height: calc(100% - 5px);
}

.sk-clue.dual .sk-arrow {
  font-size: 1.15em;
}

.sk-letter.solution {
  background: var(--accent-soft);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.sk-letter.solution-band {
  background: #fff36a;
  outline-color: #c9a600;
}

.sk-letter .part-number {
  position: absolute;
  right: 3px;
  bottom: 2px;
  font-size: 10px;
  color: var(--accent-strong);
  font-weight: 900;
}

.clues {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.clues h3 {
  margin: 0 0 4px;
  font-size: 18px;
}

.clues ol {
  columns: 2 260px;
  column-gap: 28px;
  margin: 0;
  padding-left: 24px;
}

.clues li {
  margin-bottom: 7px;
  break-inside: avoid;
}

.clue-meta {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1180px) {
  .app-shell {
    padding: 16px;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .preview-panel {
    padding: 14px;
  }

  .scandinavian-grid {
    --sk-cell: clamp(34px, 4.5vw, 48px);
  }

  h1 {
    font-size: 24px;
  }
}

@media (max-width: 720px) {
  .app-shell,
  body.embedded .app-shell {
    padding: 8px;
  }

  .panel,
  body.embedded .panel {
    padding: 10px;
  }

  h1,
  body.embedded h1 {
    font-size: 22px;
  }

  .primary-actions {
    grid-template-columns: 1fr;
  }

  .file-actions {
    grid-template-columns: 1fr;
  }

  .button-separator {
    width: 100%;
    min-height: 1px;
    margin: 4px 0;
  }

  .table-wrap {
    max-height: 340px;
  }

  .word-table {
    min-width: 560px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .workspace {
    display: block;
  }

  .editor-panel {
    display: none;
  }

  .preview-panel {
    border: 0;
    padding: 0;
  }

  .panel-header p {
    display: none;
  }

  .crossword-grid td {
    --cell: 13px;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
