/* ----------------------------------------- */
/*  Main Menu                                */
/* ----------------------------------------- */

#menu {
  width: 360px;
  flex: none;
  overflow: hidden;
  background: var(--color-cool-5-75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 0 30px #000;
  border-radius: 6px;
  pointer-events: all;
  z-index: calc(var(--z-index-window) + 1);
  outline: none;
  border: none;

  /* Open and Close Animation */
  visibility: hidden;
  max-height: 0;
  transition: visibility 0s 250ms, max-height 250ms ease-in-out;
  &.active {
    transition: max-height 250ms ease-in-out;
    visibility: visible;
    max-height: 50%;
  }

  /* Close Button */
  div[data-application-part="items"] { position: relative; }
  button[data-action="close"] {
    --button-text-color: var(--color-light-1);
    --button-background-color: none;
    --button-size: 1.5rem;
    border: none;
    line-height: normal;
    position: absolute;
    right: 0;
  }

  /* Menu Items */
  #main-menu-items {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem 1.5rem;
    li {
      align-items: center;
      cursor: var(--cursor-pointer);
      gap: 1.5rem;
      color: var(--color-light-1);
      > i {
        flex: 0 0 24px;
        font-size: var(--font-size-18);
        opacity: 0.5;
      }
      h2 {
        font-size: var(--font-size-24);
        margin: 0;
      }
      &:hover {
        text-shadow: 0 0 10px var(--color-shadow-primary);
      }
    }
  }
}

@media (prefers-reduced-transparency) {
  #menu {
    background: var(--color-cool-5);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

/* ----------------------------------------- */
/*  Hotbar                                   */
/* ----------------------------------------- */

#hotbar {
  --hotbar-size: 60px;
  --button-size: 24px;
  flex: none;
  width: max-content;
  height: var(--hotbar-size);
  margin: 0 0 16px;
  gap: 8px; // 0.5rem

  &.compact, &.md.offset, &.sm {
    height: calc((var(--hotbar-size) * 2) + 8px);
    #action-bar { width: calc((var(--hotbar-size) * 5) + 32px); }
  }

  &.offset:not(.lg, .min) {
    --offset: 0;
    transform: translateX(var(--offset));
  }

  &.min { transform: translateX(-70px); }

  &.faded-ui {
    transition: opacity var(--ui-fade-delay) var(--ui-fade-duration), transform 250ms ease;
    &:hover { transition: opacity var(--ui-fade-duration), transform 250ms ease; }
  }

  // Action Bar
  #action-bar {
    flex: none;
    width: auto;
    height: 100%;
    gap: 8px; // 0.5rem
    justify-content: center;
    flex-wrap: wrap;
    pointer-events: all;
    .slot {
      position: relative;
      flex: none;
      width: var(--hotbar-size);
      height: var(--hotbar-size);
      border: 2px solid transparent;
      border-radius: 10px;
      background: var(--slot-color, var(--color-cool-5-90));
      cursor: var(--cursor-pointer);
      .key {
        position: absolute;
        top: 0;
        left: 0;
        width: 20px;
        line-height: 20px;
        padding-right: 2px; // Push numbers towards left
        background: var(--key-bg-color-empty, var(--color-cool-5));
        border-radius: 10px 0 8px 0;
        color: var(--key-text-color, var(--color-light-1));
        text-align: center;
        pointer-events: none;
      }
      &.full .key { background: var(--key-bg-color-full, var(--color-cool-5)); }
      .slot-icon {
        width: 100%;
        height: 100%;
        border: none;
        border-radius: 10px;
        pointer-events: none;
      }
      &:hover {
        border: 2px solid var(--color-warm-1);
      }
      &.drop-target {
        background: var(--color-cool-4);
        border: 2px solid var(--color-warm-2);
      }
    }
  }

  // Control Buttons
  button {
    --button-text-color: var(--color-light-1);
    --button-hover-text-color: var(--color-warm-2);
    padding: 0;
    transition: opacity 0.25s;
    pointer-events: all;
    &:hover {
      opacity: 1.0;
      box-shadow: none;
    }
    &:focus {
      outline: none;
      box-shadow: none;
    }
  }
  .hotbar-controls {
    flex: none;
    height: var(--hotbar-size);
    justify-content: space-evenly;
    flex-wrap: nowrap;
    gap: 4px; // 0.25rem
    button {
      --button-size: 1.5rem;
      --control-size: 1.5rem;
    }
  }
  #hotbar-controls-left {
    align-content: flex-end;
  }
  #hotbar-controls-right {
    align-items: stretch;
    > div.flexcol { justify-content: space-evenly; }
  }

  /** Page Controls */
  #hotbar-page-controls {
    position: relative;
    justify-content: space-between;
    .hotbar-page-control {
      --button-text-color: var(--page-control-color, var(--color-cool-5));
      --fa-display: inline-grid;
      font-size: var(--font-size-18);
    }
    .page-next {
      &::before {
        transform: scaleX(0.75);
      }
    }
    .page-prev {
      &::before {
        transform: scaleX(0.75) scaleY(-1);
      }
    }
    .hotbar-page-number {
      width: 20px;
      height: 20px;
      margin: -10px 0 0 -10px;
      position: absolute;
      top: 50%;
      left: 50%;
      text-align: center;
      color: var(--color-light-2);
    }
  }
}

