:root {
  --bg: #f7f5f0;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #5f6670;
  --border: #ddd8cc;
  --accent: #2f62b0;
  --accent-text: #ffffff;
  --warn-bg: #fff6dc;
  --warn-border: #e6c35c;
  --error: #b3261e;
  --fabric-head: #f1eee6;
  --grid-line: rgba(0, 0, 0, 0.35);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c;
    --panel: #212429;
    --text: #e8e6e1;
    --muted: #a3a8b0;
    --border: #3a3e45;
    --accent: #7fa8e8;
    --accent-text: #10151d;
    --warn-bg: #3a3120;
    --warn-border: #8a7232;
    --error: #ff8a80;
    --fabric-head: #2a2d33;
    --grid-line: rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* "hidden" always wins over a display rule */

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.site-header { padding: 24px 16px 8px; max-width: 1280px; margin: 0 auto; display: flex; gap: 12px 24px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.site-header h1 { margin: 0 0 4px; font-size: 1.6rem; }
.site-header p { margin: 0; color: var(--muted); }

.layout {
  display: grid;
  gap: 16px;
  padding: 16px;
  max-width: 1280px;
  margin: 0 auto;
  grid-template-columns: minmax(260px, 320px) minmax(280px, 380px) 1fr;
  align-items: start;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(260px, 1fr) minmax(280px, 1fr); }
  .results { grid-column: 1 / -1; }
}

@media (max-width: 680px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}

h2 { font-size: 1.15rem; margin: 20px 0 8px; }
h2:first-child, .preview-head h2 { margin-top: 0; }
h3 { font-size: 1rem; margin: 16px 0 4px; }

label { display: block; font-weight: 600; margin: 12px 0 4px; font-size: 0.92rem; }
label.inline { display: inline-flex; gap: 6px; align-items: center; font-weight: 400; margin: 0; }

input[type="text"], select, input[type="file"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

button {
  font: inherit;
  border-radius: 8px;
  padding: 8px 14px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
#recognize { margin-top: 12px; width: 100%; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.tabs button {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  padding: 8px 10px;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.hint { color: var(--muted); font-size: 0.88rem; margin: 6px 0 0; }
.error { color: var(--error); font-weight: 600; }

.notes {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 12px 0;
  font-size: 0.92rem;
}
.notes p { margin: 4px 0; }

/* Handles can sit right on the photo's corners, so let them overflow its edge. */
.photo-stage { position: relative; margin: 20px 10px 14px; }
.photo-stage img { display: block; width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--border); }
.photo-overlay { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; overflow: visible; }
.photo-overlay .outline { fill: rgba(47, 98, 176, 0.08); stroke: #3ddc84; }
.photo-overlay .gridline { stroke: #3ddc84; opacity: 0.8; }
.photo-overlay .handle { fill: #ffffff; stroke: #1f7a46; cursor: grab; }
.photo-overlay .handle:active { cursor: grabbing; }
button.small { padding: 4px 10px; font-size: 0.88rem; margin-top: 8px; }

.preview-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.block-svg { margin-top: 12px; }
.block-svg svg { width: 100%; height: auto; display: block; border-radius: 4px; box-shadow: 0 1px 4px rgba(0,0,0,0.18); }

.fabric-list { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.fabric-list li { display: flex; align-items: center; gap: 8px; }
.fabric-list input[type="color"] {
  width: 36px; height: 32px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; flex: none;
}
.fabric-list input[type="text"] { flex: 1; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th.num, td.num { text-align: right; white-space: nowrap; }
td.size { white-space: nowrap; font-weight: 600; }
tr.fabric-head td { background: var(--fabric-head); font-weight: 700; }
.swatch {
  display: inline-block; width: 14px; height: 14px; border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.25); vertical-align: -2px; margin-right: 6px;
}
.fabric-total { color: var(--muted); font-weight: 400; }
.uses { margin: 0; padding: 0; list-style: none; color: var(--muted); }

.units { padding-left: 0; list-style: none; display: grid; gap: 10px; }
.units li { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.units .title { font-weight: 600; }
.units .sizes { color: var(--muted); font-size: 0.9rem; }
.units .method { margin: 4px 0 0; font-size: 0.92rem; }

.steps { padding-left: 22px; }
.steps li { margin-bottom: 8px; }

@media print {
  body { background: #fff; color: #000; }
  .controls, .actions, .tabs, label.inline { display: none !important; }
  .layout { display: block; }
  .panel { border: none; padding: 0 0 12px; }
  .block-svg { max-width: 260px; }
}

h3.section { margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--border); }
input[type="number"] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
.extras { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 12px; }
.extras input[type="color"] { width: 28px; height: 24px; padding: 0; border: 1px solid var(--border); border-radius: 4px; background: none; }
#yardage td.buy { font-weight: 700; white-space: nowrap; text-align: right; }
#yardage .parts { margin: 0; padding: 0; list-style: none; color: var(--muted); font-size: 0.88rem; }

.quilt-svg { margin-top: 8px; }
.quilt-svg svg { width: 100%; height: auto; display: block; max-height: 70vh; }

.photo-btn {
  padding: 3px 9px; font-size: 0.82rem; border-radius: 6px; background: transparent; color: var(--accent);
  border: 1px solid var(--accent); flex: none;
}
.photo-btn.has-photo { background: var(--accent); color: var(--accent-text); }
.fabric-list .thumb {
  width: 36px; height: 32px; border-radius: 6px; border: 1px solid var(--border); flex: none;
  background-size: cover; background-position: center;
}
.small-remove { padding: 1px 7px; font-size: 0.8rem; background: transparent; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; }
.fabric-list .remove { padding: 2px 8px; background: transparent; color: var(--muted); border: 1px solid var(--border); flex: none; }
.layout-fabric { display: inline-flex; align-items: center; gap: 6px; }
.photo-width { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; font-size: 0.9rem; color: var(--muted); }
.photo-width input { width: 72px; }
.busy { opacity: 0.6; pointer-events: none; }

.tabs button { padding: 8px 8px; font-size: 0.92rem; }
.save-form { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.save-form label { margin-top: 0; }
.save-row { display: flex; gap: 6px; }
.save-row input { flex: 1; min-width: 0; }
.saved-note { margin: 8px 0 0; color: #1f7a46; font-weight: 600; font-size: 0.92rem; }
.grid-toggle { margin-top: 10px; font-size: 0.88rem; color: var(--muted); }
.my-blocks { list-style: none; padding: 0; margin: 12px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.my-blocks li { border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: var(--bg); display: flex; flex-direction: column; gap: 6px; }
.my-blocks .mini { width: 100%; aspect-ratio: 1; display: block; border-radius: 4px; cursor: pointer; }
.my-blocks .name { font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.my-blocks .when { color: var(--muted); font-size: 0.78rem; }
.my-blocks .row-actions { display: flex; gap: 6px; }
.my-blocks .row-actions button { padding: 3px 8px; font-size: 0.82rem; }

.schemes { list-style: none; padding: 0; margin: 8px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.schemes li { position: relative; }
.scheme-chip {
  width: 100%; padding: 6px; display: flex; flex-direction: column; gap: 4px; align-items: stretch;
  background: var(--bg); color: var(--text); border: 1px solid var(--border); text-align: left; font-size: 0.84rem; line-height: 1.25;
}
.scheme-chip:hover { border-color: var(--accent); }
.scheme-chip[aria-pressed="true"] { border: 2px solid var(--accent); padding: 5px; font-weight: 600; }
.stripes { display: flex; height: 22px; border-radius: 4px; overflow: hidden; border: 1px solid rgba(0,0,0,0.15); }
.stripes span { flex: 1; background-size: cover; background-position: center; }
.schemes .delete-scheme {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0; border-radius: 50%;
  font-size: 0.78rem; line-height: 1; background: var(--panel); color: var(--muted); border: 1px solid var(--border);
}
.scheme-status-undo { margin-left: 8px; padding: 2px 10px; font-size: 0.84rem; }
#save-scheme { margin-top: 10px; }

/* Simple colour picker */
.colour-wrap { position: relative; display: inline-flex; flex: none; }
.colour-btn { width: 36px; height: 32px; padding: 0; border: 1px solid var(--border); border-radius: 6px; flex: none; }
.colour-btn:hover { border-color: var(--accent); }
.extras .colour-btn { width: 28px; height: 24px; border-radius: 4px; }
body:not(.exact-colours) .colour-wrap input[type="color"] {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none;
}
body.exact-colours .colour-btn { display: none; }
.colour-mode { display: flex; align-items: center; gap: 4px; margin-top: 8px; font-size: 0.85rem; color: var(--muted); }
.colour-mode span { margin-right: 4px; }
.colour-mode button { padding: 2px 10px; font-size: 0.85rem; background: transparent; color: var(--accent); }
.colour-mode button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.palette {
  position: absolute; z-index: 50; width: min(380px, calc(100vw - 16px)); padding: 10px 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
}
.palette-name { font-weight: 600; font-size: 0.9rem; margin-bottom: 8px; min-height: 1.4em; }
.palette-grid { display: grid; grid-template-columns: auto repeat(11, 1fr); gap: 4px; align-items: center; }
.palette-shade { font-size: 0.75rem; color: var(--muted); padding-right: 4px; }
.palette-swatch { aspect-ratio: 1; width: 100%; min-width: 0; padding: 0; border: 1px solid rgba(0, 0, 0, 0.2); border-radius: 5px; }
.palette-swatch:hover, .palette-swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.palette-swatch[aria-pressed="true"] { outline: 3px solid var(--text); outline-offset: 1px; }
.palette-more { margin-top: 10px; }
.palette-heading { font-size: 0.75rem; color: var(--muted); margin: 2px 0 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.palette-own { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; margin-bottom: 10px; }
.note-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.note-actions button.small { margin-top: 0; }

/* Accounts */
.account { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.account-email { color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }
.auth-dialog {
  width: min(420px, calc(100vw - 32px)); padding: 20px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--panel); color: var(--text);
}
.auth-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.auth-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.auth-head h2 { margin: 0; }
.auth-close { padding: 2px 10px; }
.auth-dialog input[type="email"], .auth-dialog input[type="password"] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
.auth-dialog .actions button { width: 100%; }
.auth-links { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; align-items: flex-start; }
.link-btn { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: 0.92rem; }
.danger-zone { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--border); }
.sign-in-prompt { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* Share links */
.shared-banner { margin-top: 0; }
.shared-banner p { margin: 0 0 6px; }
.share-panel { margin-top: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.share-panel p { margin: 0 0 8px; }
.share-panel .save-row input { font-size: 0.88rem; }
.share-more { display: flex; gap: 16px; flex-wrap: wrap; margin: 8px 0 0 !important; }
.my-shares { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.my-shares li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.my-shares .name { font-weight: 600; font-size: 0.9rem; }
.my-shares .when { color: var(--muted); font-size: 0.82rem; flex: 1; }
.account-stats { color: var(--accent); font-size: 0.92rem; }

/* Pro */
.pro-badge { background: #b8860b; color: #fff; font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; letter-spacing: 0.03em; }
.go-pro { background: #b8860b; border-color: #b8860b; color: #fff; }
body.free-plan .needs-pro::after {
  content: "Pro"; margin-left: 6px; padding: 0 6px; border-radius: 999px; font-size: 0.72em; font-weight: 700;
  background: #b8860b; color: #fff; vertical-align: 1px;
}
.pro-dialog { width: min(640px, calc(100vw - 32px)); }
.pro-why { font-weight: 600; margin: 10px 0 0; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.compare > div { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.compare h3 { margin: 0 0 6px; }
.compare ul { margin: 0; padding-left: 18px; font-size: 0.9rem; }
.compare li { margin: 3px 0; }
.compare .pro-col { border: 2px solid #b8860b; }
.pro-plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 14px; }
.plan { border: 1px solid var(--border); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 4px; text-align: center; position: relative; }
.plan.best { border: 2px solid #b8860b; }
.plan .ribbon { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); background: #b8860b; color: #fff; font-size: 0.72rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.plan .plan-name { font-weight: 600; }
.plan .price { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.plan .per, .plan .note { color: var(--muted); font-size: 0.82rem; }
.plan button { margin-top: auto; }
@media (max-width: 560px) { .compare, .pro-plans { grid-template-columns: 1fr; } }
.plan-box { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); display: grid; gap: 8px; justify-items: start; }
.test-checkout { max-width: 520px; margin: 40px auto; display: grid; gap: 12px; }
.test-checkout h1 { margin: 0; font-size: 1.4rem; }
.test-checkout form { margin: 0; }
