:root {
  --ink: #111827;
  --muted: #64748b;
  --line: #d8dee8;
  --paper: #ffffff;
  --wash: #eef3f8;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --red: #d71920;
  --orange: #f59e4c;
  --yellow: #f8e24b;
  --green: #18a957;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.12), transparent 32rem),
    linear-gradient(135deg, #f8fbff 0%, #e9eff6 100%);
}

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

.app {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 42px 0 56px;
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.builder,
.preview {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(216, 222, 232, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.builder {
  padding: 26px;
  position: sticky;
  top: 24px;
}

.intro h1,
.preview h2,
.sheet h2 {
  margin: 0;
  line-height: 1.05;
}

.intro h1 {
  font-size: clamp(2rem, 5vw, 3.4rem);
  max-width: 7ch;
}

.intro p:last-child {
  color: var(--muted);
  line-height: 1.6;
  margin: 14px 0 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.controls {
  margin-top: 28px;
  display: grid;
  gap: 18px;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field {
  display: grid;
  gap: 8px;
}

label,
.label-row {
  color: #334155;
  font-size: 0.86rem;
  font-weight: 800;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#word-count {
  color: var(--muted);
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

input,
select {
  min-height: 46px;
  padding: 0 13px;
}

textarea {
  resize: vertical;
  min-height: 150px;
  padding: 13px;
  line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
  outline: none;
}

.hint {
  color: var(--muted);
  font-size: 0.78rem;
}

.actions,
.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  color: #1f2937;
  background: #eef2f7;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  filter: brightness(0.98);
}

.primary,
#print-button {
  color: #fff;
  background: var(--blue);
}

.message {
  min-height: 20px;
  margin: 0;
  color: #b42318;
  font-size: 0.88rem;
  font-weight: 700;
}

.preview {
  padding: 24px;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 20px;
}

.toggle {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

.sheet {
  width: min(100%, 720px);
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.12);
}

.sheet-header {
  padding: 32px 36px 18px;
  color: var(--ink);
  text-align: center;
  background: #fff;
}

.sheet-header h2 {
  font-size: clamp(1.8rem, 5vw, 2.8rem);
}

.sheet-header p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.5;
}

.word-grid {
  --grid-size: 12;
  width: min(92%, 560px);
  aspect-ratio: 1;
  margin: 12px auto 0;
  padding: clamp(10px, 2.8vw, 20px);
  display: grid;
  grid-template-columns: repeat(var(--grid-size), 1fr);
  background: #fff;
  border: 2px solid #111827;
  border-radius: 4px;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  color: #1f2937;
  font-size: clamp(0.72rem, 2.3vw, 1.55rem);
  font-weight: 500;
  line-height: 1;
  text-transform: uppercase;
}

.cell.found::before {
  content: "";
  position: absolute;
  width: 92%;
  height: 42%;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.27);
}

.cell span {
  position: relative;
  z-index: 1;
}

.word-list {
  padding: 24px 36px 36px;
}

.word-list h3 {
  margin: 0 0 16px;
  font-size: 1.1rem;
  text-transform: uppercase;
}

.word-list ul {
  margin: 0;
  padding: 0;
  columns: 3;
  column-gap: 28px;
  list-style: none;
}

.word-list li {
  break-inside: avoid;
  margin: 0 0 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.sheet.hide-word-list .word-list {
  display: none;
}

@media (max-width: 920px) {
  .app {
    grid-template-columns: 1fr;
  }

  .builder {
    position: static;
  }
}

@media (max-width: 620px) {
  .app {
    width: min(100% - 20px, 1180px);
    padding-top: 20px;
  }

  .builder,
  .preview {
    padding: 18px;
  }

  .settings-grid,
  .preview-toolbar {
    grid-template-columns: 1fr;
    display: grid;
  }

  .sheet-header,
  .word-list {
    padding-left: 22px;
    padding-right: 22px;
  }

  .word-grid {
    border-width: 2px;
  }

  .word-list ul {
    columns: 2;
  }
}

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

  .builder,
  .preview-toolbar {
    display: none;
  }

  .app {
    width: 100%;
    display: block;
    padding: 0;
  }

  .preview {
    padding: 0;
    border: 0;
    box-shadow: none;
    background: #fff;
  }

  .sheet {
    width: 100%;
    max-width: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    page-break-inside: avoid;
  }

  .word-grid {
    width: min(86vw, 18cm);
    border-width: 2px;
    box-shadow: none;
  }

  .sheet-header {
    padding-top: 1cm;
  }
}
