:root {
  --ink: #17231f;
  --ink-soft: #4d5954;
  --paper: #f1eee7;
  --paper-deep: #e6e0d4;
  --panel: #fbfaf6;
  --accent: #dd4f2d;
  --accent-dark: #b9361b;
  --line: rgba(23, 35, 31, .16);
  --radius: 4px;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); }

body { margin: 0; min-height: 100vh; background: var(--paper); }

button, input, select, textarea { color: inherit; font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important; clip: rect(0 0 0 0) !important; white-space: nowrap !important; }

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 30;
  opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.9'/%3E%3C/svg%3E");
}

.wordmark {
  color: inherit;
  font: 800 20px/1 Arial, sans-serif;
  letter-spacing: -.06em;
  text-decoration: none;
  text-transform: uppercase;
}

.wordmark span { color: var(--accent); }
.eyebrow { margin: 0 0 12px; font-size: 11px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
.muted { color: var(--ink-soft); }

.login-layout { display: grid; min-height: 100vh; grid-template-columns: minmax(0, 1.15fr) minmax(420px, .85fr); }
.login-intro { display: flex; flex-direction: column; justify-content: space-between; padding: 48px clamp(36px, 7vw, 108px); background: var(--ink); color: var(--paper); }
.login-intro .wordmark { font-size: 25px; }
.login-intro h1 { margin: 0; max-width: 780px; font: 400 clamp(54px, 7vw, 108px)/.88 Georgia, serif; letter-spacing: -.065em; }
.login-intro .lead { max-width: 560px; margin: 35px 0 0; color: #c8cec9; font-size: clamp(17px, 1.5vw, 21px); line-height: 1.55; }
.fineprint { margin: 0; color: #89948e; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.login-panel { display: grid; place-items: center; padding: 40px; }
.login-card { display: grid; gap: 22px; width: min(100%, 420px); }
.login-card h2, .sidebar h2, .canvas-toolbar h2, .upload-card h2, .library h2 { margin: 0; font: 400 34px/1.1 Georgia, serif; letter-spacing: -.03em; }
.login-card code { padding: 2px 5px; background: var(--paper-deep); }

.field { display: grid; gap: 8px; }
.field > span { font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.field input, .field select, .field textarea {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: 0;
  background: rgba(255,255,255,.7);
  padding: 13px 14px;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(221,79,45,.12); }
.field textarea { resize: vertical; line-height: 1.45; }
.form-error { min-height: 18px; margin: -5px 0; color: #a72d19; font-size: 13px; line-height: 1.4; }

.button { display: inline-flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 50px; border: 1px solid transparent; border-radius: var(--radius); padding: 13px 18px; font-weight: 800; }
.button-primary { background: var(--accent); color: white; }
.button-primary:hover { background: var(--accent-dark); }
.button-secondary { border-color: var(--line); background: transparent; }
.button-secondary:hover { border-color: var(--ink); }
.button-wide { width: 100%; }

.topbar { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 72px; border-bottom: 1px solid var(--line); background: rgba(241,238,231,.94); padding: 0 28px; backdrop-filter: blur(16px); }
.main-nav { align-self: stretch; display: flex; gap: 25px; }
.nav-button { position: relative; border: 0; background: none; padding: 0 5px; color: var(--ink-soft); font-size: 13px; font-weight: 700; }
.nav-button.active { color: var(--ink); }
.nav-button.active::after { position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; background: var(--accent); content: ''; }
.account { display: flex; align-items: center; justify-content: flex-end; gap: 10px; color: var(--ink-soft); font-size: 12px; font-weight: 700; }
.account::before { width: 7px; height: 7px; border-radius: 50%; background: #599b65; content: ''; }
.icon-button { display: grid; width: 34px; height: 34px; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: transparent; }

.workspace { display: grid; min-height: calc(100vh - 72px); grid-template-columns: 340px minmax(0, 1fr); }
.sidebar { position: sticky; top: 72px; align-self: start; display: grid; gap: 23px; max-height: calc(100vh - 72px); overflow: auto; border-right: 1px solid var(--line); padding: 32px 28px; }
.sidebar-heading { padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.field-group { display: grid; gap: 13px; padding-top: 20px; border-top: 1px solid var(--line); }
.field-group-title { margin: 0; font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.group-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hint { color: var(--ink-soft); font-size: 11px; }
.segmented { display: flex; flex-wrap: wrap; gap: 3px; padding: 3px; border-radius: var(--radius); background: var(--paper-deep); }
.segmented button { flex: 1 1 30%; border: 0; border-radius: 3px; background: transparent; padding: 8px 4px; font-size: 11px; font-weight: 700; }
.segmented button.active { background: var(--panel); box-shadow: 0 1px 6px rgba(23,35,31,.1); }
.additional-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.additional-heading > span { font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.add-field-button { border: 0; background: transparent; padding: 3px 0; color: var(--accent); font-size: 11px; font-weight: 800; }
.additional-fields { display: grid; gap: 9px; }
.additional-empty { margin: 0; color: var(--ink-soft); font-size: 11px; line-height: 1.45; }
.additional-row { display: grid; grid-template-columns: minmax(0, 1fr) 34px; align-items: stretch; gap: 7px; }
.additional-row label { display: grid; gap: 5px; }
.additional-row label > span { font-size: 9px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.additional-row textarea { width: 100%; min-height: 58px; resize: vertical; border: 1px solid var(--line); border-radius: var(--radius); outline: 0; background: rgba(255,255,255,.7); padding: 9px 10px; font-size: 12px; line-height: 1.4; }
.additional-row textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(221,79,45,.12); }
.remove-field-button { align-self: end; width: 34px; height: 58px; border: 1px solid var(--line); border-radius: var(--radius); background: transparent; color: var(--ink-soft); font-size: 20px; }
.remove-field-button:hover { border-color: var(--accent); color: var(--accent); }
.editor-image-list { display: grid; gap: 8px; }
.editor-image-item { display: grid; grid-template-columns: 48px minmax(0, 1fr) 32px; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; background: rgba(255,255,255,.38); cursor: pointer; }
.editor-image-item.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(221,79,45,.1); }
.editor-image-item img { width: 48px; height: 42px; object-fit: contain; background: var(--paper-deep); }
.editor-image-item span { overflow: hidden; font-size: 11px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.remove-image-button { display: grid; width: 30px; height: 30px; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--ink-soft); font-size: 17px; }
.remove-image-button:hover { border-color: var(--accent); color: var(--accent); }
.image-control-note { margin: 0; color: var(--ink-soft); font-size: 10px; line-height: 1.45; }
.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.compact { gap: 5px; }
.compact > span { font-size: 9px; }
.compact input, .compact select { padding: 9px 10px; font-size: 12px; }
.span-2 { grid-column: span 2; }
.color-field input { min-height: 36px; padding: 4px; }

.canvas-area { min-width: 0; padding: 38px clamp(24px, 4vw, 64px) 70px; }
.canvas-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 25px; margin-bottom: 28px; }
.drag-note { margin: 0; color: var(--ink-soft); font-size: 12px; }
.drag-note span { color: var(--accent); font-size: 18px; }
.canvas-grid { display: grid; gap: 38px; }
.side-card { min-width: 0; }
.side-card-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.side-card-heading > span { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 50%; background: var(--ink); color: white; font-size: 9px; }
.side-card-heading h3 { margin: 0; font: 600 14px/1 Arial, sans-serif; }
.visibility-toggle { margin-left: auto; color: var(--ink-soft); font-size: 11px; }
.visibility-toggle input { accent-color: var(--accent); }
.canvas-shell { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background-color: #d9d5cc; background-image: linear-gradient(45deg,#c9c4b9 25%,transparent 25%),linear-gradient(-45deg,#c9c4b9 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#c9c4b9 75%),linear-gradient(-45deg,transparent 75%,#c9c4b9 75%); background-position: 0 0,0 8px,8px -8px,-8px 0; background-size: 16px 16px; box-shadow: 0 18px 50px rgba(23,35,31,.1); }
.canvas-shell canvas { display: block; width: 100%; height: auto; touch-action: none; }
.empty-state { display: grid; min-height: 460px; place-items: center; align-content: center; border: 1px dashed rgba(23,35,31,.25); border-radius: var(--radius); text-align: center; }
.empty-icon { display: grid; width: 72px; height: 72px; place-items: center; margin-bottom: 18px; border: 1px solid var(--ink); border-radius: 50%; font: italic 36px Georgia,serif; }
.empty-state h3 { margin: 0 0 7px; font: 400 27px Georgia, serif; }
.empty-state p { max-width: 380px; margin: 0; color: var(--ink-soft); line-height: 1.5; }

.admin-page, .result-page { min-height: calc(100vh - 72px); padding: 55px clamp(24px, 6vw, 96px) 90px; }
.admin-hero, .result-heading { display: flex; align-items: end; justify-content: space-between; gap: 50px; padding-bottom: 40px; border-bottom: 1px solid var(--line); }
.admin-hero h1, .result-heading h1 { margin: 0; font: 400 clamp(54px, 7vw, 92px)/.9 Georgia, serif; letter-spacing: -.055em; }
.admin-hero > p, .result-heading > div > p:last-child { max-width: 520px; margin: 0; color: var(--ink-soft); line-height: 1.6; }
.admin-grid { display: grid; grid-template-columns: minmax(320px, 430px) minmax(0, 1fr); gap: clamp(40px, 7vw, 110px); padding-top: 45px; }
.upload-card { display: grid; align-content: start; gap: 20px; }
.step-number { display: inline-block; margin-bottom: 8px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .15em; text-transform: uppercase; }
.drop-field { position: relative; display: flex; align-items: center; gap: 16px; min-height: 88px; border: 1px dashed rgba(23,35,31,.35); border-radius: var(--radius); padding: 14px; background: rgba(255,255,255,.35); cursor: pointer; }
.drop-field:hover { border-color: var(--accent); }
.drop-field input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-icon { display: grid; flex: 0 0 auto; width: 50px; height: 50px; place-items: center; border-radius: 50%; background: var(--paper-deep); font-size: 10px; font-weight: 800; }
.drop-field > span:last-child { display: grid; gap: 5px; min-width: 0; }
.drop-field strong, .drop-field small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drop-field small { color: var(--ink-soft); }
.dimension-note { margin: -6px 0 0; color: var(--ink-soft); font-size: 12px; }
.dimension-note.valid { color: #327041; }
.dimension-note.invalid { color: #a72d19; }
.library-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 24px; }
.counter { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 50%; background: var(--ink); color: white; font-size: 12px; }
.template-list { display: grid; gap: 14px; }
.template-item { display: grid; grid-template-columns: 140px minmax(0, 1fr) auto; align-items: center; gap: 20px; border-top: 1px solid var(--line); padding: 14px 0 0; }
.template-thumbs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.template-thumbs img { width: 100%; aspect-ratio: 1.6; object-fit: cover; background: #ddd; }
.template-meta h3 { margin: 0 0 6px; font: 400 20px Georgia,serif; }
.template-meta p { margin: 0; color: var(--ink-soft); font-size: 11px; }
.delete-button { border: 1px solid var(--line); border-radius: 50%; background: transparent; width: 38px; height: 38px; }
.delete-button:hover { border-color: var(--accent); color: var(--accent); }
.built-in-mark { color: var(--accent); font-size: 9px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.library-empty { padding: 60px 20px; border: 1px dashed var(--line); color: var(--ink-soft); text-align: center; }

.result-heading { align-items: center; }
.result-heading > div > p:last-child { margin-top: 20px; }
.result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 35px; padding-top: 45px; }
.result-card { display: grid; gap: 13px; }
.result-card img { width: 100%; border: 1px solid var(--line); box-shadow: 0 18px 50px rgba(23,35,31,.1); }
.result-card-header { display: flex; align-items: center; justify-content: space-between; }
.result-card h2 { margin: 0; font: 400 24px Georgia, serif; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.result-actions .button { min-height: 42px; padding: 9px 14px; font-size: 12px; text-decoration: none; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: min(380px, calc(100vw - 48px)); transform: translateY(30px); border-radius: var(--radius); background: var(--ink); color: white; padding: 14px 18px; opacity: 0; pointer-events: none; transition: .2s; }
.toast.visible { transform: translateY(0); opacity: 1; }

@media (min-width: 1280px) {
  .canvas-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}

@media (max-width: 900px) {
  .login-layout { grid-template-columns: 1fr; }
  .login-intro { min-height: 48vh; padding: 30px; }
  .login-intro h1 { font-size: clamp(50px, 14vw, 84px); }
  .login-intro .lead { margin-top: 20px; }
  .fineprint { display: none; }
  .login-panel { padding: 50px 24px; }
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .admin-grid { grid-template-columns: 1fr; }
  .admin-hero, .result-heading { align-items: start; flex-direction: column; }
}

@media (max-width: 620px) {
  .topbar { grid-template-columns: 1fr auto; min-height: 64px; padding: 0 16px; }
  .main-nav { position: fixed; right: 0; bottom: 0; left: 0; z-index: 25; justify-content: center; height: 58px; border-top: 1px solid var(--line); background: var(--panel); }
  .nav-button { min-width: 120px; }
  .nav-button.active::after { top: -1px; bottom: auto; }
  .account #account-label { display: none; }
  .workspace, .admin-page, .result-page { padding-bottom: 80px; }
  .sidebar { padding: 27px 20px; }
  .canvas-area { padding: 30px 16px 85px; }
  .canvas-toolbar { align-items: start; flex-direction: column; }
  .admin-page, .result-page { padding: 38px 20px 90px; }
  .template-item { grid-template-columns: 105px minmax(0,1fr) auto; gap: 10px; }
  .result-grid { grid-template-columns: 1fr; }
}
