:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --ink: #202020;
  --muted: #67625a;
  --line: #ddd7cc;
  --panel: #fffdf8;
  --accent: #d94b4b;
  --accent-2: #126b62;
  --cell: #ffffff;
  --answer: #ffe071;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  min-width: 0;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 13px;
  cursor: pointer;
}

button:hover {
  border-color: #b9b0a2;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  max-width: 100vw;
  overflow-x: hidden;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: block;
  object-fit: cover;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(32, 32, 32, 0.13);
}

.brand h1,
.brand p,
.puzzle-header h2,
.puzzle-header p,
.word-bank h3 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  line-height: 1.1;
}

.brand p,
.status,
.field span,
.puzzle-header p {
  color: var(--muted);
}

.brand p {
  font-size: 13px;
  margin-top: 4px;
}

.plan-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  margin-bottom: 20px;
}

.plan-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.plan-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 8px;
}

.plan-card.is-pro {
  border-color: #b8e986;
  background: #f3fff2;
}

.plan-card.is-pro .plan-pill,
.upgrade-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 800;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
  min-width: 0;
}

.field span {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

textarea {
  resize: vertical;
  line-height: 1.35;
}

.grid-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.segmented-two {
  grid-template-columns: repeat(2, 1fr);
}

.segment {
  border: 0;
  border-radius: 0;
  padding: 10px 6px;
  background: transparent;
}

.segment + .segment {
  border-left: 1px solid var(--line);
}

.segment.active {
  background: var(--ink);
  color: #fff;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
}

.swatch {
  width: 100%;
  aspect-ratio: 1;
  min-height: 34px;
  padding: 0;
  border-radius: 8px;
  background: var(--swatch-color);
  border: 1px solid var(--line);
}

.swatch.active {
  box-shadow:
    0 0 0 2px var(--panel),
    0 0 0 4px var(--ink);
}

.actions,
.export-actions,
.toolbar,
.tabs {
  display: flex;
  align-items: center;
  gap: 10px;
}

.export-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.actions button {
  flex: 1;
}

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

.status {
  min-height: 42px;
  font-size: 13px;
  line-height: 1.4;
}

.workspace {
  min-width: 0;
  max-width: 100vw;
  overflow-x: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.toolbar {
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.84);
  backdrop-filter: blur(8px);
}

.tab.active {
  background: var(--ink);
  color: #fff;
}

.stage-wrap {
  min-width: 0;
  max-width: 100vw;
  overflow: auto;
  padding: 28px;
  display: grid;
  place-items: start center;
}

.stage {
  width: min(100%, 760px);
  min-width: 0;
  aspect-ratio: 3 / 4;
  background: var(--puzzle-bg, #fffdf8);
  border: 1px solid var(--puzzle-line, var(--line));
  padding: 50px 48px 42px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 28px;
  position: relative;
  overflow: hidden;
}

.puzzle-header {
  text-align: center;
  min-width: 0;
}

.eyebrow {
  text-transform: uppercase;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

.puzzle-header h2 {
  margin-top: 8px;
  font-size: clamp(36px, 5.2vw, 60px);
  line-height: 0.98;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.puzzle-header p:last-child {
  margin-top: 12px;
  font-size: clamp(20px, 2.7vw, 28px);
  font-weight: 750;
  line-height: 1.25;
  text-wrap: balance;
}

.puzzle-header p.answer-subtitle {
  font-size: 16px;
  font-weight: 500;
}

.letter-grid {
  align-self: center;
  justify-self: center;
  width: min(100%, 560px);
  min-width: 0;
  aspect-ratio: 1;
  display: grid;
  gap: 2px;
}

.cell {
  display: grid;
  place-items: center;
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 700;
  font-size: clamp(13px, 2.7vw, 28px);
  line-height: 1;
  border-radius: 5px;
  color: #111;
  position: relative;
}

.language-chinese .cell {
  font-family:
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", ui-sans-serif,
    system-ui, sans-serif;
  font-size: clamp(15px, 2.8vw, 30px);
}

.cell.inactive {
  color: transparent;
}

.cell.answer {
  background: var(--answer-color, var(--answer));
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.08);
}

.word-bank {
  border-top: 1px solid var(--puzzle-line, var(--line));
  padding-top: 18px;
}

.word-bank h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
  color: var(--muted);
  margin-bottom: 10px;
}

.word-bank ul {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 0;
  margin: 0;
  list-style: none;
  justify-content: center;
}

.word-bank li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 800;
}

.word-bank li::before {
  content: "";
  width: 0.75em;
  height: 0.75em;
  border-radius: 3px;
  background: var(--word-color, var(--answer));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.watermark {
  position: absolute;
  right: 24px;
  bottom: 18px;
  z-index: 2;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: rgba(32, 32, 32, 0.78);
  font-size: 12px;
  font-weight: 800;
  padding: 7px 10px;
  pointer-events: none;
}

.watermark::before {
  content: none;
}

.stage.plan-free::after,
.workbook-page.plan-free::after {
  content: "PUZZLEFOX";
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  transform: translate(-50%, -50%) rotate(-24deg);
  width: 120%;
  color: rgba(32, 32, 32, 0.11);
  font-size: clamp(44px, 8vw, 86px);
  font-weight: 950;
  letter-spacing: 0;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(32, 32, 32, 0.42);
  padding: 18px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(100%, 520px);
  position: relative;
  border-radius: 12px;
  background: #fffdf8;
  border: 1px solid var(--line);
  padding: 28px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
}

.modal-eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

.modal h2 {
  margin: 0;
  font-size: 34px;
  line-height: 1.05;
  text-wrap: balance;
}

.modal-copy {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.pro-list {
  display: grid;
  gap: 10px;
  margin: 18px 0;
  padding: 0;
  list-style: none;
}

.pro-list li {
  position: relative;
  padding-left: 24px;
  font-weight: 700;
}

.pro-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.35em;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.pricing-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 18px;
}

.pricing-row strong {
  font-size: 24px;
}

.pricing-row span {
  color: var(--muted);
}

.license-field {
  margin-bottom: 16px;
}

.license-field input {
  text-transform: uppercase;
}

.license-message {
  min-height: 22px;
  margin: -6px 0 16px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
}

.license-message[data-tone="error"] {
  color: #b7193d;
}

.license-message[data-tone="success"] {
  color: #126b62;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -2px 0 16px;
  color: var(--ink);
  font-weight: 750;
}

.check-field input {
  width: auto;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions button {
  flex: 1;
}

.theme-xiaohongshu {
  --line: #f2c2c2;
  --accent: #ff4f6d;
  --answer: #ffdf67;
  border-color: #ffd1d9;
}

.theme-xiaohongshu .eyebrow,
.theme-xiaohongshu .word-bank h3 {
  color: #d93d58;
}

.theme-xiaohongshu .puzzle-header h2 {
  color: #b7193d;
}

.theme-worksheet {
  --line: #cfd8dc;
  --answer: #b7f0cf;
  border-color: #9ca9ad;
}

.seo-content {
  background: #fffdf8;
  border-top: 1px solid var(--line);
  padding: 72px 24px;
}

.seo-inner {
  width: min(100%, 980px);
  margin: 0 auto;
}

.seo-kicker {
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.seo-content h2 {
  margin: 10px 0 16px;
  font-size: clamp(32px, 5vw, 56px);
  line-height: 1;
  text-wrap: balance;
}

.seo-content p {
  color: var(--muted);
  font-size: 18px;
  line-height: 1.55;
}

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

.seo-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 22px;
}

.seo-grid h3 {
  margin: 0 0 10px;
  font-size: 20px;
  line-height: 1.15;
}

.seo-grid p,
.seo-faq p {
  margin: 0;
  font-size: 15px;
}

.seo-faq {
  margin-top: 46px;
}

.seo-faq h2 {
  font-size: clamp(28px, 4vw, 42px);
}

.seo-faq details {
  border-top: 1px solid var(--line);
  padding: 18px 0;
}

.seo-faq details:last-child {
  border-bottom: 1px solid var(--line);
}

.seo-faq summary {
  cursor: pointer;
  font-size: 18px;
  font-weight: 850;
}

.seo-faq summary::marker {
  color: var(--accent);
}

.batch-modal {
  width: min(100%, 680px);
}

.batch-workbook {
  display: none;
}

.workbook-page {
  width: 8.5in;
  min-height: 11in;
  margin: 0 auto;
  background: var(--puzzle-bg, #fffdf8);
  border: 1px solid var(--puzzle-line, var(--line));
  padding: 0.55in 0.5in 0.46in;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0.28in;
  position: relative;
  overflow: hidden;
  break-after: page;
  page-break-after: always;
}

.paper-a4 .workbook-page {
  width: 210mm;
  min-height: 297mm;
}

.workbook-page .letter-grid {
  width: min(100%, 6.35in);
}

.paper-a4 .workbook-page .letter-grid {
  width: min(100%, 158mm);
}

.workbook-page .puzzle-header h2 {
  font-size: 42px;
}

.workbook-page .puzzle-header p:last-child {
  font-size: 18px;
}

.workbook-page .cell {
  font-size: 23px;
}

.workbook-page.language-chinese .cell {
  font-size: 24px;
}

.workbook-page .word-bank li {
  font-size: 14px;
}

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

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .toolbar {
    flex-wrap: wrap;
  }

  .stage-wrap {
    padding: 16px;
  }

  .stage {
    padding: 30px 22px;
  }
}

@media (max-width: 640px) {
  .panel {
    padding: 22px;
  }

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

  .toolbar {
    align-items: stretch;
    gap: 14px;
    padding: 14px;
  }

  .tabs,
  .export-actions {
    width: 100%;
    justify-content: center;
  }

  .export-actions button {
    flex: 1 1 calc(50% - 10px);
    padding-inline: 8px;
    white-space: nowrap;
  }

  .stage-wrap {
    padding: 14px;
    overflow-x: hidden;
  }

  .stage {
    width: min(100%, calc(100vw - 88px), 360px);
    aspect-ratio: auto;
    min-height: 0;
    grid-template-rows: auto auto auto;
    gap: 18px;
    padding: 34px 20px 30px;
  }

  .watermark {
    right: 12px;
    bottom: 10px;
    font-size: 10px;
    padding: 5px 7px;
  }

  .modal {
    padding: 24px 20px;
  }

  .modal h2 {
    font-size: 28px;
  }

  .pricing-row,
  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .eyebrow {
    font-size: 12px;
  }

  .puzzle-header h2 {
    font-size: clamp(30px, 8vw, 40px);
    line-height: 1;
  }

  .puzzle-header p:last-child {
    font-size: clamp(15px, 4.2vw, 18px);
    line-height: 1.22;
  }

  .puzzle-header p.answer-subtitle {
    font-size: 14px;
  }

  .letter-grid {
    width: min(100%, 430px);
    gap: 1px;
  }

  .cell {
    font-size: clamp(12px, 4.2vw, 20px);
    border-radius: 4px;
  }

  .language-chinese .cell {
    font-size: clamp(13px, 4.5vw, 21px);
  }

  .word-bank {
    padding-top: 14px;
  }

  .word-bank h3 {
    font-size: 12px;
  }

  .word-bank ul {
    gap: 8px 12px;
  }

  .word-bank li {
    font-size: clamp(14px, 4.4vw, 19px);
  }

  .seo-content {
    padding: 48px 20px;
  }

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

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

  body.batch-printing {
    margin: 0;
  }

  .settings,
  .toolbar,
  .seo-content,
  .modal-backdrop {
    display: none;
  }

  body.batch-printing .app {
    display: none;
  }

  .app,
  .workspace,
  .stage-wrap {
    display: block;
    padding: 0;
    min-height: auto;
  }

  .stage {
    width: 100vw;
    min-height: 100vh;
    border: 0;
    aspect-ratio: auto;
  }

  .batch-workbook {
    display: none;
  }

  body.batch-printing .batch-workbook {
    display: block;
  }

  .workbook-page {
    margin: 0;
    border: 0;
    box-shadow: none;
  }

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