/* Replays (replay.html): additions on top of styles.css. The list of games sits on paper; one game is a
   felt figure with the table, the step controls and a strip of your choices on the left, and on the right
   what just happened and Mortal's numbers for the choice in front of you. */

.replay-book {
  padding-bottom: 24px;
}

.replay-loading {
  padding-top: 96px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 15px;
}

/* ------------------------------------------------------------------ masthead */

.replay-masthead {
  display: grid;
  gap: 18px;
  max-width: 820px;
  padding-top: 72px;
}

.replay-masthead .guide-eyebrow {
  margin: 0;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 14px;
}

.replay-masthead h1 {
  font-size: clamp(38px, 4.4vw, 60px);
  letter-spacing: -0.02em;
  line-height: 1;
  text-wrap: balance;
}

.replay-masthead .standfirst {
  margin: 0;
  font-size: 22px;
  line-height: 1.5;
  text-wrap: pretty;
}

.replay-masthead p {
  margin: 0;
}

.replay-game-result {
  font-size: 22px;
  line-height: 1.4;
}

.replay-masthead-note {
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.55;
  text-wrap: pretty;
}

.guide-error {
  color: var(--verm);
  font-family: var(--sans);
}

/* ------------------------------------------------------------------ the list of games */

.replay-games-scroll {
  margin-top: 44px;
  overflow-x: auto;
}

.replay-games {
  width: 100%;
  max-width: 880px;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 15.5px;
}

.replay-games th,
.replay-games td {
  padding: 11px 14px 11px 0;
  border-bottom: 1px solid var(--hair-2);
  text-align: left;
  vertical-align: baseline;
  white-space: nowrap;
}

.replay-games thead th {
  border-bottom-color: var(--hair);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.replay-games thead abbr {
  text-decoration: none;
}

.replay-games tbody th {
  font-weight: 500;
}

.replay-games tbody th a {
  display: inline-block;
  min-height: 24px;
}

.replay-games .replay-games-num {
  text-align: right;
}

.replay-games-place.place-1 {
  color: var(--jade);
  font-weight: 700;
}

.replay-games-place.place-4 {
  color: var(--verm);
  font-weight: 700;
}

.replay-games-score small {
  margin-left: 8px;
  color: var(--muted);
  font-size: 13px;
}

.replay-games tbody tr:hover {
  background: var(--plate);
}

.replay-games .date-short {
  display: none;
}

/* ------------------------------------------------------------------ hands */

.replay-hands {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 36px 0 18px;
}

.replay-hand-button {
  position: relative;
  min-width: 48px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--hair);
  border-radius: 2px;
  background: var(--plate);
  color: var(--ink);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 14.5px;
  font-weight: 600;
}

.replay-hand-button:hover {
  border-color: var(--felt);
}

.replay-hand-button.is-current {
  border-color: var(--felt);
  background: var(--felt);
  color: var(--cream);
}

/* A hand with a flagged choice carries a small vermilion dot. */
.replay-hand-button.has-flags::after {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--verm);
  content: "";
}

.replay-hand-button.is-current.has-flags::after {
  background: var(--verm-felt);
}

/* ------------------------------------------------------------------ the figure */

/* The table, then the step controls, the jumps and the strip of your choices under it; the panel to the
   right. On a phone the panel follows the table and the step controls stay at the foot of the screen. */
.replay-viewer {
  grid-template-areas:
    "table panel"
    "controls panel"
    "jumps panel"
    "strip panel";
  grid-template-columns: minmax(0, 620px) minmax(0, 1fr);
  grid-template-rows: auto auto auto 1fr;
  gap: 14px 44px;
}

.replay-viewer .replay-table {
  grid-area: table;
}

/* Room for Mortal's bars at every step, so the page under the panel stays put when they come and go
   (replay.js raises it if a panel needs more). */
.replay-viewer .replay-panel {
  grid-area: panel;
  min-height: 500px;
}

