:root {
  --ink: #211811;
  --muted: #786a5d;
  --paper: #fbf4e7;
  --paper-deep: #efe0c8;
  --wood: #5a321e;
  --wood-dark: #27140d;
  --brass: #c98a2f;
  --olive: #526448;
  --cream: #fffaf0;
  --line: rgba(65, 38, 20, 0.16);
  --shadow: 0 20px 60px rgba(54, 32, 19, 0.16);
  --radius: 8px;
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  overflow-x: hidden;
  background:
    linear-gradient(120deg, rgba(39, 20, 13, 0.08), transparent 34%),
    radial-gradient(circle at top right, rgba(201, 138, 47, 0.22), transparent 30%),
    repeating-linear-gradient(92deg, rgba(90, 50, 30, 0.045) 0 2px, transparent 2px 13px),
    var(--paper);
}

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

button,
input,
textarea {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px clamp(18px, 4vw, 46px);
  border-bottom: 1px solid var(--line);
  background: rgba(251, 244, 231, 0.86);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand span:last-child {
  min-width: 0;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.brand-mark {
  display: inline-block;
  width: 34px;
  aspect-ratio: 1;
  border-radius: 50% 50% 46% 54%;
  background:
    linear-gradient(145deg, rgba(255, 250, 240, 0.55), transparent 42%),
    linear-gradient(160deg, var(--brass), var(--wood));
  box-shadow: inset 0 -8px 18px rgba(39, 20, 13, 0.24), 0 10px 24px rgba(90, 50, 30, 0.2);
  transform: rotate(-18deg);
}

.brand-mark.large {
  width: 62px;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topnav a,
.ghost-button,
.ghost-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 240, 0.68);
  color: var(--wood-dark);
  cursor: pointer;
}

.topnav form {
  margin: 0;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 13px 20px;
  border: 0;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--wood-dark), var(--wood) 62%, var(--brass));
  color: var(--cream);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 16px 34px rgba(90, 50, 30, 0.24);
}

.primary-button.compact {
  min-height: 42px;
  padding: 10px 16px;
}

.flash {
  width: min(960px, calc(100% - 32px));
  margin: 16px auto 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--cream);
}

.flash.error {
  border-color: rgba(165, 64, 45, 0.36);
  color: #8d3322;
}

.flash.success {
  border-color: rgba(82, 100, 72, 0.36);
  color: var(--olive);
}

.auth-shell {
  display: grid;
  min-height: 100svh;
  padding: 24px;
  place-items: center;
}

.auth-panel {
  display: grid;
  width: min(980px, 100%);
  min-height: 560px;
  grid-template-columns: 1.05fr 0.95fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(255, 250, 240, 0.86), rgba(239, 224, 200, 0.9)),
    var(--paper);
  box-shadow: var(--shadow);
}

.auth-copy {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 18px;
  padding: clamp(28px, 6vw, 58px);
  color: var(--cream);
  background:
    linear-gradient(150deg, rgba(39, 20, 13, 0.18), rgba(39, 20, 13, 0.78)),
    repeating-linear-gradient(102deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 14px),
    linear-gradient(135deg, #7b472a, #2a160e);
}

.auth-copy h1,
.page-heading h1,
.preview-heading h1,
.empty-state h1,
.empty-state h2 {
  margin: 0;
  line-height: 1.05;
  letter-spacing: 0;
}

.auth-copy h1 {
  max-width: 460px;
  font-size: 64px;
}

.auth-copy p {
  max-width: 420px;
  margin: 0;
  color: rgba(255, 250, 240, 0.8);
}

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

.form-panel,
.upload-form {
  display: grid;
  gap: 18px;
  align-content: center;
  padding: clamp(24px, 5vw, 54px);
}

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

input,
textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 13px;
  background: rgba(255, 250, 240, 0.8);
  color: var(--ink);
  outline: none;
}

input[type="file"] {
  min-height: auto;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: rgba(201, 138, 47, 0.8);
  box-shadow: 0 0 0 4px rgba(201, 138, 47, 0.14);
}

.workspace {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 72px;
}

.workspace.narrow {
  width: min(820px, calc(100% - 32px));
}

.page-heading,
.preview-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.page-heading > div,
.preview-heading > div,
.tab-card-main {
  min-width: 0;
}

.page-heading h1,
.preview-heading h1 {
  font-size: 52px;
  overflow-wrap: anywhere;
}

.tab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.tab-card,
.empty-state,
.upload-form,
.note-strip,
.preview-stage {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 240, 0.78);
  box-shadow: 0 14px 40px rgba(54, 32, 19, 0.08);
}

.tab-card {
  display: grid;
  min-height: 238px;
  overflow: hidden;
}

.tab-card-main {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 20px;
}

