@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

:root {
  /* MD3 Dark Colors */
  --md-sys-color-background: #141218;
  --md-sys-color-on-background: #e6e1e5;

  --md-sys-color-surface: #141218;
  --md-sys-color-surface-container-low: #1d1b20;
  --md-sys-color-surface-container: #211f26;
  --md-sys-color-surface-container-high: #2b2930;
  --md-sys-color-surface-container-highest: #36343b;

  --md-sys-color-on-surface: #e6e1e5;
  --md-sys-color-on-surface-variant: #cac4d0;
  --md-sys-color-outline: #938f99;
  --md-sys-color-outline-variant: #49454f;

  --md-sys-color-primary: #d0bcff;
  --md-sys-color-on-primary: #381e72;
  --md-sys-color-primary-container: #4f378b;
  --md-sys-color-on-primary-container: #eaddff;

  --md-sys-color-secondary: #ccc2dc;
  --md-sys-color-on-secondary: #332d41;
  --md-sys-color-secondary-container: #4a4458;
  --md-sys-color-on-secondary-container: #e8def8;

  --md-sys-color-tertiary: #efb8c8;
  --md-sys-color-on-tertiary: #492532;
  --md-sys-color-tertiary-container: #633b48;
  --md-sys-color-on-tertiary-container: #ffd8e4;

  --md-sys-color-error: #f2b8b5;
  --md-sys-color-on-error: #601410;
  --md-sys-color-error-container: #8c1d18;
  --md-sys-color-on-error-container: #f9dedc;

  /* Shapes */
  --shape-corner-xs: 4px;
  --shape-corner-s: 8px;
  --shape-corner-m: 12px;
  --shape-corner-l: 16px;
  --shape-corner-xl: 28px;
  --shape-corner-full: 999px;

  /* Elevations */
  --elevation-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.15);
  --elevation-2: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 6px 2px rgba(0, 0, 0, 0.15);
  --elevation-3: 0 4px 8px 3px rgba(0, 0, 0, 0.15), 0 1px 3px rgba(0, 0, 0, 0.3);
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: 'Roboto', system-ui, sans-serif;
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  font-size: 16px;
  line-height: 1.5;
}

body.cas-app {
  /* Subtle gradient mesh for premium feel */
  background:
    radial-gradient(circle at 10% 20%, rgba(208, 188, 255, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(239, 184, 200, 0.05) 0%, transparent 40%),
    var(--md-sys-color-background);
}

.cas-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  min-height: 100%;
  box-sizing: border-box;
}

/* --- Topbar --- */
.cas-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0 32px;
}

.cas-topbar__title {
  display: flex;
  flex-direction: column;
}

.cas-eyebrow {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--md-sys-color-primary);
  margin-bottom: 4px;
}

.cas-topbar h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 400;
  /* MD3 uses lighter weights for large type */
  color: var(--md-sys-color-on-background);
  line-height: 1.2;
}

.cas-subtitle {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--md-sys-color-on-surface-variant);
  max-width: 600px;
}

.cas-link {
  display: inline-flex;
  align-items: center;
  height: 40px;
  padding: 0 24px;
  border-radius: var(--shape-corner-full);
  background-color: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-primary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background-color 0.2s;
}

.cas-link:hover {
  background-color: var(--md-sys-color-surface-container-highest);
}

/* --- Layout --- */
.cas-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}

@media (min-width: 1024px) {
  .cas-grid {
    grid-template-columns: 360px 1fr;
    align-items: start;
  }
}

/* --- Cards --- */
.cas-card {
  background-color: var(--md-sys-color-surface-container-low);
  border-radius: var(--shape-corner-l);
  /* No border in MD3 dark usually, or very subtle */
  border: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: var(--elevation-1);
  overflow: hidden;
  transition: box-shadow 0.2s;
}

.cas-card:hover {
  box-shadow: var(--elevation-2);
}

.cas-card__header {
  padding: 24px 24px 16px;
}

.cas-card__header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 400;
  color: var(--md-sys-color-on-surface);
}

.cas-card__header p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

.cas-card__body {
  padding: 0 24px 24px;
}

/* --- Form Elements --- */
.cas-stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 8px;
  margin-left: 4px;
  /* Align with input text */
}

