:root {
  --bg: #f3efe6;
  --surface: #fffdf8;
  --surface-2: #faf6ee;
  --ink: #2b2620;
  --muted: #7c7367;
  --line: #e4dccd;
  --accent: #b1512a;
  --accent-dark: #8f3f1f;
  --accent-soft: #f6e5da;
  --green: #3f7d5b;
  --danger: #a5352b;
  --shadow: 0 1px 2px rgba(43, 38, 32, .06), 0 12px 28px -18px rgba(43, 38, 32, .35);
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.65rem; font-weight: 650; }
h2 { font-size: 1.05rem; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent-dark); }
a:hover { color: var(--accent); }

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 24px;
  background: rgba(255, 253, 248, .92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -.02em;
  color: var(--ink);
  text-decoration: none;
}
.brand:hover { color: var(--ink); }
.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: linear-gradient(140deg, var(--accent) 0%, #d98b58 100%);
  box-shadow: inset 0 0 0 3px rgba(255, 253, 248, .55), inset 10px 0 0 rgba(43, 38, 32, .12);
}

.nav { display: flex; gap: 6px; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 7px 13px;
  border-radius: 999px;
  font-weight: 550;
  font-size: .93rem;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent-dark); }

.account { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.who { color: var(--muted); font-size: .9rem; }
.account form { margin: 0; }

.flash-stack {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: grid;
  gap: 8px;
  width: min(92vw, 460px);
}
.flash {
  padding: 11px 16px;
  border-radius: 10px;
  font-size: .92rem;
  box-shadow: var(--shadow);
  border: 1px solid transparent;
}
.flash-success { background: #eaf3ec; border-color: #c9e0d1; color: #245c3e; }
.flash-error { background: #fbeae7; border-color: #f0c9c2; color: #8c2f25; }

/* ---------- generic pieces ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 600;
  font-size: .92rem;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: #fbeae7; color: var(--danger); }
.btn-small { padding: 6px 11px; font-size: .85rem; border-radius: 8px; }
.btn-wide { width: 100%; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
  vertical-align: middle;
}

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

.page { max-width: 1180px; margin: 0 auto; padding: 34px 24px 64px; }
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.lede { color: var(--muted); margin-top: 6px; max-width: 60ch; }
.hint { color: var(--muted); font-size: .84rem; }
.dims { color: var(--muted); font-size: .9rem; }
.dot { opacity: .5; padding: 0 3px; }

.field { display: grid; gap: 5px; font-size: .9rem; }
.field > span { color: var(--muted); font-weight: 550; font-size: .82rem; }
.field input,
.field select {
  font: inherit;
  font-size: .95rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
}
.field select { cursor: pointer; }
.field input:focus,
.field select:focus { outline: 2px solid var(--accent-soft); outline-offset: 1px; border-color: var(--accent); }
.field small { color: var(--muted); font-size: .78rem; }
.field-narrow { max-width: 140px; }
.field-color input { padding: 3px; height: 38px; cursor: pointer; }

.field-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.field-row .field:first-child { flex: 1 1 220px; }

.stack { display: grid; gap: 12px; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- auth ---------- */

.auth-page {
  min-height: calc(100vh - 58px);
  max-width: 1040px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 48px;
  align-items: center;
  padding: 48px 24px;
}
.auth-card { display: grid; gap: 18px; }
.auth-card .lede { margin-top: -8px; }
.auth-card .stack { margin-top: 4px; }
.auth-switch { color: var(--muted); font-size: .9rem; }

.auth-art {
  height: 430px;
  border-radius: 24px;
  background: linear-gradient(160deg, #f0e3d1, #e6d3bd 60%, #dcc6ab);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  padding: 22px;
  box-shadow: var(--shadow);
}
.auth-art > p { position: relative; color: #6a5641; font-size: .92rem; max-width: 30ch; }
.art-room {
  position: absolute;
  inset: 34px;
  border-radius: 10px;
  background: #f7eede;
  box-shadow: 0 22px 45px -28px rgba(53, 40, 26, .75), inset 0 0 0 1px rgba(255, 255, 255, .6);
}
.art-sofa {
  position: absolute; left: 26px; bottom: 30px; width: 150px; height: 58px;
  background: #c07b4e; border-radius: 14px 14px 8px 8px; box-shadow: inset 0 8px 0 rgba(255,255,255,.16);
}
.art-sofa::before, .art-sofa::after {
  content: ""; position: absolute; top: -18px; width: 62px; height: 26px;
  background: #a9663d; border-radius: 10px 10px 4px 4px;
}
.art-sofa::before { left: 4px; }
.art-sofa::after { right: 4px; }
.art-table {
  position: absolute; right: 34px; top: 52px; width: 104px; height: 104px;
  border-radius: 50%; background: #8e6440; box-shadow: inset 0 0 0 8px #a5794e, 0 12px 18px -12px rgba(53,40,26,.8);
}
.art-rug {
  position: absolute; left: 40px; top: 46px; width: 170px; height: 120px;
  border-radius: 16px; background: repeating-linear-gradient(45deg, #e2c9a9 0 14px, #ead8bd 14px 28px);
  opacity: .85;
}
.art-plant {
  position: absolute; right: 28px; bottom: 24px; width: 40px; height: 40px;
  border-radius: 8px 8px 6px 6px; background: #c98b5c;
}
.art-plant::before {
  content: ""; position: absolute; left: 50%; bottom: 34px; width: 54px; height: 54px;
  transform: translateX(-50%); border-radius: 50% 42% 48% 40%;
  background: radial-gradient(circle at 40% 35%, #7c9c6a, #52724a);
}

/* ---------- dashboard ---------- */

.new-room { margin-bottom: 28px; display: grid; gap: 14px; }
.inline-form { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field:first-of-type { flex: 1 1 200px; min-width: 180px; }

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}
.room-card { display: grid; gap: 12px; }
.room-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.room-card-top h2 a { color: var(--ink); text-decoration: none; }
.room-card-top h2 a:hover { color: var(--accent-dark); }
.room-card .dims { display: flex; justify-content: space-between; gap: 10px; }
.room-card-mini {
  border-radius: 8px;
  min-height: 90px;
  max-height: 150px;
  width: 100%;
  background: #f6efe2;
  border: 1px solid var(--line);
  background-image:
    linear-gradient(rgba(177, 81, 42, .08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(177, 81, 42, .08) 1px, transparent 1px);
  background-size: 22px 22px;
}
.card-actions { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-top: auto; }
.card-actions form { margin: 0; }

.empty { text-align: center; display: grid; gap: 10px; justify-items: center; padding: 42px 20px; }

/* ---------- furniture library ---------- */

.furniture-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
}
.furniture-card { display: grid; gap: 14px; padding: 14px 14px 16px; }
.thumb-wrap {
  border-radius: 10px;
  background:
    linear-gradient(var(--surface-2), var(--surface-2)) padding-box,
    repeating-linear-gradient(0deg, rgba(0,0,0,.03) 0 1px, transparent 1px 20px);
  border: 1px solid var(--line);
  overflow: hidden;
}
.thumb { display: block; width: 100%; height: auto; aspect-ratio: 16 / 11; }
.furniture-meta { display: grid; gap: 3px; }
.furniture-meta h2 { font-size: 1rem; }
.furniture-meta .dims { font-size: .84rem; }

/* ---------- planner ---------- */

.planner-body { overflow: hidden; }
.planner {
  display: flex;
  height: calc(100vh - 58px);
  min-height: 0;
}
.sidebar {
  width: 306px;
  flex: 0 0 306px;
  overflow-y: auto;
  padding: 18px 16px 28px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: grid;
  gap: 22px;
  align-content: start;
}
.back-link { font-size: .86rem; text-decoration: none; color: var(--muted); }
.back-link:hover { color: var(--ink); }
.side-section { display: grid; gap: 10px; }
.side-section + .side-section { border-top: 1px solid var(--line); padding-top: 18px; }
.side-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.side-head h2 { font-size: .95rem; }
.mini-link {
  font-size: .8rem;
  color: var(--muted);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}
.mini-link:hover { color: var(--accent-dark); }
.mini-link.active { color: var(--accent-dark); font-weight: 650; }
.selection-name { font-weight: 650; }
.coord-grid { display: flex; gap: 10px; flex-wrap: wrap; }
.coord-grid .field-narrow { flex: 1 1 80px; max-width: none; }

.library-list { display: grid; gap: 8px; }
.library-item {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: border-color .15s, background .15s;
}
.library-item:hover { background: var(--surface-2); border-color: #d3c6b2; }
.library-item canvas { width: 48px; height: 40px; display: block; }
.library-item .name { font-weight: 600; font-size: .88rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library-item .size { color: var(--muted); font-size: .76rem; }
.library-item .plus {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-dark);
  font-weight: 700; font-size: .9rem;
}

.stage {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 20px 12px;
  gap: 12px;
}
.stage-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.stage-head h1 { font-size: 1.3rem; }
.stage-tools { display: flex; align-items: center; gap: 16px; }
.save-status { font-size: .8rem; color: var(--muted); }
.save-status[data-state="saving"] { color: var(--accent-dark); }
.save-status[data-state="error"] { color: var(--danger); }
.switch { display: inline-flex; align-items: center; gap: 7px; font-size: .85rem; color: var(--muted); cursor: pointer; }
.switch input { accent-color: var(--accent); }

.canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border-radius: var(--radius);
  background:
    radial-gradient(120% 120% at 20% 0%, rgba(255,255,255,.85), rgba(255,255,255,0) 60%),
    var(--surface-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
#planner-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.canvas-empty {
  position: absolute;
  inset: auto 16px 16px auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  max-width: 280px;
  box-shadow: var(--shadow);
  font-size: .9rem;
  pointer-events: none;
}
.stage-foot {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: .78rem;
  color: var(--muted);
  flex-wrap: wrap;
}

/* ---------- editor ---------- */

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, .85fr);
  gap: 22px;
  align-items: start;
}
.editor-form { display: grid; gap: 16px; }
.editor-form h2 { margin-top: 4px; }
.editor-form .hint { margin-top: -8px; }
.preview-card { position: sticky; top: 78px; display: grid; gap: 12px; }
.preview-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.preview-foot { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.preview-tools { display: flex; gap: 10px; flex: none; }
.part-controls,
.door-controls { display: grid; gap: 10px; padding-top: 4px; border-top: 1px dashed var(--line); }
.part-controls .coord-grid,
.door-controls .coord-grid { margin-top: 6px; }
#shape-canvas {
  width: 100%;
  aspect-ratio: 4 / 3;
  display: block;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  touch-action: none;
}
@media (pointer: fine) {
  #shape-canvas.is-custom,
  #shape-canvas.is-ruler { cursor: crosshair; }
}

.preset-row { display: flex; gap: 6px; flex-wrap: wrap; }
.preset {
  font: inherit;
  font-size: .84rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.preset:hover { border-color: #d3c6b2; color: var(--ink); }
.preset.active { background: var(--accent-soft); border-color: #e3c3af; color: var(--accent-dark); }

.custom-tools { display: grid; gap: 10px; padding: 12px; background: var(--surface-2); border-radius: 10px; border: 1px solid var(--line); }
.form-error {
  background: #fbeae7;
  border: 1px solid #f0c9c2;
  color: #8c2f25;
  border-radius: 9px;
  padding: 9px 12px;
  font-size: .88rem;
}
.form-actions { padding-top: 4px; }
.form-actions .btn { min-width: 140px; }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .auth-page { grid-template-columns: 1fr; gap: 28px; }
  .auth-art { display: none; }
  .planner { flex-direction: column; height: auto; }
  .planner-body { overflow: auto; }
  .sidebar { width: 100%; flex: none; border-right: none; border-bottom: 1px solid var(--line); order: 2; }
  .stage { order: 1; height: 66vh; min-height: 460px; }
  .editor-grid { grid-template-columns: 1fr; }
  .preview-card { position: static; }
}
@media (max-width: 620px) {
  .page { padding: 22px 16px 48px; }
  .topbar { padding: 0 14px; gap: 14px; }
  .who { display: none; }
  .stage { padding: 12px; }
  .stage-foot span:last-child { display: none; }
}
