:root {
  --theme-hue: 197;

  --text-color: hsl(var(--theme-hue), 100%, 90%);
  --bg-color: hsl(var(--theme-hue), 24%, 10%);
  --link-color: hsl(var(--theme-hue), 100%, 82%);
  --link-hover-color: hsl(var(--theme-hue), 100%, 92%);
  --border-color: hsl(var(--theme-hue), 20%, 20%);
  --error-border-color: hsl(8, 100%, 59%);
  --panel-bg-color: hsl(var(--theme-hue), 24%, 14%);
}

body {
  margin: 0;
  padding: 0;
  background-color: hsl(var(--theme-hue), 24%, 10%);
  color: var(--text-color);
  font-family: "Kanit", sans-serif;
  font-weight: 200;
  font-size: 1.1em;
  line-height: 1.45em;
}

main {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto 1fr;
  max-width: 700px;
  max-height: 100vh;
  margin: 0 auto;
  gap: 0.4em 0.8em;
  padding: 2em 0 1em;
  box-sizing: border-box;
}

.ui-label {
  font-weight: 300;
}

button {
  padding: 0.3em 0.5em;
  font-family: "Kanit", sans-serif;
  font-weight: 400;
  font-size: 1em;
  background-color: var(--link-color);
  color: var(--bg-color);
  border: none;
  border-radius: 3px;
  cursor: pointer;
  opacity: 1;
  transition: background-color 0.2s, opacity 0.2s;
  white-space: nowrap;
}

button:not(:disabled):hover,
button:not(:disabled):active {
  background-color: var(--link-hover-color);
}

button:focus {
  outline: 1px dotted currentColor;
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

#pdp1-ui {
  grid-row: 1;
  grid-column: 1;
  display: flex;
  gap: 0.1em;
}

#pdp1-ui .inputs {
  flex: 1;
  display: flex;
  gap: 0.5em;
  align-items: center;
  min-width: 0;
}

#tw-input {
  outline: none;
  min-width: 0;
  width: 42px;
  padding: 0.25em 0.4em 0.35em;
  font-family: "Kanit", sans-serif;
  font-weight: 300;
  font-size: 1em;
  background-color: var(--panel-bg-color);
  color: var(--text-color);
  border: 1px solid hsl(var(--theme-hue), 42%, 25%);
  border-radius: 3px;
}

#program-flags {
  display: flex;
  flex-direction: row;
  gap: 6px;
  margin-left: 0.6em;
  align-self: center;
}

.bulb-container, .bulb {
  height: 30px;
  width: 30px;
  border-radius: 15px;
}

.bulb-container {
  background-color: #5e564b;
}

.bulb {
  background-color: #f2ea58;
  box-shadow: inset 0 0 2px 5px #f2ba58;
  opacity: 0;
  will-change: opacity;
  transition: opacity 64ms;
}

#playlist {
  grid-row: 2 / span 2;
  grid-column: 1;
  display: flex;
  flex-direction: column;
  list-style: none;
  padding: 0;
  margin: 0;
  gap: 0.25em;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  min-height: 0;
  max-width: 460px;
  --top-fade: 1;
  --bottom-fade: 0;
  mask-image: linear-gradient(
    to bottom,
    rgba(0, 0, 0, var(--top-fade)),
  black 4em, black calc(100% - 4em),
    rgba(0, 0, 0,
    var(--bottom-fade))
  );
}

#playlist > li {
  display: flex;
  cursor: pointer;
  padding: 0.5em;
  background: hsl(var(--theme-hue), 42%, 15%);
  border-radius: 0.15em;
  border: 1px solid hsl(var(--theme-hue), 42%, 25%);
  height: 1.9em;
  align-items: center;
}

@media (hover: hover) and (pointer: fine) {
  #playlist > li:hover {
    background: hsl(var(--theme-hue), 42%, 25%);
    border: 1px solid hsl(var(--theme-hue), 42%, 35%)
  }
}

#playlist > li.active {
  background: hsl(var(--theme-hue), 42%, 20%);
  border: 1px solid hsl(var(--theme-hue), 42%, 30%);
  box-shadow: inset 0 0 0.8em hsl(var(--theme-hue), 84%, 22%);
}

#playlist > li .info {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding-top: 0.15em;
  margin-right: 0.5em;
  min-width: 0;
  font-size: 0.9em;
}

