:root {
  --bg: #1c1814;
  --panel: #2a241e;
  --ink: #f4efe6;
  --muted: #b7a99a;
  --line: #4a4036;
  --accent: #d08a3a;
  --ok: #7cb87c;
  --err: #e07a6a;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: #231e19;
}
h1 { margin: 0; font-size: 1.25rem; }
.sub { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.9rem; }
.icon-btn {
  flex-shrink: 0;
  width: 2.15rem;
  height: 2.15rem;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  color: var(--ink);
}
.icon-btn:hover { filter: brightness(1.08); }

.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 5.5rem;
  padding: 0.5rem;
  border-bottom: 1px solid var(--line);
  background: #1a1612;
}
.ad-slot[hidden] {
  display: none !important;
}

.info-page {
  min-height: calc(100vh - 76px);
  overflow: auto;
  background: var(--bg);
}
.info-body {
  max-width: 40rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}
.info-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.info-head h2 {
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: 1.35rem;
  color: var(--ink);
}
.info-body h3 {
  margin: 1.4rem 0 0.4rem;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.info-body p, .info-body li {
  line-height: 1.55;
  color: var(--ink);
}
.info-body ol { padding-left: 1.2rem; }
.info-body li { margin: 0.35rem 0; }
.solve-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}
.solve-bar .status { margin: 0; flex: 1; min-height: 1.4rem; }
.runtime-est {
  margin: 0;
  flex-shrink: 0;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

button, select, input {
  background: #3a322b;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.4rem 0.7rem;
  font: inherit;
}
button { cursor: pointer; }
button.primary { background: var(--accent); color: #1c1814; font-weight: 700; border-color: #b8742c; }
button.danger { background: #8a3a32; color: #f4efe6; font-weight: 700; border-color: #a34a40; }
button:hover { filter: brightness(1.08); }

.layout {
  display: grid;
  grid-template-columns: minmax(22rem, 0.46fr) minmax(16rem, 1fr);
  min-height: calc(100vh - 76px);
}
.layout[hidden],
.info-page[hidden] {
  display: none !important;
}
.panel { padding: 1rem 1.15rem; }
.inputs { border-right: 1px solid var(--line); overflow: auto; }
.viewer { display: flex; flex-direction: column; min-height: 0; }

h2 { font-size: 0.95rem; margin: 0.8rem 0 0.5rem; letter-spacing: 0.03em; text-transform: uppercase; color: var(--muted); }
.grid-params {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.82rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 0.4rem; color: var(--ink); }
input[type="number"] {
  width: 100%;
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"]:focus {
  -moz-appearance: auto;
  appearance: auto;
}
input[type="number"]:focus::-webkit-outer-spin-button,
input[type="number"]:focus::-webkit-inner-spin-button {
  -webkit-appearance: auto;
  margin: 0;
}

.table-head { display: flex; justify-content: space-between; align-items: center; gap: 0.4rem; }
.table-actions { display: flex; flex-wrap: nowrap; align-items: center; gap: 0.3rem; }
.table-actions select {
  min-width: 2.5rem;
  max-width: 4.5rem;
  padding: 0.25rem 0.4rem;
  font-size: 0.82rem;
}
.joined-control {
  display: inline-flex;
  align-items: stretch;
}
.joined-control > :first-child {
  border-radius: 6px 0 0 6px;
}
.joined-control > :last-child {
  border-radius: 0 6px 6px 0;
  margin-left: -1px;
  position: relative;
}
.joined-control > :focus {
  z-index: 1;
}
.table-actions button,
.table-actions .file-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.82rem;
  white-space: nowrap;
}
.svg-sprites {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}
.btn-glyph {
  width: 0.9rem;
  height: 0.9rem;
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
}
label.file-btn,
#export-cuts,
#export-svg {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.3rem;
}
label.file-btn {
  flex-shrink: 0;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #2e2721;
  color: inherit;
}
.file-btn input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.table-wrap { overflow-x: auto; }
.table-scroll {
  max-height: 14.75rem;
  overflow: auto;
  border: 1px solid var(--line);
  background: #1f1a16;
}
.table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #2e2721;
}
.table-scroll table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.table-scroll th, .table-scroll td {
  border: 1px solid var(--line);
  padding: 0;
  text-align: left;
  vertical-align: middle;
}
.table-scroll th {
  color: var(--muted);
  font-weight: 600;
  padding: 0.35rem 0.45rem;
}
.table-scroll td input {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0.32rem 0.45rem;
}
.table-scroll td.num input { text-align: right; }
.table-scroll td:last-child { width: 2.1rem; text-align: center; }
.table-scroll .remove {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0.25rem 0.4rem;
  width: 100%;
}

.status { min-height: 1.4rem; color: var(--muted); }
.status.error { color: var(--err); }
.status.ok { color: var(--ok); }

.viewer-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  align-items: end;
  margin-bottom: 0.6rem;
}
.tabs { display: flex; }
.tabs button {
  border-radius: 0;
  padding: 0.4rem 0.9rem;
}
.tabs button:first-child { border-radius: 6px 0 0 6px; }
.tabs button:last-child { border-radius: 0 6px 6px 0; }
.tabs button[aria-selected="true"] {
  background: var(--accent);
  color: #1c1814;
  font-weight: 700;
  border-color: #b8742c;
}
.sku-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.sku-list button.active {
  border-color: var(--accent);
  background: #4a3a28;
}
body.mode-2d .only-3d { display: none; }
body.mode-3d .only-2d { display: none; }
.summary {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.88rem;
  max-width: 100%;
  text-align: right;
}
#viewport, #view-2d {
  flex: 1 1 auto;
  min-height: 240px;
  max-height: min(66vh, 520px);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
#viewport { background: #14110e; }
#view-2d {
  background: #efe6d6;
  overflow: auto;
  padding: 0.75rem;
}
#view-2d svg { display: block; max-width: 100%; height: auto; }
#view-2d .piece-hit { cursor: pointer; }
.piece-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  list-style: none;
  margin: 0.55rem 0 0;
  padding: 0;
}
.piece-list button {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
}
.piece-list .swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  display: inline-block;
}
.piece-list button.active {
  border-color: var(--accent);
  background: #4a3a28;
}
.detail {
  margin-top: 0.6rem;
  padding: 0.7rem 0.8rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}
.detail strong { color: var(--ink); }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .inputs { border-right: 0; border-bottom: 1px solid var(--line); }
  #viewport, #view-2d { min-height: 200px; max-height: 50vh; }
}
