/* ============================================================
   Moulding Studio — Apple-like liquid glass theme
   ============================================================ */

:root {
  --bg: #eef0f4;
  --ink: #1d1d1f;
  --ink-sub: rgba(29, 29, 31, 0.55);
  --ink-faint: rgba(29, 29, 31, 0.35);
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.12);
  --green: #34c759;
  --hairline: rgba(255, 255, 255, 0.65);
  --divider: rgba(29, 29, 31, 0.08);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue",
          "Hiragino Sans", "Segoe UI", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  background:
    radial-gradient(1100px 700px at 12% -8%, rgba(120, 170, 255, 0.20), transparent 60%),
    radial-gradient(900px 640px at 105% 14%, rgba(180, 150, 255, 0.14), transparent 62%),
    radial-gradient(1000px 800px at 50% 118%, rgba(255, 205, 160, 0.14), transparent 60%),
    var(--bg);
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#cad-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.viewport-3d {
  position: absolute;
  inset: 0;
  z-index: 5;
}

.viewport-3d canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ============ Liquid glass panel ============ */

.glass {
  position: absolute;
  z-index: 10;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.66), rgba(255, 255, 255, 0.38));
  -webkit-backdrop-filter: blur(28px) saturate(1.7);
  backdrop-filter: blur(28px) saturate(1.7);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.9),
    inset 0 -1px 1px rgba(255, 255, 255, 0.25),
    0 2px 6px rgba(28, 36, 56, 0.06),
    0 18px 44px rgba(28, 36, 56, 0.13);
}

.panel-caption {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-sub);
}

/* ============ Top bar ============ */

.topbar {
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 60px;
  padding: 0 18px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(160deg, #4aa3ff, #0059c8);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.5), 0 4px 10px rgba(0, 90, 200, 0.35);
}

.brand-mark svg { width: 20px; height: 20px; }

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  white-space: nowrap;
}

.brand-text strong {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-text span {
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

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

/* ============ Segmented control ============ */

.segmented {
  display: flex;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: rgba(118, 118, 128, 0.14);
  box-shadow: inset 0 0.5px 2px rgba(0, 0, 0, 0.06);
}

.segmented button {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 7px 20px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-sub);
  background: transparent;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, box-shadow 160ms ease;
  white-space: nowrap;
}

.segmented button.active {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05), 0 3px 8px rgba(0, 0, 0, 0.12);
}

.segmented--small button {
  padding: 5px 14px;
  font-size: 12px;
}

/* ============ Buttons ============ */

.btn {
  appearance: none;
  border: 1px solid rgba(29, 29, 31, 0.1);
  border-radius: 999px;
  padding: 8px 16px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  white-space: nowrap;
  transition: transform 160ms cubic-bezier(0.22, 1, 0.36, 1),
              box-shadow 160ms cubic-bezier(0.22, 1, 0.36, 1),
              background 120ms ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 1px 3px rgba(28, 36, 56, 0.08);
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 5px 14px rgba(28, 36, 56, 0.14);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: inset 0 1px 3px rgba(28, 36, 56, 0.12);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn--primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(180deg, #2b8bff, #0068d6);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 4px 12px rgba(0, 104, 214, 0.35);
}

.btn--primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #3f97ff, #0071e3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 7px 18px rgba(0, 104, 214, 0.42);
}

.btn--small {
  padding: 6px 12px;
  font-size: 12px;
}

/* ============ Tool palette ============ */

.tool-palette {
  top: 94px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 196px;
  padding: 14px 10px 12px;
}

.tool-palette .panel-caption {
  padding: 0 8px 8px;
}

.tool-button {
  display: flex;
  align-items: center;
  gap: 10px;
  appearance: none;
  border: none;
  border-radius: var(--radius-md);
  padding: 9px 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: background 120ms ease, color 120ms ease;
}

.tool-button svg {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0.75;
}

.tool-button span { flex: 1; }

.tool-button kbd {
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-faint);
  border: 1px solid var(--divider);
  border-radius: 5px;
  padding: 1px 5px;
  background: rgba(255, 255, 255, 0.5);
}

.tool-button:hover { background: rgba(29, 29, 31, 0.05); }

.tool-button.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.tool-button.active svg { opacity: 1; }

.tool-button.active kbd {
  color: var(--accent);
  border-color: rgba(0, 113, 227, 0.3);
}

/* ============ Inspector ============ */

.inspector {
  top: 94px;
  right: 16px;
  bottom: 88px;
  width: 292px;
  padding: 4px 16px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.inspector::-webkit-scrollbar { width: 8px; }
.inspector::-webkit-scrollbar-thumb {
  background: rgba(29, 29, 31, 0.15);
  border-radius: 4px;
}

.inspector-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--divider);
}

