:root {
  --bg: #fff3df;
  --surface: #fffaf0;
  --surface-strong: #fffdf7;
  --ink: #4d3428;
  --muted: #836f60;
  --line: #ead4b7;
  --line-strong: #d8ad7e;
  --accent: #ec7d5d;
  --accent-strong: #bf5942;
  --accent-soft: #ffe2d5;
  --mint: #78bfa7;
  --mint-strong: #3f8f77;
  --mint-soft: #e4f5ec;
  --honey: #ffd66e;
  --honey-soft: #fff0bf;
  --blue: #6da6c8;
  --blue-soft: #e0f1f7;
  --warm: #ec7d5d;
  --warm-soft: #ffe2d5;
  --cell-size: clamp(32px, 5vw, 46px);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  position: relative;
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 214, 110, 0.38), transparent 330px),
    linear-gradient(110deg, rgba(236, 125, 93, 0.18), transparent 44%),
    linear-gradient(260deg, rgba(120, 191, 167, 0.18), transparent 52%),
    var(--bg);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0.44;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg width='180' height='180' viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke-linecap='round' stroke-width='3'%3E%3Cpath d='M24 36c10 4 18 4 27 0' stroke='%23ec7d5d'/%3E%3Cpath d='M132 28l5 9 10 1-8 7 3 10-10-5-9 5 2-10-7-7 10-1z' stroke='%23e5b948'/%3E%3Cpath d='M42 132h23M54 120v24' stroke='%2378bfa7'/%3E%3Cpath d='M126 132c7-8 18-8 25 0' stroke='%236da6c8'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 180px 180px;
}

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

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 34px 20px 22px;
}

.hero-copy {
  max-width: 760px;
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.brand-mark {
  display: inline-grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 2px solid rgba(77, 52, 40, 0.14);
  border-radius: 8px;
  background: var(--honey);
  box-shadow: 0 10px 22px rgba(191, 89, 66, 0.16);
}

.brand-mark svg {
  width: 38px;
  height: 38px;
  fill: var(--surface-strong);
  stroke: var(--ink);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 720px;
  margin-bottom: 10px;
  font-size: clamp(2rem, 3.8vw, 3.6rem);
  line-height: 1.04;
  color: #573528;
}

h2 {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 0;
  font-size: 1.35rem;
  color: #573528;
}

h2 svg {
  width: 24px;
  height: 24px;
  fill: var(--honey-soft);
  stroke: var(--accent-strong);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}

.lead {
  max-width: 680px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.level-pill {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  gap: 7px;
  border: 1px solid rgba(191, 89, 66, 0.18);
  border-radius: 999px;
  background: var(--honey-soft);
  color: #7d4a24;
  font-size: 0.9rem;
  font-weight: 850;
}

.level-pill svg,
.secondary-button svg,
.primary-button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.level-pill svg {
  fill: var(--honey);
  stroke: #b47727;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(310px, 0.86fr) minmax(360px, 1.14fr);
  gap: 18px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px 32px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.96);
  box-shadow: 0 18px 50px rgba(150, 93, 56, 0.14);
  backdrop-filter: blur(8px);
}

.editor-panel,
.result-panel-wrap {
  position: relative;
  overflow: hidden;
  padding: 18px;
}

.editor-panel::before,
.result-panel-wrap::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 7px;
  background: linear-gradient(90deg, var(--honey), var(--accent), var(--mint), var(--blue));
}

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

