:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --ink: #1c1a17;
  --ink-soft: #6f6a61;
  --ink-faint: #a39c8f;
  --line: #e7e2d8;
  --accent: #8a4b2f;
  --accent-soft: #f3e7de;
  --green: #3d5a4c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(28, 26, 23, 0.06), 0 8px 24px rgba(28, 26, 23, 0.07);
  --shadow-lg: 0 4px 12px rgba(28, 26, 23, 0.1), 0 16px 48px rgba(28, 26, 23, 0.12);
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, system-ui, sans-serif;
  --tabbar-h: 62px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 15px; line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
img { display: block; }
svg { display: block; }

/* ================= Chrome ================= */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; padding-top: calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: rgba(250, 248, 244, 0.92); backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 40;
}
.brand { font-family: var(--font-display); font-weight: 600; font-size: 21px; display: flex; align-items: center; gap: 9px; }
.brand-ico { width: 26px; height: 26px; border-radius: 6px; }
.topnav { display: none; gap: 4px; }
.topnav a { padding: 6px 13px; border-radius: 999px; font-size: 14px; color: var(--ink-soft); font-weight: 500; }
.topnav a.active { background: var(--ink); color: #fff; }
.nav-gear { color: var(--ink-soft); padding: 6px; border-radius: 999px; }
.nav-gear.active { color: var(--ink); background: #efe9dd; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 7px 6px calc(7px + env(safe-area-inset-bottom));
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 500; color: var(--ink-faint);
  min-width: 64px; padding: 3px 6px; border-radius: 10px;
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.active { color: var(--ink); }

@media (min-width: 760px) {
  .topnav { display: flex; }
  .tabbar { display: none; }
  :root { --tabbar-h: 0px; }
}

main { max-width: 1100px; margin: 0 auto; padding: 22px 20px calc(40px + var(--tabbar-h) + env(safe-area-inset-bottom)); }
main.wide { max-width: 1400px; }

/* ================= Type & primitives ================= */
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
h1 { font-family: var(--font-display); font-weight: 500; font-size: 30px; line-height: 1.15; }
h2 { font-family: var(--font-display); font-weight: 500; font-size: 20px; margin: 26px 0 12px; }
.sub { color: var(--ink-soft); font-size: 14px; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-faint); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 16px; border-radius: 999px; font-size: 14px; font-weight: 500;
  box-shadow: 0 1px 2px rgba(28,26,23,0.05); white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.danger { color: #a03325; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.big { padding: 13px 22px; font-size: 15px; }
.btn.full { width: 100%; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn svg { width: 16px; height: 16px; }

.card-s {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 18px;
}

/* ================= Home ================= */
.home-hero { margin: 6px 0 22px; }
.home-hero h1 { font-size: 34px; }

.journey { display: grid; gap: 10px; margin-bottom: 26px; }
.j-step {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 13px 16px; box-shadow: var(--shadow); cursor: pointer;
}
.j-step .jnum {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--line); font-size: 13px; font-weight: 600; color: var(--ink-soft);
}
.j-step.done { opacity: 0.62; }
.j-step.done .jnum { background: var(--green); border-color: var(--green); color: #fff; }
.j-step .grow { flex: 1; min-width: 0; }
.j-step .jt { font-weight: 600; font-size: 14.5px; }
.j-step .jd { color: var(--ink-soft); font-size: 13px; }
.j-step .go { color: var(--accent); font-weight: 600; font-size: 13px; flex: 0 0 auto; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.stat .v { font-family: var(--font-display); font-size: 26px; font-weight: 500; line-height: 1.1; }
.stat .l { color: var(--ink-soft); font-size: 12.5px; margin-top: 2px; }

.qa-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 18px 0 6px; }

.strip { display: flex; gap: 12px; overflow-x: auto; padding: 4px 2px 10px; -webkit-overflow-scrolling: touch; }
.strip::-webkit-scrollbar { display: none; }
.strip .s-item { flex: 0 0 auto; width: 150px; cursor: pointer; }
.strip .s-item.wide { width: 240px; }
.strip .s-img {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); overflow: hidden; height: 120px;
  display: flex; align-items: center; justify-content: center; padding: 10px;
}
.strip .s-item.wide .s-img { padding: 0; }
.strip .s-item.wide .s-img img { width: 100%; height: 100%; object-fit: cover; }
.strip .s-img img { max-width: 100%; max-height: 100%; object-fit: contain; filter: drop-shadow(0 2px 5px rgba(0,0,0,0.16)); }
.strip .s-cap { font-size: 12.5px; color: var(--ink-soft); margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ================= Collection ================= */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }
.card { cursor: pointer; }
.card .thumb {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center; padding: 14px;
  transition: box-shadow 0.15s;
}
.card:hover .thumb { box-shadow: var(--shadow-lg); }
.card .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; filter: drop-shadow(0 2px 6px rgba(0,0,0,0.18)); }
.card .meta { padding: 8px 2px 0; }
.card .t { font-weight: 600; font-size: 14px; line-height: 1.3; }
.card .a { color: var(--ink-soft); font-size: 13px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #efe9dd; color: #6d5b3c; margin-top: 4px; }
.badge.sold { background: #f4dcd7; color: #8c3a2b; }
.badge.green { background: #e2ece7; color: #3d5a4c; }

.empty {
  text-align: center; padding: 56px 24px; color: var(--ink-soft);
  border: 1.5px dashed var(--line); border-radius: 18px; margin-top: 10px;
  display: grid; gap: 6px; justify-items: center;
}
.empty .big { font-family: var(--font-display); font-size: 22px; color: var(--ink); }
.empty .btn { margin-top: 10px; }

.skeleton { border-radius: var(--radius); background: linear-gradient(100deg, #efeae0 40%, #f7f3ea 50%, #efeae0 60%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ================= Forms ================= */
.form { display: grid; gap: 14px; max-width: 560px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
label.f { display: grid; gap: 5px; font-size: 13px; font-weight: 500; color: var(--ink-soft); }
label.f input, label.f select, label.f textarea {
  border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; background: var(--surface);
  font-size: 15px; width: 100%;
}
label.f input:focus, label.f select:focus, label.f textarea:focus { outline: 2px solid #d8c8ba; border-color: #c9b6a4; }
.checkline { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.checkline input { width: 17px; height: 17px; accent-color: var(--accent); }
.hint { font-size: 12.5px; color: var(--ink-faint); }

/* ================= Wizard ================= */
.wiz-steps { display: flex; gap: 6px; margin-bottom: 18px; }
.wiz-steps .ws { height: 4px; flex: 1; border-radius: 2px; background: var(--line); }
.wiz-steps .ws.on { background: var(--accent); }
.photo-drop {
  border: 2px dashed var(--line); border-radius: 16px; background: var(--surface);
  padding: 40px 20px; text-align: center; color: var(--ink-soft); cursor: pointer; display: grid; gap: 8px; justify-items: center;
}
.photo-drop svg { width: 34px; height: 34px; color: var(--ink-faint); }
.photo-drop b { color: var(--ink); }

/* Wizard entry choices */
.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .choice-row { grid-template-columns: 1fr; } }
.choice {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 16px;
  padding: 20px 16px; cursor: pointer; display: grid; gap: 4px; justify-items: center; text-align: center;
  box-shadow: var(--shadow); transition: border-color 0.15s;
}
.choice:hover { border-color: var(--ink-faint); }
.choice .ch-emoji { font-size: 30px; }
.choice span { font-size: 12.5px; color: var(--ink-soft); }

/* Mat colour dots */
.matdot {
  width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--line); padding: 0; cursor: pointer;
}
.matdot.sel { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Crop tool */
.crop-wrap { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; border-radius: 12px; overflow: hidden; background: #111; }
.crop-wrap canvas { width: 100%; display: block; }
.crop-shade { position: absolute; background: rgba(10, 10, 10, 0.55); pointer-events: none; }
.crop-rect { position: absolute; border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.4); cursor: move; touch-action: none; }
.crop-h {
  position: absolute; width: 26px; height: 26px; transform: translate(-50%, -50%); touch-action: none;
}
.crop-h::after {
  content: ''; position: absolute; inset: 5px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.crop-tools { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ================= Detail / framing studio ================= */
.detail { display: grid; gap: 30px; grid-template-columns: 1fr; }
@media (min-width: 800px) { .detail { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; } }
.artwrap { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: clamp(16px, 5vw, 44px); display: flex; align-items: center; justify-content: center; }
.artwrap canvas, .artwrap img { max-width: 100%; height: auto; }

.frame-opts { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 4px; }
.frame-chip {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 9px;
  padding: 6px 10px 6px 6px; display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500;
}
.frame-chip .sw { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(0,0,0,0.12); }
.frame-chip.sel { border-color: var(--ink); background: #f4f0e8; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 6px 13px; font-size: 13px; color: var(--ink-soft); }
.seg button.sel { background: var(--ink); color: #fff; }

.list { display: grid; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 14px; font-size: 14px;
}
.list-item .grow { flex: 1; min-width: 0; }
.list-item img.mini { width: 46px; height: 46px; object-fit: contain; flex: 0 0 auto; }
.x { border: 0; background: none; color: var(--ink-soft); font-size: 16px; padding: 4px; cursor: pointer; }

/* ================= Walls ================= */
.wall-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px; }
.wall-card { border-radius: 15px; overflow: hidden; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); cursor: pointer; transition: box-shadow 0.15s; }
.wall-card:hover { box-shadow: var(--shadow-lg); }
.wall-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; }
.wall-card .meta { padding: 10px 14px 12px; }

/* ================= Planner ================= */
.planner-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.planner-bar .spacer { flex: 1; }
.layout-chips { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.layout-chips .lc { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 13px; font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.layout-chips .lc.sel { background: var(--ink); border-color: var(--ink); color: #fff; }

.stage-wrap { position: relative; border-radius: 15px; overflow: hidden; box-shadow: var(--shadow-lg); background: #111; }
.stage { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; }
.stage > img.wallphoto { width: 100%; height: auto; pointer-events: none; }
.placed { position: absolute; cursor: grab; touch-action: none; }
.placed.dragging { cursor: grabbing; z-index: 10; }
.p-outer { width: 100%; height: 100%; box-shadow: 0 3px 9px rgba(0,0,0,0.35); }
img.art { width: 100%; height: 100%; object-fit: cover; }
.placed img.art { pointer-events: none; }
.fthumb { display: block; }
.fthumb .p-outer { box-shadow: 0 4px 10px rgba(0,0,0,0.22); }
.placed.sel { outline: 2px solid #4d9fff; outline-offset: 3px; }
.placed .size-tag {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: -26px;
  background: rgba(20,20,20,0.85); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.guide { position: absolute; background: #ff5c93; z-index: 8; pointer-events: none; }
.guide.v { width: 1.5px; top: 0; bottom: 0; }
.guide.h { height: 1.5px; left: 0; right: 0; }

.tray { display: flex; gap: 10px; overflow-x: auto; padding: 14px 4px 6px; -webkit-overflow-scrolling: touch; }
.tray .tray-item { flex: 0 0 auto; width: 74px; text-align: center; cursor: pointer; }
.tray .tray-item.used { opacity: 0.35; }
.tray .tray-item .tt {
  width: 74px; height: 74px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; padding: 7px;
}
.tray .tray-item img { max-width: 100%; max-height: 100%; object-fit: contain; }
.tray .tray-item .tl { font-size: 11px; color: var(--ink-soft); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sel-tools {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-top: 12px;
}
.sel-tools select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff; font-size: 13px; }
.nudge { display: grid; grid-template-columns: repeat(3, 30px); grid-template-rows: repeat(2, 26px); gap: 3px; }
.nudge button { border: 1px solid var(--line); background: #fff; border-radius: 7px; font-size: 13px; padding: 0; }
.nudge .nu-u { grid-column: 2; grid-row: 1; }
.nudge .nu-l { grid-column: 1; grid-row: 2; }
.nudge .nu-d { grid-column: 2; grid-row: 2; }
.nudge .nu-r { grid-column: 3; grid-row: 2; }

/* ================= Modal / toast ================= */
.modal-back {
  position: fixed; inset: 0; background: rgba(28,26,23,0.5); z-index: 90;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) { .modal-back { align-items: center; padding: 24px; } }
.modal {
  background: var(--bg); border-radius: 20px 20px 0 0; width: 100%; max-width: 660px;
  max-height: 92vh; overflow-y: auto; padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .modal { border-radius: 20px; } }
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

.calib-wrap { position: relative; touch-action: none; user-select: none; border-radius: 12px; overflow: hidden; }
.calib-wrap img { width: 100%; height: auto; pointer-events: none; }
.calib-line { position: absolute; height: 2px; background: #4d9fff; transform-origin: 0 50%; box-shadow: 0 0 0 1px rgba(255,255,255,0.6); }
.calib-handle {
  position: absolute; width: 28px; height: 28px; border-radius: 50%; background: #4d9fff;
  border: 3px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,0.4); transform: translate(-50%, -50%); cursor: grab; touch-action: none;
}
.chip-row { display: flex; gap: 7px; flex-wrap: wrap; }
.chip-row .btn.small { font-size: 12.5px; }

.render-result img { width: 100%; border-radius: 14px; }

#toast {
  position: fixed; bottom: calc(24px + var(--tabbar-h) + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.25s; z-index: 120; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; }

/* ================= Login ================= */
.login { max-width: 380px; margin: 9vh auto 0; text-align: center; display: grid; gap: 14px; justify-items: center; }
.login img { width: 76px; height: 76px; border-radius: 18px; box-shadow: var(--shadow-lg); }
.login h1 { font-size: 42px; }
.login p { color: var(--ink-soft); }
.login input { border: 1px solid var(--line); border-radius: 11px; padding: 13px 14px; text-align: center; font-size: 16px; background: var(--surface); width: 100%; }

/* ================= Public gallery ================= */
.pub-hero { text-align: center; margin: 26px 0 34px; }
.pub-hero .eyebrow { margin-bottom: 8px; }
.pub-hero h1 { font-size: clamp(30px, 6vw, 44px); }
.pub-wall { margin-bottom: 34px; }
.pub-wall img.main { width: 100%; border-radius: 16px; box-shadow: var(--shadow-lg); }
.pub-foot { text-align: center; color: var(--ink-faint); font-size: 13px; margin-top: 50px; }

.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.35); border-top-color: #fff; border-radius: 50%; animation: sp 0.7s linear infinite; }
.btn:not(.primary):not(.accent) .spin { border-color: rgba(0,0,0,0.15); border-top-color: var(--ink); }
@keyframes sp { to { transform: rotate(360deg); } }
