/* One case's page: the back link, the hero with the closed chest, the result and the contents.
   No boxes: open space and hairlines. The reel is in cases-reel.css. */

.case-view {
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}

.case-back {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  min-height: 44px;
  color: var(--ash);
  text-decoration: none;
}

.case-back:hover {
  color: var(--white-hot);
}

/* The kind, the name and the price, in the middle above the reel */
.case-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  text-align: center;
}

/* The reel with the case standing on it. The stage leaves room above and below, because the case is taller
   than the reel. */
.case-stage {
  position: relative;
  padding: 90px 0;
}

/* The case sways slowly as if turned on a stand; its glow breathes behind it. It follows the pointer
   (cases-tilt.js), and goes back into the distance when an open starts (cases-open.js). */
.case-hero-stage {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 4;
  width: 380px;
  perspective: 900px;
  touch-action: pan-y;
  transform: translate(-50%, -50%);
}

/* An open starts: the case goes back into the distance, shrinks and fades out. Only the stage moves here (the
   art's own transform belongs to the sway), so a plain transform transition works in every browser. */
.case-hero-stage {
  transition: opacity var(--gone-ms, 400ms) var(--ease-out), transform var(--gone-ms, 400ms) var(--ease-out),
    filter var(--gone-ms, 400ms) var(--ease-out), visibility 0s linear 0s;
}

.case-hero-stage.is-gone {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  filter: blur(3px) brightness(0.6);
  transform: translate(-50%, -50%) scale(0.55);
  transition: opacity var(--gone-ms, 400ms) var(--ease-out), transform var(--gone-ms, 400ms) var(--ease-out),
    filter var(--gone-ms, 400ms) var(--ease-out), visibility 0s linear var(--gone-ms, 400ms);
}

/* After the lid kicks the open case moves back and fades away (owner, 2026-11-20: no case behind the reel).
   It comes forward closed again for the next open. */
.case-hero-stage.is-behind {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  filter: blur(3px) brightness(0.7);
  transform: translate(-50%, -60%) scale(0.6);
  transition: opacity var(--gone-ms, 400ms) var(--ease-out), transform var(--gone-ms, 400ms) var(--ease-out),
    filter var(--gone-ms, 400ms) var(--ease-out), visibility 0s linear var(--gone-ms, 400ms);
}

/* The light sweep on the click: a band of light cut to the case's own shape (cases-open.js sets the mask) */
.case-hero-sweep {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
  -webkit-mask: var(--sweep-mask) center / contain no-repeat;
  mask: var(--sweep-mask) center / contain no-repeat;
  transform: scale(1.1);
}

.case-hero-sweep-band {
  position: absolute;
  top: -10%;
  bottom: -10%;
  left: 0;
  width: 34%;
  background: linear-gradient(90deg, transparent, rgba(255, 244, 228, 0.6), transparent);
}

.case-hero-tilt {
  transform: rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg));
  transform-style: preserve-3d;
  transition: transform 260ms var(--ease-out);
}

.case-hero-tilt.is-released {
  transition: transform 620ms var(--ease-spring);
}

.case-hero-art {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  /* Only decoration: the tilt listens on the stage */
  pointer-events: none;
  transform-style: preserve-3d;
  animation: case-sway 9s ease-in-out infinite;
}

.case-hero-art::before {
  content: "";
  position: absolute;
  inset: 12% 8% 26%;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--tier, var(--ember)) 42%, transparent), transparent 72%);
  animation: case-breathe 4s ease-in-out infinite;
  transition: transform var(--charge-ms, 400ms) ease-in, filter var(--charge-ms, 400ms) ease-in;
}

/* While the case shakes its glow swells and brightens, so the open feels like it builds up */
.case-hero-art.is-charging::before {
  filter: brightness(1.8) saturate(1.3);
  transform: scale(1.35);
}