.select-label {
  display: grid;
  gap: 6px;
  min-width: 210px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

select,
textarea,
input[type="number"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
}

select {
  min-height: 40px;
  padding: 0 10px;
}

textarea {
  width: 100%;
  min-height: 230px;
  padding: 14px;
  resize: vertical;
  font-size: 1.05rem;
  line-height: 1.45;
  background:
    linear-gradient(transparent 31px, rgba(234, 212, 183, 0.36) 32px),
    var(--surface-strong);
  background-size: 100% 32px;
  box-shadow: inset 0 1px 0 rgba(77, 52, 40, 0.04);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

textarea:focus,
select:focus,
input:focus,
button:focus-visible {
  outline: 3px solid rgba(236, 125, 93, 0.24);
  outline-offset: 2px;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow:
    inset 0 1px 0 rgba(77, 52, 40, 0.04),
    0 0 0 4px rgba(236, 125, 93, 0.1);
}

.input-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.ai-helper {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid rgba(191, 89, 66, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 240, 191, 0.64), rgba(255, 226, 213, 0.58)),
    var(--surface-strong);
}

.ai-helper-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.ai-helper h3 {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
  color: #573528;
}

.ai-helper h3 svg {
  width: 22px;
  height: 22px;
  fill: var(--honey-soft);
  stroke: var(--accent-strong);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ai-model-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid rgba(120, 191, 167, 0.28);
  border-radius: 999px;
  background: var(--mint-soft);
  color: var(--mint-strong);
  font-size: 0.8rem;
  font-weight: 850;
  white-space: nowrap;
}

.ai-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px minmax(120px, 0.8fr);
  gap: 10px;
}

.ai-controls label,
.custom-topic {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.ai-controls input,
.ai-controls select,
.custom-topic input {
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
}

.custom-topic {
  margin-top: 10px;
}

.ai-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 40px;
  margin-top: 12px;
  border: 1px solid rgba(63, 143, 119, 0.3);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--mint), #8bcfb9);
  color: #ffffff;
  cursor: pointer;
  font-weight: 850;
  box-shadow: 0 10px 20px rgba(63, 143, 119, 0.18);
  transition:
    transform 150ms ease,
    background-color 150ms ease,
    box-shadow 150ms ease;
}

.ai-button:hover {
  transform: translateY(-1px);
  background: var(--mint-strong);
}

.ai-button:disabled {
  cursor: wait;
  opacity: 0.88;
  transform: none;
}

.ai-idle,
.ai-busy {
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.ai-idle {
  display: inline-flex;
}

.ai-busy {
  display: none;
}

.ai-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.is-ai-generating .ai-idle {
  display: none;
}

.is-ai-generating .ai-busy {
  display: inline-flex;
}

.ai-status {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--mint-strong);
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.35;
}

.rules {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0;
}

.rules label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
  transition:
    border-color 150ms ease,
    transform 150ms ease,
    background-color 150ms ease;
}

.rules label:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.rules input[type="checkbox"] {
  accent-color: var(--accent);
}

.rules label svg {
  width: 16px;
  height: 16px;
  fill: var(--honey-soft);
  stroke: #b47727;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.number-rule input {
  width: 58px;
  min-height: 28px;
  padding: 2px 6px;
}

.primary-button,
.secondary-button,
.view-toggle button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    background-color 150ms ease,
    border-color 150ms ease;
}

.primary-button {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), #f09a64);
  color: #ffffff;
  box-shadow: 0 12px 26px rgba(191, 89, 66, 0.25);
  position: relative;
  overflow: hidden;
}

.primary-button:hover,
.secondary-button:hover,
.view-toggle button.active {
  background: var(--accent-strong);
  color: #ffffff;
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.92;
  transform: none;
}

.button-busy {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.button-idle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}

.is-generating .button-idle {
  display: none;
}

.is-generating .button-busy {
  display: inline-flex;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.generation-status {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--accent-strong);
  font-size: 0.95rem;
  font-weight: 800;
  transition: color 160ms ease;
}

.validation-details,
.worksheet-details,
.history-details {
  margin-top: 10px;
  border: 1px solid rgba(234, 212, 183, 0.92);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.76);
}

.validation-details summary,
.worksheet-details summary,
.history-details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 8px 10px;
  cursor: pointer;
  list-style: none;
}