.replay-controls {
  display: flex;
  grid-area: controls;
  align-items: center;
  gap: 8px;
}

.replay-button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 44px;
  border: 1px solid rgba(244, 240, 230, 0.34);
  border-radius: 2px;
  background: transparent;
  color: var(--cream);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1;
}

.replay-button[data-go="prev"],
.replay-button[data-go="next"] {
  width: 64px;
  background: rgba(244, 240, 230, 0.1);
}

.replay-button:hover:not(:disabled) {
  border-color: var(--cream);
}

.replay-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.replay-slider {
  flex: 1 1 auto;
  min-width: 60px;
  accent-color: var(--cream-2);
}

.replay-jumps {
  display: flex;
  grid-area: jumps;
  flex-wrap: wrap;
  gap: 8px;
}

.replay-jump {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(244, 240, 230, 0.22);
  border-radius: 2px;
  background: transparent;
  color: var(--cream-2);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
}

.replay-jump:hover {
  border-color: var(--cream-2);
  color: var(--cream);
}

.replay-jump.is-flag {
  color: var(--verm-felt);
}

/* Your choices in this hand, in order: jade where you played Mortal's first choice, pale where you
   played something else it gives 5% or more, vermilion under 5%. Call chances are shorter. */
.replay-strip {
  display: flex;
  grid-area: strip;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 4px;
  min-height: 22px;
}

.replay-tick {
  width: 12px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: var(--jade-felt);
  cursor: pointer;
}

.replay-tick.is-call {
  height: 12px;
}

.replay-tick.tier-differ {
  background: var(--cream-3);
}

.replay-tick.tier-flag {
  background: var(--verm-felt);
}

.replay-tick.is-current {
  box-shadow: 0 0 0 2px var(--felt), 0 0 0 4px var(--cream);
}

/* ------------------------------------------------------------------ the table */

/* Tiles cut straight from the draw are dimmed, as in Tenhou's viewer. */
.mahjong-table .discard-tile-slot.is-tsumogiri .tiles {
  opacity: 0.62;
}

/* The latest discard carries a small dot. */
.mahjong-table .discard-tile-slot.is-last {
  position: relative;
}

.mahjong-table .discard-tile-slot.is-last::after {
  position: absolute;
  bottom: -0.16em;
  left: 50%;
  width: 0.34em;
  height: 0.34em;
  border-radius: 50%;
  background: var(--verm-felt);
  content: "";
  transform: translateX(-50%);
}

/* Your hand holds still from step to step. replay.js pads it to fourteen places (the empty ones are
   invisible) and gives every tile a bar slot; here marked tiles stay level instead of lifting, and the
   room for their labels is kept whether or not a tile is marked. */
.replay-viewer .mahjong-table .tile-threat-cell.is-ghost {
  visibility: hidden;
}

.replay-viewer .mahjong-table .tile-threat-cell[data-mark] > .tiles {
  transform: none;
}

.replay-viewer .mahjong-table .player-hand.player-current {
  padding-bottom: 1.5em;
}

.replay-viewer .mahjong-table .player-hand.player-current:has(.table-melds) {
  padding-bottom: 0;
}

.replay-viewer .mahjong-table .player-hand.player-current .table-melds {
  margin-top: 1.5em;
}

/* Your name and turn never widen the hand's block, however long the label grows. */
.replay-viewer .mahjong-table .player-hand.player-current .player-name {
  width: 0;
  min-width: 100%;
  white-space: nowrap;
}

/* Each player's turn, after their name, a shade brighter than the name so the counts scan. */
.mahjong-table .player-name .player-turn {
  color: var(--cream-2);
  font-weight: 600;
}

/* Mortal's weight on each tile in your hand, as a bar above it (scaled to its first choice). */
.mahjong-table .replay-prob {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  height: 0.9em;
  margin-bottom: 0.1em;
}

