:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-soft: #f7f9fc;
  --text: #182233;
  --muted: #7c8799;
  --line: #e3e8ef;
  --accent: #246bfd;
  --accent-soft: #edf4ff;
  --success: #11a36a;
  --shadow: 0 18px 50px rgba(18, 33, 54, .10);
  --radius: 22px;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 5%, rgba(36,107,253,.08), transparent 28rem),
    var(--bg);
  transition: background .25s ease, color .25s ease;
}

body.dark {
  --bg: #0a0f18;
  --panel: #111827;
  --panel-soft: #172033;
  --text: #edf3ff;
  --muted: #94a1b5;
  --line: #263247;
  --accent: #5b8cff;
  --accent-soft: #182b52;
  --shadow: 0 18px 55px rgba(0,0,0,.3);
}

button, input { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(1380px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 15px;
  background: var(--text);
  box-shadow: 0 10px 24px rgba(23,34,51,.14);
}

.brand-mark svg {
  width: 31px;
  fill: none;
  stroke: var(--panel);
  stroke-width: 4;
  stroke-linecap: round;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.15rem, 2vw, 1.45rem);
  letter-spacing: -.03em;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: .9rem;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(20,32,50,.05);
}

.icon-btn .moon { display: none; }
body.dark .icon-btn .sun { display: none; }
body.dark .icon-btn .moon { display: inline; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, .65fr);
  gap: 22px;
  align-items: start;
}

.calculator-card,
.result-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.calculator-card { padding: clamp(20px, 3vw, 32px); }

.result-card {
  position: sticky;
  top: 20px;
  padding: 28px;
  overflow: hidden;
}

.section-heading,
.result-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-heading h2 {
  margin: 5px 0 0;
  font-size: 1.12rem;
  letter-spacing: -.02em;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: .71rem;
  font-weight: 800;
  letter-spacing: .13em;
}

.density-pill,
.live-dot {
  flex: 0 0 auto;
  padding: 8px 11px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}

.live-dot {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.live-dot i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(17,163,106,.1);
}

.material-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 18px;
}

.material-card,
.shape-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: border-color .16s ease, transform .16s ease, background .16s ease, box-shadow .16s ease;
}

.material-card {
  min-height: 76px;
  padding: 13px 12px;
  text-align: left;
}

.material-card strong { display: block; font-size: .87rem; }
.material-card span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: .72rem;
}

.material-card:hover,
.shape-card:hover {
  transform: translateY(-1px);
  border-color: rgba(36,107,253,.45);
}

.material-card.active,
.shape-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.material-card.active::after {
  content: "✓";
  position: absolute;
  top: 9px;
  right: 9px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: .68rem;
  font-weight: 900;
}

.divider {
  height: 1px;
  margin: 28px 0;
  background: var(--line);
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-top: 18px;
}

.shape-card {
  min-height: 88px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 9px;
  padding: 12px 8px;
  font-size: .78rem;
}

.shape-icon {
  display: block;
  width: 29px;
  height: 29px;
  border: 3px solid currentColor;
  color: var(--muted);
}

.shape-card.active .shape-icon { color: var(--accent); }
.round-shape { border-radius: 50%; }

.tube-shape {
  border-radius: 50%;
  position: relative;
}
.tube-shape::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.hex-shape {
  border: none;
  width: 33px;
  height: 30px;
  background: currentColor;
  clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0 50%);
  position: relative;
}
.hex-shape::after {
  content: "";
  position: absolute;
  inset: 3px;
  background: var(--panel);
  clip-path: inherit;
}
.shape-card.active .hex-shape::after { background: var(--accent-soft); }

.square-shape { border-radius: 3px; }
.rectangle-shape {
  width: 36px;
  height: 24px;
  margin-block: 3px;
  border-radius: 3px;
}

.unit-switch {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--panel-soft);
}

.unit-switch button {
  min-width: 48px;
  border: 0;
  border-radius: 8px;
  padding: 7px 9px;
  background: transparent;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 800;
  cursor: pointer;
}

.unit-switch button.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

.fields-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-top: 18px;
}

.quantity-row {
  width: calc(50% - 7px);
  margin-top: 14px;
}

.field {
  display: block;
}

.field > span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 700;
}

.input-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
  overflow: hidden;
  transition: border-color .16s ease, box-shadow .16s ease;
}

.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36,107,253,.10);
}

