/* つみつみ ブロックランド — 見た目。ライト / ダークは CSS 変数。外部フォントは使わない */
:root {
  --bg: #eaf6ff;
  --ink: #2b2433;
  --sub: #6b6177;
  --card: #ffffff;
  --card-sh: #bcd0e4;
  --gold: #ffb703;
  --focus: #2f7cf6;
  --pg: #fff3c4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1d2b;
    --ink: #f3eefc;
    --sub: #bdb8cf;
    --card: #2b2f44;
    --card-sh: #0d0f19;
    --gold: #ffd166;
    --focus: #ffc53d;
    --pg: #4a4330;
  }
}

* { 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;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  /* 画面の下 15% には押すものを置かない(手首が当たる) */
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 10px) 15vh calc(env(safe-area-inset-left) + 10px);
}
[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: 3px; }
svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* ---- うえの おびと ボタン ---- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.logo { display: flex; align-items: center; gap: 8px; margin: 0; min-width: 0; font-size: clamp(17px, 4.6vw, 24px); font-weight: 900; white-space: nowrap; }
.logo img { width: 40px; height: 40px; flex-shrink: 0; }
@media (max-width: 520px) { .logo span { display: none; } }
@media (max-width: 400px) { .logo { display: none; } }
.ctl { display: flex; gap: 6px; }
.cbtn {
  position: relative; overflow: hidden;
  width: 62px; height: 56px; padding: 3px 2px 2px; border-radius: 14px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
}
.cbtn svg { width: 28px; height: 28px; flex-shrink: 0; fill: none; stroke: var(--ink); stroke-width: 3.6; stroke-linecap: round; stroke-linejoin: round; }
.cbtn span { font-size: 12px; font-weight: 900; line-height: 1.1; white-space: nowrap; }
.cbtn[aria-disabled="true"] { opacity: .5; }
.cbtn:active, .snd:active { transform: translateY(3px); }
#dnBtn .i-night, #dnBtn[aria-pressed="true"] .i-day { display: none; }
#dnBtn[aria-pressed="true"] .i-night { display: block; fill: #ffd166; }
#dnBtn .i-day circle { fill: #ffb703; }
#rstBtn svg path:first-child { fill: #8fd977; }
/* ながおしの しるし(1びょうで いっぱいに) */
#rstBtn::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 6px; background: var(--gold); transform: scaleX(0); transform-origin: left; }
#rstBtn.holding::after { animation: hold 1s linear forwards; }
@keyframes hold { to { transform: scaleX(1); } }

.snd { flex-shrink: 0; width: 52px; height: 56px; 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: var(--ink); }
.wave, .slash { fill: none; stroke: var(--ink); stroke-width: 3.5; stroke-linecap: round; }
.snd.off .wave, .snd:not(.off) .slash { display: none; }

/* ---- せかい ---- */
.stage {
  position: relative; min-height: 0; border: 3px solid var(--ink); border-radius: 22px; overflow: hidden;
  background: #cfeaff; touch-action: none;
}
.stage canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.say {
  position: absolute; left: 10px; top: 10px; max-width: calc(100% - 150px); margin: 0; padding: 8px 12px; border-radius: 16px; pointer-events: none;
  background: #fff; color: #2b2433; border: 3px solid #2b2433; font-size: clamp(14px, 3.8vw, 20px); font-weight: 900; z-index: 3;
}

/* ---- しゃしん(せかいの みぎうえ) ---- */
.cam { position: absolute; right: 8px; top: 8px; display: flex; gap: 8px; z-index: 4; }
.sbtn { position: relative; width: 52px; height: 52px; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); display: grid; place-items: center; }
.sbtn:active { transform: translateY(3px); }
.sbtn svg { width: 32px; height: 32px; fill: none; stroke: var(--ink); stroke-width: 2.6; stroke-linejoin: round; stroke-linecap: round; }
.badge { position: absolute; right: -6px; top: -6px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; background: #ff5a5f; color: #fff; font-size: 13px; font-weight: 900; line-height: 22px; text-align: center; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 5; }
.flash.go { animation: flash .45s ease-out; }
@keyframes flash { from { opacity: .9; } to { opacity: 0; } }
/* とった しゃしんが アルバムの ボタンへ とんでいく(--dx, --dy は bl.js が いれる) */
.pop { position: absolute; left: 50%; top: 50%; z-index: 6; pointer-events: none; border: 4px solid #fff; border-radius: 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, .28); animation: pop .95s ease-in forwards; }
@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(.7) rotate(-4deg); opacity: 0; }
  14% { transform: translate(-50%, -50%) scale(1) rotate(-4deg); opacity: 1; }
  55% { transform: translate(-50%, -50%) scale(1) rotate(-4deg); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.12) rotate(0deg); opacity: .4; }
}

