:root {
  --bg: #fdf6ee;
  --card: #ffffff;
  --line: #f0e0cc;
  --orange: #dd6b20;
  --orange-dark: #9c4221;
  --orange-soft: #fff3e6;
  --text: #1a202c;
  --muted: #5a6778;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
body { display: flex; flex-direction: column; height: 100dvh; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

#topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
#brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; white-space: nowrap; }
#tabs { display: flex; gap: 6px; }
.tab { padding: 9px 14px; border: 2px solid var(--line); border-radius: 12px; background: #fff; font-weight: 800; font-size: 15px; white-space: nowrap; }
.tab.active { border-color: var(--orange); background: var(--orange-soft); color: var(--orange-dark); }

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}
.layout[hidden] { display: none; }
.layout.puzzle { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

#side { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
#side section { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
#side h2 { margin: 0 0 8px; font-size: 15px; color: var(--orange-dark); }
#shapes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.shape {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  line-height: 1.15;
}
.shape .i { font-size: 20px; }
.shape.active { border-color: var(--orange); background: var(--orange-soft); }
.param { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-weight: 600; }
.param span { flex: 1; }
.param b { min-width: 58px; text-align: center; }
.step { width: 40px; height: 40px; border: 2px solid var(--line); border-radius: 10px; background: #fff; font-size: 20px; font-weight: 800; }
#fit { margin-top: 6px; font-size: 13px; font-weight: 700; }
#fit.ok { color: #2f855a; }
#fit.bad { color: #c53030; }
.muted { color: var(--muted); font-size: 14px; margin: 0 0 8px; line-height: 1.4; }
.face-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-bottom: 8px; }
.sw { aspect-ratio: 1; border-radius: 50%; border: 2px solid #cbd5e0; }
.sw.on { box-shadow: 0 0 0 3px var(--text); }
#in-text, .field input {
  width: 100%;
  padding: 9px 10px;
  border: 2px solid var(--line);
  border-radius: 10px;
  font-size: 16px;
  margin-bottom: 8px;
}
.stickers { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 8px; }
.st { aspect-ratio: 1; border: 2px solid transparent; border-radius: 8px; background: #f7fafc; font-size: 18px; padding: 0; }
.st.on { border-color: var(--orange); background: var(--orange-soft); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.mini-btn { padding: 7px 10px; border: 2px solid var(--line); border-radius: 10px; background: #fff; font-weight: 700; font-size: 13px; }
.field { display: block; font-weight: 700; font-size: 13px; }
.field input { margin-top: 4px; }
.actions .go { width: 100%; }

.panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.panel-head .hint { font-size: 13px; color: var(--muted); }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.legend i { display: inline-block; width: 18px; height: 0; margin-left: 6px; }
.legend .cut { border-top: 2px solid #2d3748; }
.legend .fold { border-top: 2px dashed #2d3748; }
.legend .tab { height: 10px; background: #e2e8f0; border: 1px solid #2d3748; }
#net-wrap, #pnet-wrap { flex: 1; min-height: 0; display: flex; }
#net-wrap svg, #pnet-wrap svg { width: 100%; height: 100%; }
.face { cursor: pointer; }
.view3d { flex: 1; min-height: 0; position: relative; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #fff, #f4ece2); }
.view3d canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.fold-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.fold-row input { flex: 1; accent-color: var(--orange); height: 32px; }

.go {
  height: 50px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  background: var(--orange);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  box-shadow: 0 3px 0 var(--orange-dark);
  white-space: nowrap;
}
.go:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--orange-dark); }
.go:disabled { background: #cbd5e0; box-shadow: none; }
.go.small { height: 42px; font-size: 15px; }
.go.no { background: #718096; box-shadow: 0 3px 0 #4a5568; }

#pq { padding: 8px 4px 2px; }
#pq p { margin: 0 0 10px; font-size: 17px; font-weight: 600; }
#pq .yes { color: #2f855a; }
#pq .nope { color: #c05621; }
#pscore { font-weight: 800; color: #b7791f; }

#print { display: none; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr 1fr; grid-auto-rows: minmax(360px, auto); overflow-y: auto; }
  #side { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; overflow: visible; }
  #brand span { display: none; }
}
@media (max-width: 680px) {
  .layout, .layout.puzzle { grid-template-columns: 1fr; }
  #side { grid-template-columns: 1fr; }
}

@media print {
  @page { size: A4 portrait; margin: 10mm; }
  html, body { height: auto; background: #fff; display: block; }
  #topbar, .layout { display: none !important; }
  #print { display: block; }
  .p-head { font-size: 10pt; margin-bottom: 4mm; line-height: 1.5; }
  #print svg { display: block; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
