:root {
  --petal: #fff1c7;
  --sky: #c5e8ff;
  --leaf: #2f7f67;
  --leaf-soft: #65bfa3;
  --berry: #c94f7c;
  --blueberry: #4d78bd;
  --sun: #f0bd62;
  --panel: #fff7d9;
  --panel-strong: #ffe6a3;
  --ink: #284e6f;
  --focus: #d35f8d;
  --shadow: rgba(96, 124, 170, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky), var(--petal));
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  width: 100vw;
  height: 100vh;
}

.stage {
  position: relative;
  min-width: 0;
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.status-strip {
  position: absolute;
  left: clamp(16px, 3vw, 32px);
  right: clamp(16px, 3vw, 32px);
  bottom: clamp(16px, 3vw, 28px);
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid rgba(77, 120, 189, 0.25);
  border-radius: 8px;
  background: rgba(255, 247, 217, 0.82);
  box-shadow: 0 12px 30px var(--shadow);
  backdrop-filter: blur(14px);
  pointer-events: none;
}

.status-strip span {
  overflow-wrap: anywhere;
}

.tool-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 18px;
  border-left: 1px solid rgba(77, 120, 189, 0.22);
  background: rgba(255, 241, 199, 0.92);
  box-shadow: -18px 0 42px rgba(117, 167, 232, 0.18);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--berry);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: 1.45rem;
  line-height: 1.15;
}

.control-group {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(77, 120, 189, 0.2);
  border-radius: 8px;
  background: rgba(255, 247, 217, 0.76);
}

.group-title {
  color: var(--leaf);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.piece-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.piece-card,
.material-card,
.segmented button,
.tool-button,
.primary-button,
.danger-button,
.icon-button {
  border: 1px solid rgba(77, 120, 189, 0.26);
  border-radius: 8px;
  background: #fff1c7;
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(117, 167, 232, 0.15);
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.piece-card:hover,
.material-card:hover,
.segmented button:hover,
.tool-button:hover,
.primary-button:hover,
.danger-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(117, 167, 232, 0.22);
}

.piece-card:focus-visible,
.material-card:focus-visible,
.segmented button:focus-visible,
.tool-button:focus-visible,
.primary-button:focus-visible,
.danger-button:focus-visible,
.icon-button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(211, 95, 141, 0.45);
  outline-offset: 2px;
}

.piece-card {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 48px;
  padding: 7px 9px;
  font-weight: 750;
  text-align: left;
}

.piece-card.active,
.material-card.active,
.segmented button.active {
  border-color: rgba(201, 79, 124, 0.75);
  background: #ffe6a3;
}

.piece-icon {
  width: 30px;
  height: 30px;
  border: 2px solid rgba(40, 78, 111, 0.32);
  background: linear-gradient(135deg, #f08cae, #f0bd62);
  box-shadow: inset 0 3px 8px rgba(255, 247, 217, 0.5);
}

.cube-icon {
  border-radius: 8px;
}

.square-icon {
  border-radius: 3px;
}

.wedge-icon {
  clip-path: polygon(12% 88%, 88% 88%, 88% 18%);
}

.slope-icon {
  clip-path: polygon(12% 88%, 88% 88%, 88% 42%, 12% 18%);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.segmented button,
.tool-button,
.primary-button,
.icon-button {
  min-height: 42px;
  padding: 8px 10px;
  font-weight: 800;
}

.button-row {
  display: grid;
  grid-template-columns: 42px 42px minmax(84px, 1fr) 42px;
  gap: 8px;
  align-items: center;
}

.view-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.view-grid .tool-button {
  aspect-ratio: 1;
  min-height: 42px;
  padding: 0;
}

.primary-button {
  background: #f08cae;
  color: #fff7d9;
  border-color: rgba(201, 79, 124, 0.72);
}

.danger-button {
  min-height: 42px;
  padding: 8px 10px;
  border-color: rgba(201, 79, 124, 0.42);
  background: #fff7d9;
  color: var(--berry);
  font-weight: 850;
}

.danger-button.strong {
  background: #c94f7c;
  color: #fff7d9;
}

.icon-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
}

label {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--berry);
}

.checkbox-label {
  grid-template-columns: 20px 1fr;
}

.checkbox-label input {
  accent-color: var(--leaf-soft);
}

.material-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.material-card {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 46px;
  padding: 7px 9px;
  font-weight: 800;
  text-align: left;
}

.material-card:last-child {
  grid-column: span 2;
}

.material-sample {
  width: 30px;
  height: 30px;
  border: 2px solid rgba(77, 120, 189, 0.22);
  border-radius: 8px;
  box-shadow: inset 0 4px 8px rgba(255, 247, 217, 0.5);
}

.paint-sample {
  background: linear-gradient(135deg, #f08cae, #f0bd62);
}

.wood-sample {
  background:
    repeating-linear-gradient(100deg, rgba(255, 247, 217, 0.22) 0 5px, rgba(143, 91, 54, 0.22) 5px 10px),
    linear-gradient(135deg, #b87542, #f0bd62);
}

.glass-sample {
  background:
    linear-gradient(135deg, rgba(255, 247, 217, 0.86), rgba(117, 167, 232, 0.48)),
    #9ed8ec;
}

.metal-sample {
  background:
    repeating-linear-gradient(90deg, rgba(255, 247, 217, 0.36) 0 3px, rgba(77, 120, 189, 0.22) 3px 7px),
    linear-gradient(135deg, #83a4b9, #d9e7ee);
}

.grass-sample {
  background:
    repeating-linear-gradient(80deg, rgba(255, 247, 217, 0.16) 0 4px, rgba(47, 127, 103, 0.34) 4px 8px),
    linear-gradient(135deg, #65bfa3, #bdeaa8);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(40, 78, 111, 0.28);
  backdrop-filter: blur(8px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(420px, 100%);
  padding: 18px;
  border: 1px solid rgba(77, 120, 189, 0.28);
  border-radius: 8px;
  background: #fff7d9;
  box-shadow: 0 24px 60px rgba(96, 124, 170, 0.28);
}

.modal h2 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 1.25rem;
}

.modal p {
  margin: 0 0 16px;
  color: var(--ink);
  line-height: 1.45;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 10px;
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(54vh, 1fr) auto;
    min-height: 100vh;
    height: auto;
  }

  .stage {
    min-height: 54vh;
  }

  .tool-panel {
    border-top: 1px solid rgba(77, 120, 189, 0.22);
    border-left: 0;
    box-shadow: 0 -18px 42px rgba(117, 167, 232, 0.18);
  }

  .status-strip {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 420px) {
  .tool-panel {
    padding: 12px;
  }

  .piece-grid {
    grid-template-columns: 1fr;
  }

  .material-grid {
    grid-template-columns: 1fr;
  }

  .material-card:last-child {
    grid-column: auto;
  }

  .button-row {
    grid-template-columns: repeat(3, 1fr);
  }

  #undoButton {
    grid-column: span 3;
  }
}