.mahjong-table .replay-prob i {
  display: block;
  width: 58%;
  height: calc(var(--p, 0) * 100%);
  border-radius: 1px;
  background: var(--cream-3);
}

.mahjong-table .replay-prob i.is-top {
  background: var(--jade-felt);
}

.mahjong-table .replay-prob i.is-you {
  background: var(--verm-felt);
}

/* ------------------------------------------------------------------ the panel */

.replay-event {
  margin: 0;
  color: var(--cream);
  font-family: var(--serif);
  font-size: 21px;
  line-height: 1.45;
  text-wrap: pretty;
}

.replay-event .inline-tile,
.replay-panel .inline-tile {
  position: relative;
  font-size: 1.7em;
  line-height: 0.8;
  vertical-align: -0.12em;
}

.replay-detail {
  display: grid;
  gap: 18px;
}

.replay-mortal,
.replay-result {
  display: grid;
  gap: 12px;
  padding: 16px 18px 18px;
  border: 1px solid rgba(244, 240, 230, 0.16);
  border-radius: 3px;
  background: rgba(12, 47, 34, 0.45);
}

.replay-mortal p,
.replay-result p {
  margin: 0;
}

.replay-mortal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.replay-flag {
  padding: 3px 8px;
  border-radius: 2px;
  background: var(--verm-felt);
  color: var(--felt-deep);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 700;
}

.replay-verdict {
  color: var(--cream);
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.5;
}

.replay-verdict .inline-tile {
  font-size: 1.55em;
}

.replay-bars {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.replay-bars li {
  display: grid;
  grid-template-columns: minmax(96px, 9.5em) minmax(40px, 1fr) 3.4em 2.6em;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  color: var(--cream-2);
  font-family: var(--sans);
  font-size: 14px;
}

.replay-bar-label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  white-space: nowrap;
}

.replay-bar-label .inline-tile {
  padding-right: 0;
  font-size: 1.75em;
}

.replay-bar-label span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.replay-bar {
  display: block;
  height: 10px;
  border-radius: 1px;
  background: rgba(244, 240, 230, 0.1);
  overflow: hidden;
}

.replay-bar i {
  display: block;
  height: 100%;
  min-width: 1px;
  background: var(--cream-3);
}

.replay-bars li.is-top .replay-bar i {
  background: var(--jade-felt);
}

.replay-bars li.is-you:not(.is-top) .replay-bar i {
  background: var(--verm-felt);
}

.replay-bars li b {
  color: var(--cream);
  font-weight: 600;
  text-align: right;
}

.replay-bars li.is-top,
.replay-bars li.is-you {
  color: var(--cream);
}

.replay-bar-tag {
  color: var(--verm-felt);
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.replay-bars li.is-top .replay-bar-tag {
  color: var(--jade-felt);
}

.replay-result p {
  color: var(--cream);
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.5;
}

.replay-yaku {
  color: var(--cream-2);
}

.replay-deltas {
  display: grid;
  gap: 4px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  font-family: var(--sans);
  font-size: 15px;
}

.replay-deltas li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6em 6em;
  gap: 10px;
  color: var(--cream-2);
}

.replay-deltas li.is-you {
  color: var(--cream);
  font-weight: 600;
}

.replay-deltas b {
  font-weight: 600;
  text-align: right;
}

.replay-deltas li > span:last-child {
  text-align: right;
}

.replay-deltas .is-up {
  color: var(--jade-felt);
}

.replay-deltas .is-down {
  color: var(--verm-felt);
}

/* ------------------------------------------------------------------ flagged choices, on paper */

.replay-review {
  display: grid;
  gap: 16px;
  max-width: 820px;
  margin-top: 64px;
}

.replay-counting {
  margin-top: 48px;
}

.replay-review h2 {
  font-size: clamp(28px, 3vw, 38px);
  line-height: 1.1;
}

.replay-review-note {
  margin: 0;
  color: var(--ink-2);
  font-size: 18px;
  line-height: 1.55;
  text-wrap: pretty;
}