/* ----------------------------------------- */
/*  Game Pause                               */
/* ----------------------------------------- */

#pause {
  width: 100%;
  height: 180px;
  position: fixed;
  top: calc(50vh - 100px);
  left: 0;
  background: linear-gradient(to right,
    transparent 0%,
    var(--color-cool-5-50) 40%,
    var(--color-cool-5-50) 60%,
    transparent 100%
  );
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  pointer-events: none;
  z-index: calc(var(--z-index-canvas) + 1);

  &.paused {
    display: flex;
    animation: pulse 3s ease-in-out infinite;
  }

  @keyframes pulse {
    0% {
      transform: scale(1.0);
    }
    50% {
      transform: scale(1.025);
    }
    100% {
      transform: scale(1.0);
    }
  }

  img {
    height: 100px;
    width: 100px;
    border: none;
    box-shadow: none;
    --fa-animation-duration: 5s;
  }

  figcaption {
    margin: 0;
    padding: 0;
    font-size: var(--font-size-24);
    font-family: var(--font-serif);
    text-transform: uppercase;
    font-weight: bold;
    color: #ada7b8;
    letter-spacing: 0.3em;
    line-height: 1rem;
    font-style: normal;
  }
}

/* ------------------------------------------ */
/*  Players                                   */
/* ------------------------------------------ */

#players {
  flex: none;
  gap: 8px;
  color: var(--text-color);
  font-size: var(--font-size-12);

  #players-active,
  #players-inactive {
    pointer-events: all;
    width: 200px;
    background: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px 8px;
  }
  #players-active {
    flex: none;
  }

  /* Inactive Players (Expand and Collapse) */
  #players-inactive {
    max-height: 0;
    visibility: hidden;
    transition: max-height 0.5s ease-in-out, visibility 0.5s 0s;
  }
  #players-expand {
    transition: transform 0.25s;
  }
  &.expanded {
    #players-inactive:not(:empty) {
      visibility: visible;
      max-height: 300px;
    }
    #players-expand {
      transform: rotate(180deg);
    }
  }

  .players-list {
    gap: 4px;
  }
  .player {
    color: var(--player-name-color);
    line-height: 20px;
    gap: 4px;
    &.idle .player-name {
      color: var(--player-name-idle-color);
      &::after {
        content: "\f880";
        font-family: var(--font-awesome);
        margin-left: 0.5em;
      }
    }
    &.self .player-name {
      color: var(--player-name-self-color);
    }
    &::before {
      content: "";
      display: block;
      box-sizing: border-box;
      width: 12px;
      height: 12px;
      background: var(--player-color);
      border: 1px solid var(--player-border);
      border-radius: 100%;
    }
  }

  /* Performance Monitoring */
  #performance-stats {
    font-family: var(--font-monospace);
    gap: 8px;
    white-space: nowrap;
    #latency {
      flex: none;
    }
    #fps {
      flex: 1;
    }
    label {
      margin-right: 4px;
    }
    .good .average { color: var(--color-rating-good); }
    .fair .average { color: var(--color-rating-fair); }
    .poor .average { color: var(--color-rating-poor); }
    button {
      --button-size: 20px;
      background: none;
      border: none;
      pointer-events: all;
    }
  }
}

/* ----------------------------------------- */
/*  Scene Controls                           */
/* ----------------------------------------- */

#scene-controls {
  flex: 1; // Fill available column
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 8px; // 0.5rem
  pointer-events: none;

  > menu {
    flex: none;
    height: 100%;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 8px; // 0.5rem
  }

  // Controls are always a single column
  #scene-controls-controls {
    width: var(--control-size);
  }

  // Tools can wrap to multiple columns
  #scene-controls-tools {
    flex-wrap: wrap;
    // Pips use position: fixed with anchor() so they escape the overflow: hidden clipping context. #scene-controls
    // must stay overflow: hidden in order to create the correct scrolling context.
    .notification-pip {
      position: fixed;
      top: calc(anchor(top) - 1px);
      right: calc(anchor(right) - 2px);
    }
  }
}

