:root {
  --bg: #111111;
  --fg: #e8e8e8;
  --muted: #b8b8b8;
  --off: #1a1a1a;
  --ink: #111111;
  --ring: #ffffff;
  --t0: #ff7a59;
  --t1: #ffd23f;
  --t2: #4fd1c5;
  --t3: #b794f6;
  --gap: 16px;
  --side: min(100vw - 40px, 520px);
  --pad: max(44px, (var(--side) - 3 * var(--gap)) / 4);
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.t-0 { --c: var(--t0); }
.t-1 { --c: var(--t1); }
.t-2 { --c: var(--t2); }
.t-3 { --c: var(--t3); }

[hidden] { display: none !important; }

.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

body {
  background: var(--bg);
  color: var(--fg);
  margin: 0;
  padding: 0 20px 40px;
}

main {
  max-width: 520px;
  margin: 0 auto;
}

h1 {
  font-size: 1.75rem;
  margin: 24px 0 16px;
}

.alm-intro,
#hint-tap,
#hint-noaudio {
  font-size: 1.125rem;
  line-height: 1.4;
  margin: 0 0 12px;
}

#hint-silent,
.alm-grownups,
.alm-unofficial {
  font-size: 1rem;
  color: var(--muted);
}

#hint-silent {
  margin: 24px 0 0;
}

button { font-size: 1.125rem; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 0 0;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: var(--fg);
  font-size: 1.125rem;
  text-decoration: none;
}

.lang {
  display: flex;
  gap: 8px;
}

.lang button {
  min-width: 44px;
  min-height: 44px;
  background: transparent;
  color: var(--muted);
  border: 2px solid var(--muted);
  border-radius: var(--radius);
  font-weight: 700;
  cursor: pointer;
}

.lang button[aria-pressed="true"] {
  background: var(--fg);
  color: var(--ink);
  border-color: var(--fg);
}

#session,
.controls,
.clip,
#stop,
#resume,
.back,
.lang button {
  touch-action: manipulation;
}

.clip {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

@media (hover: hover) {
  .clip:hover {
    filter: brightness(1.15);
  }

  .back:hover {
    text-decoration: underline;
  }
}

.clip:active {
  transform: scale(.96);
}

.grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-columns: repeat(4, var(--pad));
  grid-template-rows: auto repeat(4, var(--pad));
  gap: var(--gap);
  justify-content: center;
}

.col-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-bottom: 4px;
  color: var(--c);
  font-size: .875rem;
}

.col-head span {
  color: var(--fg);
  text-align: center;
  overflow-wrap: anywhere;
}

.col-head .icon {
  width: 16px;
  height: 16px;
  fill: var(--c);
}

.clip {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--pad);
  height: var(--pad);
  padding: 0;
  overflow: hidden;
  border: 2px solid var(--c);
  border-radius: var(--radius);
  background: var(--off);
  color: var(--c);
  box-sizing: border-box;
}

.clip .icon {
  width: 45%;
  height: 45%;
  fill: currentColor;
}

.progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 6px;
  width: 0;
  background: var(--ink);
  display: none;
}

.is-playing {
  background: var(--c);
  color: var(--ink);
}

.is-playing .progress,
.is-pending-off .progress {
  display: block;
}

.is-pending-on {
  border-width: 3px;
  border-style: dashed;
}

.is-pending-off {
  background: var(--c);
  color: var(--ink);
}

.is-pending-off::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 3px dashed var(--ink);
  border-radius: 8px;
  pointer-events: none;
}

.clip[aria-disabled="true"] {
  border-style: dotted;
  cursor: not-allowed;
}

#session.paused .clip.is-playing,
#session.paused .clip.is-pending-off {
  border-style: dotted;
  border-color: var(--ink);
}

#session.paused .progress {
  display: none;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  margin-top: 24px;
}

.controls .icon {
  width: 20px;
  height: 20px;
  margin-right: 8px;
  fill: currentColor;
  vertical-align: middle;
}

#stop {
  min-height: 56px;
  min-width: 120px;
  background: #e8e8e8;
  color: #111;
  border: 0;
  border-radius: var(--radius);
  font-weight: 700;
}

#resume {
  min-height: 56px;
  background: var(--bg);
  color: #fff;
  border: 3px solid #fff;
  border-radius: var(--radius);
  font-weight: 700;
}

footer#about {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid #333;
}

footer#about p {
  margin: 0 0 16px;
  line-height: 1.5;
}

.alm-inspired {
  display: inline-block;
  min-height: 44px;
  padding: 10px 0;
  color: var(--fg);
  font-size: 1rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.alm-inspired:visited { color: var(--fg); }

@media (prefers-reduced-motion: no-preference) {
  @keyframes alm-fade-in {
    from { opacity: .3; }
    to { opacity: 1; }
  }

  @keyframes alm-fade-out {
    from { opacity: 1; }
    to { opacity: .3; }
  }

  .is-pending-on {
    animation: alm-fade-in .5s ease-in-out infinite alternate;
  }

  .is-pending-off {
    animation: alm-fade-out .5s ease-in-out infinite alternate;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --head: 36px;
    --side: max(212px, min(100vh - 56px, 100vw - 176px, 376px));
  }

  @supports (height: 100svh) {
    :root {
      --side: max(212px, min(100svh - 56px, 100vw - 176px, 376px));
    }
  }

  #session {
    display: grid;
    grid-template-columns: auto 128px;
    grid-template-rows: auto;
    grid-template-areas:
      "grid controls";
    column-gap: 24px;
    row-gap: 0;
  }

  .grid {
    grid-area: grid;
    grid-template-rows: var(--head) repeat(4, var(--pad));
  }

  .controls {
    grid-area: controls;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 0;
  }
}