/* The light burst when the lid lifts: one pulse in the tier colour, from the middle of the case */
.case-hero-art::after {
  content: "";
  position: absolute;
  inset: 30% 22%;
  z-index: 2;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--tier, var(--ember)) 70%, #fff8ec) 0%, transparent 70%);
  opacity: 0;
  pointer-events: none;
}

.case-hero-art.is-open::after {
  animation: case-burst calc(var(--lid-ms, 400ms) + 300ms) ease-out;
}

.case-hero-art img {
  /* Absolute, so a picture's own size never sets the height of the box */
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scale(1.1);
  /* The art is cut out (transparent around the case), so it stands on the reel with no dark square behind it */
  transition: opacity var(--lid-ms, 260ms) ease-in-out, transform var(--lid-ms, 360ms) ease-in-out,
    filter var(--lid-ms, 260ms) ease-in-out;
}

.case-hero-open {
  opacity: 0;
  filter: brightness(1.6);
  transform: scale(1.02) translateY(4px);
}

/* Lid lift, slowly (--lid-ms from cases-open.js): the closed case swells, brightens and fades while the open one
   rises out of the light and settles */
.case-hero-art.is-open .case-hero-open {
  opacity: 1;
  filter: brightness(1);
  transform: scale(1.1);
}

.case-hero-art.is-open .case-hero-closed {
  opacity: 0;
  filter: brightness(1.8);
  transform: scale(1.16) translateY(-4px);
}

@keyframes case-sway {
  0%, 100% { transform: translateY(0) rotateY(-8deg); }
  50% { transform: translateY(-6px) rotateY(8deg); }
}

@keyframes case-burst {
  0% { opacity: 0; transform: scale(0.4); }
  30% { opacity: 0.9; }
  100% { opacity: 0; transform: scale(1.5); }
}

@keyframes case-breathe {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.8; }
}

.case-hero-label {
  margin: 0;
  color: var(--tier, var(--ember));
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.case-name {
  margin: 0;
  font-size: 2.25rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.case-price {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  margin: 0;
  padding: 0 16px 0 8px;
  border-radius: var(--radius);
  background: rgba(255, 107, 26, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 107, 26, 0.35);
  color: var(--ember-light);
  font-size: 1.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.case-price[hidden] {
  display: none;
}

.case-price .coin {
  width: 24px;
  height: 24px;
}

/* Under the reel: the amount, the Open button, Fast, then what the player needs to open the case */
.case-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-4);
}

.case-qty {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.case-qty[hidden] {
  display: none;
}

.case-qty-chip {
  min-width: 52px;
  height: 44px;
  padding: 0 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out), color 150ms var(--ease-out);
}

.case-qty-chip:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.case-qty-chip:focus-visible {
  outline: 2px solid var(--ember-light);
  outline-offset: 2px;
}

.case-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-3);
}

/* After an open: Sell all and Open again side by side, right under the drops, and the amounts under them */
.case-controls.has-drops .case-actions {
  order: -1;
}


.case-actions .case-sell-all,
.case-actions #case-again {
  min-width: 240px;
}

.case-actions [hidden] {
  display: none;
}

.case-open {
  min-width: 320px;
  height: 56px;
  padding: 0 32px;
}

.case-open[hidden] {
  display: none;
}

.case-fast {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: var(--ash);
  cursor: pointer;
}

/* The kit's checkbox: a small control square, ember-tinted with a tick when on */
.case-fast input {
  appearance: none;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin: 0;
  background: var(--surface-control);
  border: 1px solid var(--steel);
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out);
}

.case-fast input:hover {
  border-color: var(--line-ember);
}

.case-fast input:checked {
  background: var(--tint-ember) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffb347' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 5 5 9-10'/%3E%3C/svg%3E") center / 12px no-repeat;
  border-color: var(--ember);
}

