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

body,
p {
  margin: 0;
}

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

:root {
  --s1: 0.5rem;
  --s2: 1rem;
  --s3: 1.5rem;
  --s4: 2rem;
  --s5: 3rem;
  --s6: 4rem;
  --color-primary: #333;
  --color-secondary: #fff;
  --color-tertiary: hsl(200, 5%, 30%);
  --color-brand: #e64747;
  --color-brand-alt: hsl(240, 50%, 70%);
  --color-line: #dedede;

  font-family: system-ui;
  touch-action: manipulation;
}

body {
  text-rendering: optimizeSpeed;
  line-height: 1.5;
  background-image: url(assets/background-grain.png), url(assets/background.svg);
  background-size: auto, cover;
  background-repeat: repeat, no-repeat;
}

.app:not([hidden]) {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100vh;

  /* prettier-ignore */
  padding:
    env(safe-area-inset-top, 0)
    env(safe-area-inset-right, 0)
    env(safe-area-inset-bottom, 0)
    env(safe-area-inset-left, 0);
}

.rate-section:not([hidden]) {
  width: 100%;
  padding-top: var(--s4);
  padding-bottom: var(--s2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.card {
  --height: min(calc(80vmin * 1.5), 80vh);

  display: inline-block;
  background-color: var(--color-primary);
  width: calc(var(--height) * 0.6666);
  height: var(--height);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: -1px 5px 15px 3px rgba(0, 0, 0, 0.28);
  position: relative;
  border: 1px solid var(--color-line);
  transition: border 100ms ease-in-out;
}

@media (hover: hover) {
  a.card:hover {
    border: 1px solid var(--color-brand);
  }
}

.card .poster {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card p {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: var(--s3) var(--s2) var(--s2);

  /* prettier-ignore */
  background-image:
    linear-gradient(
      179deg,
      rgba(238, 238, 238, 0) 0%,
      rgba(238, 238, 238, 0) 20%,
      rgba(0, 0, 0, 0.31) 40%,
      rgba(0, 0, 0, 0.9) 100%
    );
  text-align: left;
  color: var(--color-secondary);
  font-weight: bold;
  font-family: system-ui;
  font-size: 1rem;
}

.card-stack {
  --empty-text: var(--i18n-loading);

  position: relative;
}

.card-stack:empty {
  min-height: min(calc(80vmin * 1.5), 80vh);
  width: 40vw;
}

.card-stack:empty::after {
  content: var(--empty-text);
  font-weight: bold;
  color: var(--color-tertiary);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  white-space: nowrap;
}

.card-stack > .card {
  transition: transform 150ms ease-in;
  touch-action: manipulation;
}

.card-stack > .card .poster {
  transition: opacity 150ms ease-in;
}

.card-stack > .card:nth-of-type(n + 2) {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

.card-stack > .card:nth-of-type(n + 2) .poster {
  opacity: 0.5;
}

.card-stack > .card:nth-of-type(1) {
  z-index: 4;
}

.card-stack > .card:nth-of-type(2) {
  transform: translate(-1%, -1%);
  z-index: 3;
}

.card-stack > .card:nth-of-type(3) {
  transform: translate(-2%, -2%);
  z-index: 2;
}

.card-stack > .card:nth-of-type(4) {
  transform: translate(-3%, -3%);
  z-index: 1;
}

@media screen and (min-width: 48em) {
  .card-stack > .card:nth-of-type(2) {
    transform: translate(-16.6%, -3%);
  }

  .card-stack > .card:nth-of-type(3) {
    transform: translate(-33.3%, -6%);
  }

  .card-stack > .card:nth-of-type(4) {
    transform: translate(-50%, -10%);
  }
}

.card-stack > .card:nth-of-type(n + 5) {
  display: none;
}

.rate-controls {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: var(--s5);
  margin-top: var(--s3);
}

.rate-controls button {
  all: unset;
  font-size: 3rem;
  cursor: pointer;
  transition: transform 200ms linear;
}

.rate-controls[disabled] button {
  opacity: 0.5;
}

@media screen and (hover: hover) {
  .rate-controls:not([disabled]) .rate-thumbs-up:hover {
    transform: scale(1.2) rotate(-20deg) translate(0, -1rem);
  }

  .rate-controls:not([disabled]) .rate-thumbs-down:hover {
    transform: scale(1.2) rotate(20deg) translate(0, 1rem);
  }
}

.matches-section:not([hidden]) {
  text-align: center;
}

.matches-section hr {
  width: 80vw;
  border: 0.5px solid var(--color-brand-alt);
  border-radius: 2px;
  margin: auto;
  position: relative;
  overflow: visible;
}

.matches-section hr::before {
  content: attr(data-room-code);
  position: absolute;
  bottom: 0;
  left: 0;
  display: block;
  font-size: 0.7rem;
  background: var(--color-brand-alt);
  color: var(--color-secondary);
  padding: 0.25rem 0.5rem 0.25rem 0.25rem;
  border-radius: 0 1rem 1rem 0;
  box-shadow: -1px 1px 10px 3px rgba(0, 0, 0, 0.1);
  font-weight: bold;
  transform: translate(-90%, 50%);
}

.matches-title {
  font-family: system-ui;
  font-weight: 600;
  font-size: 1.125rem;
  color: var(--color-primary);
  margin-top: var(--s1);
}

.matches-title .matches-count {
  width: 1.125rem;
  height: 1.125rem;
  border-radius: 100%;
  background-color: var(--color-brand);
  color: var(--color-secondary);
  font-family: monospace;
  font-weight: bold;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  top: -3px;
}

.matches-title .matches-count::before {
  content: attr(data-count);
}

.matches-title .matches-count[data-count='0'] {
  background-color: var(--color-primary);
}

.matches-list {
  display: grid;
  position: relative;
  grid-auto-flow: column;
  list-style: none;
  width: 100%;
  min-height: 70vh;
  height: max-content;
  grid-gap: var(--s4);
  overflow: auto;
  padding: var(--s4) 0 var(--s3) 10vw;
  scroll-snap-type: x mandatory;
}

.matches-list li {
  scroll-snap-align: start;
  scroll-margin-left: 10vw;
  scroll-snap-margin-left: 10vw;
}

.matches-list::after {
  content: '';
  width: calc(10vw - var(--s4));
  display: block;
}

.matches-list:empty::before {
  position: absolute;
  min-width: 80vw;
  left: 50%;
  top: 50%;
  content: var(--i18n-no-matches);
  transform: translate(-50%, -50%);
  font-weight: bold;
  color: var(--color-tertiary);
}

.login-section:not([hidden]) {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: var(--s3);
}

.login-section .logo {
  width: clamp(4rem, 50%, 15.5rem);
  margin-bottom: var(--s6);
  color: var(--color-brand);
}

.login-form {
  display: grid;
  grid-template-columns: 1fr;
  grid-auto-rows: min-content;
  gap: 1rem;
  width: 80%;
}

.login-form label {
  margin-left: var(--s1);
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: calc(var(--s1) * -1);
  align-self: center;
}

.login-form input {
  background: transparent;
  border: 2px solid var(--color-brand);
  border-radius: 0.3rem;
  padding: var(--s1);
  font-size: 1.2rem;
  flex-grow: 1;
  margin: 0;
  width: 100%;
}

.login-form .room-code-container {
  display: flex;
  max-width: 100%;
}

.login-form .room-code-container input {
  border-bottom-right-radius: 0;
  border-top-right-radius: 0;
}

.login-form .room-code-container .generate-button {
  appearance: none;
  border: none;
  background: var(--color-brand);
  color: var(--color-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  overflow: visible;
  grid-column: 2;
  border-radius: 0 0.3rem 0.3rem 0;
}

.login-form .generate-button abbr {
  padding: 0 0.5rem;
  text-decoration: none;
}

.login-form .submit-button {
  border: none;
  grid-column: 1 / -1;
  margin-top: var(--s6);
  background-color: var(--color-brand);
  color: var(--color-secondary);
  padding: var(--s2) var(--s1);
  border-radius: var(--s4);
  font-size: 1.2rem;
  font-weight: bold;
  cursor: pointer;
}

@media screen and (min-width: 48em) {
  .login-form {
    grid-template-columns: 10rem 1fr;
    width: 80%;
    max-width: 35rem;
  }

  .login-form .input-description {
    grid-column: 2;
  }

  .login-form .submit-button {
    justify-self: end;
    width: 200px;
    grid-column: 2;
  }
}

footer {
  display: flex;
  align-items: center;
  justify-content: center;
  color: hsl(240, 40%, 40%);
  font-size: 0.5rem;
  font-weight: bold;
  padding: 1rem 0;
}
