/* A theme is these variables. The defaults are similar to shadcn/ui's neutral theme. */
:root {
  --app-font: system-ui, sans-serif;
  --app-text: #0a0a0a;
  --app-muted-text: #737373;
  --app-background: #ffffff;
  --app-hover: #f5f5f5;
  --app-border: #e5e5e5;
  --app-ring: #a1a1a1;
  --app-accent: #171717;
  --app-error: #e7000b;
  --app-radius: 4px;
  --app-sidebar-width: 280px;
}

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

body {
  display: flex;
  overflow: hidden;
  font: 14px var(--app-font);
  color: var(--app-text);
  background: var(--app-background);
  accent-color: var(--app-accent);
}

/* Form controls otherwise keep the platform's smaller font. */
input,
select,
textarea,
button {
  font: inherit;
}

#sidebar {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-sizing: border-box;
  width: var(--app-sidebar-width);
  padding: 16px;
  overflow: auto;
  border-right: 1px solid var(--app-border);
}

#sidebar:empty {
  display: none;
}

main {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
}

/* On a narrow screen, such as a phone's, the product sits above its sidebar. */
@media (max-width: 600px) {
  body:has(main) {
    flex-direction: column;
  }

  body:has(main) #sidebar {
    order: 1;
    width: auto;
    height: 67%;
    border-right: 0;
    border-top: 1px solid var(--app-border);
  }
}

/* skyworld writes the size it last rendered at onto the canvas inline, which
   would otherwise pin it there. */
#canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* Fields and buttons as shadcn draws its inputs and outline buttons. */
.parameter :is(input:not([type='checkbox'], [type='range'], [type='color']), select, textarea),
#sidebar > button {
  box-sizing: border-box;
  min-width: 0;
  min-height: 36px;
  padding: 6px 12px;
  color: inherit;
  background: var(--app-background);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  box-shadow: 0 1px 2px rgb(0 0 0 / 5%);
}

.parameter :is(input, select, textarea):focus-visible,
#sidebar > button:focus-visible,
.parameter-tile:focus-visible {
  outline: none;
  border-color: var(--app-ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--app-ring) 50%, transparent);
}

.parameter input:invalid {
  border-color: var(--app-error);
}

/* A select's menu as shadcn draws it, where the browser lets a page style it
   (https://developer.mozilla.org/docs/Learn_web_development/Extensions/Forms/Customizable_select).
   Elsewhere the platform's own menu opens. */
@supports (appearance: base-select) {
  .parameter select,
  .parameter ::picker(select) {
    appearance: base-select;
  }

  /* A customizable select is a flex row that would put its text at the top,
     above where an input puts its own. */
  .parameter select {
    align-items: center;
  }

  /* The selected option on one line, cut short. The menu and the select's
     title show it whole. */
  .parameter selectedcontent {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .parameter ::picker(select) {
    margin-block: 4px;
    padding: 4px;
    background: var(--app-background);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    box-shadow: 0 4px 12px rgb(0 0 0 / 10%);
  }

  /* Lucide's chevron-down, as on the app's buttons. */
  .parameter select::picker-icon {
    content: '';
    width: 16px;
    height: 16px;
    background: var(--app-muted-text);
    mask: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>');
    transition: rotate 0.2s;
  }

  .parameter select:open::picker-icon {
    rotate: 180deg;
  }

  .parameter option {
    padding: 6px 8px;
    border-radius: var(--app-radius);
  }

  .parameter option:is(:hover, :focus-visible) {
    background: var(--app-hover);
  }

  .parameter option::checkmark {
    order: 1;
    margin-left: auto;
  }
}

#sidebar > button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 500;
}

#sidebar > button:hover:enabled,
.parameter-tile-labelled:hover:enabled {
  background: var(--app-hover);
}

.parameter > :disabled,
#sidebar > button:disabled {
  opacity: 0.5;
}

.configurator {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.parameter {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

.parameter[hidden] {
  display: none;
}

.parameter-label {
  font-weight: 500;
}

.parameter-label,
.parameter-error {
  grid-column: 1 / -1;
}

.parameter[data-type='checkbox'] {
  grid-template-columns: auto 1fr;
}

.parameter[data-type='checkbox'] .parameter-label {
  grid-row: 1;
  grid-column: 2;
}

.parameter input[type='checkbox'] {
  width: 16px;
  height: 16px;
  margin: 0;
}

.parameter-unit:empty,
.parameter-error:empty {
  display: none;
}

.parameter-unit,
.parameter fieldset > small {
  color: var(--app-muted-text);
}

.parameter-error {
  color: var(--app-error);
}

/* A parameter's controls side by side: a slider between its limits, a select
   and its custom value, a group of swatches. */
.parameter fieldset {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.parameter fieldset > select,
.parameter fieldset > input[type='range'] {
  flex: 1;
  min-width: 0;
}

.parameter fieldset > input:not([type='range'], [type='color']) {
  width: 6em;
}

.parameter fieldset > img {
  max-height: 32px;
}

.parameter-group-title {
  flex-basis: 100%;
}

/* Options drawn as their colour or image. */
.parameter-tile,
.parameter-swatch,
.parameter input[type='color'] {
  box-sizing: border-box;
  width: 32px;
  height: 24px;
  padding: 0;
  color: inherit;
  background: var(--app-background);
  border: 1px solid var(--app-border);
  border-radius: 2px;
}

.parameter-tile img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
}

.parameter-tile-labelled {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: auto;
  height: auto;
  padding: 8px;
  border-radius: var(--app-radius);
}

.parameter-tile-labelled img {
  max-width: 64px;
  max-height: 64px;
}

.parameter-tile[aria-pressed='true'] {
  outline: 2px solid var(--app-accent);
  outline-offset: 2px;
}

.parameter-tile:disabled {
  opacity: 0.5;
}

.icon {
  flex: none;
  width: 16px;
  height: 16px;
}

.spinner {
  display: flex;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.notification {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 16px;
  background: var(--app-background);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  box-shadow: 0 4px 12px rgb(0 0 0 / 10%);
}
