:root {
  --ink: #111;
  --muted: #444;
  --line: #000;
  --bg: #e9ecef;
  --paper: #fff;
  --accent: #2563eb;
  --pad: clamp(28px, 6vw, 52px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  /* System sans-serif stack: works fully offline, no webfont download. */
  font-family: Arial, Helvetica, "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  /* stylelint-disable-next-line property-no-vendor-prefix -- keep iOS Safari text-inflation guard */
  -webkit-text-size-adjust: 100%;
}

/* ---------- App chrome (hidden when printing) ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  background: #111;
  color: #fff;
  box-shadow: 0 1px 8px rgb(0 0 0 / 25%);
}

.toolbar .brand {
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-right: auto;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar .brand small {
  font-weight: 400;
  opacity: 0.6;
  font-size: 11px;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #2d2d2d;
  color: #fff;
  transition:
    background 0.15s,
    transform 0.05s;
}

.btn:hover {
  background: #3a3a3a;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--accent);
}

.btn.primary:hover {
  background: #1d4fd7;
}

.btn.ghost {
  background: transparent;
  border: 1px solid #444;
}

.btn input[type="file"] {
  display: none;
}

.themepick {
  gap: 8px;
}

.themepick select {
  appearance: none;
  background: #2d2d2d;
  color: #fff;
  border: 1px solid #555;
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 8px;
  cursor: pointer;
}

.themepick select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.hint {
  max-width: 850px;
  margin: 14px auto 0;
  padding: 0 12px;
  font-size: 12.5px;
  color: #555;
  line-height: 1.5;
}

.hint b {
  color: #222;
}

.hint .dot {
  color: var(--accent);
}

/* ---------- Paper / page ---------- */
.stage {
  padding: 18px 12px 60px;
}

.page {
  background: var(--paper);
  width: 100%;
  max-width: 820px; /* ~ A4 width feel on screen */
  margin: 0 auto;
  padding: var(--pad);
  box-shadow: 0 6px 30px rgb(0 0 0 / 18%);
  border-radius: 4px;
  line-height: 1.4;
  font-size: 13.5px;
  color: var(--ink);
  overflow-wrap: break-word;
  word-break: normal;
}

.page * {
  overflow-wrap: break-word;
}

/* editable affordance */
[contenteditable] {
  outline: none;
  border-radius: 3px;
  transition:
    box-shadow 0.12s,
    background 0.12s;
}

[contenteditable]:hover {
  box-shadow: 0 0 0 2px rgb(37 99 235 / 12%);
}

[contenteditable]:focus {
  box-shadow: 0 0 0 2px rgb(37 99 235 / 55%);
  background: #f5f8ff;
}

[contenteditable]:empty::before {
  content: attr(data-ph);
  color: #aaa;
}

/* ---------- Header ---------- */
.name {
  font-size: 27px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.3px;
  line-height: 1.1;
}

.role {
  font-size: 15px;
  font-weight: 400;
  text-align: center;
  margin-top: 3px;
  color: #222;
}

.contacts {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 9px;
  line-height: 1.7;
}

.contacts .c {
  display: inline-block;
  margin: 0 8px;
  white-space: nowrap;
}

.contacts .ic {
  opacity: 0.85;
  margin-right: 3px;
}

/* ---------- Sections ---------- */
section {
  margin-top: 20px;
}

.sec-head {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.rule {
  border: 0;
  border-top: 1.2px solid var(--line);
  margin: 4px 0 11px;
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 0.3fr) minmax(0, 0.7fr);
  gap: 14px;
  margin-bottom: 14px;
}

.row:last-child {
  margin-bottom: 0;
}

.meta {
  font-size: 12px;
  color: #333;
  line-height: 1.6;
}

.meta .strong {
  font-weight: 700;
}

.body .pos {
  font-weight: 700;
  font-size: 13.5px;
}

.body .org {
  font-style: italic;
  color: #222;
}

ul {
  margin: 6px 0 0;
  padding-left: 17px;
}

li {
  margin-bottom: 4px;
}

/* skills grid - label stacked over italic values (matches reference) */
.skills-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px 34px;
}

.skill {
  font-size: 12.8px;
  min-width: 0;
}

.skill .k {
  font-weight: 700;
  display: block;
}

.skill .sep {
  display: none;
}

.skill .v {
  color: #222;
  display: block;
}

/* interests */
.interests {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px 14px;
}

.interests .i {
  font-size: 12.8px;
}

.interests .i::before {
  content: "•";
  margin-right: 7px;
}

.ext {
  font-size: 10px;
  opacity: 0.5;
  margin-left: 3px;
  vertical-align: 1px;
}

/* row toolbelt for add/remove (screen only) */
.editmark {
  display: inline-flex;
  gap: 4px;
  margin-left: 8px;
  vertical-align: middle;
  opacity: 0;
  transition: opacity 0.12s;
}

/* Reveal the per-item add/remove controls on hover/focus of the item or the
   control itself. .editmark:hover is listed first to satisfy stylelint's
   no-descending-specificity (lower-specificity selector before the compound
   ones) while keeping identical behavior. */
.editmark:hover,
li:hover > .editmark,
.skill:hover > .editmark,
.i:hover > .editmark,
.meta:hover .editmark,
.body:hover .editmark,
[contenteditable]:focus > .editmark {
  opacity: 1;
}

/* touch devices have no hover: keep controls always visible but muted */
@media (hover: none) {
  .editmark {
    opacity: 0.55;
  }
}

.editmark button {
  border: 0;
  background: #eef;
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  padding: 3px 6px;
  color: #2563eb;
  font-weight: 700;
}