.form-input,
.form-input-num {
  width: 100%;
  box-sizing: border-box;
  background-color: var(--md-sys-color-surface-container-high);
  border: 1px solid transparent;
  /* default no border */
  border-radius: var(--shape-corner-xs);
  padding: 12px 16px;
  font-size: 16px;
  color: var(--md-sys-color-on-surface);
  outline: none;
  transition: all 0.2s;
  border-bottom: 2px solid var(--md-sys-color-outline);
}

.form-input:focus,
.form-input-num:focus {
  background-color: var(--md-sys-color-surface-container-highest);
  border-bottom-color: var(--md-sys-color-primary);
}

.hint {
  font-size: 11px;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 6px;
  margin-left: 16px;
}

.cas-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.cas-divider {
  height: 1px;
  background-color: var(--md-sys-color-outline-variant);
  margin: 4px 0;
}

/* Toggles / Checkboxes */
.cas-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--shape-corner-m);
  background-color: var(--md-sys-color-surface-container-high);
  cursor: pointer;
  user-select: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  transition: background 0.2s;
}

.cas-toggle:hover {
  background-color: var(--md-sys-color-surface-container-highest);
}

.cas-toggle input {
  accent-color: var(--md-sys-color-primary);
  width: 18px;
  height: 18px;
}

/* Segmented Buttons (Material options) */
.material-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: transparent;
}

.option-btn {
  background-color: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface-variant);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-corner-s);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
}

.option-btn:hover {
  background-color: var(--md-sys-color-surface-container-highest);
}

.option-btn.active {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border-color: transparent;
}

.option-btn.active::before {
  content: '✓';
  margin-right: 8px;
  font-weight: bold;
}

/* Validation */
.cas-validation {
  min-height: 24px;
  color: var(--md-sys-color-error);
  font-size: 13px;
  padding: 8px 16px;
  background-color: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  border-radius: var(--shape-corner-s);
  display: none;
  /* Hide when empty */
}

.cas-validation:not(:empty) {
  display: block;
}

/* Actions */
.cas-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
}

button {
  font-family: inherit;
}

.generate-btn,
.secondary-btn,
.show-drawing-btn {
  border: none;
  border-radius: var(--shape-corner-full);
  padding: 0 24px;
  height: 40px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.2s, background 0.2s;
}

.generate-btn {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  flex: 1;
}

.generate-btn:hover {
  box-shadow: var(--elevation-1);
  filter: brightness(1.05);
  /* slightly lighter */
}

.generate-btn:disabled {
  background-color: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
  cursor: not-allowed;
}

.secondary-btn {
  background-color: transparent;
  border: 1px solid var(--md-sys-color-outline);
  color: var(--md-sys-color-primary);
}

.secondary-btn:hover {
  background-color: rgba(208, 188, 255, 0.08);
  /* Primary color with low opacity */
}

.show-drawing-btn {
  width: 100%;
  margin-top: 12px;
  background-color: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
}

.show-drawing-btn:hover {
  background-color: var(--md-sys-color-outline-variant);
}

/* --- Preview Area --- */
.cas-preview3d {
  height: 600px;
  background-color: #000;
  /* Pure black for contrast with 3d scene */
  padding: 0;
  position: relative;
}

.cas-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

@media (max-width: 768px) {
  .cas-preview3d {
    height: 400px;
  }
}

/* --- Modal --- */
.cas-modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.2, 0, 0, 1);
}

.cas-modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.cas-modal-content {
  background-color: var(--md-sys-color-surface-container);
  border-radius: var(--shape-corner-xl);
  box-shadow: var(--elevation-3);
  width: 90vw;
  max-width: 900px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.2, 0, 0, 1);
  overflow: hidden;
}

.cas-modal-overlay.active .cas-modal-content {
  transform: scale(1);
}

.cas-modal-header {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.cas-modal-header h3 {
  margin: 0;
  font-size: 22px;
  font-weight: 400;
  color: var(--md-sys-color-on-surface);
}

.cas-close-btn {
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 24px;
  cursor: pointer;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.cas-close-btn:hover {
  background-color: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
}

.cas-modal-body {
  padding: 24px;
  overflow-y: auto;
  background-color: var(--md-sys-color-surface-container-low);
}

.cas-drawing {
  background-color: #ffffff;
  /* Drawing preview must be white usually */
  padding: 20px;
  border-radius: var(--shape-corner-m);
  display: flex;
  justify-content: center;
}