/* ---------------------------------------- */
/*  Scene Navigation                        */
/* ---------------------------------------- */

#scene-navigation {
  flex: 1;
  overflow: visible;
  max-height: 100%;
  padding-right: 30px; // For button
  gap: 0.5rem;
  position: relative;

  #scene-navigation-expand {
    position: absolute;
    top: 4px;
    right: 0;
    width: 24px;
    height: 24px;
    font-size: var(--font-size-12);
    text-align: center;
    line-height: 24px;
    pointer-events: all;
    > i {
      pointer-events: none;
      transition: transform 0.25s;
    }
  }

  // Active or Inactive Scenes
  .scene-navigation-menu {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 0.5rem;
    list-style: none;
    margin: 0;
    padding: 0;

    // Single Scene
    .scene {
      width: 100%;
      max-width: 20vw;
      position: relative;
      padding: 0.5rem;
      gap: var(--spacer-2);
      font-size: var(--font-size-12);
      transition: background-color, opacity, color 0.25s;
      cursor: var(--cursor-pointer);
      &.view {
        cursor: var(--cursor-default);
      }
    }

    // Scene Icons
    .icons {
      color: var(--color-text-emphatic);
      flex: 0 0 fit-content;
      font-size: var(--font-size-10);
      gap: var(--spacer-4);
      justify-content: end;
      opacity: 0.5;
    }

    // Hovered Scene
    .scene:hover .scene-name {
      text-shadow: 0 0 2px var(--color-shadow-highlight);
    }

    // Drag-and-Drop Target
    .scene.drop-target-before,
    .scene.drop-target-after {
      &::before {
        display: block;
        content: "";
        border-top: 2px solid var(--color-border-highlight);
        width: 100%;
        position: absolute;
        left: 0;
        top: -6px;
      }
    }
    .scene.drop-target-after::before {
      top: unset;
      bottom: -6px;
    }

    // Player Pips
    .scene-players {
      display: flex;
      gap: 2px;
      list-style: none;
      margin: 0;
      padding: 0;
      position: absolute;
      bottom: -6px;
      left: 2px;
      .scene-player {
        width: 12px;
        height: 12px;
        line-height: 10px;
        background: var(--color-bg);
        border: 1px solid var(--color-border);
        border-radius: 100%;
        color: #FFF;
        font-size: 8px; // non-scaling
        text-align: center;
      }
    }
  }

  // Levels
  .scene-levels {
    overflow-y: auto;
    scrollbar-gutter: stable;
    scroll-snap-type: y mandatory;
    height: calc(min(var(--max-levels, 3), 3) * (var(--control-size) + .5rem));
    flex-wrap: nowrap;
    pointer-events: all;
    padding-right: .5rem;

    .level-row {
      padding-left: 1rem;
      scroll-snap-align: start;
    }

    .scene-level {
      cursor: var(--cursor-pointer);
      &.active::after { content: none; }
    }
  }

  // Inactive Scenes
  #scene-navigation-active, #scene-navigation-viewed {
    flex: none;
  }
  #scene-navigation-inactive {
    flex: 1;
    height: 0; // Workaround to get full-height wrapping to work
    padding-bottom: calc(var(--hotbar-height) + 1rem); // Allow space for hotbar
    visibility: hidden;
  }

  // Expanded List
  &.expanded {
    #scene-navigation-inactive {
      visibility: visible;
    }
    #scene-navigation-expand > i {
      transform: rotate(180deg);
    }
  }
}

/* ---------------------------------------- */
/* Notifications                            */
/* ---------------------------------------- */

#notifications {
  position: fixed;
  top: 10vh;
  width: 100%;
  margin: 0;
  padding: 0 20%;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  list-style: none;
  z-index: var(--z-index-notification);
  pointer-events: none;

  > .notification {
    box-shadow: 0 0 10px black;
    &::after {
      content: "\f057";
      font-family: var(--font-awesome);
      font-weight: 900; // fa-solid
      position: absolute;
      top: -4px;
      right: -4px;
      width: 16px;
      line-height: 16px;
    }
  }
}

