*,
*::after,
*::before {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:where(html) {
  color-scheme: light dark;
  hanging-punctuation: first allow-end last;
  interpolate-size: allow-keywords;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
  text-size-adjust: none;
  -webkit-text-size-adjust: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

:where(html.translated-rtl) {
  direction: rtl;
}

@media (prefers-reduced-motion: reduce) {
  :where(html) {
    scroll-behavior: auto;
  }
}

:where(body) {
  min-block-size: 100svb;
  min-inline-size: 300px;
}

:where(canvas, img, picture, svg, video) {
  block-size: auto;
  border: none;
  display: block;
  max-inline-size: 100%;
}

:where(button, input, progress, select, textarea) {
  appearance: none;
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  hanging-punctuation: none;
  line-height: inherit;
  text-align: start;
  touch-action: manipulation;
}

:where(button) {
  cursor: pointer;
  user-select: none;
}

:where(textarea) {
  resize: vertical;
}

:where(textarea:not([rows])) {
  field-sizing: content;
}

:where(fieldset, iframe) {
  border: none;
}

:where(p, li, h1, h2, h3, h4, h5, h6) {
  overflow-wrap: break-word;
  text-wrap: pretty;
}

:where(abbr[title]) {
  border: none;
  text-decoration: none;
}

:where(cite) {
  font-style: inherit;
}

:where(small) {
  font-size: inherit;
}

:where(li, ol, ul) {
  list-style: none;
}

:where(dialog, [popover]) {
  background: transparent;
  border: none;
  color: inherit;
  margin: auto;
  max-block-size: none;
  max-inline-size: none;
  position: fixed;
}

:where([popover]) {
  inset: auto;
}

:where(dialog:not([open], [popover]), [popover]:not(:popover-open)) {
  display: none;
}

:where([hidden]:not([hidden='until-found'])) {
  display: none !important;
}

.poppins-light {
  font-family: 'Poppins', sans-serif;
  font-weight: 300;
  font-style: normal;
}

.poppins-regular {
  font-family: 'Poppins', sans-serif;
  font-weight: 400;
  font-style: normal;
}

.poppins-semibold {
  font-family: 'Poppins', sans-serif;
  font-weight: 600;
  font-style: normal;
}

.poppins-bold {
  font-family: 'Poppins', sans-serif;
  font-weight: 700;
  font-style: normal;
}

.changa-one-regular {
  font-family: 'Changa One', sans-serif;
  font-weight: 400;
  font-style: normal;
}

.changa-one-regular-italic {
  font-family: 'Changa One', sans-serif;
  font-weight: 400;
  font-style: italic;
}

body {
  margin: 0;
  background: oklch(0.24 0 270);

  display: flex;
  flex-direction: column;
  gap: 1.5rem;

  justify-content: center;
  align-items: center;

  min-height: 100vh;
}

canvas {
  background: oklch(0.3 0 0);
  box-shadow: 0 0px 50px oklch(0 0 0 / 0.65);
}

.game-container {
  position: relative; /* important for overlay positioning */
  display: flex;
  justify-content: center;
  align-items: center;
}

.text-header {
  color: oklch(0.65 0.2 300);
  text-shadow: 0 0px 20px oklch(0 0 0 / 0.2);
}

.text-footer {
  color: oklch(0.65 0.2 300);
  text-shadow: 0 0px 8px oklch(0 0 0 / 0.2);
}

/* Debug HUD */

.dev-hud {
  position: absolute;
  top: 1rem;
  left: 1rem;

  min-width: 180px;
  padding: 0.75rem 1rem;

  background: oklch(0 0 0 / 0.65);
  backdrop-filter: blur(6px);

  border: 1px solid oklch(1 0 0 / 0.1);
  border-radius: 8px;

  box-shadow: 0 0 25px oklch(0 0 0 / 0.6);

  font-size: 0.85rem;
  pointer-events: none; /* doesn't interfere with gameplay */

  transition:
    opacity 0.5s,
    transform 0.5s;
  @starting-style {
    opacity: 0;
    transform: translateY(20px);
  }
}

.hud-header {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  opacity: 0.7;
  margin-bottom: 0.5rem;
}

.hud-content {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.hidden {
  display: none;
}

/* Game score, etc. HUD */

.score-hud {
  position: absolute;
  left: calc(100% + 1.5rem);
  top: 0;

  display: flex;
  flex-direction: column;
  gap: 1.5rem;

  min-width: 120px;
}

.score-block {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.score-label {
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  opacity: 0.6;
  color: oklch(1 0 0);
}

.score-value {
  font-size: 1.5rem;
  font-weight: 600;
  color: oklch(1 0 0);
}

/* Preview canvas - purely for the "Next Piece" preview */
.preview-container {
  position: absolute;
  left: calc(100% + 1rem);
  bottom: 0;

  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.preview-label {
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  opacity: 0.6;
  color: oklch(1 0 0);
}

#previewCanvas {
  background: oklch(0 0 0 / 0.15);
  border: 1px solid oklch(1 0 0 / 0.15);
  border-radius: 4px;
  box-shadow: 0 0 10px oklch(0.6 0.16 272 / 0.3);
  max-inline-size: none;
}

/* Start screen overlay related */

.start-screen {
  position: absolute;
  inset: 0;

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;

  background: oklch(0 0 0 / 0.85);
  backdrop-filter: blur(8px);

  z-index: 100;

  transition:
    opacity 0.3s,
    visibility 0.3s;

  &.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  & .prompt {
    font-size: 2.5rem;
    color: white;
    margin: 0;
    text-shadow: 0 0px 20px oklch(0.6 0.16 272 / 0.8);
  }
}

.start-button {
  padding: 1rem 3rem;
  font-size: 1.25rem;
  color: white;
  background: linear-gradient(
    135deg,
    oklch(0.6 0.16 272) 0%,
    oklch(0.5 0.14 300) 100%
  );
  border: none;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 4px 15px oklch(0.6 0.16 272 / 0.4);
  transition:
    transform 0.2s,
    box-shadow 0.2s;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px oklch(0.6 0.16 272 / 0.6);
  }

  &:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px oklch(0.6 0.16 272 / 0.4);
  }
}

.controls-hint {
  color: oklch(1 0 0 / 0.75);
  text-align: center;
  font-size: 0.9rem;
  line-height: 1.6;

  & p {
    &.action {
      color: oklch(1 0.16 272 / 0.6);
    }

    &.inputs {
      color: oklch(1 0 0);
      margin-bottom: 0.75rem;
    }
  }
}

/* Audio settings */

.audio-settings {
  display: flex;
  flex-direction: row;
  gap: 1rem;
}

.audio-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: oklch(1 0 0);
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;

  & span {
    line-height: 1;
    display: flex;
    align-items: center;
  }

  &:hover {
    opacity: 0.8;
  }

  & input[type='checkbox'] {
    appearance: none; /* Remove default styling */
    width: 20px;
    height: 20px;
    cursor: pointer;
    margin: 0;
    flex-shrink: 0;
    border-radius: 4px;
    border: 2px solid oklch(0.6 0.16 272);
    background-color: transparent;
    position: relative;
    transition: all 0.2s;

    &:checked {
      background-color: oklch(0.6 0.16 272);

      &::after {
        content: '';
        position: absolute;
        left: 5px;
        top: 2px;
        width: 5px;
        height: 10px;
        border: solid white;
        border-width: 0 2px 2px 0;
        transform: rotate(45deg);
      }
    }
  }
}
