:root {
  --ink: #111827;
  --paper: #efece3;
  --aqua: #20c7c7;
  --aqua-soft: #d4f1ee;
  --yellow: #ffd84d;
  --coral: #ff6b5e;
  --white: #fffdf8;
  --muted: #5d6570;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
}
button, input, select { color: inherit; font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.topbar {
  display: flex;
  align-items: baseline;
  gap: 18px;
  padding: 13px 22px;
  border-bottom: 3px solid var(--ink);
  background: var(--aqua);
}
.brand {
  font-size: 1.1rem;
  font-weight: 950;
  letter-spacing: -.045em;
  text-transform: uppercase;
}
.brand span { display: inline-block; margin-right: 2px; font-size: 1.3em; }
.lede { margin: 0; font-size: .82rem; font-weight: 700; }

.layout {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  grid-template-rows: minmax(480px, 1fr) auto;
  gap: 14px;
  width: min(1220px, calc(100% - 28px));
  min-height: calc(100vh - 100px);
  margin: 16px auto 9px;
}
.panel {
  border: 3px solid var(--ink);
  background: var(--white);
  box-shadow: 4px 4px 0 var(--ink);
}

.controls {
  grid-row: 1 / 3;
  align-self: start;
}
.control-section {
  padding: 13px;
  border-bottom: 3px solid var(--ink);
}
.control-section:last-child { border-bottom: 0; }
.section-title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 12px;
}
.section-title .step {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 27px;
  height: 27px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
  font-size: .75rem;
  font-weight: 950;
}
.section-title strong,
.section-title small { display: block; }
.section-title strong { font-size: .8rem; text-transform: uppercase; }
.section-title small { margin-top: 1px; color: var(--muted); font-size: .65rem; }