.tab-card h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.tab-card p {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.file-chip {
  width: fit-content;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(82, 100, 72, 0.13);
  color: var(--olive);
  font-size: 12px;
  font-weight: 900;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.meta-row span {
  max-width: 100%;
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(239, 224, 200, 0.72);
  overflow-wrap: anywhere;
}

.meta-row.wide {
  margin-top: 12px;
}

.card-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: rgba(239, 224, 200, 0.42);
}

.card-actions form {
  margin: 0;
}

.card-actions a,
.card-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 0;
  background: transparent;
  color: var(--wood);
  cursor: pointer;
  font-weight: 700;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 16px;
  padding: 56px 20px;
  text-align: center;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

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

.file-drop {
  padding: 18px;
  border: 1px dashed rgba(90, 50, 30, 0.35);
  border-radius: var(--radius);
  background: rgba(239, 224, 200, 0.38);
}

.file-drop small {
  color: var(--muted);
  font-weight: 500;
}

.account-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 14px;
  border-radius: var(--radius);
  background: rgba(239, 224, 200, 0.42);
}

.account-summary > div {
  min-width: 0;
}

.account-summary strong,
.account-summary small {
  display: block;
  overflow-wrap: anywhere;
}

.account-summary small,
.help-text {
  color: var(--muted);
}

.help-text {
  margin: -4px 0 0;
  font-size: 13px;
  line-height: 1.55;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.note-strip {
  margin-bottom: 16px;
  padding: 16px;
  color: var(--wood-dark);
  white-space: pre-wrap;
}

.preview-stage {
  min-height: 68vh;
  overflow: auto;
  touch-action: pan-x pan-y pinch-zoom;
  -webkit-overflow-scrolling: touch;
}

.preview-stage iframe {
  display: block;
  width: 100%;
  height: 72vh;
  border: 0;
  background: var(--cream);
}

.preview-stage img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.preview-stage pre {
  min-height: 64vh;
  margin: 0;
  padding: 24px;
  overflow: auto;
  color: #1b1713;
  background:
    linear-gradient(rgba(255, 250, 240, 0.92), rgba(255, 250, 240, 0.92)),
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(90, 50, 30, 0.12) 31px 32px);
  line-height: 32px;
  white-space: pre-wrap;
}

@media (max-width: 760px) {
  body {
    background:
      linear-gradient(130deg, rgba(39, 20, 13, 0.07), transparent 38%),
      radial-gradient(circle at top right, rgba(201, 138, 47, 0.18), transparent 34%),
      var(--paper);
  }

  .topbar,
  .page-heading,
  .preview-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    gap: 12px;
    padding: 12px 14px;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 30px;
    flex: 0 0 auto;
  }

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

  .topnav a,
  .topnav form,
  .topnav button {
    width: 100%;
  }

  .topnav a,
  .ghost-button,
  .ghost-link {
    min-height: 42px;
    padding: 9px 10px;
  }

  .auth-shell {
    align-items: start;
    padding: 12px;
  }

  .auth-panel {
    grid-template-columns: 1fr;
    min-height: auto;
    border-radius: 12px;
  }

  .auth-copy {
    min-height: 210px;
    gap: 12px;
    padding: 26px 22px;
  }

  .auth-copy h1 {
    font-size: 38px;
  }

  .auth-copy p {
    font-size: 15px;
  }

  .form-panel,
  .upload-form {
    gap: 15px;
    padding: 20px;
  }

  input,
  textarea {
    min-height: 46px;
    font-size: 16px;
  }

  .flash {
    width: calc(100% - 24px);
    margin-top: 12px;
  }

  .workspace,
  .workspace.narrow {
    width: calc(100% - 24px);
    padding: 22px 0 42px;
  }

  .page-heading,
  .preview-heading {
    gap: 12px;
    margin-bottom: 16px;
  }

  .page-heading h1,
  .preview-heading h1 {
    font-size: 34px;
  }

  .page-heading .primary-button,
  .preview-actions,
  .preview-actions .primary-button,
  .preview-actions .ghost-link {
    width: 100%;
  }

  .tab-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .tab-card {
    min-height: auto;
  }

  .tab-card-main {
    gap: 10px;
    padding: 16px;
  }

  .tab-card h2 {
    font-size: 22px;
  }

  .card-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 10px 12px;
  }

  .card-actions a,
  .card-actions button {
    min-height: 38px;
    padding: 0 6px;
  }

  .empty-state {
    gap: 12px;
    padding: 38px 16px;
  }

  .empty-state h1,
  .empty-state h2 {
    font-size: 28px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  .file-drop {
    padding: 14px;
  }

  .account-summary {
    padding: 12px;
  }

  .preview-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .note-strip {
    margin-bottom: 12px;
    padding: 14px;
    font-size: 14px;
  }

  .preview-stage {
    min-height: 62svh;
    overflow: auto;
  }

  .preview-stage iframe {
    height: 64svh;
    min-height: 520px;
  }

  .preview-stage pre {
    min-height: 58svh;
    padding: 18px;
    font-size: 14px;
    line-height: 28px;
  }
}

@media (max-width: 430px) {
  .auth-copy h1 {
    font-size: 34px;
  }

  .page-heading h1,
  .preview-heading h1 {
    font-size: 30px;
  }

  .topnav a,
  .ghost-button,
  .ghost-link {
    font-size: 14px;
  }

  .preview-actions {
    grid-template-columns: 1fr;
  }

  .meta-row {
    font-size: 12px;
  }
}

@media (max-width: 360px) {
  .brand small {
    display: none;
  }

  .topbar {
    padding-inline: 10px;
  }

  .workspace,
  .workspace.narrow {
    width: calc(100% - 16px);
  }
}