.input-wrap input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  padding: 13px 14px;
  background: transparent;
  color: var(--text);
  font-weight: 750;
}

.suffix {
  padding-right: 13px;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 700;
}

.action-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  margin-top: 22px;
}

.primary-btn,
.secondary-btn {
  min-height: 48px;
  border-radius: 13px;
  border: 0;
  font-weight: 800;
  cursor: pointer;
}

.primary-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--accent);
  color: white;
  box-shadow: 0 10px 24px rgba(36,107,253,.24);
}

.secondary-btn {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
}

.stock-preview {
  height: 230px;
  display: grid;
  place-items: center;
  margin: 18px -8px 6px;
  border-radius: 18px;
  background:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px),
    var(--panel-soft);
  background-size: 22px 22px;
  perspective: 700px;
}

.preview-object {
  position: relative;
  width: 185px;
  height: 82px;
  border-radius: 41px;
  background: linear-gradient(90deg, #8d99a8 0%, #dce2e9 34%, #9ba8b6 70%, #778493 100%);
  box-shadow: 15px 24px 34px rgba(0,0,0,.17);
  transform: rotateX(-8deg) rotateY(-19deg) rotateZ(-3deg);
}

.preview-object::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 0;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #f0f3f7 0%, #b9c2cc 42%, #7d8997 72%, #697583 100%);
  box-shadow: inset -8px -5px 15px rgba(0,0,0,.16);
}

.preview-object.tube-preview::after {
  content: "";
  position: absolute;
  left: 24px;
  top: 24px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #45505d;
  box-shadow: inset 2px 2px 7px rgba(0,0,0,.65), 0 0 0 4px rgba(255,255,255,.16);
}

.preview-object.hex-preview,
.preview-object.square-preview,
.preview-object.rectangle-preview {
  border-radius: 8px;
}

.preview-object.hex-preview::before {
  border-radius: 0;
  clip-path: polygon(25% 5%,75% 5%,100% 50%,75% 95%,25% 95%,0 50%);
}

.preview-object.square-preview::before,
.preview-object.rectangle-preview::before {
  border-radius: 7px;
}

.preview-object.rectangle-preview { height: 65px; }
.preview-object.rectangle-preview::before { height: 65px; width: 82px; }

.dimension-line,
.dimension-text { display: none; }

.main-result {
  padding: 24px 0;
  text-align: center;
}

.main-result > span {
  display: block;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 700;
}

.main-result strong {
  display: block;
  margin: 7px 0 3px;
  font-size: clamp(2.5rem, 5vw, 3.5rem);
  line-height: 1;
  letter-spacing: -.06em;
}

.main-result strong small {
  font-size: 1.05rem;
  letter-spacing: 0;
  color: var(--muted);
}

.main-result em {
  color: var(--muted);
  font-size: .8rem;
  font-style: normal;
}

.result-list {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.result-list div {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 13px 0;
  font-size: .8rem;
}

.result-list div + div { border-top: 1px solid var(--line); }
.result-list span { color: var(--muted); }
.result-list strong { text-align: right; }

.formula-box {
  margin-top: 18px;
  padding: 14px 15px;
  border-radius: 13px;
  background: var(--panel-soft);
}

.formula-box span {
  color: var(--muted);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.formula-box p {
  margin: 6px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
  font-size: .75rem;
}

.note {
  margin: 15px 3px 0;
  color: var(--muted);
  font-size: .7rem;
  line-height: 1.55;
}

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .result-card { position: static; }
}

@media (max-width: 720px) {
  .app-shell { width: min(100% - 20px, 1380px); padding-top: 14px; }
  .brand p { display: none; }
  .material-grid { grid-template-columns: repeat(2, 1fr); }
  .shape-grid { grid-template-columns: repeat(3, 1fr); }
  .fields-grid { grid-template-columns: 1fr; }
  .quantity-row { width: 100%; }
}

@media (max-width: 430px) {
  .calculator-card, .result-card { border-radius: 18px; }
  .calculator-card, .result-card { padding: 18px; }
  .shape-grid { grid-template-columns: repeat(2, 1fr); }
  .section-heading { align-items: flex-start; }
  .action-row { grid-template-columns: 1fr; }
  .secondary-btn { order: 2; }
  .stock-preview { height: 190px; }
}


.material-controls {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(180px, .65fr);
  gap: 14px;
  margin-top: 18px;
}

.select-wrap {
  position: relative;
}

.select-wrap::after {
  content: "⌄";
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-54%);
  color: var(--muted);
  pointer-events: none;
  font-size: 1rem;
  font-weight: 800;
}

