/* 1970s game-show board: mod palette (teal, orange, amber, cream, chocolate) plus the smiley's yellow */
.apps-page {
  --brown: #5a3b2e;
  --brown-2: #3a261d;
  --rust: #ff6a2b;
  --orange: #f06b1c;
  --amber: #f29b30;
  --teal: #7cc0a9;
  --mustard: #ffcf09;
  --cream: #f0e2b6;
  --plate: #111;
  --retro: "Righteous", var(--font);

  /* faint mod rings, like the palette swatch */
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 207, 9, .16), transparent 55%),
    radial-gradient(circle at 50% 50%, transparent 0 22px, rgba(240, 226, 182, .05) 23px 31px, transparent 32px) 0 0 / 80px 80px,
    var(--brown-2);
  color: var(--cream);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 0 64px;
  box-sizing: border-box;
}

.apps-page main { width: 100%; padding: 0 16px; box-sizing: border-box; }

/* Header: smiley over a band of '70s stripes */
.apps-header {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 32px 16px 0;
  margin-bottom: 36px;
  box-sizing: border-box;
}

.stripes {
  width: 100%;
  height: 34px;
  background: linear-gradient(var(--teal) 0 25%, var(--amber) 25% 50%, var(--orange) 50% 75%, var(--brown) 75% 100%);
  margin-top: 14px;
}

.home-link { display: block; border-radius: 50%; }
.home-link img { width: 84px; height: 84px; display: block; transition: transform .25s ease; }
.home-link:hover img { transform: rotate(-10deg) scale(1.06); }
.home-link:focus-visible { outline: 3px solid var(--mustard); outline-offset: 4px; }

.apps-header h1 {
  margin: 4px 0 0;
  font-family: var(--retro);
  font-weight: 400;
  font-size: clamp(2.6rem, 9vw, 4rem);
  line-height: 1;
  letter-spacing: .04em;
  color: var(--mustard);
  text-shadow: 3px 3px 0 var(--orange), 6px 6px 0 var(--teal), 9px 9px 0 #1f140f;
}

/* The board. --cols is set by apps.js so the panel spans exactly one row. */
.app-grid {
  --tile: 176px;
  --gap: 18px;
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), var(--tile));
  gap: var(--gap);
  justify-content: center;
  padding: 18px;
  margin: 0 auto;
  width: max-content;
  max-width: 100%;
  box-sizing: border-box;
  background: #1f140f;
  border: 6px solid var(--brown);
  border-radius: 10px;
  box-shadow: 0 0 0 3px var(--mustard), 0 18px 40px rgba(0, 0, 0, .5);
}

/* Phones: shrink the booths so a row of three still fits */
@media (max-width: 600px) {
  .app-grid { --gap: 8px; --tile: min(150px, calc((100vw - 32px - 32px - 16px) / 3)); padding: 10px; }
}

.app-tile {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  display: block;
  -webkit-tap-highlight-color: transparent;
}

/* Each booth: a glowing colored frame around a dark set */
.booth {
  --c: var(--orange);
  position: relative;
  display: flex;
  flex-direction: column;
  width: var(--tile);
  height: var(--tile);
  box-sizing: border-box;
  border: 7px solid var(--c);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .08), transparent 45%),
    linear-gradient(180deg, #6b4636 0%, #4e3226 70%, #3e271d 100%);
  box-shadow:
    0 0 0 2px #000,
    0 0 14px 2px color-mix(in srgb, var(--c) 70%, transparent),
    inset 0 0 0 2px rgba(0, 0, 0, .55),
    inset 0 0 18px rgba(0, 0, 0, .6);
  overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease, filter .18s ease;
}

.app-tile:nth-child(3n + 1) .booth { --c: var(--orange); }
.app-tile:nth-child(3n + 2) .booth { --c: var(--teal); }
.app-tile:nth-child(3n + 3) .booth { --c: var(--amber); }

.booth .icon {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.booth .icon img {
  width: calc(var(--tile) * .5);
  height: calc(var(--tile) * .5);
  border-radius: 18%;
  display: block;
  object-fit: cover;
  box-shadow: 0 3px 0 #000, 0 0 0 3px #000;
}

/* Black nameplate along the bottom */
.plate {
  margin: 0 calc(var(--tile) * .055) calc(var(--tile) * .055);
  flex: none;
  background: var(--plate);
  border: 2px solid #444;
  border-radius: 3px;
  padding: 5px 4px 4px;
  font-family: var(--retro);
  font-size: clamp(9px, calc(var(--tile) * .085), 15px);
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--cream);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 600px) {
  .plate { letter-spacing: 0; padding: 4px 2px 3px; }
  .booth { border-width: 5px; }
}

.app-tile:hover .booth { transform: translateY(-3px); filter: brightness(1.12); }
.app-tile:active .booth { transform: translateY(1px); }
.app-tile:focus-visible { outline: none; }
.app-tile:focus-visible .booth { outline: 4px solid var(--cream); outline-offset: 3px; }

