/* Chiffermötet, scoutappar.se
   Skärm: skogsgrön och gul accent, som övriga scoutappar.
   Utskrift: ren A4-layout med sideskift per ark. */

:root {
  --bg: #f6f4ee;
  --ink: #1d2a22;
  --muted: #5a6a60;
  --green: #1f6b3a;
  --forest: #0b2514;
  --forest-2: #163624;
  --yellow: #f4cb57;
  --yellow-deep: #d6ae30;
  --card: #fffef9;
  --line: #ddd8c8;
  --danger: #8a2b2b;
  --ok: #1f6b3a;
  --focus: #f4cb57;
  --sheet-w: 210mm;
  --sheet-h: 297mm;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.55;
}

body.pack-ready { padding-bottom: 72px; }

a { color: var(--green); }
a:hover { color: var(--forest); }

:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--yellow);
  color: var(--forest);
  padding: 8px 12px;
  z-index: 20;
}
.skip-link:focus { left: 8px; top: 8px; }

/* ---------- Skärm: sidhuvud och formulär ---------- */

.site-header {
  background: var(--forest);
  color: #fff;
  padding: 22px 20px 26px;
}

.site-header-inner,
.wrap,
.site-footer-inner {
  max-width: 880px;
  margin: 0 auto;
}

.brand-link {
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.02em;
  font-size: 1.05rem;
}
.brand-link:hover { color: var(--yellow); }

.site-header h1 {
  margin: 10px 0 8px;
  font-size: clamp(2rem, 6vw, 2.7rem);
  line-height: 1.15;
  font-weight: 800;
}

.lead {
  margin: 0;
  max-width: 38em;
  color: #cfe5d2;
  font-size: 1.08rem;
}

.wrap { padding: 22px 20px 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 22px;
  margin: 0 0 18px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1.25rem;
  color: var(--forest);
}

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

.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }

label, .label {
  font-weight: 650;
  font-size: 0.95rem;
}

.hint {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0;
}

input[type="text"],
input[type="number"],
select,
textarea {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cfc9b8;
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
}

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

input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--green);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-weight: 500;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

button, .btn {
  font: inherit;
  font-weight: 800;
  border: 0;
  border-radius: 10px;
  padding: 0.75em 1.25em;
  cursor: pointer;
}