.replay-review-list {
  display: grid;
  gap: 0;
  margin: 8px 0 0;
  padding: 0;
  border-top: 1px solid var(--hair);
  list-style: none;
}

.replay-review-list li {
  border-bottom: 1px solid var(--hair-2);
}

.replay-review-item {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 52px;
  padding: 8px 4px;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 15px;
  text-align: left;
}

.replay-review-item:hover {
  background: var(--plate);
}

.replay-review-item .inline-tile {
  font-size: 1.7em;
  line-height: 0.8;
  vertical-align: -0.12em;
}

.replay-review-you {
  color: var(--verm);
}

.replay-review-top {
  color: var(--jade);
}

.replay-review-empty {
  padding: 14px 0;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 15px;
}

.replay-keys {
  margin: 28px 0 0;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13.5px;
}

.replay-keys kbd {
  padding: 1px 6px;
  border: 1px solid var(--hair);
  border-radius: 3px;
  background: var(--plate);
  font-family: var(--sans);
  font-size: 12.5px;
}

@media (hover: none), (pointer: coarse) {
  .replay-keys {
    display: none;
  }
}

/* ------------------------------------------------------------------ narrower screens */

@media (max-width: 1179px) {
  .replay-viewer {
    grid-template-areas:
      "table"
      "controls"
      "jumps"
      "strip"
      "panel";
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
  }

  .replay-viewer > :not(.replay-table) {
    width: 100%;
    max-width: 640px;
    justify-self: center;
  }
}

@media (max-width: 640px) {
  .replay-masthead {
    gap: 14px;
    padding-top: 40px;
  }

  .replay-masthead .standfirst,
  .replay-game-result {
    font-size: 19px;
  }

  .replay-games {
    font-size: 14px;
  }

  .replay-games th,
  .replay-games td {
    padding-right: 8px;
  }

  .replay-games th:last-child,
  .replay-games td:last-child {
    padding-right: 0;
  }

  .replay-games .date-long,
  .replay-games .replay-games-hands,
  .replay-games-score small {
    display: none;
  }

  .replay-games .date-short {
    display: inline;
  }

  .replay-games thead th {
    white-space: normal;
    letter-spacing: 0.06em;
    vertical-align: bottom;
  }

  .replay-hands {
    flex-wrap: nowrap;
    margin: 28px calc(-1 * var(--page-pad)) 12px;
    padding: 0 var(--page-pad) 4px;
    overflow-x: auto;
  }

  .replay-hand-button {
    flex: 0 0 auto;
  }

  .replay-viewer {
    grid-template-areas:
      "table"
      "strip"
      "jumps"
      "panel"
      "controls";
    row-gap: 12px;
  }

  .replay-viewer > .replay-strip,
  .replay-viewer > .replay-jumps,
  .replay-viewer > .replay-panel {
    padding: 0 8px;
  }

  /* The step controls stay at the foot of the screen while the table is in view. */
  .replay-controls {
    position: sticky;
    bottom: 0;
    z-index: 5;
    gap: 6px;
    margin-bottom: -22px;
    padding: 10px 8px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(244, 240, 230, 0.16);
    background: var(--felt);
  }

  .replay-button {
    width: 44px;
  }

  .replay-button[data-go="prev"],
  .replay-button[data-go="next"] {
    width: 56px;
  }

  .replay-jump {
    flex: 1 1 auto;
  }

  .replay-event {
    font-size: 19px;
  }

  .replay-mortal,
  .replay-result {
    padding: 14px 12px 16px;
  }

  .replay-bars li {
    grid-template-columns: minmax(84px, 8em) minmax(30px, 1fr) 3.2em 2.4em;
    gap: 8px;
    font-size: 13.5px;
  }

  .replay-review-item {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 4px 12px;
  }

  .replay-review-where {
    grid-column: 1 / -1;
  }

  .replay-review-note {
    font-size: 16.5px;
  }
}