/* Lit booth: mustard frame with chasing marquee bulbs */
.app-tile[aria-expanded="true"] .booth {
  --c: var(--mustard);
  box-shadow:
    0 0 0 2px #000,
    0 0 26px 6px color-mix(in srgb, var(--mustard) 75%, transparent),
    inset 0 0 0 2px rgba(0, 0, 0, .55),
    inset 0 0 18px rgba(0, 0, 0, .6);
}

.app-tile[aria-expanded="true"] .booth::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 4px dotted var(--cream);
  border-radius: 3px;
  pointer-events: none;
  animation: marquee .7s steps(2) infinite;
}

@keyframes marquee {
  50% { border-color: var(--mustard); }
}

/* Detail panel: a full row under the lit booth */
.app-panel {
  grid-column: 1 / -1;
  justify-self: center;
  width: max(100%, min(100vw - 32px, 460px));
  position: relative;
  box-sizing: border-box;
  background:
    linear-gradient(var(--teal) 0 6px, var(--amber) 6px 12px, var(--orange) 12px 18px, transparent 18px),
    var(--brown);
  border: 7px solid var(--mustard);
  border-radius: 8px;
  box-shadow: 0 0 0 2px #000, 0 0 26px 4px color-mix(in srgb, var(--mustard) 45%, transparent);
  padding: 38px 24px 24px;
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 4px 20px;
  align-items: start;
}

/* Pointer back up to the booth it came from */
.app-panel::before {
  content: "";
  position: absolute;
  top: -19px;
  left: calc(var(--pointer, 50%) - 11px);
  border: 11px solid transparent;
  border-bottom-color: var(--mustard);
  border-top: 0;
}

.app-panel .panel-icon {
  width: 88px;
  height: 88px;
  border-radius: 18%;
  overflow: hidden;
  box-shadow: 0 0 0 3px #000, 0 4px 0 3px #000;
  grid-row: span 3;
}

.app-panel .panel-icon img { width: 100%; height: 100%; display: block; object-fit: cover; }

.app-panel h2 {
  margin: 0 44px 0 0;
  justify-self: start;
  font-family: var(--retro);
  font-weight: 400;
  font-size: 1.4rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  background: var(--plate);
  border: 2px solid #444;
  border-radius: 3px;
  padding: 4px 12px 2px;
}

.app-panel .tagline { margin: 8px 0 0; color: var(--mustard); font-weight: 700; }
.app-panel .desc { margin: 10px 0 0; line-height: 1.55; font-family: system-ui, sans-serif; color: var(--cream); }

.app-panel .actions { grid-column: 2; margin-top: 18px; }

/* Big mustard buzzer button */
.visit {
  display: inline-block;
  background: var(--mustard);
  color: #1a0f08;
  font-family: var(--retro);
  letter-spacing: .05em;
  text-transform: uppercase;
  text-decoration: none;
  padding: 11px 20px 9px;
  border: 3px solid #000;
  border-radius: 999px;
  box-shadow: 0 5px 0 var(--orange), 0 5px 0 3px #000;
  transition: transform .12s ease, box-shadow .12s ease;
}

.visit:hover { transform: translateY(-2px); box-shadow: 0 7px 0 var(--orange), 0 7px 0 3px #000; }
.visit:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--orange), 0 1px 0 3px #000; }
.visit:focus-visible { outline: 3px solid var(--cream); outline-offset: 5px; }

.close {
  position: absolute;
  top: 28px;
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid #000;
  background: var(--teal);
  color: #1a0f08;
  font: 700 20px/1 var(--font);
  cursor: pointer;
  box-shadow: 0 3px 0 #000;
}

.close:hover { background: var(--mustard); }
.close:focus-visible { outline: 3px solid var(--cream); outline-offset: 3px; }

@media (max-width: 520px) {
  .app-panel { grid-template-columns: 64px 1fr; padding: 34px 18px 20px; gap: 4px 14px; }
  .app-panel .panel-icon { width: 64px; height: 64px; grid-row: span 2; }
  .app-panel h2 { font-size: 1.1rem; }
  .app-panel .desc, .app-panel .actions { grid-column: 1 / -1; }
}

/* The morph: the lit booth stretches into the panel row */
::view-transition-group(app-panel) {
  animation-duration: .45s;
  animation-timing-function: cubic-bezier(.2, .8, .2, 1);
}
::view-transition-old(app-panel),
::view-transition-new(app-panel) {
  height: 100%;
  width: 100%;
  object-fit: fill;
}
::view-transition-group(*) { animation-duration: .45s; }

@media (prefers-reduced-motion: reduce) {
  .booth, .visit, .home-link img { transition: none; }
  .app-tile[aria-expanded="true"] .booth::after { animation: none; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