.inspector-section:last-child { border-bottom: none; }

.inspector-section .panel-caption { margin-bottom: 10px; }

.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.field-row:last-child { margin-bottom: 0; }

.field-row > label {
  width: 52px;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-sub);
}

.field-row--buttons { gap: 6px; }

.field-row--slider input[type="range"] { flex: 1; min-width: 0; }

.field-value {
  width: 42px;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.section-note {
  margin: 0 0 10px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink-sub);
}

/* ============ Selects & sliders ============ */

select {
  appearance: none;
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(29, 29, 31, 0.12);
  border-radius: var(--radius-sm);
  padding: 7px 26px 7px 10px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236e6e73' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
      no-repeat right 9px center / 10px,
    rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 1px 2px rgba(28, 36, 56, 0.05);
  cursor: pointer;
}

select:focus-visible,
.btn:focus-visible,
.segmented button:focus-visible,
.tool-button:focus-visible {
  outline: 2px solid rgba(0, 113, 227, 0.5);
  outline-offset: 2px;
}

.select-block {
  width: 100%;
  margin-bottom: 10px;
}

input[type="range"] {
  accent-color: var(--accent);
  cursor: pointer;
}

input[type="range"]:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

/* ============ Template progress & steps ============ */

.template-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.progress-track {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: rgba(118, 118, 128, 0.18);
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #4aa3ff, var(--accent));
  transition: width 320ms cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-fill.complete { background: linear-gradient(90deg, #5fd77e, var(--green)); }

.progress-text {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink-sub);
}

.template-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.template-steps li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  transition: background 160ms ease;
}

.template-steps .step-index {
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  flex-shrink: 0;
  border-radius: 50%;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ink-sub);
  background: rgba(118, 118, 128, 0.16);
}

.template-steps .step-label {
  flex: 1;
  font-weight: 600;
}

.template-steps .step-tool {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 2px 6px;
  white-space: nowrap;
}

.template-steps li.done {
  background: rgba(52, 199, 89, 0.1);
}

.template-steps li.done .step-index {
  color: #fff;
  background: var(--green);
}

.template-steps li.done .step-label {
  color: var(--ink-sub);
}

.template-steps li.done .step-tool {
  color: var(--green);
  background: rgba(52, 199, 89, 0.14);
}

/* ============ Status bar ============ */

.status-bar {
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 18px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}

.status-chip {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px 10px;
}

.status-item {
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-sub);
}

/* ============ Zoom cluster ============ */

.zoom-cluster {
  bottom: 16px;
  right: 16px;
  display: flex;
  padding: 4px;
  border-radius: 999px;
}

.zoom-cluster button {
  appearance: none;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  transition: background 120ms ease;
}

.zoom-cluster button:hover { background: rgba(29, 29, 31, 0.07); }

/* ============ Help ============ */

.help-button {
  bottom: 16px;
  left: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink-sub);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color 120ms ease;
}

.help-button:hover { color: var(--accent); }

.help-popover {
  bottom: 72px;
  left: 16px;
  max-width: 340px;
  padding: 16px 18px;
}

.help-popover .panel-caption { margin-bottom: 8px; }

.help-popover ul {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 12.5px;
  line-height: 1.8;
  color: rgba(29, 29, 31, 0.78);
}

.help-popover li::before {
  content: "·";
  margin-right: 7px;
  color: var(--accent);
  font-weight: 700;
}

/* ============ 3D viewer panel ============ */

.viewer-panel {
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 9px 16px;
  border-radius: 999px;
  white-space: nowrap;
}

.viewer-hint {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-sub);
}

.viewer-message {
  font-size: 12.5px;
  font-weight: 600;
  color: #c2410c;
}

/* ============ 3D mode visibility ============ */

body.mode-3d #cad-canvas,
body.mode-3d .tool-palette,
body.mode-3d .inspector,
body.mode-3d .status-bar,
body.mode-3d .zoom-cluster,
body.mode-3d .help-button,
body.mode-3d .help-popover {
  display: none;
}

/* ============ Responsive ============ */

@media (max-width: 1080px) {
  .brand-text span { display: none; }
  .tool-palette { width: 60px; }
  .tool-palette .panel-caption,
  .tool-button span,
  .tool-button kbd { display: none; }
  .tool-button { justify-content: center; }
}

@media (max-width: 860px) {
  .topbar {
    height: auto;
    flex-wrap: wrap;
    padding: 10px 14px;
  }
  .inspector {
    top: auto;
    bottom: 76px;
    right: 12px;
    width: 260px;
    max-height: 46vh;
  }
  .tool-palette { top: 130px; left: 12px; }
  .status-bar { display: none; }
}
