*,
*::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: #4f7a57;

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

body {
  text-rendering: optimizeSpeed;
  line-height: 1.5;
  background-image: linear-gradient(160deg, #1a1228 0%, #2d1b3d 100%);
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
  min-height: 100vh;
}

.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: 14px;
  overflow: hidden;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  position: relative;
}

/* Frosted glass rim: bright top highlight + bright ring + darkened edges */
.card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 5;
  box-shadow:
    inset 0 1.5px 1px rgba(255, 255, 255, 0.55),
    inset 0 0 0 1.5px rgba(255, 255, 255, 0.22),
    inset 0 0 14px 2px rgba(0, 0, 0, 0.45),
    inset 0 -16px 30px rgba(0, 0, 0, 0.32);
}

@media (hover: hover) {
  a.card:hover::after {
    box-shadow:
      inset 0 1.5px 1px rgba(255, 255, 255, 0.75),
      inset 0 0 0 1.5px rgba(255, 255, 255, 0.4),
      inset 0 0 14px 2px rgba(0, 0, 0, 0.45),
      inset 0 -16px 30px rgba(0, 0, 0, 0.32);
  }
}

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

.card-detail {
  position: absolute;
  inset: 0;
  background: rgba(14, 12, 26, 0.78);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  display: flex;
  flex-direction: column;
  padding: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease 0.1s;
  overflow: hidden;
}

.card--expanded .card-detail {
  opacity: 1;
  pointer-events: auto;
}

/* Keep the full poster visible so the frosted panel blurs over it */
.card--expanded .poster:not(.poster--thumb) {
  opacity: 1;
}

.card-detail-top {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.card .poster--thumb {
  /* ~2/7 of the card width, preserving the 2:3 poster aspect ratio */
  width: calc(var(--height) * 0.6666 * 2 / 7);
  height: auto;
  aspect-ratio: 2 / 3;
  flex-shrink: 0;
  border-radius: 4px;
  object-fit: cover;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.card-detail-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 2px;
  min-width: 0;
}

.card-title {
  font-size: 32.8px;
  font-weight: bold;
  color: #f0f0f0;
  line-height: 1.3;
  margin: 0;
}

.card-year {
  font-weight: normal;
  color: #888;
}

.card-rating {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(76, 175, 80, 0.18);
  border: 1px solid rgba(76, 175, 80, 0.45);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 1rem;
  font-weight: bold;
  color: #7ee084;
  width: fit-content;
}

.card-rating--mid {
  background: rgba(255, 152, 0, 0.18);
  border-color: rgba(255, 152, 0, 0.5);
  color: #ffb74d;
}

.card-rating-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.card-detail-top + .card-summary {
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  padding-top: 10px;
}

.card-summary {
  font-size: 17.8px;
  color: rgba(255, 255, 255, 0.92);
  line-height: 1.6;
  margin: 0;
  overflow-y: auto;
  flex: 1;
}

.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);
  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);
  color: #f4efe1;
  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: #f4efe1;
  margin-top: var(--s1);
}

.matches-title .matches-count {
  width: 1.125rem;
  height: 1.125rem;
  border-radius: 100%;
  background-color: var(--color-brand);
  color: #f4efe1;
  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%;
  background: rgba(255, 255, 255, 0.08);
  -webkit-backdrop-filter: blur(16px) saturate(130%);
  backdrop-filter: blur(16px) saturate(130%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

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

.login-form input {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  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: #f4efe1;
  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;
  justify-self: center;
  width: 80%;
  margin-top: 1.5rem;
  background-color: var(--color-brand);
  color: #f4efe1;
  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: center;
    width: 160px;
    grid-column: 1 / -1;
  }
}

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