/*
  The draw dialog. Sizes, colors and fonts are the ones of the three "Losovanie" frames in the Figma file:
  form (911 x 566), spinning reel (the same, the button greyed out) and the won prize (the same size, so it does not jump).
  The colors are the variables of styles.css.
*/

.roll-dialog {
  width: min(911px, calc(94vw / var(--zoom, 1)));
  max-height: calc(100vh / var(--zoom, 1) - 16px);
  padding: 0;
  background: var(--surface-primary);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text-primary);
  overflow: hidden auto;
}

.roll-dialog[open] {
  display: flex;
  flex-direction: column;
  height: 566px;
}

.roll-dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

/* header: 49 px high, the title bold 16 px, a thin cross on the right */
.roll-header {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface-secondary);
  border-bottom: 1px solid var(--border-subtle);
}

.roll-title {
  margin: 0;
  height: 28px;
  font-size: 16px;
  font-weight: 700;
  line-height: 28px;
}

.roll-close {
  display: block;
  border-radius: 4px;
  padding: 0.5rem;
  background: none;
  border: 0;
  cursor: pointer;
}

.roll-close:hover {
  background: var(--surface-hover);
}

.roll-close img {
  display: block;
  width: fit-content;
  height: fit-content;
}

.roll-close:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 4px;
}

.roll-form {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.roll-main {
  position: relative;
  display: grid;
  flex: 1;
  place-items: center;
  min-height: 0;
  padding: 20px 0;
}

/* the form: two fields 286 px wide, a 43 px high input under a medium 14 px label */
.roll-fields {
  display: grid;
  gap: 20px;
  width: 286px;
  max-width: 100%;
}

.roll-field {
  display: grid;
  gap: 5px;
  font-size: 14px;
  font-weight: 500;
  line-height: normal;
}

.roll-field input {
  box-sizing: border-box;
  width: 100%;
  height: 43px;
  padding: 0 12px;
  background: var(--surface-secondary);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text-primary);
  font: inherit;
  font-weight: 400;
}

.roll-field input:focus {
  outline: none;
  border-color: var(--brand);
}

.roll-check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.roll-check input {
  appearance: none;
  display: grid;
  flex: none;
  place-content: center;
  width: 20px;
  height: 20px;
  margin: 0;
  background: var(--surface-secondary);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.roll-check input::after {
  content: '';
  width: 5px;
  height: 10px;
  margin-top: -2px;
  border: solid #000;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  transition: transform 0.12s;
}

.roll-check input:checked {
  background: var(--brand);
  border-color: var(--brand);
}

.roll-check input:checked::after {
  transform: rotate(45deg) scale(1);
}

.roll-check input:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.roll-check input:hover:not(:checked) {
  border-color: var(--brand);
}

.roll-error,
.field-error {
  display: block;
  margin: 0;
  color: #ff6b6b;
  font-size: 13px;
}

.roll-win-error {
  padding: 0 10px 4px;
  text-align: center;
}

/* footer: 10 px around buttons that are 40 px high */
.roll-footer {
  display: flex;
  flex: none;
  padding: 10px;
}

.roll-button {
  box-sizing: border-box;
  width: 100%;
  height: 40px;
  padding: 10px 20px;
  background: var(--surface-hover);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
  cursor: pointer;
}

.roll-button:hover {
  background: var(--surface-hover);
}

.roll-button-primary {
  background: var(--brand);
  color: var(--surface-primary);
}

.roll-button-primary:hover {
  background: var(--brand-hover);
}

/* while the reel runs the start button is grey */
.roll-button:disabled {
  background: var(--text-disabled);
  color: var(--surface-primary);
  cursor: default;
}

.roll-button-outline {
  background: var(--surface-secondary);
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

.roll-decision {
  display: flex;
  gap: 20px;
  width: 100%;
}

/* the reel: a banner 264 px high (one and a half times the design, so fewer and bigger pictures are in view) that runs from edge to edge of the dialog (the 860 px in the design is only a sample
   picture), tiles of 150 x 150 with the name of the prize under the picture and a green marker in the middle */
.reel-window {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 264px;
  background: var(--bg-canvas);
  transition: filter 0.7s ease;
}

/* who draws which door, above the banner */
.roll-summary {
  position: absolute;
  /* in the middle between the header and the reel, which is centered in the same box */
  top: calc((100% - 264px) / 4);
  transform: translateY(-50%);
  left: 0;
  width: 100%;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
}

.roll-summary-hl {
  color: var(--brand);
}

/* the won state: the banner behind the card is blurred and darkened */
.reel-window.is-blurred {
  filter: blur(4px);
}

.reel-window::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.7s ease;
}

.reel-window.is-blurred::after {
  opacity: 1;
}

.reel-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(50% - 1.5px);
  width: 3px;
  background: var(--brand);
  z-index: 2;
}

.reel-track {
  position: relative;
  height: 100%;
}

