:root {
  --paper: #f7f4ed;
  --panel: #fffdf8;
  --ink: #25231f;
  --muted: #746f65;
  --line: #ded8cc;
  --line-strong: #b9b1a4;
  --accent: #285e52;
  --accent-strong: #17483f;
  --soft: #ece8df;
  --danger: #9d3f36;
  --success: #2f6d4f;
  --shadow: 0 18px 50px rgba(55, 48, 36, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--paper); color: var(--ink); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
a { color: inherit; }

.site-header {
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(18px, 4vw, 56px);
  border-bottom: 1px solid rgba(185,177,164,.65);
  background: rgba(247,244,237,.94);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 750; letter-spacing: -.02em; }
.brand-mark { width: 32px; height: 32px; display: grid; place-items: center; background: var(--accent); color: white; border-radius: 9px; font-family: Georgia, serif; font-size: 20px; }
.github-button { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line-strong); background: var(--panel); border-radius: 9px; padding: 8px 12px; text-decoration: none; font-weight: 700; font-size: 14px; }
.github-button svg { width: 17px; height: 17px; fill: currentColor; }

.page-shell { width: min(1500px, 100%); margin: 0 auto; padding: clamp(24px, 4vw, 54px) clamp(16px, 3vw, 42px) 64px; }
.hero-copy { margin-bottom: 22px; }
h1 { margin: 0 0 7px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(34px, 4vw, 52px); line-height: 1.02; letter-spacing: -.035em; font-weight: 700; }
.hero-copy p { margin: 0; color: var(--muted); font-size: 16px; max-width: 760px; line-height: 1.55; }

