:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --ink: #20242a;
  --muted: #6a717c;
  --line: #d9ddd9;
  --accent: #2f6f73;
  --accent-dark: #214e51;
  --soft: #edf4f2;
  --danger: #b44b4b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 440px) 1fr;
  min-height: 100vh;
}

.editor-panel {
  height: 100vh;
  overflow: auto;
  padding: 28px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.editor-header,
.section-title-row,
.preview-actions,
.resume-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 26px;
  line-height: 1.2;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  font-size: 26px;
  line-height: 1;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 24px 0;
}

.toolbar button,
.add-button,
.ghost {
  min-height: 42px;
  border-radius: 8px;
  color: var(--ink);
  background: var(--soft);
  font-weight: 700;
}

.toolbar .primary {
  color: #fff;
  background: var(--accent);
}

.toolbar .primary:hover,
.icon-button:hover {
  background: var(--accent-dark);
}

.avatar-box,
.template-box,
.history-box {
  margin-bottom: 28px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.avatar-box h2,
.template-box h2,
.history-box h2,
.resume-form h2 {
  margin-bottom: 14px;
  font-size: 16px;
}

.avatar-control {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  align-items: center;
}

.avatar-thumb {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  overflow: hidden;
  border: 1px dashed var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
  font-weight: 700;
}

.avatar-thumb.has-image {
  border-style: solid;
  background-position: center;
  background-size: cover;
  color: transparent;
}

.upload-button {
  display: inline-grid;
  min-height: 38px;
  align-items: center;
  padding: 0 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

#avatarInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.avatar-control p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.template-card {
  display: grid;
  gap: 8px;
  min-height: 86px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}

.template-card span {
  display: block;
  height: 36px;
  border-radius: 6px;
  background:
    linear-gradient(90deg, var(--accent) 0 22%, transparent 22%),
    linear-gradient(#d9ddd9 0 0) 32px 8px / 70% 4px no-repeat,
    linear-gradient(#d9ddd9 0 0) 32px 18px / 56% 4px no-repeat,
    #f7f8f6;
}

.template-card strong {
  font-size: 13px;
}

.template-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 115, 0.12);
}

.template-card[data-template="classic"] span {
  background:
    linear-gradient(#20242a 0 0) 10px 8px / 42% 5px no-repeat,
    linear-gradient(#d9ddd9 0 0) 10px 20px / 80% 3px no-repeat,
    linear-gradient(#d9ddd9 0 0) 10px 28px / 68% 3px no-repeat,
    #f7f8f6;
}

.template-card[data-template="sidebar"] span {
  background:
    linear-gradient(90deg, #243947 0 34%, transparent 34%),
    linear-gradient(#d9ddd9 0 0) 44% 9px / 45% 4px no-repeat,
    linear-gradient(#d9ddd9 0 0) 44% 20px / 38% 4px no-repeat,
    #f7f8f6;
}

.template-card[data-template="timeline"] span {
  background:
    radial-gradient(circle at 18px 10px, var(--accent) 0 4px, transparent 5px),
    radial-gradient(circle at 18px 24px, var(--accent) 0 4px, transparent 5px),
    linear-gradient(90deg, transparent 16px, var(--accent) 16px 19px, transparent 19px),
    linear-gradient(#d9ddd9 0 0) 34px 9px / 62% 4px no-repeat,
    linear-gradient(#d9ddd9 0 0) 34px 23px / 52% 4px no-repeat,
    #f7f8f6;
}

.template-card[data-template="formal"] span {
  background:
    linear-gradient(#20242a 0 0) center 7px / 56% 5px no-repeat,
    linear-gradient(#9b8d72 0 0) center 18px / 80% 2px no-repeat,
    linear-gradient(#d9ddd9 0 0) center 28px / 64% 3px no-repeat,
    #f7f8f6;
}

.ghost {
  min-height: 34px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 230px;
  overflow: auto;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.history-load {
  min-width: 0;
  padding: 0;
  color: inherit;
  background: transparent;
  text-align: left;
}

.history-item strong {
  display: block;
  overflow: hidden;
  margin-bottom: 2px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item span {
  color: var(--muted);
  font-size: 12px;
}

.history-actions {
  display: flex;
  gap: 6px;
}

.history-actions button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--muted);
  background: var(--soft);
}

.history-actions button:last-child {
  color: var(--danger);
}

.resume-form {
  display: grid;
  gap: 26px;
}

.resume-form section {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 115, 0.12);
}

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

.dynamic-list {
  display: grid;
  gap: 12px;
}

.field-card {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.remove-button {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: var(--danger);
  background: transparent;
  font-size: 20px;
  line-height: 1;
}

.add-button {
  width: 100%;
}

.preview-panel {
  height: 100vh;
  overflow: auto;
  padding: 28px;
}

.preview-actions {
  max-width: 900px;
  margin: 0 auto 16px;
  color: var(--muted);
  font-size: 13px;
}

.resume-page {
  width: min(900px, 100%);
  min-height: 1272px;
  margin: 0 auto;
  padding: 58px 64px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(32, 36, 42, 0.12);
}

.resume-body {
  display: block;
}

.resume-head {
  align-items: flex-start;
  padding-bottom: 28px;
  border-bottom: 2px solid var(--ink);
}

.resume-avatar {
  display: none;
  width: 104px;
  height: 104px;
  overflow: hidden;
  flex: 0 0 auto;
  margin: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #eef1ee;
  box-shadow: 0 0 0 1px var(--line);
}

.resume-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.resume-page.has-avatar .resume-avatar {
  display: block;
}

.resume-page.has-avatar .resume-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
}

.resume-head h2 {
  margin-bottom: 8px;
  font-size: 42px;
  line-height: 1;
}

.resume-head p {
  margin-bottom: 0;
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
}

.contact-list {
  display: grid;
  gap: 6px;
  max-width: 280px;
  margin: 0;
  padding: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  list-style: none;
  text-align: right;
}

.resume-section {
  display: grid;
  gap: 12px;
  margin-top: 28px;
}

.resume-section h3 {
  margin-bottom: 2px;
  color: var(--accent-dark);
  font-size: 15px;
  letter-spacing: 0;
}

.resume-section p,
.resume-item li {
  color: #343a42;
  font-size: 14px;
  line-height: 1.75;
}

.resume-items {
  display: grid;
  gap: 18px;
}

.resume-items.compact {
  gap: 10px;
}

.resume-item-title {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  margin-bottom: 6px;
}

.resume-item-title strong {
  font-size: 15px;
}

.resume-item-title span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.resume-item-subtitle {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.resume-item ul {
  margin: 0;
  padding-left: 18px;
}

.skill-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.skill-tags span {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #30363d;
  background: #fbfcfa;
  font-size: 13px;
}

.template-classic {
  padding: 54px 66px;
}

.template-classic .resume-head {
  display: block;
  padding-bottom: 18px;
  text-align: center;
  border-bottom: 1px solid #20242a;
}

.template-classic.has-avatar .resume-avatar,
.template-formal.has-avatar .resume-avatar {
  margin: 0 auto 16px;
}

.template-classic .resume-head h2 {
  font-size: 38px;
}

.template-classic .contact-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: none;
  margin-top: 14px;
  gap: 10px 16px;
  text-align: center;
}

.template-classic .resume-section {
  grid-template-columns: 120px 1fr;
  gap: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid #ecefea;
}

.template-classic .resume-section h3 {
  color: #20242a;
}

.template-sidebar {
  display: grid;
  grid-template-columns: 255px 1fr;
  column-gap: 34px;
  align-items: start;
  padding: 0;
  overflow: hidden;
  background: linear-gradient(90deg, #243947 0 255px, #fff 255px);
}

.template-sidebar .resume-head {
  display: contents;
  padding: 0;
  border-bottom: 0;
}

.template-sidebar.has-avatar .resume-avatar {
  grid-column: 1;
  grid-row: 1;
  width: 118px;
  height: 118px;
  margin: 42px auto 12px;
  border-color: rgba(255, 255, 255, 0.92);
}

.template-sidebar .resume-head > div,
.template-sidebar .skills-section,
.template-sidebar .education-section {
  background: transparent;
}

.template-sidebar .resume-head > div {
  grid-column: 1;
  grid-row: 1;
  width: 255px;
  min-height: 150px;
  padding: 44px 28px 18px;
}

.template-sidebar.has-avatar .resume-head > div {
  grid-row: 2;
  min-height: 0;
  padding-top: 0;
  text-align: center;
}

.template-sidebar .resume-head h2,
.template-sidebar .resume-head p,
.template-sidebar .contact-list,
.template-sidebar .resume-head .contact-list li {
  color: #fff;
}

.template-sidebar .resume-head h2 {
  font-size: 34px;
}

.template-sidebar .contact-list {
  grid-column: 1;
  grid-row: 2;
  width: 255px;
  max-width: 255px;
  padding: 0 28px 26px;
  text-align: left;
}

.template-sidebar.has-avatar .contact-list {
  grid-row: 3;
  padding-top: 8px;
}

.template-sidebar .resume-body {
  display: contents;
}

.template-sidebar .summary-section,
.template-sidebar .experience-section,
.template-sidebar .project-section {
  grid-column: 2;
  padding-right: 48px;
  margin-top: 0;
}

.template-sidebar .education-section,
.template-sidebar .skills-section {
  grid-column: 1;
  margin-top: 0;
  padding: 24px 28px 0;
}

.template-sidebar .education-section {
  grid-row: 3;
}

.template-sidebar .skills-section {
  grid-row: 4;
  padding-bottom: 56px;
}

.template-sidebar.has-avatar .education-section {
  grid-row: 4;
}

.template-sidebar.has-avatar .skills-section {
  grid-row: 5;
}

.template-sidebar .summary-section {
  grid-row: 1 / span 2;
  padding-top: 44px;
}

.template-sidebar .experience-section {
  grid-row: 3;
}

.template-sidebar .project-section {
  grid-row: 4;
  padding-bottom: 56px;
}

.template-sidebar .education-section h3,
.template-sidebar .skills-section h3,
.template-sidebar .education-section *,
.template-sidebar .skills-section * {
  color: #fff;
}

.template-sidebar .skill-tags span {
  border-color: rgba(255, 255, 255, 0.24);
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.template-timeline .resume-head {
  border-bottom: 0;
}

.template-timeline .resume-head h2 {
  font-size: 40px;
}

.template-timeline .resume-section {
  position: relative;
  padding-left: 32px;
}

.template-timeline .resume-section::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 3px;
  bottom: 0;
  width: 2px;
  background: #d2dedb;
}

.template-timeline .resume-section h3::before {
  content: "";
  position: absolute;
  left: 2px;
  width: 14px;
  height: 14px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.template-timeline .resume-item {
  padding: 12px 0 0;
}

.template-formal {
  padding: 56px 70px;
  font-family: Georgia, "Times New Roman", "Songti SC", serif;
}

.template-formal .resume-head {
  display: block;
  text-align: center;
  border-bottom: 3px double #9b8d72;
}

.template-formal .resume-head h2 {
  font-size: 40px;
  letter-spacing: 0;
}

.template-formal .resume-head p {
  color: #7c6d53;
}

.template-formal .contact-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: none;
  margin-top: 14px;
  gap: 10px 18px;
  text-align: center;
}

.template-formal .resume-section h3 {
  padding-bottom: 7px;
  border-bottom: 1px solid #cfc6b4;
  color: #20242a;
  font-size: 16px;
}

.template-formal .skill-tags span {
  border-radius: 0;
  background: #faf8f2;
}

.empty-state {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .editor-panel,
  .preview-panel {
    height: auto;
  }

  .editor-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .resume-page {
    min-height: auto;
    padding: 40px 28px;
  }

  .resume-page.template-sidebar {
    padding: 0;
  }
}

@media (max-width: 620px) {
  .editor-panel,
  .preview-panel {
    padding: 18px;
  }

  .two-col,
  .toolbar,
  .resume-item-title {
    grid-template-columns: 1fr;
  }

  .resume-head,
  .editor-header,
  .section-title-row,
  .preview-actions {
    align-items: flex-start;
  }

  .contact-list {
    max-width: none;
    text-align: left;
  }

  .resume-head h2 {
    font-size: 34px;
  }

  .template-classic .resume-section {
    display: grid;
    grid-template-columns: 1fr;
  }

  .template-sidebar {
    display: block;
    padding: 0 0 28px;
    background: #fff;
  }

  .template-sidebar .resume-head,
  .template-sidebar .resume-body {
    display: block;
  }

  .template-sidebar .resume-head > div,
  .template-sidebar .contact-list {
    width: 100%;
    max-width: none;
    background: #243947;
  }

  .template-sidebar .resume-head > div,
  .template-sidebar .contact-list,
  .template-sidebar .education-section,
  .template-sidebar .skills-section,
  .template-sidebar .summary-section,
  .template-sidebar .experience-section,
  .template-sidebar .project-section {
    grid-column: 1;
  }

  .template-sidebar .contact-list {
    padding: 24px 28px;
  }

  .template-sidebar .summary-section,
  .template-sidebar .experience-section,
  .template-sidebar .project-section,
  .template-sidebar .education-section,
  .template-sidebar .skills-section {
    padding: 24px 28px 0;
  }

  .template-sidebar .education-section,
  .template-sidebar .skills-section,
  .template-sidebar .summary-section,
  .template-sidebar .experience-section,
  .template-sidebar .project-section {
    grid-row: auto;
  }

  .template-sidebar .education-section h3,
  .template-sidebar .skills-section h3,
  .template-sidebar .education-section *,
  .template-sidebar .skills-section * {
    color: var(--ink);
  }
}

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

  .editor-panel,
  .preview-actions {
    display: none;
  }

  .app-shell,
  .preview-panel {
    display: block;
    height: auto;
    overflow: visible;
    padding: 0;
  }

  .resume-page {
    width: 100%;
    min-height: 0;
    margin: 0;
    padding: 18mm 17mm;
    border-radius: 0;
    box-shadow: none;
  }

  .resume-page.template-sidebar {
    padding: 0;
  }

  @page {
    size: A4;
    margin: 0;
  }
}
