* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #111;
  background: #fff;
}

body {
  height: 100svh;
  min-height: 600px;
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto;
}

.topbar {
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e2e2e2;
  gap: 14px;
  background: #fff;
  flex-wrap: wrap;
}

.brand h1 {
  font-size: 17px;
  letter-spacing: 0.08em;
  margin: 0;
  font-weight: 700;
}

.brand h1 span {
  font-size: 11px;
  color: #666;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.brand p {
  font-size: 11px;
  color: #555;
  margin: 4px 0 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.style-select-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
}

.style-select-wrap select {
  appearance: auto;
  border: 1px solid #111;
  border-radius: 0;
  background: #fff;
  color: #111;
  min-height: 44px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.style-select-wrap select:disabled {
  color: #888;
  border-color: #d4d4d4;
}

#status-badge {
  font-size: 12px;
  white-space: nowrap;
  border-left: 2px solid #111;
  padding-left: 10px;
  font-weight: 600;
}

#viewport {
  position: relative;
  min-height: 0;
  background: #e9ebee;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#loading-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(238, 240, 243, 0.92);
  z-index: 2;
  padding: 20px;
}

.loader-box {
  background: #fff;
  border: 1px solid #111;
  padding: 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 420px;
  text-align: center;
}

.loader-box strong {
  font-size: 14px;
}

.loader-box span {
  font-size: 12px;
  color: #555;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.hud-caption {
  pointer-events: none;
  position: absolute;
  top: 12px;
  left: 18px;
  color: #333;
  font-size: 11px;
  line-height: 1.7;
  background: rgba(255, 255, 255, 0.84);
  padding: 6px 10px;
  border: 1px solid #d4d4d4;
}

.hud-caption span {
  display: block;
}

.control-bar {
  padding: 10px 24px 8px;
  border-top: 1px solid #e2e2e2;
  background: #fff;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(2, 44px);
  gap: 4px;
}

.pad .up {
  grid-column: 2;
  grid-row: 1;
}

.pad .left {
  grid-column: 1;
  grid-row: 2;
}

.pad .down {
  grid-column: 2;
  grid-row: 2;
}

.pad .right {
  grid-column: 3;
  grid-row: 2;
}

.pad button {
  padding: 0;
  font-size: 17px;
  touch-action: none;
  user-select: none;
}

button {
  appearance: none;
  border-radius: 0;
  border: 1px solid #d4d4d4;
  background: #fff;
  color: #111;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #f3f3f3;
}

button:focus-visible {
  outline: 2px solid #111;
  outline-offset: 2px;
}

button[aria-pressed="true"],
button.active {
  background: #111;
  color: #fff;
  border-color: #111;
}

button:disabled {
  color: #888;
  cursor: wait;
}

.primary-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.sliders {
  margin-left: auto;
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.slider-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: #333;
  min-width: 145px;
}

.slider-item output {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
}

.slider-item input[type="range"] {
  width: 100%;
  min-height: 28px;
  margin: 0;
  accent-color: #111;
  cursor: pointer;
}

.credit-note {
  margin: 8px 0 0;
  font-size: 10px;
  color: #666;
  line-height: 1.4;
}

.credit-note code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
}

dialog {
  border: 1px solid #111;
  border-radius: 0;
  padding: 20px;
  width: min(680px, calc(100% - 24px));
  max-height: calc(100svh - 32px);
  overflow: auto;
  color: #111;
  background: #fff;
}

dialog::backdrop {
  background: rgba(17, 17, 17, 0.5);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.dialog-header h2 {
  font-size: 16px;
  margin: 0;
}

.dialog-header p {
  font-size: 12px;
  color: #555;
  margin: 4px 0 0;
}

.dialog-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.parts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px;
}

.part-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  padding: 8px 12px;
  font-size: 12px;
  min-height: 44px;
}

.part-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1px solid #111;
  margin-right: 8px;
  flex-shrink: 0;
}

@media (max-width: 720px) {
  .topbar {
    padding: 8px 12px;
    gap: 8px;
  }
  .brand h1 {
    font-size: 14px;
  }
  .brand p {
    display: none;
  }
  .style-select-wrap span {
    display: none;
  }
  .control-bar {
    padding: 8px 12px;
  }
  .control-row {
    gap: 8px;
  }
  .sliders {
    margin-left: 0;
    width: 100%;
    justify-content: space-between;
  }
  .slider-item {
    min-width: 130px;
    flex: 1;
  }
}
