/* Werewolf Soundboard - full-moon night, built for small thumbs */

* { box-sizing: border-box; }

:root {
  --ink: #f2eeff;
  --night-1: #1a1636;
  --night-2: #0b0a1a;
  --pad-face: rgba(14, 12, 34, 0.93);
}

html, body {
  height: 100%;
  margin: 0;
}

/* env() arrived in iOS 11; older phones keep the plain padding above */
@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-top: calc(env(safe-area-inset-top, 0px) + 6px);
    padding-right: calc(env(safe-area-inset-right, 0px) + 12px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    padding-left: calc(env(safe-area-inset-left, 0px) + 12px);
  }
  .moon { top: calc(env(safe-area-inset-top, 0px) + 6px); }
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 6px 12px 12px;
  background: radial-gradient(130% 80% at 50% 0%, var(--night-1) 0%, var(--night-2) 70%) fixed, var(--night-2);
  color: var(--ink);
  font: 16px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  /* a kid will drag, long-press and double-tap everything */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

/* ---------- night sky ---------- */

.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.stars { position: absolute; inset: 0; }

.stars i {
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.55;
  animation: twinkle 4s ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.2; }
  50%      { opacity: 0.85; }
}

.moon {
  position: absolute;
  top: 6px;
  right: 4%;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 30%, #fffdf2 0%, #f6edd0 45%, #ded0a6 100%);
  box-shadow:
    0 0 28px 10px rgba(255, 246, 209, 0.28),
    0 0 90px 36px rgba(255, 240, 190, 0.14);
  transition: transform 0.45s ease, box-shadow 0.45s ease;
}

/* a couple of craters, no image needed */
.moon::before,
.moon::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(176, 160, 116, 0.35);
}
.moon::before { width: 15px; height: 15px; top: 24%; left: 22%; }
.moon::after  { width: 9px;  height: 9px;  top: 56%; left: 55%; }

body.playing .moon {
  transform: scale(1.12);
  box-shadow:
    0 0 44px 16px rgba(255, 246, 209, 0.45),
    0 0 130px 52px rgba(255, 236, 170, 0.22);
}

.treeline {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 22vh;
  min-height: 90px;
  fill: #05040d;
  opacity: 0.9;
}

/* ---------- header ---------- */

.head {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 0 0 8px;
}

.head h1 {
  margin: 0;
  font-size: 15px;                   /* fallback: clamp() is iOS 13.4+ */
  font-size: clamp(14px, 4vw, 20px);
  font-weight: 800;
  letter-spacing: 0.01em;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.6);
}

.wolf {
  display: inline-block;
  font-size: 1.15em;
  filter: drop-shadow(0 0 10px rgba(124, 108, 255, 0.55));
  transition: transform 0.25s ease;
}

body.playing .wolf { animation: howlshake 0.9s ease-in-out infinite; }

@keyframes howlshake {
  0%, 100% { transform: rotate(-7deg) translateY(0) scale(1.05); }
  50%      { transform: rotate(7deg) translateY(-5px) scale(1.12); }
}

/* ---------- buttons ---------- */

main {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.grid { margin-bottom: 10px; }

.grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(3, 1fr);
  grid-gap: 10px;                    /* older WebKit */
  gap: 10px;
  min-height: 0;
}

.pad {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 84px;
  padding: 8px;
  border: 2px solid color-mix(in srgb, var(--c) 60%, transparent);
  border-radius: 22px;
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--c) 42%, transparent),
      color-mix(in srgb, var(--c) 16%, transparent)),
    var(--pad-face);
  color: var(--ink);
  font: inherit;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 6px 18px rgba(0, 0, 0, 0.45);
  transition: transform 0.08s ease, box-shadow 0.18s ease, filter 0.18s ease;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

/* color-mix is well supported on iOS 16.4+, but keep a plain fallback */
@supports not (color: color-mix(in srgb, red 50%, blue)) {
  .pad {
    border-color: var(--c);
    background: var(--c);
    filter: saturate(0.85) brightness(0.8);
  }
}

.pad .emoji {
  font-size: 32px;                   /* fallback */
  font-size: clamp(26px, 8.5vw, 46px);
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
}

.pad .label {
  max-width: 100%;
  padding: 0 4px;
  font-size: 14px;                   /* fallback */
  font-size: clamp(12px, 3.6vw, 18px);
  font-weight: 700;
  text-align: center;
  /* never let a label clip against the pad edge on a narrow phone */
  word-wrap: break-word;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.55);
}

.pad.pressed {
  transform: scale(0.95);
}

.pad.active {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 0 0 3px color-mix(in srgb, var(--c) 70%, transparent),
    0 0 34px 6px color-mix(in srgb, var(--c) 55%, transparent),
    0 6px 18px rgba(0, 0, 0, 0.45);
  filter: brightness(1.18);
}

/* tap ripple */
.pad .ripple {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  pointer-events: none;
  animation: ripple 0.55s ease-out forwards;
}

@keyframes ripple {
  from { transform: scale(0.4); opacity: 0.5; }
  to   { transform: scale(14);  opacity: 0; }
}

.controls {
  flex: 0 0 auto;
  display: flex;
}

/* margin rather than gap: flex gap is Safari 14.1+ */
.controls .ctl + .ctl { margin-left: 10px; }

.ctl {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 58px;
  padding: 8px 6px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font: 700 15px/1 -apple-system, BlinkMacSystemFont, sans-serif;  /* fallback */
  font-size: clamp(14px, 4vw, 17px);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.2s ease,
              background 0.2s ease, border-color 0.2s ease;
}

.ctl .ctl-emoji { font-size: 1.25em; line-height: 1; }

.ctl.pressed { transform: scale(0.97); }

.ctl:disabled { opacity: 0.4; cursor: default; }

/* music playing */
.ctl.on {
  border-color: rgba(124, 108, 255, 0.85);
  background: rgba(124, 108, 255, 0.28);
  box-shadow:
    0 0 0 3px rgba(124, 108, 255, 0.28),
    0 0 26px 4px rgba(124, 108, 255, 0.3);
}

.hint {
  position: relative;
  z-index: 1;
  margin: 10px 2px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 204, 92, 0.14);
  border: 1px solid rgba(255, 204, 92, 0.4);
  color: #ffe9b8;
  font-size: 14px;
  text-align: center;
}

/* ---------- landscape / bigger screens ---------- */

@media (orientation: landscape) and (max-height: 540px) {
  .head { padding: 0 0 8px; }
  .head h1 { font-size: 18px; }
  .grid {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
  }
  .moon { width: 56px; height: 56px; }
  .treeline { height: 14vh; }
  .ctl { min-height: 48px; }
}

@media (min-width: 700px) {
  body { padding-left: 6vw; padding-right: 6vw; }
  .moon { width: 96px; height: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  .stars i, .wolf { animation: none !important; }
  .pad, .moon { transition: none; }
}