.validation-details summary::-webkit-details-marker,
.worksheet-details summary::-webkit-details-marker,
.history-details summary::-webkit-details-marker {
  display: none;
}

.validation-details summary::after,
.worksheet-details summary::after,
.history-details summary::after {
  content: "";
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-right: 2px solid var(--accent-strong);
  border-bottom: 2px solid var(--accent-strong);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 160ms ease;
}

.validation-details[open] summary::after,
.worksheet-details[open] summary::after,
.history-details[open] summary::after {
  transform: rotate(225deg) translate(-2px, -1px);
}

.validation-title,
.worksheet-title,
.history-title {
  color: var(--ink);
  font-size: 0.94rem;
  font-weight: 850;
}

.validation-metrics,
.worksheet-metrics,
.history-metrics {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
}

.metric {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid rgba(216, 173, 126, 0.34);
  border-radius: 999px;
  background: var(--honey-soft);
  font-size: 0.82rem;
  font-weight: 850;
  white-space: nowrap;
}

.metric.good {
  background: var(--mint-soft);
  color: var(--mint-strong);
}

.metric.warn {
  background: var(--honey-soft);
  color: #9d6630;
}

.validation-details.has-rejections .metric.warn {
  background: var(--warm-soft);
  color: var(--accent-strong);
}

.validation-details .validation-grid {
  margin: 0;
  padding: 0 10px 10px;
}

.validation-details h3 {
  margin-bottom: 6px;
  font-size: 0.86rem;
}

.worksheet-details {
  margin-top: 14px;
}

.worksheet-details .summary-grid {
  margin: 0;
  padding: 0 10px 10px;
}

.history-details {
  margin-top: 12px;
  background:
    linear-gradient(135deg, rgba(255, 240, 191, 0.45), rgba(228, 245, 236, 0.4)),
    rgba(255, 253, 247, 0.82);
}

.history-panel {
  padding: 0 10px 10px;
}

.history-hint {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 650;
  line-height: 1.35;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
}

.history-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  width: 100%;
  min-height: 58px;
  padding: 10px;
  border: 1px solid rgba(216, 173, 126, 0.68);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.92);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 5px 14px rgba(111, 74, 54, 0.06);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.history-card:hover,
.history-card:focus-visible {
  border-color: rgba(191, 89, 66, 0.42);
  box-shadow: 0 8px 20px rgba(111, 74, 54, 0.1);
  transform: translateY(-1px);
}

.history-card-title {
  overflow: hidden;
  font-size: 0.94rem;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-card-date {
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 850;
  white-space: nowrap;
}

.history-card-meta {
  display: flex;
  flex-wrap: wrap;
  grid-column: 1 / -1;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 780;
}

.history-card-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--honey-soft);
}

.history-card-meta span:nth-child(2) {
  background: var(--mint-soft);
  color: var(--mint-strong);
}

.history-empty,
.history-error {
  margin: 0;
  padding: 11px 12px;
  border: 1px dashed rgba(216, 173, 126, 0.82);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.86);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 750;
  line-height: 1.35;
}

.history-error {
  border-style: solid;
  border-color: rgba(191, 89, 66, 0.24);
  background: var(--warm-soft);
  color: var(--accent-strong);
}

.secondary-button,
.view-toggle button {
  border-color: var(--line);
  background: var(--surface-strong);
  color: var(--ink);
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
}

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

.share-card-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
}