#playlist > li .title {
  line-height: 1em;
  text-wrap: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

#playlist > li .artist {
  font-size: 0.9em;
  line-height: 1.1em;
  opacity: 0.9;
}

#playlist > li .play-button {
  margin-left: 1em;
  height: 1.6em;
  width: 1.6em;
  border-radius: 0.8em;
  background-color: var(--link-color);
  color: var(--bg-color);
  opacity: 0.5;
}

@media (hover: hover) and (pointer: fine) {
  #playlist > li:hover .play-button {
    background-color: var(--link-hover-color);
    opacity: 1;
  }
}
#playlist > li:active .play-button {
  background-color: var(--link-hover-color);
  opacity: 1;
}

#playlist > li:not(.playing) .play-icon {
  border-left: 0.7em solid hsl(var(--theme-hue), 70%, 25%);
  border-top: 0.45em solid transparent;
  border-bottom: 0.45em solid transparent;
  margin-left: 0.55em;
  margin-top: 0.36em;
}

#playlist > li.active .play-button {
  opacity: 1;
}

#playlist > li.playing .play-icon {
  width: 16px;
  height: 22px;
  position: relative;
  opacity: 1;
}

#playlist > li.playing .play-icon {
  width: 12px;
  position: relative;
  left: 8px;
}

#playlist > li.playing .play-icon::before,
#playlist > li.playing .play-icon::after {
  content: '';
  position: absolute;
  width: 4px;
  height: 16px;
  background: hsl(var(--theme-hue), 70%, 25%);
  border-radius: 2px;
  top: 0.35em;
}

#playlist > li.playing .play-icon::before {
    left: 0;
}

#playlist > li.playing .play-icon::after {
    right: 0;
}

#logs-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.8em;
  grid-row: 1;
  grid-column: 2;
}

#roygbiv-link {
  color: var(--link-color);
  font-weight: 300;
}

#roygbiv-link:hover {
  color: var(--link-hover-color);
}

#logs-pane {
  grid-row: 3;
  grid-column: 2;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#logs-label {
  padding-bottom: 0.2em;
}

#temperament-control {
  grid-row: 2;
  grid-column: 2;
  display: grid;
  grid-template-columns: auto auto;
  justify-content: end;
  align-items: center;
  gap: 0.4em 0.8em;
}

#temperament-control > .ui-label {
  text-align: right;        /* labels in the left column, right-aligned */
}

.pitch-group {
  display: flex;
  align-items: center;
  gap: 1em;
}

.tuning-opt {
  display: flex;
  align-items: center;
  gap: 0.3em;
  cursor: pointer;
  white-space: nowrap;
}

/* themed checkbox: panel-bg box, filled with link-color + a drawn check when on */
.tuning-opt input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 1em;
  height: 1em;
  margin: 0;
  cursor: pointer;
  position: relative;
  background-color: var(--panel-bg-color);
  border: 1px solid hsl(var(--theme-hue), 42%, 25%);
  border-radius: 3px;
}

.tuning-opt input[type="checkbox"]:checked {
  background-color: var(--link-color);
  border-color: var(--link-color);
}

.tuning-opt input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 0.28em;
  top: 0.06em;
  width: 0.22em;
  height: 0.45em;
  border: solid var(--bg-color);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.tuning-opt input[type="checkbox"]:focus-visible {
  outline: 1px dotted currentColor;
  outline-offset: 2px;
}

#temperament-select, #module-select {
  justify-self: stretch;
  min-width: 0;
  padding: 0.25em 0.4em 0.35em;
  font-family: "Kanit", sans-serif;
  font-weight: 300;
  font-size: 1em;
  background-color: var(--panel-bg-color);
  color: var(--text-color);
  border: 1px solid hsl(var(--theme-hue), 42%, 25%);
  border-radius: 3px;
}

.module-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15em 0.6em;
  min-width: 0;
}

#module-select {
  flex: none;
}

/* the label sits level with the select, not with the select and its status line together */
#temperament-control > label[for="module-select"] {
  align-self: start;
  padding-top: 0.4em;
}

/* The status is a line of its own under the select: as wide as the column but never widening it (contain: inline-size), and
   one line tall even when empty (once the worklet has acknowledged the module), so the controls keep their place whatever it
   says. */
