@import url("./root.css");
@import url("./form.css");

#cropped,
#test-canvas {
  display: none;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 3rem;
  padding: 0.5rem 2rem;
  padding-bottom: 0rem;
  max-width: 140ch;
  margin-inline: auto;

  h1 {
    font-size: 1.6rem;
    margin: 0;
    font-family: "Rye", cursive;

    svg {
      stroke-width: 3px;
      width: 2rem;
    }
  }

  .credits {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    font-size: 0.75rem;
    gap: 0.125rem;
    color: var(--color-muted-foreground);
    text-align: right;

    a {
      color: inherit;
      text-decoration: none;

      &:hover {
        text-decoration: underline;
      }
    }
  }

  @media (width <= 40rem) {
    flex-direction: column;
    align-items: start;
    height: auto;
    padding-bottom: 0.5rem;

    .credits {
      margin-top: 0.5rem;
      align-items: start;
    }
  }
}

.outer-container {
  width: 100%;
  height: calc(100svh - 3rem);
  display: flex;
  max-width: 140ch;
  margin-inline: auto;
  padding: 0.5rem;
  gap: 0.5rem;

  @media (width <= 70rem) {
    flex-direction: column;
    height: 100%;
  }
}

.sidebar {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: auto;
  gap: 0.5rem;
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 1rem;
  background: var(--color-bg-sidebar);

  .preset-container {
    display: flex;
    gap: 0.5rem;
    overflow: auto;
    width: max-content;
    padding: 0.25rem;

    .preset {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 0.5rem;
      width: 8rem;
      height: 8rem;
      padding: 0;
      border: 1px solid var(--color-border);
      border-radius: 0.5rem;
      background: var(--color-bg);
      cursor: pointer;
      transition: all 0.2s;
      font-weight: normal;
      font-size: 0.75rem;

      &:hover {
        border-color: var(--color-border-active);
        box-shadow: 0 0 0 2px var(--color-border-active);
      }

      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 0.5rem;
      }
    }
  }

  .actions {
    position: sticky;
    bottom: -0.5rem;
    left: -0.5rem;
    width: 100%;
    border-top: 1px solid var(--color-border);
    display: flex;
    background: var(--color-bg-sidebar);
    justify-content: space-between;
    margin-top: 1rem;
    margin-bottom: -0.5rem;
    gap: 0.5rem;
    padding: 0.5rem;

    button {
      all: unset;
      cursor: pointer;
      padding: 0.5rem;
      border-radius: 0.5rem;
      gap: 0.5rem;
      display: flex;
      align-items: center;
      justify-content: center;
      background: var(--color-border);
      transition: all 0.2s;

      &:disabled {
        cursor: not-allowed;
        opacity: 0.5;
      }

      &:hover {
        background: var(--color-border-active);
      }

      &:active {
        background: var(--color-border-active);
      }

      svg {
        stroke-width: 3px;
        width: 1rem;
        height: 1rem;
      }
    }
  }
}

.preview {
  display: flex;
  flex-direction: column;
  justify-content: start;
  align-items: center;
  padding: 0.5rem;
  gap: 0.25rem;
  border: 1px solid var(--color-border);
  border-radius: 1rem;

  canvas {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    aspect-ratio: 8.5 / 11;
    max-width: 100%;
    max-height: calc(100% - 2.75rem);
    border-radius: 0.5rem;

    @media (prefers-color-scheme: dark) {
      opacity: 0.7;
    }

    @media (width <= 70rem) {
      aspect-ratio: auto;
      height: 40rem;
    }
  }

  .share {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;

    img {
      width: 8rem;
      height: 8rem;
    }

    .code {
      font-family: monospace;
      font-size: 1.25rem;
      letter-spacing: 0.1rem;
      user-select: all;
    }
  }
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.25rem;
  padding-inline-start: 1rem;
  width: 100%;

  h2 {
    display: flex;
    align-items: center;
    font-weight: 600;
    gap: 0.5rem;
    margin: 0;
  }

  i svg {
    stroke-width: 4px;
  }

  .actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;

    button {
      all: unset;
      position: relative;
      cursor: pointer;
      padding: 0.5rem;
      border-radius: 0.5rem;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.2s;
      overflow: hidden;

      &:disabled {
        cursor: not-allowed;
        opacity: 0.5;
      }

      &[popovertarget="download-options"] {
        anchor-name: --download-button;
      }

      &:hover {
        background: var(--color-border);
      }

      &:active {
        background: var(--color-border-active);
      }

      svg {
        stroke-width: 3px;
        width: 1rem;
        height: 1rem;
      }

      .status {
        position: absolute;
        inset: 0;
        background: var(--color-bg-sidebar);
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        gap: 0.5rem;
        opacity: 0;
        transition: opacity 0.2s;

        &.active {
          opacity: 1;
        }
      }
    }
  }
}

