:root {
  --ink-strong: #22312f;
  --ink-muted: #546b66;
  --paper: #f6f1e6;
  --paper-deep: #efe5d1;
  --panel: rgba(250, 245, 235, 0.93);
  --line-soft: rgba(34, 49, 47, 0.12);
  --line-strong: rgba(34, 49, 47, 0.3);
  --accent: #b65a3f;
  --accent-soft: #d58c68;
  --teal: #2f7a73;
  --teal-soft: #d3ebe8;
  --shadow: 0 24px 60px rgba(41, 27, 18, 0.16);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shell-max-width: 1980px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(214, 140, 104, 0.24), transparent 32%),
    radial-gradient(circle at top right, rgba(47, 122, 115, 0.22), transparent 24%),
    linear-gradient(180deg, #f8f2e7 0%, #f2ead9 52%, #ebe2cf 100%);
}

body {
  margin: 0;
  color: var(--ink-strong);
  font-family: 'Trebuchet MS', 'Lucida Sans Unicode', sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  max-width: var(--shell-max-width);
  margin: 0 auto;
  padding: 24px clamp(18px, 2.4vw, 34px) 32px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 22px;
}

.eyebrow,
.stage-kicker {
  margin: 0 0 8px;
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero h1,
.stage-card__header h2,
.print-sheet h2,
.print-sheet h3,
.panel-section h2 {
  margin: 0;
  font-family: 'Palatino Linotype', 'Book Antiqua', serif;
  font-weight: 700;
}

.hero h1 {
  font-size: clamp(2rem, 4vw, 3.35rem);
  line-height: 0.95;
}

.hero-copy {
  max-width: 760px;
  margin: 14px 0 0;
  color: var(--ink-muted);
  line-height: 1.6;
}

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: end;
}

.hero-actions--compact {
  justify-content: start;
}

.action-button {
  border: 0;
  border-radius: 999px;
  padding: 0.85rem 1.2rem;
  color: #fff9f2;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-soft) 100%);
  box-shadow: 0 12px 28px rgba(182, 90, 63, 0.24);
}

.action-button--ghost {
  color: var(--ink-strong);
  background: rgba(255, 250, 242, 0.82);
  box-shadow: inset 0 0 0 1px rgba(34, 49, 47, 0.16);
}

.app-grid {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.control-panel,
.stage-card {
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: var(--radius-lg);
  background: var(--panel);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.control-panel {
  position: sticky;
  top: 22px;
  padding: 18px;
  display: grid;
  gap: 16px;
}

.panel-section {
  border-radius: var(--radius-md);
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.12)),
    rgba(255, 250, 244, 0.7);
  border: 1px solid rgba(34, 49, 47, 0.08);
}

.section-heading {
  margin-bottom: 14px;
}

.section-heading--inline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.section-heading p,
.stage-help,
.panel-section p {
  margin: 8px 0 0;
  color: var(--ink-muted);
  line-height: 1.45;
}

.field-grid {
  display: grid;
  gap: 12px;
}

.field-grid--two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-grid--three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-label {
  display: grid;
  gap: 8px;
  font-size: 0.92rem;
}

.field-label span {
  color: var(--ink-muted);
}

.field-label input,
.field-label select {
  width: 100%;
  border: 1px solid rgba(34, 49, 47, 0.15);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
  background: rgba(255, 255, 255, 0.74);
  color: var(--ink-strong);
}

.field-label input:focus,
.field-label select:focus,
.action-button:focus-visible {
  outline: 3px solid rgba(47, 122, 115, 0.25);
  outline-offset: 2px;
}

.workspace {
  display: grid;
  gap: 14px;
}

.notice-bar {
  min-height: 48px;
  padding: 13px 18px;
  border-radius: 18px;
  background: rgba(255, 248, 234, 0.88);
  border: 1px solid rgba(182, 90, 63, 0.14);
  color: var(--ink-strong);
  box-shadow: 0 12px 30px rgba(68, 50, 26, 0.08);
}

.stage-card {
  --stage-height: clamp(640px, 74vh, 960px);
  overflow: hidden;
}

.stage-card__header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
  padding: 22px 24px 14px;
}

.stage-help {
  max-width: 420px;
}

.stage-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 0 24px 14px;
}

.stage-tools__cluster {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stage-tools__hint,
.tile-snap-copy,
.zoom-card__copy {
  margin: 0;
  color: var(--ink-muted);
  line-height: 1.4;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0.72rem 1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(34, 49, 47, 0.12);
}

.toggle-chip input {
  margin: 0;
}

.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0.6rem 0.9rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(34, 49, 47, 0.12);
}

.inline-field select {
  border: 0;
  background: transparent;
}

.stage-frame {
  position: relative;
  min-height: var(--stage-height);
  padding: 0 18px 18px;
}

.entity-popover,
.entity-menu {
  position: absolute;
  z-index: 9;
  width: min(420px, calc(100% - 28px));
  border-radius: 20px;
  border: 1px solid rgba(34, 49, 47, 0.14);
  background: rgba(255, 250, 244, 0.97);
  box-shadow: 0 28px 60px rgba(41, 27, 18, 0.22);
  backdrop-filter: blur(16px);
}

.entity-popover {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.entity-popover--sheet {
  left: 14px !important;
  right: 14px;
  top: auto !important;
  bottom: 14px;
  width: auto;
  max-height: min(78vh, 760px);
  overflow: auto;
}

.entity-popover__header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}

.entity-popover__header--drag {
  cursor: move;
  user-select: none;
}

.entity-popover__meta {
  display: grid;
  gap: 6px;
  pointer-events: none;
}

.entity-popover__meta h3 {
  margin: 0;
  font-family: 'Palatino Linotype', 'Book Antiqua', serif;
  font-size: 1.35rem;
}

