/* ===================== Base ===================== */
:root {
  --bg: #f6f4f1;
  --panel: #ffffff;
  --ink: #1c1b19;
  --muted: #6b675f;
  --line: #e6e1d8;
  --accent: #8a6d4b;
  --accent-ink: #fff;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
code {
  background: #efece6;
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.85em;
}

/* ===================== Layout ===================== */
.topbar {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--accent); font-size: 20px; }
.brand-name { font-family: "Playfair Display", serif; font-size: 22px; font-weight: 600; }
.tagline { margin: 0; color: var(--muted); font-size: 13px; }

.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 0;
  min-height: calc(100vh - 64px);
}
.controls {
  padding: 20px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  max-height: calc(100vh - 64px);
}
.preview-wrap { display: flex; flex-direction: column; background: #eceae6; }

/* ===================== Panels & controls ===================== */
.panel { margin-bottom: 22px; }
.panel-title {
  display: block;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-bottom: 8px;
}
.hint { margin: 0 0 8px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }

textarea#guestInput {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  background: #fbfaf8;
}
textarea#guestInput:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.file-btn {
  display: inline-block;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  background: #fbfaf8;
}
.file-btn:hover { background: #f1eee9; }
.link-btn {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-size: 13px; text-decoration: underline; padding: 4px;
}
.status { font-size: 12.5px; margin: 8px 0 0; min-height: 1em; }
.status.ok { color: #2f7d4f; }
.status.warn { color: #b5651d; }
.status.err { color: #b3261e; }

.field { display: block; margin-top: 12px; }
.field span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; background: #fbfaf8;
}

/* Theme picker */
.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.theme-chip {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  background: #fff;
  text-align: left;
}
.theme-chip:hover { border-color: var(--accent); }
.theme-chip.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.theme-chip .swatch { font-size: 18px; line-height: 1.1; }
.theme-chip .tname { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Segmented control */
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 6px; }
.seg-btn {
  flex: 1; padding: 9px 6px; border: none; background: #fff; cursor: pointer;
  font-size: 13px; color: var(--muted); border-right: 1px solid var(--line);
}
.seg-btn:last-child { border-right: none; }
.seg-btn.is-active { background: var(--accent); color: var(--accent-ink); }

/* Buttons */
.primary-btn {
  width: 100%; padding: 12px; border: none; border-radius: 10px;
  background: var(--ink); color: #fff; font-size: 15px; font-weight: 600;
  cursor: pointer; margin-bottom: 10px;
}
.primary-btn:hover { background: #000; }
.buy-btn {
  width: 100%; padding: 11px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
}
.buy-btn:hover { filter: brightness(1.05); }
.ghost-btn {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; cursor: pointer; font-size: 13px;
}
.have-key { margin-top: 10px; font-size: 13px; }
.have-key summary { cursor: pointer; color: var(--muted); }
.key-row { display: flex; gap: 8px; margin-top: 8px; }
.key-row input { flex: 1; padding: 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 12px; }
.unlocked-badge { color: #2f7d4f; font-size: 13px; font-weight: 600; margin: 10px 0 0; }
.privacy-note { font-size: 12px; color: var(--muted); margin-top: 18px; border-top: 1px dashed var(--line); padding-top: 14px; }

/* ===================== Preview ===================== */
.preview-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 20px; font-size: 13px; color: var(--muted);
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.preview-scroll { flex: 1; overflow: auto; padding: 28px; display: flex; justify-content: center; }
.print-area {
  background: #fff;
  width: 210mm;            /* A4 width baseline */
  min-height: 297mm;
  padding: 22mm 20mm;
  box-shadow: 0 6px 30px rgba(0,0,0,0.12);
  color: #1c1b19;
}

/* ---- Rendered content ---- */
.sheet-title { text-align: center; margin: 0 0 4px; }
.sheet-sub { text-align: center; color: #555; margin: 0 0 26px; }

.chart-cols { column-count: 3; column-gap: 26px; }
.chart-entry {
  break-inside: avoid;
  display: flex; justify-content: space-between; gap: 10px;
  padding: 3px 0; font-size: 14px; border-bottom: 1px dotted #d8d2c7;
}
.chart-entry .gt { color: #8a6d4b; font-variant-numeric: tabular-nums; white-space: nowrap; }

.table-card {
  break-inside: avoid; page-break-inside: avoid;
  border: 1px solid #e0d9cc; border-radius: 8px;
  padding: 18px 20px; margin-bottom: 18px;
}
.table-card h3 { margin: 0 0 10px; }
.table-card ul { margin: 0; padding-left: 18px; }
.table-card li { font-size: 14px; padding: 1px 0; }

.escort-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.escort-card {
  break-inside: avoid;
  border: 1px dashed #cfc7b8;
  padding: 16px 14px; text-align: center;
  min-height: 42mm; display: flex; flex-direction: column; justify-content: center;
}
.escort-card .en { font-size: 18px; }
.escort-card .et { margin-top: 6px; color: #8a6d4b; font-size: 14px; }

.empty-state { text-align: center; color: #aaa; padding: 80px 20px; }

/* ===================== Themes ===================== */
.theme-classic .sheet-title, .theme-classic h3, .theme-classic .en { font-family: "Playfair Display", serif; }
.theme-classic { --t-accent: #8a6d4b; }

.theme-modern { font-family: Inter, sans-serif; }
.theme-modern .sheet-title { font-weight: 300; letter-spacing: 0.12em; text-transform: uppercase; }
.theme-modern .chart-entry .gt, .theme-modern .escort-card .et { color: #111; }

.theme-script .sheet-title, .theme-script .en, .theme-script h3 { font-family: "Great Vibes", cursive; font-weight: 400; }
.theme-script .sheet-title { font-size: 46px; }
.theme-script { --t-accent: #9a7b9b; }

.theme-boho { font-family: "Cormorant Garamond", serif; }
.theme-boho .sheet-title { font-family: "Cormorant Garamond", serif; font-weight: 600; letter-spacing: 0.02em; }
.theme-boho .chart-entry .gt, .theme-boho .escort-card .et { color: #9c6b4a; }

/* ===================== Watermark ===================== */
.watermark {
  position: fixed; inset: 0; pointer-events: none; z-index: 5;
  overflow: hidden; opacity: 0.10;
  display: flex; align-items: center; justify-content: center;
}
.watermark-tile {
  font-size: 26px; font-weight: 700; color: #000;
  transform: rotate(-30deg); white-space: nowrap;
  line-height: 3.2; width: 200vw; word-spacing: 8px;
  /* repeat the text visually by duplicating via box-shadow-free tiling */
}
body.is-unlocked .watermark { display: none; }

/* ===================== Print ===================== */
@page { size: A4; margin: 14mm; }
@media print {
  .app { display: none !important; }
  body { background: #fff; }
  .watermark { position: fixed; opacity: 0.12; }
  body.is-unlocked .watermark { display: none !important; }

  /* The print area is cloned to a print container by app.js before printing.
     We display that clone full-bleed. */
  #printOnly { display: block !important; }
  .print-area {
    width: auto; min-height: auto; box-shadow: none; padding: 0; margin: 0;
  }
  .table-card, .escort-card, .chart-entry { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
#printOnly { display: none; }

/* ===================== Responsive ===================== */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .controls { max-height: none; border-right: none; border-bottom: 1px solid var(--line); }
  .print-area { width: 100%; min-height: auto; padding: 16px; }
  .preview-scroll { padding: 12px; }
}