.select-wrap select {
  width: 100%;
  min-height: 46px;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  padding: 0 42px 0 14px;
  background: var(--panel-soft);
  color: var(--text);
  font-weight: 750;
  cursor: pointer;
  transition: border-color .16s ease, box-shadow .16s ease;
}

.select-wrap select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36,107,253,.10);
}

.result-list .price-highlight {
  margin: 3px -10px;
  padding: 15px 10px;
  border-radius: 11px;
  background: var(--accent-soft);
  border-top: 0;
}

.result-list .price-highlight span,
.result-list .price-highlight strong {
  color: var(--accent);
  font-weight: 850;
}

@media (max-width: 720px) {
  .material-controls {
    grid-template-columns: 1fr;
  }
}


/* PHP/mobile production refinements */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

button,
select,
input {
  min-height: 44px;
}

input,
select {
  font-size: 16px;
}

.primary-btn,
.secondary-btn,
.shape-card,
.icon-btn,
.unit-switch button {
  touch-action: manipulation;
}

@media (hover: none) and (pointer: coarse) {
  .material-card:hover,
  .shape-card:hover {
    transform: none;
  }
}

@media (max-width: 600px) {
  .app-shell {
    width: 100%;
    padding: 10px 10px calc(18px + env(safe-area-inset-bottom));
  }

  .topbar {
    margin-bottom: 12px;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
  }

  .calculator-card,
  .result-card {
    border-radius: 16px;
    padding: 16px;
  }

  .workspace {
    gap: 14px;
  }

  .section-heading,
  .result-top {
    gap: 10px;
  }

  .section-heading h2 {
    font-size: 1rem;
  }

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

  .shape-card {
    min-height: 78px;
  }

  .fields-grid,
  .material-controls {
    gap: 10px;
  }

  .divider {
    margin: 22px 0;
  }

  .action-row {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 20px -16px -16px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--panel) 94%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }

  .stock-preview {
    height: 170px;
    margin-inline: 0;
  }

  .preview-object {
    transform: scale(.88) rotateX(-8deg) rotateY(-19deg) rotateZ(-3deg);
  }

  .main-result {
    padding: 18px 0;
  }

  .main-result strong {
    font-size: clamp(2.25rem, 14vw, 3rem);
  }

  .result-list div {
    align-items: center;
    font-size: .78rem;
  }
}

@media (max-width: 360px) {
  .shape-grid {
    grid-template-columns: 1fr 1fr;
  }

  .brand h1 {
    font-size: 1rem;
  }

  .density-pill {
    padding: 7px 9px;
    font-size: .7rem;
  }
}


/* SolidWorks-style 3D stock viewport */
.solid-viewport {
  position: relative;
  height: 280px;
  overflow: hidden;
  padding: 0;
  background:
    radial-gradient(circle at 50% 32%, rgba(255,255,255,.95), rgba(234,239,246,.92) 45%, rgba(214,222,232,.96) 100%);
  border: 1px solid var(--line);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

body.dark .solid-viewport {
  background:
    radial-gradient(circle at 50% 32%, rgba(49,63,83,.95), rgba(25,34,49,.97) 48%, rgba(15,22,34,.99) 100%);
}

.solid-viewport:active { cursor: grabbing; }

#solidCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.view-badge,
.view-hint {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  background: color-mix(in srgb, var(--panel) 84%, transparent);
  backdrop-filter: blur(8px);
  color: var(--muted);
}

.view-badge {
  top: 12px;
  left: 12px;
  padding: 6px 9px;
  border-radius: 8px;
  font-size: .62rem;
  font-weight: 900;
  letter-spacing: .11em;
}

.view-hint {
  right: 12px;
  bottom: 12px;
  padding: 6px 9px;
  border-radius: 8px;
  font-size: .66rem;
  font-weight: 700;
}

@media (max-width: 600px) {
  .solid-viewport { height: 220px; }
  .view-hint { display: none; }
}


/* Clean solid preview: opaque faces, no internal/back edge overlay */
#solidCanvas {
  opacity: 1 !important;
  mix-blend-mode: normal;
}

.solid-viewport {
  isolation: isolate;
}
