/*********************************
 * Copyright (c) 2026 FumbleCrop *
 * All rights reserved.          *
 * See COPYRIGHT.md for details. *
 *********************************/

/**********
 * LAYOUT *
 **********/
:root {
    --card-width: 12.5rem;
    --card-height: calc(var(--card-width) * 1.75);
    --interaction-area-padding: 2.5rem;
    --shoe-minimum-width-multiple: 1.5;
    --dragging-z-index: 100;
}

* {
    /* Take padding and borders around the element
     into account when sizing elements. */
    box-sizing: border-box;
}

body {
    /* Remove the default outer gap. */
    margin: 0;

    /* Avoid those distracting scroll bars that briefly appear during
     * CSS animations when a whirling div strays outside the viewport.
     */
    overflow: hidden;
}

main {
    /* The height of the viewport - "d" is for "dynamic". */
    height: 100dvh;

    /* Flex layout allows .table-view-surround to occupy the
     vertical space left by .shoe-surround. */
    display: flex;
    flex-direction: column;
}

/*
 * Vertically, the shoe always occupies its natural size,
 * and the rest of the vertical flex box will fit around it.
 *
 * Horizontally, the card placeholders spread or overlap
 * to fill the available space. The container becomes scrollable
 * when there isn't enough space.
 */

.shoe-surround {
    /* Keep this region at its natural height.
   Parent's flex layout will not grow or shrink it. */
    flex: none;
    padding: var(--interaction-area-padding);
}

/* This lays out the card anchors in a row.
 * The card anchors have the same dimensions as the cards.
 *
 * Except when `min-width` overrides, the height the
 * width is determined by the parent element.
 * The height is determined by the height of the
 * card anchors and internal padding.
 */
#shoe-track {
  --padding: 1rem;
  min-width: calc(var(--shoe-minimum-width-multiple) * var(--card-width) + 2 * var(--padding));
  padding: var(--padding);

  /* Lay out the card anchors in an evenly-spaced row. */
  display: flex;
  justify-content: space-between;
}

.shoe-card-anchor, .card {
    width: var(--card-width);
    height: var(--card-height);
}

.shoe-card-anchor {
  /* `justify-content: space-between` does what I want when
   * there's enough space for all the elements, but it won't
   * make them overlap. This trick solves that problem.
   *
   * To the layout engine, this makes every card anchor except
   * the last look like a zero-width div, with the anchor pinned
   * to it at the anchor's left edge.
   */
  &:not(:last-child) {
      margin-right: calc(-1 * var(--card-width));
  }

  /* Create the co-ordinate system for the
     absolutely-positioned card to be placed */
  position: relative;
}

.card-front, .card-back {
  /* Position them at the top left of the .card's content area. */
  position: absolute;
}


.table-view-surround {
    /* May want to adjust this for smaller screens */
    padding: var(--interaction-area-padding);

    /* Vertically fill exactly the remaining space in the
     parent element (assuming no other flex elements).
     shrink the content height down to 0 if there's no space. */
    flex: 1;
    min-height: 0;
}
#table-view {
    /* Vertically fill parent element */
    height: 100%;

    /* Provide scrolling when the contents overflows */
    overflow: auto;

    /* Scroll actions in the table-view should not affect containing elements. */
    overscroll-behavior: contain;

    /* Make programmatic scrolling immediate, without smooth animation. */
    scroll-behavior: auto;

    /* Disable the browser's automatic scroll-position compensation
     when content moves. JavaScript manages that compensation. */
    overflow-anchor: none;

}
#tabletop {
    /* Provide a co-ordinate system for the cards contained within */
    position: relative;

    /* Be sure to fill the #viewport */
    min-width: 100%;
    min-height: 100%;
}

/***************
 * CARD LAYOUT *
 ***************/

.card .card-visible {
  &, .card-front, .card-front .card-image, .card-back, .card-annotations {
    width: 100%; height: 100%;
    position: absolute;
  }
  .card-back { transform: rotateY(180deg); }

  /* Arrange the two `.card-annotation`s at the top and bottom
   * of their `.card-annotations` containers, turning one of them
   * upside town. */
  .card-front .card-annotations {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .card-annotation { flex: none; }
    &.card-annotations-reversed { rotate: 0.5turn; }

    .card-annotation-title .card-annotation-title-reversed-suffix {
      display: block;
    }
  }
}