.notification {
  --border-color: transparent;
  --background-color: rgb(0 0 0 / 50%);
  --icon-glyph: "";

  position: relative;
  display: flex;
  align-items: center;
  margin: 0;
  padding: 0.5rem 1rem;
  background: var(--background-color);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  color: var(--color-light-3);
  font-size: var(--font-size-14);
  line-height: 1em;
  text-shadow: 1px 1px black;
  pointer-events: all;

  > p {
    margin: 0;
    order: 1;
  }

  > .pct {
    display: none;
    font-weight: bold;
    margin-right: 0.5rem;
    order: 0;
  }

  &::before {
    content: var(--icon-glyph);
    font-family: var(--font-awesome);
    font-weight: 900; // fa-solid
    margin-right: 8px;
  }

  &.info {
    --icon-glyph: "\f05a";
    --background-color: var(--color-level-info-bg);
    --border-color: var(--color-level-info)
  }

  &.warning {
    --background-color: var(--color-level-warning-bg);
    --border-color: var(--color-level-warning);
    --icon-glyph: "\f071";
    color: var(--color-light-2);
  }

  &.error {
    --background-color: var(--color-level-error-bg);
    --border-color: var(--color-level-error);
    --icon-glyph: "\f06a";
  }

  &.success {
    --background-color: var(--color-level-success-bg);
    --border-color: var(--color-level-success);
    --icon-glyph: "\f00c";
  }

  /** Progress Bars */
  &.progress {
    background: linear-gradient(90deg,
    var(--background-color) var(--pct),
    var(--border-color) calc(var(--pct) + 2px),
    rgb(0 0 0 / 80%) calc(var(--pct) + 2px),
    rgb(0 0 0 / 50%) 100%
    );
    > .pct {
      display: inline-block;
    }
  }

  /** Software Update Channels */
  &.channel-hint {
    width: 100%;
    flex: none;
  }
  &.stable {
    --background-color: rgba(138, 211, 4, 0.4);
    --icon-glyph: "\f6d9";
  }
  &.testing {
    --background-color: rgba(211, 192, 4, 0.4);
    --icon-glyph: "\f0ad";
  }
  &.development {
    --background-color: rgba(211, 119, 4, 0.4);
    --icon-glyph: "\f6e3";
  }
  &.prototype {
    --background-color: rgba(211, 20, 4, 0.4);
    --icon-glyph: "\f1e2";
  }
}

/* ---------------------------------------- */
/*  Faded Elements                          */
/* ---------------------------------------- */

.faded-ui {
  opacity: var(--ui-fade-opacity);
  transition: opacity var(--ui-fade-delay) var(--ui-fade-duration); // Delay before fading out
  &:hover {
    transition: opacity var(--ui-fade-duration); // Fade in immediately
    opacity: 1.0;
  }
}

.detached .faded-ui { opacity: 1; }

/* ----------------------------------------- */
/*  Placeable Palette                        */
/* ----------------------------------------- */

.application.placeable-palette {
  .form-fields { flex: 1; }
  .form-footer button { --button-size: var(--input-height); }
  .standard-form {
    gap: var(--spacer-8);
    .form-group:first-child { margin-top: unset; }
  }
  fieldset {
    gap: var(--spacer-8);
    display: contents;
    padding: var(--spacer-4) var(--spacer-12);
    legend { display: none; }
  }
  details {
    &:focus { outline: none; }
    &[open] {
      summary { display: none; }
      > fieldset {
        display: flex;
        legend {
          display: unset;
          &::before {
            content: "\f0d7";
            font-family: var(--font-awesome);
            font-weight: bold;
            margin-right: 6px;
          }
        }
      }
    }
    summary {
      list-style: none;
      &::before {
        content: "\f0da";
        font-family: var(--font-awesome);
        font-weight: bold;
        margin-right: 6px;
      }
    }
  }
  .window-content {
    gap: var(--spacer-8);
    padding: var(--spacer-8);
  }
  .multiple-values.placeholder-fa-solid::placeholder { font-family: var(--font-body); }
}

#ambient-sound-palette, #ambient-light-palette, #ambient-light-filter {
  .constrain-walls > label { flex: max-content; }
}

#region-palette {
  .elevation .form-fields { flex: min-content; }

  // Tri-color swatch to indicate random color in the region palette.
  color-picker:has(> input[type=text]:placeholder-shown) {
    > input[type=color] {
      &::-webkit-color-swatch-wrapper { padding: 0; }
      &::-webkit-color-swatch {
        background: conic-gradient(red 0deg 120deg, lime 120deg 240deg, blue 240deg 360deg);
        border: none;
      }
    }
  }
  color-picker:has(> input[type=text]:placeholder-shown) > input[type=color]::-moz-color-swatch {
    background: conic-gradient(red 0deg 120deg, lime 120deg 240deg, blue 240deg 360deg);
    border: none;
  }
}