.btn-primary {
  background: var(--yellow);
  color: #10301a;
}
.btn-primary:hover { background: #ffd96e; }

.btn-secondary {
  background: var(--forest);
  color: #fff;
}
.btn-secondary:hover { background: #163d26; }

.btn-ghost {
  background: transparent;
  color: var(--green);
  border: 1px solid var(--green);
}
.btn-ghost:hover { background: #e9eee4; }

.warning, .error, .note {
  border-radius: 10px;
  padding: 10px 12px;
  margin: 10px 0 0;
  font-size: 0.95rem;
}
.warning { background: #fcf8e9; border: 1px solid #e4d48a; }
.error { background: #fbeaea; border: 1px solid #e3b3b3; color: var(--danger); }
.note { background: #e9eee4; border: 1px solid #c4cdb9; }

.site-footer {
  padding-bottom: 88px;
  border-top: 1px solid var(--line);
  margin-top: 28px;
  padding: 22px 20px 40px;
  color: var(--muted);
  font-size: 0.92rem;
}

.site-footer p { margin: 0 0 8px; }

/* ---------- Förhandsvisning på skärm ---------- */


.howto {
  margin: 16px 0 0;
  padding: 12px 12px 12px 32px;
  background: rgba(11, 37, 20, 0.35);
  border: 1px solid rgba(244, 203, 87, 0.35);
  border-radius: 12px;
  color: #e8f3ea;
  font-size: 0.98rem;
}
.howto li { margin: 0 0 6px; }
.howto li:last-child { margin: 0; }
.howto strong { color: #f4cb57; }

.hint.warn { color: var(--danger); }
.hint.ok { color: var(--ok); }

#char-count { min-height: 1.2em; }

.print-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--forest);
  color: #fff;
  padding: 14px 16px;
  border-radius: 12px;
  margin: 0 0 16px;
}
.print-bar[hidden] { display: none !important; }
.print-bar p { margin: 0; font-weight: 650; }

#preview-mobile-note { display: none; }

@media screen and (max-width: 720px) {
  #preview-mobile-note { display: block; }
  .sheet-scroll {
    justify-content: flex-start;
    padding-bottom: 8px;
  }
  .sheet-scroll::-webkit-scrollbar { height: 8px; }
}


.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 8px 0 14px;
}
.preview-head .btn-primary { flex: 0 0 auto; }

.preview-head h2 { margin: 0; font-size: 1.35rem; }

#print-root {
  display: flex;
  flex-direction: column;
  gap: 28px;
  align-items: center;
  padding: 0 12px 40px;
}

.sheet-scroll {
  width: 100%;
  overflow-x: auto;
  display: flex;
  justify-content: center;
}

.sheet {
  width: var(--sheet-w);
  min-height: var(--sheet-h);
  background: #fff;
  color: #1d2a22;
  padding: 14mm 16mm 12mm;
  box-shadow: 0 10px 30px rgba(11, 37, 20, 0.18);
  border: 1px solid #e4dfd3;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-brand {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  border-bottom: 3px solid var(--forest);
  padding-bottom: 6px;
  margin: 0;
  font-size: 11pt;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--forest);
}

.sheet-brand span { font-weight: 500; color: var(--muted); }

.sheet h2 {
  margin: 4px 0 0;
  font-size: 26pt;
  line-height: 1.1;
  color: var(--forest);
}

.sheet .cipher-label {
  margin: 0;
  font-size: 14pt;
  font-weight: 700;
}

.sheet .intro {
  margin: 0;
  font-size: 11pt;
}

.cipher-display {
  margin: 6px 0;
  padding: 8mm 6mm;
  border: 2px solid var(--forest);
  border-radius: 4px;
  background: #fafaf6;
  min-height: 40mm;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2mm 3mm;
}

.cipher-text {
  font-family: "Courier New", Courier, ui-monospace, monospace;
  font-size: 22pt;
  line-height: 1.45;
  letter-spacing: 0.02em;
  text-align: center;
  width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.cipher-text.compact { font-size: 16pt; }
.cipher-text.morse { font-size: 18pt; letter-spacing: 0.04em; }

.pp-sym { display: inline-flex; }
.pp-space { display: inline-block; width: 14px; }
.pp-break { flex-basis: 100%; height: 0; }
.pp-raw { font-weight: 700; font-size: 16pt; padding: 0 2px; }

.key-block {
  border: 1px solid #cfc9b8;
  border-radius: 4px;
  padding: 5mm 5mm 4mm;
  background: #fff;
}

.key-block h3 {
  margin: 0 0 6px;
  font-size: 11pt;
  color: var(--forest);
}

.key-block p { margin: 0 0 6px; font-size: 9.5pt; }

.key-scroll { overflow-x: auto; }

table.key {
  border-collapse: collapse;
  font-size: 9.5pt;
  margin: 0 0 4px;
}

table.key th, table.key td {
  border: 1px solid #bbb;
  padding: 2px 6px;
  text-align: center;
  white-space: nowrap;
}

table.key th { background: #e9eee4; font-weight: 700; }

table.key.siffer td, table.key.siffer th { padding: 2px 4px; font-size: 8.5pt; }

.morse-list {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px 8px;
  font-family: "Courier New", Courier, monospace;
  font-size: 9pt;
  margin: 0;
}

.morse-list span { white-space: nowrap; }

.answer {
  margin-top: auto;
  padding-top: 4mm;
}

.answer h3 {
  margin: 0 0 4px;
  font-size: 12pt;
}

.lines {
  display: flex;
  flex-direction: column;
  gap: 7mm;
  margin: 3mm 0 4mm;
}

.lines span {
  display: block;
  border: 0;
  border-bottom: 0.75pt solid #222;
  height: 11mm;
  background: transparent;
}

.sheet-end {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-end;
  font-size: 9.5pt;
  color: #333;
  border-top: 1px solid #ddd;
  padding-top: 3mm;
  margin-top: 2mm;
}

.fine { color: var(--muted); font-size: 8.5pt; margin: 0; max-width: 70%; }

/* Ledarark */

.leader h2 { font-size: 22pt; }
.sheet.leader .intro { font-size: 10pt; }
.sheet.leader .key-block { padding: 3.5mm 4mm 3mm; }

.facit { width: 100%; border-collapse: collapse; font-size: 10pt; }
.facit th, .facit td {
  border: 1px solid #cfc9b8;
  padding: 4px 6px;
  vertical-align: top;
  text-align: left;
}
.facit th { background: #e9eee4; }
.facit .plain { font-weight: 700; }
.facit .encoded {
  font-family: "Courier New", Courier, monospace;
  font-size: 8.5pt;
  word-break: break-word;
}

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

.plan-grid h3, .leader h3 {
  margin: 8px 0 4px;
  font-size: 12pt;
  color: var(--forest);
}

.plan-grid ul, .leader ul { margin: 0; padding-left: 1.15em; }
.plan-grid li, .leader li { margin: 0 0 2px; font-size: 10.5pt; }

.mini-pp {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 1px;
  vertical-align: middle;
}

.keys-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.badge-spare {
  display: inline-block;
  background: var(--yellow);
  color: #10301a;
  font-weight: 800;
  font-size: 9pt;
  padding: 1px 8px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 30px 16px;
}

@media screen and (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
  .sheet {
    box-shadow: 0 4px 16px rgba(11, 37, 20, 0.14);
  }
  .morse-list { grid-template-columns: repeat(4, 1fr); }
  .plan-grid { grid-template-columns: 1fr; }
}

/* ---------- Utskrift: ett ark per A4-sida ---------- */

@page {
  size: A4 portrait;
  margin: 10mm;
}

@media print {
  html, body {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  .no-print { display: none !important; }

  a { color: inherit; text-decoration: none; }

  #print-root {
    display: block;
    padding: 0;
    gap: 0;
  }

  .sheet-scroll {
    display: block;
    overflow: visible;
    width: auto;
  }

  .sheet {
    width: auto;
    min-height: auto;
    height: auto;
    padding: 0;
    margin: 0;
    border: 0;
    box-shadow: none;
    border-radius: 0;
    break-inside: avoid;
    page-break-inside: avoid;
    break-after: page;
    page-break-after: always;
  }

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

  .cipher-display { background: #fff; }

  .sheet-end, .fine { color: #333; }

  /* Ledararket får flöda över till nästa sida om det behövs. */
  .sheet.leader {
    break-inside: auto;
    page-break-inside: auto;
    min-height: 0;
  }

  .key-block, .plan-grid, table.facit, .sheet.leader ul {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .sheet.leader h3, .sheet.leader h3 + p {
    break-after: avoid;
    page-break-after: avoid;
  }

  .morse-list { grid-template-columns: repeat(6, 1fr); }
}