/* every tile sits at the left edge and is moved with a transform, see drawReel in roll.js */
.reel-tile {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-sizing: border-box;
  width: 222px;
  height: 100%;
  padding: 0 36px;
  will-change: transform;
}

.reel-tile img,
.reel-placeholder {
  display: block;
  width: 150px;
  height: 150px;
  object-fit: cover;
  border-radius: 15px;
  background: var(--surface-hover);
}

/* the name under each picture, two lines at most, a longer one is cut off with ... (the height is always two lines, so
   the pictures of all tiles stay at the same place) */
.reel-tile-name {
  display: -webkit-box;
  width: 150px;
  height: 35px;
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  line-height: 17.5px;
  text-align: center;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow-wrap: anywhere;
}

/* the won prize: the card in the middle, in front of the blurred reel */
.roll-card-slot {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  z-index: 2;
  animation: roll-pop 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

/* the won card can be tilted by the pointer, see tilt.js, it springs back a little too far when let go */
.roll-card-slot .winning-card {
  transform: perspective(800px) rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg));
  transition: transform 0.6s cubic-bezier(0.2, 1.4, 0.4, 1);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.roll-card-slot .winning-card.is-tilting {
  transition: none;
  cursor: grabbing;
}

/* the shine follows the pointer */
.roll-card-slot .winning-card::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  background: radial-gradient(circle at var(--glare-x, 50%) var(--glare-y, 50%), rgba(255, 255, 255, 0.4), transparent 55%);
  opacity: var(--glare, 0);
  pointer-events: none;
  transition: opacity 0.3s ease;
}

@keyframes roll-pop {
  from {
    scale: 0.2;
    opacity: 0;
  }
  to {
    scale: 1;
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .reel-window,
  .reel-window::after {
    transition: none;
  }
}

/*
  The dialog "Výhra" (Figma frame 6): 371 px wide. The cards of a door with several winners are in a strip that
  scrolls sideways, the one in the middle is whole and the neighbours peek out, arrows move to the next one.
*/
.prize-dialog {
  width: min(calc(94vw / var(--zoom, 1)), 371px);
  padding: 0;
  background: var(--surface-primary);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text-primary);
  overflow: hidden;
}

.prize-dialog[open] {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.prize-dialog:focus {
  outline: none;
}

.prize-dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.prize-carousel {
  position: relative;
  z-index: 1;
}

/* the header and the footer stay above the strip, so its free space does not catch their clicks */
.prize-dialog .roll-header,
.prize-dialog .roll-footer {
  position: relative;
  z-index: 2;
}

/* the padding lets the first and the last card reach the middle, a card is 205.214 px wide */
.prize-dialog-cards {
  display: flex;
  gap: 20px;
  /* the free space above and below (taken back by the margin) is for the tilted card, overflow would cut it off */
  padding: 30px calc(50% - 102.607px);
  margin: -30px 0;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.prize-dialog-cards::-webkit-scrollbar {
  display: none;
}

.prize-dialog-cards > * {
  scroll-snap-align: center;
  opacity: 0.45;
  transform: scale(0.92);
  transition: opacity 0.45s ease, transform 0.45s ease;
}

/* the card in the middle is whole, the neighbours are smaller and dimmed */
.prize-dialog-cards > .is-current {
  opacity: 1;
  /* tilted by the pointer, see the tilt code in app.js, it springs back a little too far when let go */
  transform: perspective(800px) rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg));
  transition: opacity 0.45s ease, transform 0.6s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.prize-dialog.can-tilt .prize-dialog-cards > .is-current {
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.prize-dialog-cards > .is-current.is-tilting {
  transition: opacity 0.45s ease;
}

.prize-dialog.can-tilt .prize-dialog-cards > .is-current.is-tilting {
  cursor: grabbing;
}

/* the shine follows the pointer */
.prize-dialog-cards > .is-current::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: 11px;
  background: radial-gradient(circle at var(--glare-x, 50%) var(--glare-y, 50%), rgba(255, 255, 255, 0.4), transparent 55%);
  opacity: var(--glare, 0);
  pointer-events: none;
  transition: opacity 0.3s ease;
}


.prize-arrow {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: rgba(20, 21, 23, 0.85);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  cursor: pointer;
  transform: translateY(-50%);
}

.prize-arrow:hover {
  background: var(--surface-hover);
}

.prize-arrow:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.prize-arrow-prev {
  left: 8px;
}

.prize-arrow-next {
  right: 8px;
}

.prize-arrow-prev img {
  transform: scaleX(-1);
}

.prize-dialog-footer {
  gap: 10px;
}

/* opened from the tab of the prizes: the buttons are not there, but their place stays */
.prize-dialog-footer.is-placeholder {
  visibility: hidden;
}

.prize-dialog-footer .roll-button {
  flex: 1;
  width: auto;
  text-align: center;
  text-decoration: none;
}