/* What the player needs: a soft panel, the title in ember, the numbers in bold */
.case-terms {
  display: grid;
  gap: var(--sp-2);
  width: min(100%, 560px);
  padding: var(--sp-4) var(--sp-5);
  border: var(--border);
  border-radius: var(--radius);
  background: var(--surface-panel);
  text-align: center;
}

.case-terms[hidden],
.case-terms-title[hidden] {
  display: none;
}

.case-terms-title {
  margin: 0;
  color: var(--ember-light);
  font-size: 1.1rem;
  font-weight: 700;
}

.case-terms-list {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--ash);
}

.case-terms-list strong {
  color: var(--white-hot);
  font-variant-numeric: tabular-nums;
}

/* The contents: the same section header as the list, then the skins from the most expensive */
.case-contents {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  gap: var(--sp-4);
  row-gap: var(--sp-6);
  margin: 0;
  padding: 0;
  list-style: none;
}

.case-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: var(--sp-2) var(--sp-2) var(--sp-3);
  background: linear-gradient(180deg, var(--iron-light) 40%, color-mix(in srgb, var(--rarity, var(--steel)) 26%, var(--iron-light)));
  border-bottom: 3px solid var(--rarity, var(--steel));
  border-radius: var(--radius);
}

.case-item:focus-visible {
  outline: 2px solid var(--ember-light);
  outline-offset: 3px;
}

.case-item-image {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  margin-bottom: 4px;
}

.case-item-title {
  overflow: hidden;
  min-width: 0;
  color: var(--white-hot);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-item-wear {
  color: var(--ash);
  font-size: var(--text-xs);
}

.case-item-price {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--ember-light);
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.case-item-price .coin {
  width: 16px;
  height: 16px;
}

/* The chance hangs under the tile: the skin's total chance (all its wears together).
   Hidden until hover, keyboard focus or a tap. Free cases never have one. */
.case-item-chance {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  z-index: 3;
  display: grid;
  gap: 4px;
  width: max-content;
  padding: 8px 10px;
  background: var(--surface-panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--white-hot);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -4px);
  transition: opacity 0.15s var(--ease-out), transform 0.15s var(--ease-out);
}

.case-item-chance-total {
  font-weight: 700;
}

.case-item:hover .case-item-chance,
.case-item:focus-visible .case-item-chance,
.case-item.is-showing .case-item-chance {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* On phones the shared header wraps to two rows and is taller than its box, so the page starts lower */
@media (max-width: 640px) {
  .page.cases-page {
    padding-top: 48px;
  }
}

@media (max-width: 760px) {
  .case-stage {
    padding: 60px 0;
  }

  .case-hero-stage {
    width: 260px;
  }

  .case-name {
    font-size: 1.7rem;
  }

  .case-open {
    width: 100%;
    min-width: 0;
  }

  .case-actions {
    width: 100%;
  }
}

/* The "Use bonus balance" button (cases-bonus.js): to the right of Open, out of the flow, so Open stays centred
   and nothing shifts when it appears. The note under it says how much bonus is left after the open. */
.case-actions {
  position: relative;
}

.case-bonus,
.case-bonus-note {
  position: absolute;
  left: calc(50% + 160px + var(--sp-3));
}

.case-bonus {
  top: 0;
  height: 56px;
  padding: 0 18px;
  white-space: nowrap;
}

.case-bonus[aria-pressed="true"] {
  border-color: var(--ember);
  background: var(--tint-ember);
  color: var(--ember-light);
}

.case-bonus-note {
  top: 62px;
  margin: 0;
  color: var(--ash);
  font-size: var(--text-xs);
  white-space: nowrap;
}

.case-bonus[hidden],
.case-bonus-note[hidden] {
  display: none;
}

.case-price-old {
  margin-right: 8px;
  color: var(--ash);
  font-weight: 500;
}

.case-price-now {
  color: var(--ember-light);
}

/* Narrow screens: no room at the side, so the button and the note go under Open. */
@media (max-width: 900px) {
  .case-bonus,
  .case-bonus-note {
    position: static;
  }
}