.photo-container {
  overflow: auto;
  width: 100%;

  .photo-options {
    display: flex;
    overflow: auto;
    gap: 0.5rem;
    width: max-content;
    padding: 0.25rem;

    .label-separator {
      font-size: 0.75rem;
      font-weight: 600;
      color: var(--color-muted);
      padding: 0.5rem 1rem;
      align-self: center;
      writing-mode: vertical-lr;
    }

    #current-photo {
      position: relative;
      gap: 0.5rem;
      width: 8rem;
      height: 8rem;
      border: 1px solid var(--color-border);
      border-radius: 0.5rem;
      background: var(--color-bg);
      font-size: 0.75rem;
      color: var(--color-muted-foreground);
      text-align: center;

      .none-label {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        background: repeating-conic-gradient(
            var(--color-bg) 0 25%,
            var(--color-border) 0 50%
          )
          50% / 20px 20px;
      }

      img {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 0.5rem;
        opacity: 0;

        &.visible {
          opacity: 1;
        }
      }
    }

    .photo-preset,
    .upload-button,
    .clear-button {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 0.5rem;
      width: 8rem;
      height: 8rem;
      padding: 0;
      border: 1px solid var(--color-border);
      border-radius: 0.5rem;
      background: var(--color-bg);
      cursor: pointer;
      transition: all 0.2s;
      font-weight: normal;
      font-size: 0.75rem;

      &:hover {
        border-color: var(--color-border-active);
        box-shadow: 0 0 0 2px var(--color-border-active);
      }

      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 0.5rem;
      }
    }
  }
}

[popover] {
  padding: 1rem;
  border: 1px solid var(--color-border);
  border-radius: 2rem;
  background: var(--color-bg-sidebar);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  width: min(calc(100% - 2rem), 40rem);
  height: 24rem;
  overflow: auto;
  position: fixed;
  z-index: 10;
  margin: 0;
  pointer-events: all;
  position: fixed;
  top: calc(100vh - 24rem - 1rem);
  left: 50%;
  transform: translateX(-50%);
  transition: all 0.2s;

  @starting-style {
    opacity: 0;
    transform: translateX(-50%) translateY(2rem);
  }

  &::backdrop {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100svh;
    background: #000000aa;
    pointer-events: all;
    backdrop-filter: blur(0.25rem);
    transition: all 0.2s;

    @starting-style {
      background: #00000000;
      backdrop-filter: blur(0);
    }
  }

  .actions {
    display: flex;
    margin-top: 1rem;

    button {
      height: 100%;
      height: 6rem;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      border-radius: 1rem;
      gap: 0.25rem;
      flex: 1;

      &:disabled {
        cursor: not-allowed;
        opacity: 0.5;
      }
    }
  }
}

#take-photo {
  height: 80vh;
  top: calc(100vh - 80vh - 1rem);

  video {
    width: 100%;
    height: calc(100% - 12.5rem);
    border-radius: 1rem;
    background: var(--color-border);
    object-fit: cover;
  }

  .actions {
    border-top: 0;
    padding-top: 0;
  }
}

.options {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-left: 2rem;

  .option {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: 1rem;

    label {
      font-weight: 600;
      font-size: 0.875rem;
    }

    svg {
      height: 0.875rem;
      aspect-ratio: 1 / 1;
      margin-right: -0.25rem;
    }
  }

  .option-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    overflow: auto;
    max-width: 100%;
    margin-top: -1.2rem;
    padding-left: 2rem;
    padding-right: 0.25rem;
    padding-bottom: 0.25rem;

    label {
      min-width: 15ch;

      span {
        font-size: 0.75rem;
      }
    }

    & > button {
      all: unset;
      position: relative;
      cursor: pointer;
      padding: 0.5rem;
      border-radius: 0.5rem;
      gap: 0.5rem;
      display: flex;
      height: 0.75rem;
      font-size: 0.75rem;
      margin-top: auto;
      align-items: center;
      justify-content: center;
      border: 1px solid var(--color-border);
      transition: all 0.2s;
      min-width: 8rem;
      flex-shrink: 0;
      overflow: hidden;

      &:disabled {
        cursor: not-allowed;
        opacity: 0.5;
      }

      &:hover {
        background: var(--color-border);
      }

      &:active {
        background: var(--color-border);
      }

      svg {
        stroke-width: 2px;
        width: 1em;
        height: 1em;
      }
    }

    .status {
      position: absolute;
      inset: 0;
      background: var(--color-bg-sidebar);
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 0.5rem;
      opacity: 0;
      transition: opacity 0.2s;

      &.active {
        opacity: 1;
      }

      & svg {
        animation: spin 1s linear infinite;
        width: 1rem;
        height: 1rem;
      }
    }
  }
}

@media print {
  html,
  body {
    transform: none !important;
  }

  .nav,
  .sidebar,
  .preview .header {
    display: none;
  }

  .outer-container,
  .preview {
    flex: none;
    width: 100%;
    height: 100%;
    margin: 0;
    max-width: 100%;
    max-height: 100%;
    border: 0;
    border-radius: 0;
    padding: 0;
  }

  canvas {
    width: 100% !important;
    height: 100% !important;
    border: 0 !important;
    border-radius: 0 !important;
    max-width: 100% !important;
    max-height: 100% !important;
    aspect-ratio: 8.5 / 11 !important;
    opacity: 100% !important;
  }

  body {
    margin: 0;
    padding: 0;
    background: white;
  }
}

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