.workspace { display: grid; grid-template-columns: minmax(390px, .88fr) minmax(520px, 1.12fr); gap: 18px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.constructor-panel { padding: clamp(18px, 2.2vw, 28px); }
.preview-panel { min-height: 690px; overflow: hidden; }
.panel-heading { padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin: 2px 0 0; font-family: Georgia, serif; font-size: 24px; }
.eyebrow { color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-size: 11px; font-weight: 800; }
.preview-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 7px; margin-bottom: 14px; }
.field > span, .file-field > span:first-child { font-weight: 760; font-size: 13px; }
.field small { color: var(--muted); text-align: right; margin-top: -3px; }
input[type="text"], textarea { width: 100%; border: 1px solid var(--line-strong); background: #fff; color: var(--ink); border-radius: 10px; padding: 11px 12px; outline: none; transition: border-color .16s, box-shadow .16s; }
textarea { resize: vertical; line-height: 1.45; }
input[type="text"]:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(40,94,82,.11); }
.advanced-controls { border: 1px solid var(--line); border-radius: 10px; margin: 3px 0 15px; background: #fbf9f4; }
.advanced-controls summary { padding: 11px 12px; font-size: 13px; font-weight: 750; cursor: pointer; }
.advanced-controls[open] summary { border-bottom: 1px solid var(--line); }
.advanced-controls .field-row { padding: 13px 13px 0; }
.file-field { margin: 0 13px 13px; display: flex; align-items: center; flex-wrap: wrap; gap: 9px; color: var(--muted); font-size: 12px; }
.file-field input { max-width: 230px; }
.action-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.primary-button, .secondary-button, .text-button, .icon-button { border-radius: 9px; border: 1px solid transparent; padding: 10px 13px; font-weight: 750; font-size: 13px; }
.primary-button { background: var(--accent); color: #fff; min-width: 146px; }
.primary-button:hover:not(:disabled) { background: var(--accent-strong); }
.secondary-button, .icon-button { border-color: var(--line-strong); background: #fff; color: var(--ink); }
.secondary-button:hover:not(:disabled), .icon-button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-strong); }
.text-button { background: transparent; color: var(--muted); padding-inline: 8px; }

.status { margin-top: 15px; border-radius: 10px; padding: 11px 12px; background: var(--soft); color: #5f5a51; font-size: 13px; line-height: 1.45; }
.status[data-tone="working"] { color: #5c4d21; background: #f5ecd2; }
.status[data-tone="success"] { color: #265b41; background: #e5f2e9; }
.status[data-tone="error"] { color: var(--danger); background: #f8e8e5; }

.answer-editor { display: grid; gap: 9px; margin-top: 16px; }
.answer-editor-head { display: grid; grid-template-columns: 34px minmax(120px,.8fr) 42px minmax(150px,1.2fr); gap: 8px; padding: 0 7px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; }
.answer-row { display: grid; grid-template-columns: 34px minmax(120px,.8fr) 42px minmax(150px,1.2fr); gap: 8px; align-items: center; padding: 7px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.initial-pill { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-family: Georgia, serif; font-weight: 800; background: var(--soft); }
.answer-row input[type="text"] { padding: 8px 9px; border-radius: 8px; min-width: 0; }
.lock-control { display: grid; place-items: center; }
.lock-control input { width: 18px; height: 18px; accent-color: var(--accent); }

.puzzle-preview { padding: clamp(18px, 2.2vw, 28px); }
.empty-preview { min-height: 610px; display: grid; place-items: center; }
.empty-state { text-align: center; color: var(--muted); max-width: 360px; }
.empty-grid { width: 270px; max-width: 80vw; margin: 0 auto 18px; display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; transform: rotate(-1deg); }
.empty-grid span { aspect-ratio: 1; border: 1px solid var(--line-strong); border-radius: 3px; background: #fff; }
.preview-meta { margin-bottom: 18px; }
.preview-meta h3 { margin: 0; font-family: Georgia, serif; font-size: 22px; }
.preview-meta p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.quote-board { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 3px; padding: 17px; border: 1px solid var(--line); background: #fff; border-radius: 12px; margin-bottom: 22px; }
.quote-word { display: inline-flex; align-items: flex-end; gap: 2px; margin-right: 7px; }
.quote-punctuation { align-self: center; margin-left: -1px; color: var(--muted); }
.puzzle-cell { width: 27px; min-width: 27px; height: 37px; position: relative; display: inline-grid; place-items: center; border-bottom: 1.6px solid var(--ink); }
.cell-number { position: absolute; top: 0; left: 1px; font-size: 8px; line-height: 1; color: var(--muted); font-variant-numeric: tabular-nums; }
.cell-value { font-family: Georgia, serif; font-weight: 700; font-size: 17px; padding-top: 6px; min-height: 22px; }
.answer-clues { display: grid; gap: 12px; }
.preview-answer { display: grid; grid-template-columns: 28px minmax(0,1fr); gap: 8px; }
.preview-answer-label { font-family: Georgia, serif; font-weight: 800; padding-top: 2px; }
.preview-clue { margin: 0 0 7px; font-size: 13px; line-height: 1.4; }
.preview-answer-cells { display: flex; flex-wrap: wrap; gap: 2px; }
.preview-answer .puzzle-cell { width: 25px; min-width: 25px; height: 35px; }
.solve-input { width: 100%; height: 100%; border: 0; outline: 0; text-align: center; background: transparent; font-family: Georgia, serif; font-size: 17px; font-weight: 800; text-transform: uppercase; padding: 7px 0 0; }
.test-mode-note { display: inline-flex; gap: 8px; align-items: center; margin: -4px 0 14px; color: var(--accent-strong); font-size: 12px; font-weight: 760; }
.test-mode-note::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.after-tool-content { max-width: 780px; margin: 54px auto 0; border-top: 1px solid var(--line); padding-top: 34px; }
.after-tool-content h2 { font-family: Georgia, serif; font-size: 30px; margin: 0 0 10px; }
.after-tool-content p { color: var(--muted); line-height: 1.75; }
footer { border-top: 1px solid var(--line); text-align: center; color: var(--muted); font-size: 13px; padding: 24px; }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 1fr; }
  .preview-panel { min-height: 0; }
  .empty-preview { min-height: 360px; }
}
@media (max-width: 650px) {
  .site-header { height: 58px; padding-inline: 14px; }
  .brand > span:last-child { display: none; }
  .page-shell { padding-inline: 12px; padding-top: 24px; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .panel { border-radius: 13px; }
  .constructor-panel, .puzzle-preview { padding: 15px; }
  .panel-heading { align-items: flex-start; flex-direction: column; padding: 15px; }
  .preview-actions { width: 100%; justify-content: flex-start; }
  .answer-editor-head { display: none; }
  .answer-row { grid-template-columns: 32px minmax(0,1fr) 36px; }
  .answer-row .clue-input { grid-column: 2 / -1; }
  .puzzle-cell { width: 25px; min-width: 25px; }
  .action-row > button { flex: 1 1 auto; }
}

@media print {
  @page { margin: 14mm; }
  body { background: #fff; }
  .site-header, .constructor-panel, .preview-actions, .after-tool-content, footer, .eyebrow { display: none !important; }
  .page-shell, .hero-tool, .workspace, .preview-panel { display: block; width: 100%; max-width: none; margin: 0; padding: 0; border: 0; box-shadow: none; }
  .hero-copy { display: none; }
  .panel-heading { border: 0; padding: 0 0 12px; }
  .puzzle-preview { padding: 0; }
  .quote-board { break-inside: avoid; }
  .preview-answer { break-inside: avoid; }
  body.print-key .cell-value::before { content: attr(data-solution); }
  body.print-key .solve-input { display: none; }
}
