:root {
  --ink: #232323;
  --muted: #69707a;
  --line: #d9dde3;
  --panel: #ffffff;
  --paper: #fffdf7;
  --accent: #4f883d;
  --accent-dark: #3e6d30;
  --accent-soft: #e8f2e4;
  --amber: #f4b942;
  --blue: #4f883d;
  --bg: #f3f5f2;
  --shadow: 0 18px 48px rgba(29, 43, 38, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(79, 136, 61, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(79, 136, 61, 0.05) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

.app-shell {
  display: grid;
  gap: 20px;
  min-height: 100vh;
  padding: 18px;
}

.controls-panel,
.preview-panel {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(217, 221, 227, 0.9);
  box-shadow: var(--shadow);
}

.controls-panel {
  align-self: start;
  border-radius: 8px;
  padding: 18px;
}

.preview-panel {
  border-radius: 8px;
  min-width: 0;
  padding: 18px;
}

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

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  font-size: 24px;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 21px;
}

.settings-form {
  display: grid;
  gap: 14px;
}

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

label {
  font-size: 14px;
  font-weight: 750;
}

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

textarea {
  min-height: 132px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 127, 95, 0.15);
}

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

.stepper {
  display: grid;
  grid-template-columns: 38px 1fr 38px;
  gap: 6px;
}

.stepper input {
  text-align: center;
}

.icon-button,
.primary-button,
.secondary-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 800;
}

.icon-button {
  color: #fff;
  background: var(--accent);
  padding: 0;
}

.primary-button {
  color: #fff;
  background: var(--accent);
  padding: 10px 14px;
}

.full-width {
  width: 100%;
}

.secondary-button {
  color: var(--accent-dark);
  background: var(--accent-soft);
  padding: 10px 14px;
}

.compact {
  min-height: 36px;
  padding: 8px 12px;
}

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

button:active {
  transform: translateY(1px);
}

button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

[data-lucide] {
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  font-style: normal;
  line-height: 1;
}

[data-lucide="minus"]::before {
  content: "-";
}

[data-lucide="plus"]::before {
  content: "+";
}

[data-lucide="download"]::before {
  content: "PDF";
  font-size: 10px;
}

[data-lucide="printer"]::before {
  content: "P";
  font-size: 12px;
}

.switch-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.switch {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 9px 10px;
  font-weight: 650;
}

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

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

.worksheet {
  --text-scale: 1;
  width: min(100%, 794px);
  min-height: 1123px;
  margin: 0 auto;
  border: 1px solid #d6d0c5;
  background: var(--paper);
  box-shadow: 0 14px 34px rgba(61, 51, 37, 0.13);
  padding: 54px;
  overflow: hidden;
}

.worksheet.landscape {
  width: min(100%, 1123px);
  min-height: 794px;
}

.worksheet-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: start;
  border-bottom: 3px solid var(--ink);
  padding-bottom: 18px;
}

.worksheet-title {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 38px;
  line-height: 1.04;
}

.name-line {
  min-width: 190px;
  border-bottom: 2px solid var(--ink);
  padding-top: 22px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.instruction {
  margin: 22px 0 16px;
  border-left: 6px solid #c8ced6;
  background: #f3f4f6;
  padding: 12px 14px;
  font-size: calc(18px * var(--text-scale));
  font-weight: 700;
}

.cipher-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.chip {
  border: 1px solid #cfd7d1;
  border-radius: 999px;
  background: #fff;
  padding: 6px 10px;
  color: #39433e;
  font-size: calc(13px * var(--text-scale));
  font-weight: 800;
}

.coded-area {
  margin: 18px 0 22px;
}

.coded-grid {
  display: flex;
  flex-wrap: wrap;
  gap: calc(7px * var(--text-scale));
}

.letter-box {
  display: inline-flex;
  width: calc(34px * var(--text-scale));
  height: calc(34px * var(--text-scale));
  align-items: center;
  justify-content: center;
  border: 2px solid #303030;
  background: #fff;
  font-size: calc(18px * var(--text-scale));
  font-weight: 850;
}

.word-gap {
  width: calc(18px * var(--text-scale));
}

.coded-lines {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "Courier New", Courier, monospace;
  font-size: calc(24px * var(--text-scale));
  font-weight: 800;
  line-height: 1.55;
}

.answer-lines {
  display: grid;
  gap: 11px;
  margin-top: 18px;
}

.answer-line {
  height: 28px;
  border-bottom: 1.8px solid #333;
}

.legend {
  margin-top: 26px;
  border: 1px solid #cfd7d1;
  background: #fff;
  padding: 13px;
}

.legend h3,
.answer-key h3 {
  margin: 0 0 10px;
  font-size: calc(15px * var(--text-scale));
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(calc(58px * var(--text-scale)), 1fr));
  gap: 6px;
}

.legend-pair {
  border: 1px solid #e0e3e0;
  padding: 5px;
  text-align: center;
  font-family: "Courier New", Courier, monospace;
  font-size: calc(13px * var(--text-scale));
  font-weight: 800;
}

.answer-key {
  margin-top: 24px;
  border-top: 2px dashed #333;
  padding-top: 16px;
}

.answer-key p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: calc(16px * var(--text-scale));
  font-weight: 750;
}

.option-substitution {
  display: none;
}

body[data-cipher="substitution"] .option-substitution,
body[data-cipher="caesar"] .option-caesar {
  display: grid;
}

body:not([data-cipher="caesar"]) .option-caesar {
  display: none;
}

@media (min-width: 850px) {
  .app-shell {
    grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
    align-items: start;
  }

  .controls-panel {
    position: sticky;
    top: 18px;
    max-height: calc(100vh - 36px);
    overflow: auto;
  }
}

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

  .controls-panel,
  .preview-panel {
    padding: 14px;
  }

  .two-col,
  .switch-grid {
    grid-template-columns: 1fr;
  }

  .worksheet {
    min-height: 0;
    padding: 28px;
  }

  .worksheet-header {
    grid-template-columns: 1fr;
  }

  .worksheet-title {
    font-size: 30px;
  }

  .letter-box {
    width: calc(29px * var(--text-scale));
    height: calc(29px * var(--text-scale));
    font-size: calc(15px * var(--text-scale));
  }
}

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

  .controls-panel,
  .preview-toolbar {
    display: none;
  }

  .app-shell,
  .preview-panel {
    display: block;
    min-height: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
    background: #fff;
  }

  .worksheet {
    width: 210mm;
    min-height: 297mm;
    border: 0;
    box-shadow: none;
  }

  .worksheet.landscape {
    width: 297mm;
    min-height: 210mm;
  }
}