.field { display: grid; gap: 4px; }
.field > span:first-child {
  font-size: .65rem;
  font-weight: 850;
  letter-spacing: .025em;
  text-transform: uppercase;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.input-wrap { position: relative; display: block; }
input[type="number"], select {
  width: 100%;
  height: 39px;
  padding: 0 42px 0 9px;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: #fff;
  font-weight: 750;
}
select { padding-right: 6px; }
input:focus, select:focus {
  outline: 3px solid color-mix(in srgb, var(--aqua) 75%, transparent);
  outline-offset: 0;
}
.input-wrap em {
  position: absolute;
  top: 50%;
  right: 9px;
  translate: 0 -50%;
  color: var(--muted);
  font-size: .63rem;
  font-style: normal;
  font-weight: 850;
}
.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 10px;
  font-size: .74rem;
  font-weight: 800;
  cursor: pointer;
}
.check-field input {
  width: 19px;
  height: 19px;
  margin: 0;
  accent-color: var(--aqua);
}
.drawing-help ol,
.help-compact {
  margin: -2px 0 12px;
  padding-left: 22px;
  color: var(--muted);
  font-size: .68rem;
  line-height: 1.45;
}
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.icon-button {
  font-size: 1rem;
  line-height: 1;
  text-transform: none;
  letter-spacing: 0;
}
.button {
  min-height: 38px;
  border: 2px solid var(--ink);
  background: var(--aqua);
  box-shadow: 2px 2px 0 var(--ink);
  font-size: .67rem;
  font-weight: 900;
  text-transform: uppercase;
  cursor: pointer;
}
.button.secondary { background: #fff; }
.button:hover:not(:disabled) { background: var(--yellow); }
.button:active:not(:disabled) { translate: 2px 2px; box-shadow: none; }
.button:disabled { cursor: not-allowed; opacity: .35; }

.save-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.save-row input {
  width: 100%;
  height: 39px;
  padding: 0 9px;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: #fff;
  font-weight: 750;
}
.save-row .button { padding: 0 12px; }
.save-status {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 700;
}
.plan-list {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}
.plan-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  border: 2px solid var(--ink);
  background: #fff;
}
.plan-load {
  min-width: 0;
  padding: 7px 9px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.plan-load strong {
  display: block;
  overflow: hidden;
  font-size: .74rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.plan-load small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: .64rem;
  font-weight: 700;
}
.plan-load:hover { background: var(--aqua-soft); }
.plan-list li.is-active { box-shadow: 2px 2px 0 var(--ink); }
.plan-list li.is-active .plan-load { background: var(--yellow); }
.plan-delete {
  width: 32px;
  border: 0;
  border-left: 2px solid var(--ink);
  background: transparent;
  font-size: .9rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}
.plan-delete:hover { background: var(--coral); }

.editor-panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 13px;
  border-bottom: 3px solid var(--ink);
  background: var(--aqua);
}
.panel-head strong, .panel-head span { display: block; }
.panel-head strong { font-size: .84rem; text-transform: uppercase; }
.panel-head > div:first-child span { margin-top: 1px; font-size: .68rem; font-weight: 650; }
.head-tools {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}
.view-toggle { display: flex; }
.view-toggle button {
  min-width: 52px;
  height: 28px;
  padding: 0 9px;
  border: 2px solid var(--ink);
  background: var(--white);
  font-size: .63rem;
  font-weight: 900;
  text-transform: uppercase;
  cursor: pointer;
}
.view-toggle button + button { border-left-width: 0; }
.view-toggle button.is-active { background: var(--ink); color: var(--white); }
.view-toggle button:hover:not(.is-active) { background: var(--yellow); }
.magnet-badge {
  flex: 0 0 auto;
  padding: 5px 7px;
  border: 2px solid var(--ink);
  background: var(--yellow);
  font-size: .63rem;
  font-weight: 900;
  text-transform: uppercase;
}
.magnet-badge span { display: inline; font-size: 1.1em; }

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 410px;
  overflow: hidden;
  background: var(--aqua-soft);
}
#floorplan {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 410px;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}
#floorplan:focus-visible { outline: 4px solid var(--yellow); outline-offset: -4px; }
#floorplan[hidden] { display: none; }
.viewer-3d {
  position: absolute;
  inset: 0;
  background: var(--aqua-soft);
  cursor: grab;
  touch-action: none;
}
.viewer-3d[hidden] { display: none; }
.viewer-3d:active { cursor: grabbing; }
.viewer-3d canvas { display: block; width: 100%; height: 100%; }
.viewer-3d[data-state="loading"]::after,
.viewer-3d[data-state="error"]::after {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  padding: 7px 10px;
  border: 2px solid var(--ink);
  background: var(--yellow);
  box-shadow: 3px 3px 0 var(--ink);
  font-size: .7rem;
  font-weight: 850;
}
.viewer-3d[data-state="loading"]::after { content: "Memuat tampilan 3D…"; }
.viewer-3d[data-state="error"]::after { content: "Tampilan 3D butuh koneksi internet"; }
.canvas-tip {
  position: absolute;
  top: 12px;
  left: 50%;
  translate: -50% 0;
  padding: 6px 9px;
  border: 2px solid var(--ink);
  background: var(--yellow);
  box-shadow: 2px 2px 0 var(--ink);
  font-size: .67rem;
  font-weight: 850;
  pointer-events: none;
}
.canvas-tip[hidden] { display: none; }
.editor-footer {
  display: flex;
  align-items: center;
  gap: 15px;
  min-height: 39px;
  padding: 7px 11px;
  border-top: 3px solid var(--ink);
  font-size: .64rem;
  font-weight: 750;
}
.editor-footer > span { display: flex; align-items: center; gap: 5px; }
.legend { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--ink); }
.legend.floor { background: color-mix(in srgb, var(--aqua) 55%, white); }
.legend.cut { background: color-mix(in srgb, var(--coral) 55%, white); }
.legend.plin { background: var(--yellow); }
.legend.wall { background: var(--ink); }
.layout-summary {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.text-button {
  margin-left: auto;
  padding: 2px 0;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  font-size: .64rem;
  font-weight: 850;
  cursor: pointer;
}
.text-button:hover { color: #087b7b; }

.room-shape {
  fill: color-mix(in srgb, var(--aqua) 58%, white);
  stroke: var(--ink);
  stroke-width: 4;
  stroke-linejoin: round;
  filter: url(#shadow);
}
.wall-band {
  fill: var(--ink);
  stroke: var(--ink);
  stroke-width: 1;
  stroke-linejoin: miter;
  filter: url(#shadow);
}
.floor-shape {
  fill: color-mix(in srgb, var(--aqua) 40%, white);
  stroke: none;
}
.tile {
  fill: color-mix(in srgb, var(--aqua) 58%, white);
  stroke: color-mix(in srgb, var(--ink) 38%, transparent);
  stroke-width: 1.2;
}
.tile.is-cut { fill: color-mix(in srgb, var(--coral) 48%, white); }
.plin-line {
  fill: none;
  stroke: var(--yellow);
  stroke-width: 9;
}
.draft-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 4;
  stroke-linejoin: round;
}
.preview-line {
  fill: none;
  stroke: var(--coral);
  stroke-width: 3;
  stroke-dasharray: 8 6;
}
.partition-draft {
  fill: none;
  stroke: color-mix(in srgb, var(--ink) 72%, white);
  stroke-width: 5;
  stroke-dasharray: 10 7;
}
.point {
  fill: var(--yellow);
  stroke: var(--ink);
  stroke-width: 3;
}
.point.start { fill: var(--coral); }
.point.wall-snap { fill: var(--aqua); stroke-width: 3.5; }
.wall-snap-guide {
  stroke: var(--aqua);
  stroke-width: 10;
  stroke-linecap: round;
  opacity: 0.55;
  pointer-events: none;
}
.wall-corner-marker {
  fill: var(--coral);
  stroke: var(--ink);
  stroke-width: 2;
  pointer-events: none;
}
.point.preview { fill: color-mix(in srgb, var(--yellow) 72%, white); }
.point.closing { transform-box: fill-box; transform-origin: center; scale: 1.35; }
.dimension-bg { fill: var(--white); stroke: var(--ink); stroke-width: 1.5; }
.dimension-bg.is-live { fill: var(--yellow); stroke-width: 2.5; }
.dimension-text.is-live { font-size: 12px; }
.dimension-text {
  fill: var(--ink);
  font-size: 11px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}
.area-label-bg { fill: var(--yellow); stroke: var(--ink); stroke-width: 2; }
.area-label {
  fill: var(--ink);
  font-size: 15px;
  font-weight: 950;
  text-anchor: middle;
  dominant-baseline: middle;
}

.results {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) 300px;
  min-width: 0;
}
.result-lead {
  display: grid;
  grid-template-columns: auto auto;
  align-content: center;
  padding: 12px 15px;
  border-right: 3px solid var(--ink);
  background: var(--yellow);
}
.result-lead small { grid-column: 1 / -1; font-size: .61rem; font-weight: 900; text-transform: uppercase; }
.result-lead strong { font-size: 2.15rem; line-height: 1; letter-spacing: -.06em; }
.result-lead span { align-self: end; margin: 0 0 3px 5px; font-size: .68rem; font-weight: 850; }
.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  min-width: 0;
}
.metrics div {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  padding: 11px 9px;
  border-right: 2px solid var(--ink);
}
.metrics small, .box-results small {
  color: var(--muted);
  font-size: .59rem;
  font-weight: 800;
  text-transform: uppercase;
}
.metrics b { margin-top: 3px; font-size: .9rem; letter-spacing: -.025em; }
.box-results { display: grid; grid-template-columns: 1fr 1fr; }
.box-results > div {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 9px 11px;
}
.box-results > div + div { border-left: 2px solid var(--ink); }
.box-results span { font-size: .62rem; font-weight: 750; text-transform: uppercase; }
.box-results strong { margin: 1px 0; font-size: 1.08rem; }
.box-results small { text-transform: none; }

.disclaimer {
  width: min(1220px, calc(100% - 28px));
  margin: 0 auto 18px;
  color: var(--muted);
  font-size: .68rem;
}

@media (max-width: 1020px) {
  .results { grid-template-columns: 150px 1fr; }
  .box-results { grid-column: 1 / -1; border-top: 3px solid var(--ink); }
  .box-results > div { padding: 8px 15px; }
}

@media (max-width: 760px) {
  .topbar { padding-inline: 14px; }
  .lede { display: none; }
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    width: min(100% - 20px, 620px);
    margin-top: 12px;
  }
  .controls, .results { grid-row: auto; grid-column: auto; }
  .controls { order: 2; }
  .editor-panel { order: 1; }
  .results { order: 3; }
  .canvas-wrap, #floorplan { min-height: 360px; }
  .results { grid-template-columns: 135px 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metrics div:nth-child(2) { border-right: 0; }
  .metrics div:nth-child(-n + 2) { border-bottom: 2px solid var(--ink); }
  .panel-head > div:first-child span { max-width: 230px; }
  .magnet-badge { display: none; }
  .editor-footer { flex-wrap: wrap; gap: 8px 14px; }
  .text-button { width: 100%; margin-left: 0; text-align: left; }
  .disclaimer { width: min(100% - 20px, 620px); }
}