/* ---- アルバム(画面の 下15% には 押すものを おかない) ---- */
.album {
  position: fixed; inset: 0; z-index: 20; display: grid; grid-template-rows: minmax(0, 1fr); background: rgba(20, 16, 30, .45);
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 10px) 15vh calc(env(safe-area-inset-left) + 10px);
}
.apanel {
  min-height: 0; width: min(100%, 760px); justify-self: center; display: grid; grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg); border: 3px solid var(--ink); border-radius: 22px; overflow: hidden;
}
.apanel:focus { outline: none; }
.ahead { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 8px 4px 16px; }
.ahead h2 { margin: 0; font-size: 20px; font-weight: 900; }
.ahint { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); margin: 0; padding: 6px 12px; border-radius: 14px; background: #fff; color: #2b2433; border: 3px solid #2b2433; font-size: 15px; font-weight: 900; white-space: nowrap; pointer-events: none; }
.abtn { width: 52px; height: 52px; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); display: grid; place-items: center; }
.abtn svg { width: 26px; height: 26px; fill: none; stroke: var(--ink); stroke-width: 5; stroke-linecap: round; }
.abody { min-height: 0; overflow-y: auto; padding: 6px 12px 12px; }
.aempty { margin: 24px 8px; text-align: center; font-size: 18px; font-weight: 900; color: var(--sub); line-height: 1.6; }
.agrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.acard { display: block; aspect-ratio: 4 / 3; min-height: 48px; border-radius: 12px; overflow: hidden; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); }
.acard canvas { display: block; width: 100%; height: 100%; }
.acard:active, .abtn:active, .abig:active, .amid:active { transform: translateY(3px); }
.aview { height: 100%; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.aphoto { flex: 1 1 auto; min-height: 90px; display: grid; place-items: center; }
#acv { display: block; box-sizing: content-box; border-radius: 14px; border: 3px solid var(--ink); }
.actl { flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.abig, .amid, .ahold { min-height: 52px; border-radius: 16px; font-size: 17px; font-weight: 900; box-shadow: 0 4px 0 var(--card-sh); }
.abig { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; gap: 6px; background: #36c46b; color: #fff; box-shadow: 0 4px 0 #1f8a47; }
.abig svg { width: 28px; height: 28px; }
.amid { grid-column: 1 / -1; background: var(--card); }
.anote { grid-column: 1 / -1; margin: 2px 0 -2px; font-size: 13px; font-weight: 700; color: var(--sub); text-align: center; }
.arow { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ahold { position: relative; overflow: hidden; background: var(--card); font-size: 15px; }
.ahold::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 6px; background: var(--gold); transform: scaleX(0); transform-origin: left; }
.ahold.holding::after { animation: hold 1s linear forwards; }
.ahold.full { background: var(--pg); }
@media (orientation: landscape) and (max-height: 600px) {
  .aview { flex-direction: row; }
  .actl { width: 250px; align-content: start; }
  .abig, .amid, .ahold { min-height: 50px; font-size: 15px; }
}
/* ブロックを たくさん おいても ほかの ページを みていない とき: めくる ボタンを ゆらす */
.blk.pg.nudge { animation: nudge .7s ease-in-out 3; }
@keyframes nudge { 0%, 100% { transform: none; } 25% { transform: rotate(-7deg) scale(1.06); } 75% { transform: rotate(7deg) scale(1.06); } }

/* ---- ブロックを えらぶ ---- */
.tray {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px;
  width: min(100%, 520px); justify-self: center;
}
.blk {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  min-height: 58px; padding: 3px 2px 2px; border-radius: 14px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh);
}
.blk:active { transform: translateY(3px); }
.blk[aria-pressed="true"] { box-shadow: 0 4px 0 var(--card-sh), 0 0 0 4px var(--gold); }
/* ページを めくる ボタン(もっと / ブロック) */
.blk.pg { background: var(--pg); }
.bi { display: block; width: 36px; height: 36px; }
.bn { font-size: clamp(11px, 3vw, 13px); font-weight: 900; white-space: nowrap; line-height: 1.15; }

@media (min-width: 700px) and (min-height: 601px) {
  .tray { grid-template-columns: repeat(12, minmax(0, 1fr)); width: min(100%, 940px); }
  .blk { min-height: 70px; }
  .bi { width: 42px; height: 42px; }
  .bn { font-size: 14px; }
}

/* スマホを横にしたとき: ボタンを みぎに ならべて、せかいを おおきく */
@media (orientation: landscape) and (max-height: 600px) {
  #app { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr); column-gap: 10px; row-gap: 6px; }
  .stage { grid-column: 1; grid-row: 1 / span 2; }
  .top { grid-column: 2; grid-row: 1; justify-content: center; }
  .logo { display: none; }
  .ctl { gap: 4px; }
  .cbtn { width: 50px; height: 50px; border-radius: 12px; }
  .cbtn svg { width: 22px; height: 22px; }
  .cbtn span { font-size: 10px; }
  .snd { width: 50px; height: 50px; border-radius: 12px; margin-left: 0; }
  .snd svg { width: 26px; height: 26px; }
  .tray { grid-column: 2; grid-row: 2; grid-template-columns: repeat(4, 50px); width: auto; gap: 4px; align-content: start; justify-content: center; }
  .blk { min-height: 0; height: 50px; border-radius: 12px; padding: 2px 1px 1px; }
  .bi { width: 28px; height: 28px; }
  .bn { font-size: 10px; }
  .blk[aria-pressed="true"] { box-shadow: 0 3px 0 var(--card-sh), 0 0 0 3px var(--gold); }
}

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