:root {
  --bg: #060b16;
  --panel: rgba(11, 20, 39, 0.82);
  --panel-border: rgba(99, 139, 245, 0.2);
  --text: #e8efff;
  --muted: #97a8cc;
  --accent: #30d5ff;
  --accent-soft: rgba(48, 213, 255, 0.2);
  --ok: #4cd4a9;
  --warn: #ff8b8b;
  --shadow: 0 18px 42px rgba(1, 4, 12, 0.55);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Space Grotesk', 'Segoe UI', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 14% 8%, #14346f 0%, transparent 44%),
    radial-gradient(circle at 90% 82%, #0a3049 0%, transparent 38%),
    linear-gradient(160deg, #040813 0%, #070f21 55%, #03060e 100%);
}

.app-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  gap: 0.95rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(9px);
  padding: 1rem;
}

.tab-nav {
  display: flex;
  gap: 0.55rem;
  align-items: center;
}

.tab-btn {
  border: 1px solid rgba(114, 169, 255, 0.32);
  border-radius: 999px;
  background: rgba(7, 15, 30, 0.92);
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 0.45rem 0.95rem;
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease, background-color 120ms ease;
}

.tab-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.tab-btn.is-active {
  color: #041020;
  background: linear-gradient(135deg, #2dd6ff, #57f0d1);
  border-color: rgba(95, 247, 220, 0.65);
}

.tab-panel[hidden] {
  display: none;
}

.app-header h1 {
  margin: 0.2rem 0;
  letter-spacing: 0.03em;
  font-size: clamp(1.7rem, 5vw, 2.2rem);
}

.kicker {
  margin: 0;
  color: var(--accent);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

h2 {
  margin: 0 0 0.75rem;
  font-size: 1.03rem;
  font-weight: 600;
}

.field-grid {
  display: grid;
  gap: 0.7rem;
  grid-template-columns: 1fr;
}

.field {
  display: grid;
  gap: 0.35rem;
}

.field[hidden] {
  display: none !important;
}

.field span,
.metric .label {
  color: var(--muted);
  font-size: 0.85rem;
}

input,
select {
  width: 100%;
  border: 1px solid rgba(138, 180, 255, 0.28);
  border-radius: 12px;
  background: rgba(5, 13, 27, 0.82);
  color: var(--text);
  padding: 0.68rem 0.72rem;
  font: inherit;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.mode-toggle {
  margin-top: 0.9rem;
  display: inline-flex;
  background: rgba(8, 17, 34, 0.95);
  border-radius: 999px;
  border: 1px solid rgba(114, 161, 255, 0.26);
  overflow: hidden;
}

.mode-toggle label {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.mode-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-toggle span {
  cursor: pointer;
  padding: 0.56rem 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.mode-toggle input:checked + span {
  color: #041020;
  background: linear-gradient(135deg, #2dd6ff, #57f0d1);
  font-weight: 700;
}

.advanced-panel {
  margin-top: 0.9rem;
  border: 1px solid rgba(126, 163, 255, 0.24);
  border-radius: 14px;
  padding: 0.7rem;
  background: rgba(7, 14, 29, 0.72);
}

.advanced-panel summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.7rem;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
}

.check-row input[type='checkbox'] {
  width: 1rem;
  height: 1rem;
}

.check-row.is-disabled {
  opacity: 0.52;
}

#threePreview,
#threePreview canvas {
  touch-action: none;
  user-select: none;
}

.three-debug {
  margin: 0.35rem 0 0;
  padding: 0.45rem 0.55rem;
  border: 1px solid rgba(126, 223, 255, 0.24);
  border-radius: 10px;
  background: rgba(3, 8, 17, 0.62);
  color: #9fd6ff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.74rem;
  line-height: 1.35;
}

.trunk-grid {
  margin-top: 0.25rem;
}

.output-grid {
  display: grid;
  gap: 0.7rem;
}

.preset-row {
  margin-top: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.preset-btn,
.action-btn {
  border: 1px solid rgba(114, 169, 255, 0.32);
  border-radius: 10px;
  background: rgba(7, 15, 30, 0.92);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  padding: 0.5rem 0.72rem;
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.preset-btn:hover,
.action-btn:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(48, 213, 255, 0.12);
  transform: translateY(-1px);
}

.preset-btn:disabled,
.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.preset-btn.active {
  border-color: var(--accent);
  background: rgba(25, 69, 117, 0.5);
}

.helper-result {
  margin-top: 0.8rem;
  display: grid;
  gap: 0.65rem;
}

.designer-grid {
  display: grid;
  gap: 0.8rem;
}

.designer-panel {
  border: 1px solid rgba(103, 145, 255, 0.18);
  border-radius: 14px;
  background: rgba(8, 16, 31, 0.68);
  padding: 0.75rem;
}

.designer-panel h3 {
  margin: 0 0 0.55rem;
  font-size: 0.92rem;
  color: #dbe7ff;
}

.designer-panel svg {
  width: 100%;
  min-height: 220px;
  border-radius: 12px;
  border: 1px solid rgba(138, 180, 255, 0.16);
  background:
    radial-gradient(circle at 50% 8%, rgba(52, 114, 214, 0.14), transparent 48%),
    rgba(3, 8, 17, 0.84);
}

.diagram-controls {
  margin-top: 0.8rem;
  border: 1px solid rgba(103, 145, 255, 0.18);
  border-radius: 13px;
  background: rgba(8, 16, 31, 0.65);
  padding: 0.7rem;
  display: grid;
  gap: 0.6rem;
}

.diagram-controls-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}

.diagram-controls-row input {
  font-size: 1rem;
  padding: 0.6rem 0.65rem;
}

.field.compact span {
  font-size: 0.78rem;
  opacity: 0.9;
}

.diagram-controls-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.8rem;
}

.diagram-volume {
  font-weight: 700;
  color: rgba(201, 228, 255, 0.95);
}

.action-btn {
  background: linear-gradient(135deg, rgba(45, 214, 255, 0.18), rgba(87, 240, 209, 0.14));
  font-weight: 600;
}

.metric {
  border: 1px solid rgba(103, 145, 255, 0.24);
  border-radius: 13px;
  background: rgba(8, 16, 31, 0.8);
  padding: 0.72rem;
  display: grid;
  gap: 0.18rem;
}

.metric .value {
  font-size: clamp(1rem, 4vw, 1.15rem);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.metric.highlight {
  border-color: rgba(48, 213, 255, 0.42);
  box-shadow: 0 0 24px rgba(48, 213, 255, 0.12);
}

input.is-maxed {
  border-color: rgba(48, 213, 255, 0.85) !important;
  box-shadow: 0 0 0 2px rgba(48, 213, 255, 0.18);
}

input.is-too-shallow {
  border-color: rgba(255, 109, 109, 0.95) !important;
  box-shadow: 0 0 0 2px rgba(255, 109, 109, 0.18);
}

.warnings {
  margin: 0;
  padding-left: 1rem;
  min-height: 1.3rem;
  color: var(--warn);
}

.warnings.ok {
  color: var(--ok);
  list-style: none;
  padding-left: 0;
}

.cut-sheet {
  border: 1px solid rgba(103, 145, 255, 0.24);
  border-radius: 13px;
  overflow: hidden;
  background: rgba(7, 14, 29, 0.74);
}

.workflow-guide {
  background: linear-gradient(135deg, rgba(45, 214, 255, 0.12), rgba(87, 240, 209, 0.08));
  border-color: rgba(45, 214, 255, 0.3);
  text-align: center;
  font-size: 0.95rem;
  font-weight: 500;
}

.workflow-text {
  margin: 0;
  line-height: 1.4;
}

.section-hint {
  margin: 0 0 0.7rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.space-info {
  margin-top: 0.7rem;
  padding: 0.6rem;
  background: rgba(48, 213, 255, 0.08);
  border: 1px solid rgba(48, 213, 255, 0.2);
  border-radius: 10px;
  font-size: 0.9rem;
  color: var(--accent);
  text-align: center;
}

.sticky-results {
  position: sticky;
  top: 1rem;
  z-index: 10;
}

/* Mobile Optimizations */
@media (max-width: 640px) {
  .app-shell {
    padding: 0.7rem;
    gap: 0.7rem;
  }

  .card {
    padding: 0.8rem;
    border-radius: 14px;
  }

  h2 {
    font-size: 0.95rem;
    margin-bottom: 0.6rem;
  }

  .field-grid {
    gap: 0.5rem;
  }

  .sticky-results {
    position: static;
    margin: 0.5rem 0;
    background: linear-gradient(135deg, rgba(45, 214, 255, 0.15), rgba(87, 240, 209, 0.1));
    border-color: rgba(45, 214, 255, 0.35);
  }

  .output-grid {
    gap: 0.5rem;
  }

  .metric {
    padding: 0.6rem;
  }

  .metric .value {
    font-size: 1rem;
  }

  .preset-row {
    gap: 0.35rem;
    margin-top: 0.6rem;
  }

  .preset-btn {
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
    flex: 1 1 calc(50% - 0.2rem);
  }

  details.advanced-panel {
    padding: 0.5rem;
  }

  .tab-nav {
    gap: 0.4rem;
  }

  .tab-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
  }

  .mode-toggle {
    width: 100%;
    margin-top: 0.7rem;
  }

  .mode-toggle label {
    flex: 1;
  }

  .mode-toggle span {
    display: block;
    text-align: center;
    padding: 0.5rem;
  }

  .workflow-text {
    font-size: 0.85rem;
  }
}

@media (max-width: 480px) {
  .app-shell {
    padding: 0.5rem;
    gap: 0.5rem;
  }

  .card {
    padding: 0.7rem;
  }

  h2 {
    font-size: 0.9rem;
  }

  .metric .value {
    font-size: 0.95rem;
  }

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

  .preset-btn {
    font-size: 0.75rem;
    padding: 0.35rem 0.5rem;
  }
}

@media (min-width: 720px) {
  .designer-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.cut-sheet table {
  width: 100%;
  border-collapse: collapse;
}

.cut-sheet th,
.cut-sheet td {
  padding: 0.55rem 0.62rem;
  text-align: left;
  border-bottom: 1px solid rgba(96, 131, 212, 0.24);
  font-size: 0.86rem;
}

.cut-sheet th {
  color: var(--muted);
  font-weight: 600;
}

.cut-sheet tr:last-child td {
  border-bottom: none;
}

.cut-sheet-message {
  margin: 0;
  padding: 0.75rem;
  color: var(--warn);
  font-size: 0.9rem;
}

.build-note {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.viz-card svg {
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid rgba(103, 145, 255, 0.24);
  background:
    radial-gradient(circle at 30% 20%, rgba(52, 117, 255, 0.18), transparent 50%),
    rgba(4, 10, 20, 0.88);
}

.diagram-handle {
  cursor: grab;
}

.diagram-handle:active {
  cursor: grabbing;
}

@media (min-width: 720px) {
  .field-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dimension-grid {
    grid-template-columns: repeat(auto-fit, minmax(9.5rem, max-content));
    justify-content: start;
    column-gap: 0.8rem;
    row-gap: 0.7rem;
  }

  .dimension-grid .field {
    width: auto;
    justify-items: start;
  }

  .dimension-grid input[type='number'] {
    width: 9ch;
    max-width: 9ch;
    min-width: 9ch;
  }

  .field input[type='number'],
  .field select {
    max-width: 14rem;
  }

  .single-row {
    grid-template-columns: minmax(0, 1fr);
  }

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

  .metric.highlight {
    grid-column: span 2;
  }
}

@media (min-width: 980px) {
  .dimension-grid {
    grid-template-columns: repeat(4, max-content);
  }
}