#module-status {
  flex: 1 0 100%;
  contain: inline-size;
  font-size: 0.85em;
  line-height: 1.45em;
  min-height: 1.45em;
  opacity: 0.7;
}

/* ?room=legacy: the select is hidden and the status (three lines at most) stands in its place */
#module-select[hidden] + #module-status {
  min-height: 4.35em;
}

#logs {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-sizing: border-box;
  background-color: hsl(var(--theme-hue), 24%, 6%);
  font-family: Rubik, monospace;
  font-weight: 300;
  font-size: 0.8em;
  line-height: 1em;
  padding: 1em;
  border-radius: 0.5em;
  border: 1px solid hsl(var(--theme-hue), 30%, 22%);
  overflow-y: auto;
  scroll-behavior: smooth;
}

#logs > .log-comment {
  color: hsl(var(--theme-hue), 100%, 64%);
  margin-top: 0.4em;
}

@media (max-width: 700px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 3fr auto auto 1fr;
    padding: 1em;
  }

  #pdp1-ui {
    grid-row: 1;
    grid-column: 1;
  }

  #playlist {
    grid-row: 3;
    grid-column: 1;
    max-width: none;
  }

  #logs-header {
    grid-row: 4;
    grid-column: 1;
  }

  #temperament-control {
    grid-row: 5;
    grid-column: 1;
  }

  #logs-pane {
    grid-row: 6;
    grid-column: 1;
  }
}


@font-face {
  font-family: 'Kanit';
  font-style: normal;
  font-weight: 400;
  src: local('Kanit Regular'), url('fonts/kanit/Kanit-Regular.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: normal;
  font-weight: 100;
  src: local('Kanit Thin'), url('fonts/kanit/Kanit-Thin.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: italic;
  font-weight: 400;
  src: local('Kanit Italic'), url('fonts/kanit/Kanit-Italic.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: italic;
  font-weight: 100;
  src: local('Kanit Thin Italic'), url('fonts/kanit/Kanit-ThinItalic.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: normal;
  font-weight: 200;
  src: local('Kanit ExtraLight'), url('fonts/kanit/Kanit-ExtraLight.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: italic;
  font-weight: 200;
  src: local('Kanit ExtraLight Italic'), url('fonts/kanit/Kanit-ExtraLightItalic.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: normal;
  font-weight: 300;
  src: local('Kanit Light'), url('fonts/kanit/Kanit-Light.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: italic;
  font-weight: 300;
  src: local('Kanit Light Italic'), url('fonts/kanit/Kanit-LightItalic.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: normal;
  font-weight: 500;
  src: local('Kanit Medium'), url('fonts/kanit/Kanit-Medium.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: italic;
  font-weight: 500;
  src: local('Kanit Medium Italic'), url('fonts/kanit/Kanit-MediumItalic.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: normal;
  font-weight: 600;
  src: local('Kanit SemiBold'), url('fonts/kanit/Kanit-SemiBold.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: italic;
  font-weight: 600;
  src: local('Kanit SemiBold Italic'), url('fonts/kanit/Kanit-SemiBoldItalic.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: normal;
  font-weight: 700;
  src: local('Kanit Bold'), url('fonts/kanit/Kanit-Bold.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: italic;
  font-weight: 700;
  src: local('Kanit Bold Italic'), url('fonts/kanit/Kanit-BoldItalic.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: normal;
  font-weight: 800;
  src: local('Kanit ExtraBold'), url('fonts/kanit/Kanit-ExtraBold.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: italic;
  font-weight: 800;
  src: local('Kanit ExtraBold Italic'), url('fonts/kanit/Kanit-ExtraBoldItalic.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: normal;
  font-weight: 900;
  src: local('Kanit Black'), url('fonts/kanit/Kanit-Black.woff') format('woff');
}

@font-face {
  font-family: 'Kanit';
  font-style: italic;
  font-weight: 900;
  src: local('Kanit Black Italic'), url('fonts/kanit/Kanit-BlackItalic.woff') format('woff');
}

@font-face {
  font-family: Rubik;
  font-weight: 300;
  src: url('fonts/rubik/Rubik-Light.woff2');
}

@font-face {
  font-family: Rubik;
  font-weight: 500;
  src: url('fonts/rubik/Rubik-Medium.woff2');
}