:root {
  --ink: #fffdf7;
  --deep: #20164a;
  --animals: #ff6b6b;
  --music: #ffd43b;
  --life: #4dabf7;
  --wonder: #b197fc;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }
html { color-scheme: dark; }

body {
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, #5f3dc4 0, transparent 32rem),
    radial-gradient(circle at 90% 80%, #0b7285 0, transparent 34rem),
    var(--deep);
  font-family: "Yu Gothic UI", "Hiragino Maru Gothic ProN", sans-serif;
}

button, input, select { font: inherit; }
button, a, summary { touch-action: manipulation; }
button:focus-visible, a:focus-visible, summary:focus-visible, input:focus-visible {
  outline: 4px solid #ffe066;
  outline-offset: 3px;
}

.stage {
  width: min(1100px, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: auto;
  padding:
    max(clamp(16px, 3vw, 32px), env(safe-area-inset-top))
    max(clamp(16px, 3vw, 32px), env(safe-area-inset-right))
    max(clamp(16px, 3vw, 32px), env(safe-area-inset-bottom))
    max(clamp(16px, 3vw, 32px), env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto minmax(290px, 1fr) auto auto;
  gap: 18px;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { margin: 0; font-size: clamp(24px, 4vw, 40px); letter-spacing: .08em; }
.topbar h1 { min-width: 0; }
.brand-logo { display: block; width: clamp(160px, 29vw, 300px); max-width: 100%; height: auto; }
.start-logo { display: block; width: min(520px, 100%); height: auto; margin: auto; }

.parent-access {
  position: relative;
  overflow: hidden;
  min-width: 88px;
  border: 1px solid #ffffff38;
  border-radius: 16px;
  padding: 7px 12px;
  color: #fff;
  background: #ffffff10;
  box-shadow: inset 0 1px #ffffff20;
  text-align: center;
}
.parent-access::after {
  position: absolute;
  inset: auto 0 0;
  height: 4px;
  background: #ffe066;
  content: "";
  transform: scaleX(0);
  transform-origin: left;
}
.parent-access.holding::after { animation: parent-hold 2s linear forwards; }
.parent-access span, .parent-access small { display: block; }
.parent-access span { font-weight: 900; }
.parent-access small { margin-top: 2px; font-size: 10px; opacity: .7; }

.volume-control {
  display: flex;
  padding: 3px;
  border: 1px solid #ffffff44;
  border-radius: 999px;
  background: #ffffff0d;
}
.volume-control button {
  min-width: 36px;
  min-height: 36px;
  border: 0;
  border-radius: 999px;
  color: inherit;
  background: transparent;
  font-weight: 800;
}
.volume-control button[aria-pressed="true"] {
  color: #25194c;
  background: #ffe066;
  box-shadow: 0 2px 8px #0004;
}

.play-area {
  position: relative;
  overflow: hidden;
  min-height: 290px;
  border: 2px solid #ffffff2e;
  border-radius: 38px;
  background: linear-gradient(145deg, #ffffff24, #ffffff0c);
  box-shadow: 0 24px 70px #08031f66, inset 0 1px #ffffff33;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  isolation: isolate;
}

.playfield { position: absolute; inset: 16px 16px 82px; overflow: hidden; }
.waiting-mark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(100px, 22vw, 190px);
  opacity: .88;
  transition: opacity .25s ease;
}
.playfield.started .waiting-mark { opacity: 0; }
.sound-card {
  position: absolute;
  left: var(--left);
  top: var(--top);
  width: clamp(86px, 15vw, 142px);
  height: clamp(86px, 15vw, 142px);
  display: grid;
  place-items: center;
  border: 2px solid #ffffff6b;
  border-radius: 42% 58% 48% 52% / 52% 44% 56% 48%;
  background: var(--card-color);
  box-shadow: 0 16px 26px #09032055, inset 0 2px 1px #ffffff55;
  font-size: clamp(52px, 9vw, 94px);
  line-height: 1;
  filter: saturate(1.08);
  animation: card-arrive 2.8s cubic-bezier(.17,.89,.32,1.25) forwards;
}
.sound-name { margin: 12px 0 8px; font-size: clamp(22px, 4vw, 38px); font-weight: 800; letter-spacing: .06em; }
.key-badge { padding: 5px 13px; border-radius: 999px; background: #00000032; font: 800 13px/1.4 monospace; letter-spacing: .14em; }

.burst { position: absolute; inset: 0; z-index: -1; }
.particle {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--particle-color);
  left: 50%;
  top: 48%;
  animation: scatter .55s ease-out forwards;
}

.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; font-size: 12px; opacity: .8; }
.legend span { white-space: nowrap; }
.dot { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; }
.dot.animals { background: var(--animals); }
.dot.music { background: var(--music); }
.dot.life { background: var(--life); }
.dot.wonder { background: var(--wonder); }

.keys { display: grid; grid-template-columns: repeat(10, minmax(34px, 1fr)); gap: 6px; }
.mini-key {
  min-height: 42px;
  border: 1px solid #ffffff26;
  border-radius: 11px;
  color: #fff;
  background: #ffffff10;
  font-weight: 800;
  box-shadow: 0 4px 0 #0b062755;
  touch-action: manipulation;
}
.mini-key[data-category="animals"] { border-bottom: 3px solid var(--animals); }
.mini-key[data-category="music"] { border-bottom: 3px solid var(--music); }
.mini-key[data-category="life"] { border-bottom: 3px solid var(--life); }
.mini-key[data-category="wonder"] { border-bottom: 3px solid var(--wonder); }
.mini-key:active, .mini-key.active { transform: translateY(3px); box-shadow: 0 1px 0 #0b062755; background: #ffffff2a; }

.start-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
  background: #171033e8;
  backdrop-filter: blur(12px);
}
.start-screen.hidden { display: none; }
.start-content { display: grid; width: min(560px, 100%); justify-items: center; gap: 20px; }
.start-title { text-align: center; text-shadow: 0 8px 24px #0008; }
.start-title strong { display: block; font-size: clamp(34px, 7vw, 62px); letter-spacing: .08em; }
.start-button {
  border: 0;
  border-radius: 32px;
  padding: 26px 34px;
  color: #25194c;
  background: #ffe066;
  box-shadow: 0 10px 0 #e8b627, 0 24px 50px #0008;
  font-size: clamp(20px, 4vw, 32px);
  font-weight: 900;
}
.start-button > span { display: block; margin-bottom: 8px; font-size: 52px; }
.start-button small { display: block; margin-top: 9px; font-size: 12px; font-weight: 700; opacity: .68; }

.start-settings-button {
  border: 1px solid #ffffff45;
  border-radius: 999px;
  padding: 10px 18px;
  color: #fff;
  background: #ffffff10;
  font-weight: 800;
}

.device-lock-guide {
  width: min(500px, 100%);
  border-top: 1px solid #ffffff24;
  padding-top: 14px;
  color: #ffffffc7;
  font-size: 13px;
  line-height: 1.65;
}
.device-lock-guide summary { width: fit-content; margin: auto; cursor: pointer; font-weight: 800; }
.device-lock-guide p { margin: 12px 0; }
.device-lock-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; }
.device-lock-links a { color: #ffe066; }

.creator-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; }
.creator-links a { display: inline-flex; align-items: center; min-height: 44px; color: #ffe066; text-underline-offset: 4px; }
.start-creator-links { font-size: 12px; }
.creator-info { margin-top: 24px; border-top: 1px solid #ffffff24; padding-top: 20px; }
.creator-info h3 { margin: 0; font-size: 16px; }
.creator-info p { margin: 8px 0; color: #ffffffc7; font-size: 13px; line-height: 1.65; }
.creator-info .creator-links { justify-content: flex-start; font-size: 13px; }
.creator-info small { display: block; margin-top: 8px; color: #ffffffad; font-size: 11px; }
.analytics-notice { margin: 18px 0 0; color: #ffffffad; font-size: 11px; line-height: 1.65; }

.parent-panel {
  width: min(620px, calc(100% - 28px));
  max-height: min(780px, calc(100dvh - 28px));
  border: 1px solid #ffffff45;
  border-radius: 30px;
  padding: 0;
  overflow: auto;
  color: #fff;
  background: #21184bf5;
  box-shadow: 0 30px 100px #05010ccc, inset 0 1px #ffffff26;
}
.parent-panel::backdrop { background: #09031dcc; backdrop-filter: blur(8px); }
.parent-panel-card { padding: clamp(22px, 5vw, 38px); }
.parent-panel-label {
  margin: 0 0 5px;
  color: #ffe066;
  font: 900 11px/1.2 monospace;
  letter-spacing: .16em;
}
.parent-panel h2 { margin: 0; font-size: clamp(25px, 5vw, 38px); text-wrap: balance; }
.parent-panel-note { margin: 9px 0 24px; color: #ffffffad; font-size: 13px; }
.setting-row {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-top: 1px solid #ffffff20;
}
.setting-row strong, .setting-row small { display: block; }
.setting-row small { margin-top: 4px; color: #ffffff9c; font-size: 11px; }
.setting-toggle { cursor: pointer; }
.setting-toggle input {
  appearance: none;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
  border: 1px solid #ffffff52;
  border-radius: 999px;
  background: radial-gradient(circle at 14px 50%, #fff 0 8px, transparent 9px), #ffffff17;
  accent-color: #ffe066;
  cursor: pointer;
}
.setting-toggle input:checked {
  border-color: #ffe066;
  background: radial-gradient(circle at 34px 50%, #25194c 0 8px, transparent 9px), #ffe066;
}
.parent-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.parent-actions button {
  min-height: 48px;
  border: 1px solid #ffffff32;
  border-radius: 16px;
  padding: 10px 14px;
  color: #fff;
  background: #ffffff10;
  font-weight: 800;
}
.parent-actions .primary-action {
  grid-column: 1 / -1;
  border: 0;
  color: #261a4d;
  background: #ffe066;
}
.parent-actions button:disabled { opacity: .42; }
.parent-panel-help { margin: 18px 0 0; color: #ffffff94; font-size: 11px; line-height: 1.65; }
.parent-panel-help kbd { border: 1px solid #ffffff40; border-radius: 5px; padding: 2px 5px; color: #fff; background: #ffffff10; }

@media (hover: hover) {
  button:hover, summary:hover, a:hover { filter: brightness(1.12); }
}

body.hide-keys .keys, body.hide-keys .legend { display: none; }
body.hide-keys .stage { grid-template-rows: auto minmax(290px, 1fr); }
body.parent-open .sound-card, body.parent-open .particle { animation-play-state: paused; }
body.reduce-motion .sound-card { animation-duration: .15s; }
body.reduce-motion .particle { display: none; }

@keyframes parent-hold { to { transform: scaleX(1); } }

@keyframes card-arrive {
  0% { transform: scale(.2) rotate(var(--tilt)); opacity: 0; }
  14% { transform: scale(1.12) rotate(0); opacity: 1; }
  25%, 76% { transform: scale(1) translateY(0); opacity: 1; }
  100% { transform: scale(.82) translateY(-28px); opacity: 0; }
}
@keyframes scatter {
  to { transform: translate(var(--x), var(--y)) scale(0); opacity: 0; }
}

@media (max-width: 600px) {
  .stage { grid-template-rows: auto minmax(300px, 1fr) auto auto; padding: 14px; }
  .topbar { align-items: center; }
  .parent-access { min-width: 80px; padding: 6px 9px; }
  .volume-control button { min-width: 32px; min-height: 32px; }
  .play-area { border-radius: 28px; }
  .keys { grid-template-columns: repeat(9, 1fr); }
  .mini-key { min-height: 38px; font-size: 12px; }
  .parent-actions { grid-template-columns: 1fr; }
  .parent-actions .primary-action { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; }
}