.editmark button:hover {
  background: #dde4ff;
}

.addbtn {
  display: inline-block;
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--accent);
  background: #eef;
  border: 0;
  border-radius: 6px;
  padding: 4px 9px;
  cursor: pointer;
  font-weight: 700;
}

.addbtn:hover {
  background: #dde4ff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 30%);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
  z-index: 200;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

/* ====================================================================
     THEMES - pure CSS, scoped under <body data-theme="..."> set by app.js.
     "modern" is the default look above (no overrides needed). Themes only
     restyle; they never change DOM structure, so editing/add-remove/autosave/
     upload-parsing/print all keep working. Any new grid uses minmax(0,...) so
     text wraps instead of overflowing the right edge (esp. in the PDF).
     ==================================================================== */

/* ---------- Classic: serif, traditional, centered section heads ---------- */
body[data-theme="classic"] {
  --accent: #1f2937;
}

body[data-theme="classic"] .page {
  font-family: Georgia, "Times New Roman", Times, serif;
}

body[data-theme="classic"] .name {
  font-family: Georgia, "Times New Roman", Times, serif;
  letter-spacing: 0.5px;
}

body[data-theme="classic"] .role {
  font-style: italic;
}

body[data-theme="classic"] .sec-head {
  text-align: center;
  letter-spacing: 2px;
}

body[data-theme="classic"] .rule {
  border-top-width: 2px;
}

body[data-theme="classic"] .body .pos {
  font-weight: 700;
}

/* ---------- Compact: tighter spacing, denser multi-column body ---------- */
body[data-theme="compact"] {
  --pad: clamp(20px, 4vw, 38px);
}

body[data-theme="compact"] .page {
  font-size: 12.5px;
  line-height: 1.3;
}

body[data-theme="compact"] section {
  margin-top: 13px;
}

body[data-theme="compact"] .name {
  font-size: 23px;
}

body[data-theme="compact"] .role {
  font-size: 13px;
}

body[data-theme="compact"] .contacts {
  margin-top: 6px;
}

body[data-theme="compact"] .row {
  gap: 10px;
  margin-bottom: 9px;
}

body[data-theme="compact"] li {
  margin-bottom: 2px;
}

body[data-theme="compact"] .rule {
  margin: 3px 0 8px;
}

/* Denser columns only where there's room; below 641px the mobile rules
     (single column) apply because these overrides don't exist there. */
@media (width >= 641px) {
  body[data-theme="compact"] .skills-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px 22px;
  }

  body[data-theme="compact"] .interests {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* ---------- Mobile ---------- */
@media (width <= 640px) {
  .page {
    font-size: 13px;

    --pad: 22px;
  }

  .row {
    grid-template-columns: 1fr;
    gap: 2px;
    margin-bottom: 13px;
  }

  .meta {
    color: #555;
    font-size: 11.5px;
  }

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

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

  .toolbar .brand small {
    display: none;
  }

  .name {
    font-size: 24px;
  }
}

/* ---------- Print = the actual PDF ---------- */

/* @page owns the printable margin; .page padding goes to 0 so we never
     double-apply and overflow the printable box (was clipping the right edge). */
@page {
  size: a4;
  margin: 15mm;
}

@media print {
  html,
  body {
    background: #fff;
    width: auto;
  }

  .toolbar,
  .hint,
  .editmark,
  .addbtn,
  .toast {
    display: none !important;
  }

  .stage {
    padding: 0;
    margin: 0;
  }

  .page {
    box-shadow: none;
    border-radius: 0;
    margin: 0;
    max-width: 100%;
    width: 100%;
    padding: 0;
    font-size: 9.8pt;
    line-height: 1.34;
  }

  [contenteditable]:hover,
  [contenteditable]:focus {
    box-shadow: none;
    background: transparent;
  }

  section {
    margin-top: 11pt;
  }

  .name {
    font-size: 21pt;
  }

  .role {
    font-size: 12pt;
  }

  .contacts {
    font-size: 9pt;
    margin-top: 6pt;
  }

  .sec-head {
    font-size: 10pt;
  }

  .rule {
    margin: 3pt 0 7pt;
  }

  .row {
    gap: 10pt;
    margin-bottom: 8pt;
  }

  .skills-grid {
    gap: 6pt 26pt;
  }

  li {
    margin-bottom: 2pt;
  }

  ul {
    margin-top: 4pt;
  }

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

  /* keep sections from breaking awkwardly across pages */
  section,
  .row,
  .skill {
    break-inside: avoid;
  }

  /* --- per-theme print rules so the PDF matches the on-screen theme --- */
  body[data-theme="classic"] .page,
  body[data-theme="classic"] .name {
    font-family: Georgia, "Times New Roman", Times, serif;
  }

  body[data-theme="classic"] .sec-head {
    text-align: center;
    letter-spacing: 2px;
  }

  body[data-theme="classic"] .role {
    font-style: italic;
  }

  body[data-theme="classic"] .rule {
    border-top-width: 1.6px;
  }

  body[data-theme="compact"] .page {
    font-size: 9pt;
    line-height: 1.28;
  }

  body[data-theme="compact"] section {
    margin-top: 9pt;
  }

  body[data-theme="compact"] .row {
    margin-bottom: 6pt;
  }

  body[data-theme="compact"] li {
    margin-bottom: 1.5pt;
  }

  /* minmax(0,...) keeps text wrapping so the extra columns never clip at A4's
       right margin. */
  body[data-theme="compact"] .skills-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5pt 18pt;
  }

  body[data-theme="compact"] .interests {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