.view-toggle {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  width: min(100%, 520px);
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.view-toggle button {
  min-height: 34px;
  padding: 0 12px;
  line-height: 1.12;
  white-space: normal;
}

.validation-grid,
.summary-grid {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.validation-grid {
  grid-template-columns: 1fr 1fr;
}

.summary-grid {
  grid-template-columns: repeat(3, 1fr);
}

.word-list {
  min-height: 42px;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.9);
  color: var(--ink);
  line-height: 1.45;
  list-style: none;
}

.word-list li {
  display: block;
  margin: 0 0 7px;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid rgba(234, 212, 183, 0.7);
  background: #fff4d0;
  font-weight: 750;
}

.word-list li:nth-child(3n + 2) {
  background: var(--mint-soft);
}

.word-list li:nth-child(3n) {
  background: var(--blue-soft);
}

.word-list li:last-child {
  margin-bottom: 0;
}

.word-list.chips {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px;
  min-height: 34px;
  max-height: 116px;
  overflow: auto;
  padding: 8px;
}

.word-list.chips li {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  margin: 0;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.82rem;
  line-height: 1.2;
}

.word-list.chips.rejected {
  max-height: 132px;
}

.word-list.chips.rejected li {
  max-width: 100%;
  border-color: rgba(191, 89, 66, 0.18);
  background: var(--warm-soft);
  color: var(--accent-strong);
  white-space: normal;
}

.word-list.compact {
  max-height: 160px;
  overflow: auto;
}

.instructions-panel {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  border: 1px solid rgba(216, 173, 126, 0.62);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 240, 191, 0.68), rgba(228, 245, 236, 0.52)),
    var(--surface-strong);
  animation: result-in 180ms ease-out both;
}

.instructions-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.instructions-header h3 {
  margin-bottom: 0;
  font-size: 1.3rem;
}

.instructions-count {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(120, 191, 167, 0.28);
  border-radius: 999px;
  background: var(--mint-soft);
  color: var(--mint-strong);
  font-size: 0.84rem;
  font-weight: 850;
  white-space: nowrap;
}

.instructions-meta {
  display: grid;
  justify-items: end;
  gap: 6px;
  min-width: 142px;
}

.instructions-save-status {
  min-height: 18px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 760;
  line-height: 1.25;
  text-align: right;
}

.instructions-save-status[data-status="saving"],
.instructions-save-status[data-status="dirty"] {
  color: var(--accent-strong);
}

.instructions-save-status[data-status="saved"] {
  color: var(--mint-strong);
}

.instructions-save-status[data-status="error"] {
  color: #bf5942;
}

.instructions-list {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.instruction-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid rgba(234, 212, 183, 0.8);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.88);
  box-shadow: 0 8px 20px rgba(111, 74, 54, 0.06);
}

.instruction-number {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 2px solid #6f4a36;
  background: var(--surface-strong);
  color: var(--accent-strong);
  font-size: 0.86rem;
  font-weight: 900;
}

.instruction-body {
  display: grid;
  min-width: 0;
  gap: 8px;
}

.instruction-field {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.instruction-label,
.instruction-answer-label {
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.instruction-clue-input {
  width: 100%;
  min-height: 62px;
  resize: vertical;
  padding: 10px 11px;
  border: 1.5px solid rgba(216, 173, 126, 0.86);
  border-radius: 8px;
  background: #fffaf1;
  color: var(--ink);
  font-size: 0.96rem;
  font-weight: 760;
  line-height: 1.35;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.instruction-clue-input:focus {
  outline: 3px solid rgba(120, 191, 167, 0.28);
  border-color: var(--mint);
  background: #ffffff;
}

.instruction-answer-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.instruction-body strong {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--honey-soft);
  color: #6f4329;
  font-size: 0.85rem;
  letter-spacing: 0;
}

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

.empty-state {
  display: grid;
  gap: 14px;
  min-height: 360px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background:
    linear-gradient(135deg, rgba(255, 240, 191, 0.42), rgba(228, 245, 236, 0.5)),
    rgba(255, 255, 255, 0.62);
}

.empty-state svg {
  width: min(170px, 70%);
  height: auto;
}

.empty-state svg path {
  fill: #fff0bf;
  stroke: #d69b52;
  stroke-width: 3;
}

.empty-state svg rect {
  fill: var(--surface-strong);
  stroke: var(--accent-strong);
  stroke-width: 2;
}

.empty-state span {
  max-width: 310px;
  font-weight: 750;
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  min-height: 360px;
  padding: 22px;
  border: 1px solid rgba(191, 89, 66, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 240, 191, 0.85), rgba(255, 226, 213, 0.72)),
    rgba(255, 255, 255, 0.85);
  color: var(--ink);
}

.loading-state h3 {
  margin-bottom: 6px;
  font-size: 1.15rem;
}

.loading-state p {
  max-width: 360px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.loader-grid {
  display: grid;
  grid-template-columns: repeat(3, 18px);
  gap: 5px;
}

.loader-grid span {
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent-strong);
  background: var(--surface-strong);
  animation: pulse-cell 900ms ease-in-out infinite;
}

.loader-grid span:nth-child(2),
.loader-grid span:nth-child(4),
.loader-grid span:nth-child(6),
.loader-grid span:nth-child(8) {
  animation-delay: 120ms;
}

.loader-grid span:nth-child(5) {
  background: var(--honey-soft);
  animation-delay: 240ms;
}

.crossword-board {
  display: grid;
  justify-content: center;
  gap: 0;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 16px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 240, 191, 0.34), rgba(224, 241, 247, 0.46)),
    #fffaf0;
  border: 1px solid rgba(216, 208, 194, 0.8);
  overflow: auto;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  position: relative;
}