/******************
 * POINTER EVENTS *
 ******************/

/* Card anchors in the shoe can overlap. Empty anchors should not
 * catch clicks over cards in anchors beneath them. */
 .shoe-card-anchor       { pointer-events: none; }
 .shoe-card-anchor .card { pointer-events: all ; }


/********************
 * CARD INTERACTION *
 ********************/

/* .card is the element that the JavaScript interacts with for
 * most of the user actions.  Pointer events, positioning and
 * applying classes to change appearance all happens here.
 */

.card {
  /* Disable the default pointer interactions. */
  user-select: none;
  touch-action: none;

  margin: 0;
  padding: 0;
  border: 0;
}

/* During a drag action, the card is effectively "lifted out of the
 * document". I.e. it is positioned relative to the viewport and in
 * a higher z plane. */
.card.dragging {
    position: fixed;
    z-index: var(--dragging-z-index);
}

/*******************
 * CARD APPEARANCE *
 *******************/

/* The .card itself is invisible.
 *
 * .card-visible is quite a literal 3D vissual representation
 * of a playing card. It has a .card-front and a .card-back
 * which are flipped with respect to one another. Only
 * the side that is turned to the "camera" is visible. */

/* Consider exploring perspective for the whole page later. */
.card {
  perspective: 1000px;
}

/* When the .card-visible turns, its two sides turn with it. */
.card .card-visible {
  transform-style: preserve-3d;
  .card-front, .card-back {
    backface-visibility: hidden;
  }
}

/******************
 * CARD ANIMATION *
 ******************/


/* The intermediate states in the transition are found by taking
 * intermediate values to the arguments to `rotateX` and `rotateY`,
 * so different ways of expressing the rotation produce very
 * different motions.
 */

.card .card-visible {
  transform: rotateX(0turn  ) rotateY(0turn  );
  transition: transform 0.6s ease;
}
.card.concealed .card-visible {
  transform: rotateX(0turn  ) rotateY(0.5turn);
}
.card.reversed .card-visible {
  transform: rotateX(0.5turn) rotateY(0.5turn);
}
.card.concealed.reversed .card-visible {
  transform: rotateX(0.5turn) rotateY(0turn  );
}

/* Show annotaions on hover.
 */

.card .card-visible .card-annotations .card-annotation {
  opacity: 0%;
  transition: opacity 0.2s ease;
}

.card:hover:not(.concealed):not(.dragging) {
  &.reversed .card-annotations.card-annotations-reversed .card-annotation,
  &:not(.reversed) .card-annotations:not(.card-annotations-reversed) .card-annotation {
    &.card-annotation-title {
     opacity: 100%;
     transition: opacity 0.2s 0.2s ease;
    }
    &.card-annotation-interpretations {
      opacity: 100%;
      transition: opacity 0.8s 1s ease;
    }
  }
}



/*****************
 * CARD MOVEMENT *
 *****************/

.card {
  position: absolute;
  top: 0;
  left: 0;
}



/**************
 * APPEARANCE *
 **************/

body {
    background-color: #181d1c;
}

#table-view {
    border: 1px solid #647569;
    border-radius: 1rem;
    background: #334d43;
    box-shadow: inset 0 0 70px #10261b55;
}

#tabletop {
    background-image: radial-gradient(#b8cbb513 0.05rem, transparent 0.05rem);
    background-size: 1rem 1rem;
}

.card {
  &, .card-front, .card-front .card-image, .card-back, .card-annotations, .card-annotation {
    border-radius: 1rem;
  }
}

.card .card-visible {
  box-shadow: inset 0 0 0 3px #ffffff0a;

  .card-back {
    background-color: olive;
  }

  .card-front .card-image {
    background-size: 100% 100%;
  }

  .card-annotations .card-annotation {
    color: black;
    background-color: #eee8aae0; /* translucent palegoldenrod */

    padding: var(--card-border-radius);

    &.card-annotation-title {
      padding-bottom: 0.5em;
      border-bottom-left-radius: 0;
      border-bottom-right-radius: 0;
      
      text-align: center;
      font-size: 1.5rem;

      .card-annotation-title-reversed-suffix {
        font-style: italic;
      }
    }

    &.card-annotation-interpretations {
      padding-top: 0.5em;
      border-top-left-radius: 0;
      border-top-right-radius: 0;
      
      text-align: left;
      font-size: 1rem;
    }
  }
}