/* わくわく きせかえ — 見た目。ライト=ひるの おへや・ダーク=よるの おへや。外部フォントは使わない */
:root {
  --bg: #fff4e0;
  --wall: #fffaf2;
  --floor: #f6e7cf;
  --ink: #2b2433;
  --sub: #6b6177;
  --card: #ffffff;
  --card-sh: #e2cba5;
  --panel: rgba(255, 255, 255, .72);
  --gold: #ffc53d;
  --focus: #2f7cf6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #211c1a;
    --wall: #3a322d;
    --floor: #2c2521;
    --ink: #f3eefc;
    --sub: #c4b8ab;
    --card: #ece2d2;
    --card-sh: #0d0b0a;
    --panel: rgba(33, 28, 26, .72);
    --focus: #ffc53d;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "BIZ UDPGothic", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  overflow: hidden;
}
#app {
  position: fixed; inset: 0; width: 100%; max-width: 960px; margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  gap: 6px;
  /* 画面の下 15% には押すものを置かない(手首が当たる) */
  padding: calc(env(safe-area-inset-top) + 8px) max(6px, env(safe-area-inset-right)) 15vh max(6px, env(safe-area-inset-left));
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; margin: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 4px solid var(--focus); outline-offset: 2px; }
svg { display: block; width: 100%; height: 100%; overflow: visible; }
#probe { position: absolute; left: -99px; top: 0; width: 10px; height: 10px; visibility: hidden; pointer-events: none; }

/* ---- うえの おび ---- */
.top { display: contents; }
.logo { grid-row: 1; grid-column: 1; justify-self: start; display: flex; align-items: center; gap: 8px; margin: 0; min-width: 0; font-size: clamp(16px, 4.2vw, 22px); font-weight: 900; white-space: nowrap; }
.logo img { width: 40px; height: 40px; flex-shrink: 0; }
@media (max-width: 520px) { .logo span { display: none; } }
.pals { grid-row: 1; grid-column: 2; display: flex; gap: 6px; }
.snd { grid-row: 1; grid-column: 3; justify-self: end; flex-shrink: 0; width: 52px; height: 52px; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); display: grid; place-items: center; }
.snd svg { width: 32px; height: 32px; }
.spk { fill: #2b2433; }
.wave, .slash { fill: none; stroke: #2b2433; stroke-width: 3.5; stroke-linecap: round; }
.snd.off .wave, .snd:not(.off) .slash { display: none; }
.pbtn { width: 52px; height: 52px; padding: 3px; border-radius: 14px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); }
.pbtn[aria-pressed="true"] { box-shadow: 0 4px 0 var(--card-sh), 0 0 0 4px var(--gold); }
.pbtn:active, .snd:active { transform: translateY(3px); }

/* ---- ステージ ---- */
.stage {
  grid-row: 2; grid-column: 1 / -1;
  position: relative; min-height: 0; border: 3px solid var(--ink); border-radius: 22px; overflow: hidden;
  background: linear-gradient(var(--wall) 0 70%, var(--floor) 70%);
}
.bgsvg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: hidden; }
.figure {
  position: absolute; bottom: 2%; left: 50%; translate: -50% 0; height: 94%; aspect-ratio: 3 / 4;
  display: block; z-index: 1;
}
.figure:focus-visible { outline-offset: -4px; border-radius: 20px; }
.sway, .spin, .fig { display: block; width: 100%; height: 100%; }
.sway { perspective: 700px; transform-origin: 50% 100%; }
.spin { transform-origin: 50% 80%; }
.fig { transform-origin: 50% 100%; }
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
.fx i {
  position: absolute; left: calc(50% - 9px); top: 44%; width: 18px; height: 18px; background: var(--c);
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  animation: spark .8s ease-out calc(var(--k) * 28ms) both;
}
@keyframes spark {
  from { transform: translate(0, 0) scale(.3) rotate(0); opacity: 1; }
  to { transform: translate(calc(var(--x) * 24vmin), calc(var(--y) * 22vmin)) scale(1.3) rotate(120deg); opacity: 0; }
}
.fx b {
  position: absolute; left: calc(50% + var(--x) * 22vmin); bottom: 46%; font-size: 26px; line-height: 1; font-weight: 900; color: var(--c);
  text-shadow: 0 0 0 #2b2433; animation: note 1.5s ease-out both;
}
@keyframes note {
  from { transform: translateY(0) rotate(-10deg); opacity: 0; }
  20% { opacity: 1; }
  to { transform: translateY(-26vmin) rotate(14deg); opacity: 0; }
}

/* おどる */
.dancing .sway { animation: bounce .36s ease-in-out infinite; }
.dancing .aL { animation: wl .72s ease-in-out infinite; }
.dancing .aR { animation: wr .72s ease-in-out -.36s infinite; }
@keyframes bounce {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-5%) rotate(3deg); }
}
@keyframes wl { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(120deg); } }
@keyframes wr { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-120deg); } }