.cell.filled {
  display: grid;
  place-items: center;
  border: 2px solid #6f4a36;
  background: var(--surface-strong);
  box-shadow: 0 2px 0 rgba(111, 74, 54, 0.18);
}

.crossword-board.is-revealing .cell.filled {
  animation: reveal-cell 320ms ease-out both;
  animation-delay: calc(var(--cell-index) * 24ms);
}

.cell-number {
  position: absolute;
  top: 2px;
  left: 3px;
  color: var(--accent-strong);
  font-size: 0.62rem;
  font-weight: 900;
}

.letter {
  color: #5b3a2c;
  font-size: calc(var(--cell-size) * 0.52);
  font-weight: 900;
  line-height: 1;
}

#result-panel {
  animation: result-in 220ms ease-out both;
}

.share-modal-open {
  overflow: hidden;
}

.share-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}

.share-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(77, 52, 40, 0.38);
  backdrop-filter: blur(7px);
}

.share-modal-panel {
  position: relative;
  width: min(100%, 560px);
  max-height: min(740px, calc(100vh - 40px));
  overflow: auto;
  padding: 24px;
  border: 1px solid rgba(216, 173, 126, 0.85);
  border-radius: 14px;
  background: var(--surface-strong);
  box-shadow: 0 28px 80px rgba(77, 52, 40, 0.22);
}

.share-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.share-modal-header h2 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.6rem, 5vw, 2.1rem);
  line-height: 1.08;
}

