* {
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
}

html,
body {
  margin: 0;
}

body {
  font-family: sans-serif;
}

[hidden] {
  display: none !important;
}

[disabled] {
  opacity: .5;
}

[\:if], [\:else], [\:each] {
  display: none!important;
}

@font-face {
  font-family: wavefont;
  font-display: block;
  src: url(./asset/wavefont.woff2) format('woff2');
}

.wavefont {
  display: block;
  font-family: wavefont;
  font-size: var(--wavefont-size, 50px);
  line-height: var(--wavefont-lh);
  letter-spacing: var(--wavefont-spacing, 0px);
  font-variation-settings: 'wght' var(--wavefont-wght, 25), 'ROND' var(--wavefont-rond, 100), 'YALN' var(--wavefont-yaln, 0);
  text-rendering: optimizeSpeed;
  font-smooth: antialiased;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: antialiased;
}

.container {
  display: flex;
  position: relative;
  width: 100%;
  margin: 1rem auto;
  padding: 0 0 0;
  justify-content: center;
}

#wavearea {
  height: 100%;
  margin: 0;
  padding: 0 2vw;
  display: flex;
  flex-direction: column;
  /* --wavefont-size: max(4rem, min(10.8vw, 6rem)); */
  --wavefont-size: 50px;
  --wavefont-lh: calc(var(--wavefont-size) * 1.4);
  --wavefont-spacing: 0px;
  --wavefont-wght: 25;
  --wavefont-rond: 0;
  --wavefont-yaln: 0;
  --secondary: rgb(0 0 0 / 33%);
  --primary: black;

  #waveform {
    position: relative;
    width: 100%;
    /* this 0.5ch fixes inconsistent breaking, seemingly round error */
    max-width: calc(4 * 216 * 1ch + 0.5ch);
    margin: 0 1rem;
    margin-left: 4rem;
  }

  #editarea {
    outline: none;
    width: 100%;
    color: var(--primary);
    position: relative;
    word-break: break-all;
    white-space: break-spaces;
    p::selection {
      background-color: var(--secondary);
    }
  }


  /* played samples dimmer */
  #editarea.playing:before,
  #editarea.playing:after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, .75);
    pointer-events: none;
    z-index: 1;
  }

  #editarea:before {
    bottom: 0;
    left: -1px;
    right: -1px;
    top: calc(var(--carety) + var(--wavefont-lh));
  }

  #editarea:after {
    top: var(--carety);
    right: -1px;
    left: var(--caretx);
    height: var(--wavefont-lh);
  }


  #timecodes {
    position: absolute;
    top: 0;
    left: -3rem;
    font-family: sans-serif;
    letter-spacing: 0;
    font-size: .75rem;
    margin: 0;
    word-break: keep-all;
    white-space: pre;
    color: var(--secondary);
    line-height: var(--wavefont-lh);
  }

  #status {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    font-family: sans-serif;
    letter-spacing: 0;
    font-size: .75rem;
    margin: 0;
    padding: .35rem .75rem;
    white-space: pre;
    color: var(--secondary);
    background: var(--bg, #fff);
    border-top: 1px solid var(--border, #eee);
    z-index: 100;
    text-align: center;
  }

  #timecodes {
    display: flex;
    flex-direction: column;
  }

  #timecodes>* {
    margin: 0;
    text-decoration: none;
    color: var(--secondary);
  }

  #error {
    font-family: sans-serif;
    font-size: .875rem;
    color: #999;
    text-align: center;
    padding: 2rem 1rem;
  }

  #caret-line {
    position: absolute;
    margin-left: -3.8rem;
    width: 3rem;
    height: var(--wavefont-lh);
    top: var(--carety);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    margin-left: -4rem;
  }

  #floater {
    position: sticky;
    top: 0;
    bottom: var(--wavefont-lh);
    height: 0;
    display: flex;
    line-height: 0;
    opacity: 0;
    transition: opacity .3s ease;

    &.loaded {
      opacity: 1;
    }

    #play {
      background: linear-gradient(to bottom, rgb(255 255 255 / 0%) 0%, rgb(255 255 255 / 100%) 25%, rgb(255 255 255 / 100%) 75%, rgb(255 255 255 / 0%) 100%);
      height: var(--wavefont-lh );
    }
  }

  #play {
    padding: 0;
    text-align: center;
    appearance: none;
    border: none;
    cursor: pointer;
    justify-content: center;
      align-items: center;
    -webkit-tap-highlight-color: transparent;
    z-index: 1;
    display: flex;
    background: none;

    #clickarea {
      height: calc(var(--wavefont-lh) * 3);
      width: 100%;
      position: absolute;
      top: -100%;

      height: 4rem;
      width: 4rem;
      position: absolute;
      left: -1rem;
      top: 0;
      bottom: 0;
      margin: auto;
    }
  }

  #opener {
    nav {
      display: flex;
      flex-direction: row;
      gap: 1rem;
    }

    #file {
      width: 0.1px;
      height: 0.1px;
      opacity: 0;
      overflow: hidden;
      position: absolute;
      z-index: -1;
    }

    #file+label {
      display: flex;
      align-items: center;
      font-size: 1rem;
      cursor: pointer;
      user-select: none;
    }

  }

  /* Files list */
  #files {
    margin-top: 2rem;
    width: 100%;
    max-width: 600px;

    h3 {
      font-size: 0.875rem;
      font-weight: 600;
      margin: 0;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: #666;
    }

    select {
      padding: 0.25rem 0.5rem;
      border: 1px solid #e0e0e0;
      border-radius: 0.25rem;
      background: white;
      font-size: 0.75rem;
      cursor: pointer;

      &:hover {
        border-color: #d0d0d0;
      }
    }

    ul {
      list-style: none;
      padding: 0;
      margin: 0 -1rem;
    }

    li {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      margin-bottom: 0.5rem;
    }

    .file-button {
      flex: 1;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0.75rem 1rem;
      border-radius: 0.375rem;
      cursor: pointer;
      transition: all 0.2s;
      font-family: inherit;
      font-size: 0.875rem;
      text-align: left;

      &:hover {
        background: #e8e8e8;
        border-color: #d0d0d0;
      }

      &:active {
        transform: scale(0.98);
      }

      .file-name {
        font-weight: 500;
        color: #333;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .file-date {
        color: #999;
        font-size: 0.75rem;
        white-space: nowrap;
        margin-left: 1rem;
      }
    }

    .delete-button {
      padding: 0.5rem;
      border-radius: 0.375rem;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.2s;
      flex-shrink: 0;

      &:hover {
        background: #fee;
        border-color: #fcc;
      }

      span {
        display: block;
        color: #666;
      }

      &:hover span {
        color: #c00;
      }
    }
  }
}