.entity-popover__badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.entity-popover__badge--wall {
  color: var(--accent);
  background: rgba(182, 90, 63, 0.12);
}

.entity-popover__badge--object {
  color: var(--teal);
  background: rgba(47, 122, 115, 0.12);
}

.entity-popover__body {
  display: grid;
  gap: 12px;
}

.entity-popover__header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.entity-popover__hint {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.entity-popover__metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.entity-popover__metric {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.62);
}

.entity-popover__metric dt {
  margin: 0 0 4px;
  color: var(--ink-muted);
  font-size: 0.8rem;
}

.entity-popover__metric dd {
  margin: 0;
  font-weight: 600;
}

.entity-menu {
  display: grid;
  gap: 6px;
  width: min(250px, calc(100% - 28px));
  padding: 8px;
}

.entity-menu__button {
  border: 0;
  border-radius: 14px;
  padding: 0.78rem 0.9rem;
  text-align: left;
  background: transparent;
  color: var(--ink-strong);
}

.entity-menu__button:hover,
.entity-menu__button:focus-visible {
  background: rgba(47, 122, 115, 0.1);
  outline: none;
}

#plan-svg,
#zoom-svg,
#print-plan-svg {
  display: block;
  width: 100%;
  height: auto;
  background:
    linear-gradient(135deg, rgba(255, 250, 243, 0.92), rgba(246, 238, 223, 0.88)),
    repeating-linear-gradient(
      0deg,
      rgba(47, 122, 115, 0.05) 0,
      rgba(47, 122, 115, 0.05) 18px,
      transparent 18px,
      transparent 36px
    );
  border: 1px solid rgba(34, 49, 47, 0.1);
  border-radius: 18px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.38);
  touch-action: none;
}

#plan-svg {
  height: var(--stage-height);
  min-height: var(--stage-height);
  cursor: grab;
}

#zoom-svg {
  height: auto;
  min-height: 290px;
  aspect-ratio: 4 / 3;
}

.zoom-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 250, 244, 0.88);
  border: 1px solid rgba(34, 49, 47, 0.1);
  box-shadow: 0 20px 42px rgba(41, 27, 18, 0.16);
}

.zoom-card--floating {
  position: fixed;
  top: 88px;
  left: calc(100vw - clamp(340px, 29vw, 520px) - 28px);
  right: auto;
  width: clamp(340px, 29vw, 520px);
  z-index: 40;
  pointer-events: auto;
}

.zoom-card__header--drag {
  cursor: move;
  user-select: none;
}

.zoom-card__header--drag h3,
.zoom-card__header--drag p {
  pointer-events: none;
}

.zoom-card__header {
  display: grid;
  gap: 6px;
}

.resize-edge {
  stroke: rgba(47, 122, 115, 0.72);
  stroke-width: 28;
  stroke-linecap: round;
  opacity: 0.9;
}

.resize-edge--wall {
  stroke: rgba(182, 90, 63, 0.82);
}

.resize-handle {
  fill: rgba(255, 250, 242, 0.98);
  stroke: rgba(47, 122, 115, 0.92);
  stroke-width: 6;
}

.tile-snap-block {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}

.chip-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mini-button {
  border: 0;
  border-radius: 999px;
  padding: 0.5rem 0.8rem;
  background: rgba(34, 49, 47, 0.08);
  color: var(--ink-strong);
}

.mini-button--accent {
  background: rgba(47, 122, 115, 0.15);
}

.mini-button--danger {
  background: rgba(182, 90, 63, 0.16);
}

.mini-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

.stats-grid div,
.print-facts div {
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.54);
}

.stats-grid dt,
.print-facts dt {
  color: var(--ink-muted);
  font-size: 0.82rem;
  margin: 0 0 4px;
}

.stats-grid dd,
.print-facts dd {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.cut-list,
.print-cut-list,
.print-wall-list {
  display: grid;
  gap: 8px;
}

.cut-item,
.print-cut-item,
.print-wall-item {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid rgba(34, 49, 47, 0.08);
}

.cut-item__head,
.print-cut-item__head,
.print-wall-item__head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  font-weight: 600;
}

.cut-item__meta,
.print-cut-item__meta,
.print-wall-item__meta {
  margin-top: 6px;
  color: var(--ink-muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.print-sheet {
  display: none;
}

.empty-state {
  padding: 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--ink-muted);
}

@media (max-width: 1480px) {
  .app-grid {
    grid-template-columns: minmax(280px, 330px) minmax(0, 1fr);
  }

  .control-panel {
    position: static;
  }

  .stage-card {
    --stage-height: clamp(580px, 68vh, 820px);
  }
}

@media (max-width: 1180px) {
  .app-grid,
  .app-grid {
    grid-template-columns: 1fr;
  }

  .control-panel,
  .stage-card {
    position: static;
  }

  .workspace {
    grid-column: auto;
  }

  .stage-card__header {
    flex-direction: column;
  }

  .stage-frame {
    padding: 0 16px 16px;
  }

  .stage-card {
    --stage-height: clamp(520px, 64vh, 760px);
  }

  .zoom-card--floating {
    position: static;
    left: auto;
    top: auto;
    width: 100%;
    margin-top: 14px;
    pointer-events: auto;
  }

  .entity-popover,
  .entity-menu {
    width: calc(100% - 28px);
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 18px;
  }

  .hero,
  .stage-card__header,
  .section-heading--inline {
    flex-direction: column;
    align-items: start;
  }

  .hero-actions {
    justify-content: start;
  }

  .field-grid--two,
  .field-grid--three,
  .stats-grid,
  .entity-popover__metrics {
    grid-template-columns: 1fr;
  }

  .stage-card {
    --stage-height: 480px;
  }
}