.share-modal-close {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.share-modal-close svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

.share-modal-copy {
  margin: 16px 0 18px;
  color: var(--muted);
  line-height: 1.55;
}

.share-link-field {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-weight: 800;
}

.share-link-field span {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.share-link-field input {
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--ink);
}

.share-channel-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.share-channel {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(63, 143, 119, 0.28);
  border-radius: 8px;
  background: var(--mint-soft);
  color: #225c4c;
  font-weight: 850;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.share-status {
  min-height: 22px;
  margin: 14px 0 0;
  color: var(--accent-strong);
  font-weight: 800;
}

.print-qr-symbols {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.share-page {
  color: var(--ink);
}

.share-hero,
.share-sheet-stack,
.share-empty {
  width: min(1040px, calc(100% - 32px));
  margin: 0 auto;
}

.share-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  padding: 36px 0 26px;
}

.share-hero h1,
.share-empty h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(2.2rem, 6vw, 4.5rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.share-hero .lead,
.share-empty p {
  max-width: 680px;
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.share-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.share-hero-actions .primary-button,
.share-hero-actions .secondary-button,
.share-empty .primary-button {
  min-height: 44px;
  padding: 0 18px;
  text-decoration: none;
}

.share-sheet-stack {
  display: grid;
  gap: 22px;
  padding: 0 0 44px;
}

.share-sheet {
  position: relative;
  min-height: 720px;
  padding: 34px 34px 116px;
  border: 2px solid #f0b25f;
  border-radius: 18px;
  background:
    linear-gradient(180deg, #fff7df 0, #ffffff 230px),
    #ffffff;
  box-shadow: 0 20px 50px rgba(77, 52, 40, 0.12);
  overflow: hidden;
}

.share-sheet .print-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.share-sheet .print-kicker,
.share-sheet .print-name {
  margin: 0;
  color: #8a5838;
  font-weight: 850;
}

.share-sheet h2 {
  margin: 4px 0 0;
  color: #573528;
  font-size: clamp(2rem, 6vw, 3rem);
  line-height: 1.05;
}

.share-sheet .print-note {
  max-width: 680px;
  margin-bottom: 22px;
  color: #6f4a36;
  font-weight: 650;
}

.share-board {
  margin: 0 auto;
}

.share-sheet .print-clues {
  margin-top: 24px;
}

.share-sheet .print-clues h3 {
  display: inline-flex;
  margin: 0 0 12px;
  padding: 7px 14px;
  border: 1px solid #f0b25f;
  border-radius: 999px;
  background: var(--honey-soft);
  color: #573528;
}

.share-sheet .word-bank-print {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.share-sheet .word-bank-print li {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #ead4b7;
  border-radius: 10px;
  background: var(--surface-strong);
  color: #4d3428;
  font-weight: 800;
}

.share-branding {
  position: absolute;
  right: 28px;
  bottom: 24px;
  left: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid #ead4b7;
  padding-top: 12px;
}

.share-branding .print-branding-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
  color: #6f4a36;
  font-size: 0.82rem;
}

.share-branding .print-branding-logo {
  color: #bf5942;
  font-weight: 900;
}

.share-branding a {
  color: #2f765f;
  font-weight: 850;
  text-decoration: none;
}

.share-branding .print-qr {
  width: 72px;
  height: 72px;
  flex: 0 0 72px;
  border: 1px solid #ead4b7;
  border-radius: 8px;
  background: #ffffff;
}

.share-empty {
  display: grid;
  min-height: 70vh;
  align-content: center;
  justify-items: start;
  padding: 32px 0;
}

.print-sheets {
  display: none;
}

@media (max-width: 880px) {
  .app-header {
    flex-direction: column;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .validation-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .validation-details summary,
  .worksheet-details summary,
  .history-details summary {
    align-items: flex-start;
  }

  .validation-metrics,
  .worksheet-metrics,
  .history-metrics {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .section-header {
    flex-direction: column;
  }

  .view-toggle {
    width: 100%;
  }

  .view-toggle button {
    padding: 0 8px;
    font-size: 0.92rem;
  }

  .instructions-panel {
    padding: 12px;
  }

  .instructions-header {
    flex-direction: column;
  }

  .select-label {
    width: 100%;
  }

  .loading-state {
    flex-direction: column;
    text-align: center;
  }

  .ai-helper-header {
    flex-direction: column;
  }

  .ai-controls {
    grid-template-columns: 1fr;
  }

  .share-link-field span,
  .share-channel-grid,
  .share-hero {
    grid-template-columns: 1fr;
  }

  .share-hero-actions {
    justify-content: stretch;
  }

  .share-hero-actions .primary-button,
  .share-hero-actions .secondary-button {
    width: 100%;
    justify-content: center;
  }

  .share-sheet {
    min-height: auto;
    padding: 24px 18px;
  }

  .share-sheet .print-header,
  .share-branding {
    flex-direction: column;
    align-items: flex-start;
  }

  .share-branding {
    position: static;
    margin-top: 18px;
    width: 100%;
  }

  .share-sheet .word-bank-print {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}

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

@keyframes pulse-cell {
  0%,
  100% {
    transform: scale(1);
    background: var(--surface-strong);
  }

  50% {
    transform: scale(0.84);
    background: var(--honey-soft);
  }
}

@keyframes reveal-cell {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.92);
  }

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

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

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

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

  :root {
    --cell-size: 12mm;
  }

  body {
    background: #ffffff;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  body::before {
    display: none;
  }

  .app-header,
  .app-shell {
    display: none;
  }

  .print-sheets {
    display: block;
  }

  .print-page {
    position: relative;
    box-sizing: border-box;
    min-height: calc(297mm - 24mm);
    padding: 10mm 10mm 25mm;
    border: 2.2pt solid #f0b25f;
    border-radius: 8mm;
    background:
      linear-gradient(180deg, #fff7df 0, #ffffff 50mm),
      #ffffff;
    break-after: page;
    page-break-after: always;
    color: #4d3428;
    overflow: hidden;
  }

  .print-qr-symbols {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
  }

  .print-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .print-page::before {
    content: "";
    position: absolute;
    inset: 5mm;
    z-index: 0;
    border: 1.1pt dashed rgba(236, 125, 93, 0.48);
    border-radius: 6mm;
    pointer-events: none;
  }

  .print-page::after {
    content: "";
    position: absolute;
    right: 11mm;
    top: 10mm;
    z-index: 0;
    width: 23mm;
    height: 23mm;
    background-image: url("data:image/svg+xml,%3Csvg width='80' height='80' viewBox='0 0 80 80' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M40 8l7.6 15.4 17 2.5-12.3 12 2.9 16.9L40 46.8 24.8 54.8l2.9-16.9-12.3-12 17-2.5z' fill='%23fff0bf' stroke='%23bf5942' stroke-width='4'/%3E%3Cpath d='M28 34h24M40 22v24' stroke='%2378bfa7' stroke-width='5'/%3E%3C/g%3E%3C/svg%3E");
    background-size: contain;
    opacity: 0.46;
    pointer-events: none;
  }

  .print-header {
    display: block;
    margin-bottom: 6mm;
    padding-right: 28mm;
    position: relative;
    z-index: 1;
  }

  .print-kicker,
  .print-name {
    margin: 0;
    color: #8a5838;
    font-size: 12pt;
    font-weight: 800;
  }

  .print-kicker {
    text-transform: uppercase;
  }

  .print-name {
    margin-top: 3mm;
    padding-top: 0;
    text-align: left;
  }

  .print-page h2 {
    margin: 1mm 0 0;
    color: #573528;
    font-size: 30pt;
    line-height: 1.05;
  }

  .print-page h3 {
    display: inline-flex;
    margin: 0 0 4mm;
    padding: 1.8mm 4mm;
    border: 1.4pt solid #f0b25f;
    border-radius: 999px;
    background: #fff0bf;
    color: #573528;
    font-size: 15pt;
    line-height: 1.1;
  }

  .print-note {
    position: relative;
    z-index: 1;
    max-width: 150mm;
    margin: 0 0 7mm;
    padding: 3mm 5mm;
    border: 1.2pt solid #ead4b7;
    border-radius: 5mm;
    background: #ffffff;
    color: #6f4a36;
    font-size: 13pt;
    font-weight: 750;
    line-height: 1.35;
  }

  .print-board {
    position: relative;
    z-index: 1;
    overflow: visible;
    padding: 6mm;
    border: 1.6pt solid #ead4b7;
    border-radius: 5mm;
    background: #fffdf7;
  }

  .cell.filled {
    border: 1.7pt solid #6f4a36;
    background: #ffffff;
    box-shadow: none;
  }

  .cell-number {
    top: 1.4mm;
    left: 1.6mm;
    color: #bf5942;
    font-size: 7pt;
  }

  .letter {
    color: #4d3428;
    font-size: 19pt;
  }

  .print-clues {
    position: relative;
    z-index: 1;
    margin-top: 8mm;
  }

  .word-bank-print {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 3mm;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 13.5pt;
    line-height: 1.28;
  }

  .word-bank-print li {
    min-height: 12mm;
    margin: 0;
    padding: 3mm 4mm;
    border: 1.1pt solid #ead4b7;
    border-radius: 5mm;
    background: #fff8e8;
    color: #4d3428;
    font-weight: 760;
    break-inside: avoid;
  }

  .word-bank-print li:nth-child(3n + 2) {
    background: #e4f5ec;
  }

  .word-bank-print li:nth-child(3n) {
    background: #e0f1f7;
  }

  .solution-page {
    border-color: #78bfa7;
    background:
      linear-gradient(180deg, #e4f5ec 0, #ffffff 48mm),
      #ffffff;
  }

  .solution-page::before {
    border-color: rgba(120, 191, 167, 0.55);
  }

  .solution-page h3,
  .solution-page .word-bank-print li {
    background: #e4f5ec;
  }

  .print-branding {
    position: absolute;
    right: 10mm;
    bottom: 7mm;
    left: 10mm;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 7mm;
    padding-top: 3mm;
    border-top: 1pt solid rgba(234, 212, 183, 0.9);
    color: #6f4a36;
  }

  .print-branding-copy {
    display: grid;
    gap: 1mm;
    min-width: 0;
    font-size: 8.8pt;
    font-weight: 700;
    line-height: 1.15;
  }

  .print-branding-logo {
    color: #bf5942;
    font-size: 11pt;
    font-weight: 900;
  }

  .print-branding a {
    color: #2f765f;
    font-size: 8.4pt;
    font-weight: 850;
    text-decoration: none;
  }

  .print-qr {
    width: 19mm;
    height: 19mm;
    flex: 0 0 19mm;
    padding: 1.4mm;
    border: 1pt solid #ead4b7;
    border-radius: 2mm;
    background: #ffffff;
  }

  .share-page .share-hero {
    display: none;
  }

  .share-page .share-sheet-stack {
    display: block;
    width: auto;
    margin: 0;
    padding: 0;
  }

  .share-page .share-sheet {
    min-height: calc(297mm - 24mm);
    padding: 10mm 10mm 25mm;
    border-width: 2.2pt;
    border-radius: 8mm;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
  }

  .share-page .share-sheet:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .share-page .share-sheet .print-header {
    display: block;
    margin-bottom: 6mm;
    padding-right: 28mm;
  }

  .share-page .share-sheet h2 {
    margin: 1mm 0 0;
    font-size: 30pt;
  }

  .share-page .share-sheet .print-note {
    max-width: 150mm;
    margin: 0 0 7mm;
    padding: 3mm 5mm;
    border: 1.2pt solid #ead4b7;
    border-radius: 5mm;
    background: #ffffff;
    font-size: 13pt;
    font-weight: 750;
  }

  .share-page .share-board {
    padding: 6mm;
    border: 1.6pt solid #ead4b7;
    border-radius: 5mm;
    background: #fffdf7;
  }

  .share-page .share-sheet .word-bank-print {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 3mm;
    font-size: 13.5pt;
  }

  .share-page .share-sheet .word-bank-print li {
    min-height: 12mm;
    padding: 3mm 4mm;
    border-radius: 5mm;
    font-weight: 760;
  }

  .share-page .share-branding {
    right: 10mm;
    bottom: 7mm;
    left: 10mm;
    flex-direction: row;
    align-items: center;
    gap: 7mm;
    padding-top: 3mm;
  }

  .share-page .share-branding .print-branding-copy {
    font-size: 8.8pt;
    line-height: 1.15;
  }

  .share-page .share-branding .print-qr {
    width: 19mm;
    height: 19mm;
    flex-basis: 19mm;
  }
}