/* ---- いろ(縦: ステージの みぎ / 横: えらぶ ところ) ---- */
.colors {
  grid-row: 2; grid-column: 1 / -1; justify-self: end; align-self: start; margin: 11px; z-index: 2;
  display: grid; grid-template-columns: repeat(2, 48px); gap: 4px; padding: 4px; border-radius: 16px; background: var(--panel);
}
.colors.off { opacity: .4; }
.sw { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 14px; }
.sw::before { content: ""; width: 36px; height: 36px; border-radius: 50%; background: var(--sw); border: 3px solid #2b2433; }
.sw[aria-pressed="true"] { background: var(--card); box-shadow: 0 0 0 4px var(--gold); }
.sw:active { transform: translateY(2px); }

/* ---- アルバム ---- */
.album { grid-row: 2; grid-column: 1 / -1; justify-self: start; align-self: start; margin: 11px; z-index: 2; padding: 4px; border-radius: 16px; background: var(--panel); }
.thumbs { display: grid; grid-template-columns: repeat(2, 48px); gap: 4px; }
.th { position: relative; width: 48px; height: 48px; border-radius: 12px; overflow: hidden; background: var(--card); box-shadow: 0 0 0 2px var(--card-sh) inset; }
.th.empty { background: transparent; box-shadow: 0 0 0 2px var(--card-sh) inset; opacity: .6; }
.th svg { position: absolute; inset: 0; }
.th.pop { animation: pop .35s cubic-bezier(.3, 1.6, .6, 1); }
@keyframes pop { from { transform: scale(.4); } to { transform: none; } }
.th:active { transform: scale(.94); }

/* ---- えらぶ ---- */
.tabs { grid-row: 3; grid-column: 1 / -1; justify-self: center; width: min(100%, 640px); display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.tab { height: 52px; padding: 5px; border-radius: 14px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); }
.tab[aria-pressed="true"] { background: var(--gold); box-shadow: 0 4px 0 #c99410; }
.tab svg { width: 100%; height: 100%; }
.items { grid-row: 4; grid-column: 1 / -1; justify-self: center; width: min(100%, 640px); display: grid; grid-template-columns: repeat(var(--h, 4), minmax(0, 1fr)); gap: 4px; }
.it { height: 52px; padding: 4px; border-radius: 14px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); display: grid; place-items: center; }
.it svg { width: 100%; height: 100%; max-width: 44px; }
.it .bgi { position: relative; display: block; width: 44px; height: 44px; border-radius: 10px; overflow: hidden; border: 2.5px solid #2b2433; }
.it .bgi svg { position: absolute; inset: 0; max-width: none; overflow: hidden; }
.it[aria-pressed="true"] { box-shadow: 0 4px 0 var(--card-sh), 0 0 0 4px var(--gold); background: #fff6d6; }
.tab:active, .it:active, .ab:active { transform: translateY(3px); }
.acts { grid-row: 5; grid-column: 1 / -1; justify-self: center; width: min(100%, 420px); display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.ab { height: 52px; padding: 5px; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); }
.ab svg { width: 100%; height: 100%; max-width: 44px; margin: 0 auto; }
.ab.busy { opacity: .6; }

@media (min-width: 560px) {
  .items { grid-template-columns: repeat(var(--n, 8), minmax(0, 1fr)); }
  .tabs { gap: 4px; }
}
@media (max-width: 400px) {
  #app { padding-left: 4px; padding-right: 4px; }
}

/* スマホを横にしたとき: えらぶ ところを みぎに */
@media (orientation: landscape) and (max-height: 600px) {
  #app { grid-template-columns: minmax(0, 1fr) 414px; grid-template-rows: auto repeat(4, minmax(48px, 64px)); gap: 4px 8px; }
  .top { display: flex; align-items: center; gap: 8px; grid-row: 1; grid-column: 1 / -1; }
  .logo, .pals, .snd, .album { grid-row: auto; grid-column: auto; margin: 0; }
  .logo img { width: 32px; height: 32px; }
  .logo span { display: none; }
  .pbtn, .snd { width: 48px; height: 48px; }
  .album { padding: 0; background: none; margin-left: 4px; }
  .thumbs { grid-template-columns: repeat(6, 48px); }
  .snd { margin-left: auto; }
  .stage { grid-row: 2 / 6; grid-column: 1; }
  .tabs { grid-row: 2; grid-column: 2; width: 100%; gap: 3px; }
  .items { grid-row: 3; grid-column: 2; width: 100%; grid-template-columns: repeat(var(--n, 8), minmax(0, 1fr)); gap: 3px; }
  .colors { grid-row: 4; grid-column: 2; justify-self: stretch; align-self: stretch; margin: 0; padding: 0; background: none; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 3px; }
  .sw { width: auto; height: 100%; min-height: 48px; }
  .acts { grid-row: 5; grid-column: 2; width: 100%; }
  .tab, .it, .ab { height: 100%; min-height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .dancing .sway, .dancing .aL, .dancing .aR { animation: none !important; }
}
