/* ぷかぷか つり — 見た目。ライト=ひるの うみ・ダーク=よるの うみ。外部フォントは使わない */
:root {
  --bg: #d9f1ff;
  --ink: #26304d;
  --sub: #55607f;
  --card: #ffffff;
  --card-sh: #9cc3dc;
  --gold: #ffc53d;
  --focus: #2f7cf6;
  --panel: #f2fbff;
  --cell: #ffffff;
  --sil: brightness(0) opacity(.28);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1626;
    --ink: #eef2ff;
    --sub: #aab6d6;
    --card: #26324f;
    --card-sh: #070b14;
    --focus: #ffc53d;
    --panel: #18233d;
    --cell: #26324f;
    --sil: brightness(0) invert(1) opacity(.22);
  }
}

* { 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; top: 0; bottom: 0; left: 0; right: 0;
  max-width: 1100px; margin: 0 auto;
  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; }
.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; }
.snd:active { transform: translateY(3px); }

/* ---- うみ ---- */
.stage { position: relative; min-height: 0; border: 3px solid var(--ink); border-radius: 22px; overflow: hidden; background: #4ec3e8; }
.stage canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; }
#cv { touch-action: none; cursor: pointer; }
.say {
  position: absolute; left: 50%; bottom: 7%; transform: translateX(-50%); width: max-content; max-width: 92%; margin: 0; padding: 8px 18px; border-radius: 20px;
  background: #fff; color: #26304d; border: 3px solid #26304d; text-align: center; line-height: 1.25;
  font-size: clamp(18px, 5.6vw, 32px); font-weight: 900; z-index: 3; pointer-events: none; text-wrap: balance;
}

/* ---- ボタン ---- */
.tray { display: flex; gap: 14px; align-items: center; justify-content: center; }
.tb {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  min-width: 96px; min-height: 64px; padding: 4px 10px; border-radius: 18px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh);
}
.tb svg { width: 34px; height: 34px; flex-shrink: 0; }
.tb span { font-size: 15px; font-weight: 900; white-space: nowrap; }
.tb:active { transform: translateY(3px); }
.maku { min-width: 150px; background: var(--gold); color: #26304d; box-shadow: 0 4px 0 #b88a12; }
.maku.off { opacity: .55; }
.maku.on { animation: pulse .7s ease-in-out infinite alternate; box-shadow: 0 4px 0 #b88a12, 0 0 0 5px rgba(255, 255, 255, .85); }
@keyframes pulse { to { transform: scale(1.07); } }

/* ---- ずかん ---- */
.book { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; background: var(--panel); color: var(--ink); }
.bk-top { display: flex; align-items: center; gap: 8px; padding: 6px 8px; flex-shrink: 0; }
.bk-top h2 { margin: 0; font-size: 20px; font-weight: 900; white-space: nowrap; }
.bk-bucket { display: flex; align-items: center; gap: 6px; margin-left: auto; min-width: 0; }
.bk-bucket canvas { position: static; width: 44px; height: 40px; flex-shrink: 0; }
.bk-bucket b { font-size: 16px; font-weight: 900; min-width: 2.2em; }
.rel { min-width: 104px; min-height: 48px; padding: 4px 10px; border-radius: 14px; background: var(--gold); color: #26304d; font-size: 15px; font-weight: 900; box-shadow: 0 3px 0 #b88a12; white-space: nowrap; }
.rel:disabled { opacity: .4; cursor: default; box-shadow: none; }
.bkx { width: 52px; height: 52px; border-radius: 14px; background: var(--card); box-shadow: 0 3px 0 var(--card-sh); flex-shrink: 0; display: grid; place-items: center; }
.bkx svg { width: 24px; height: 24px; }
.bk-grid { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; padding: 4px 8px 10px; align-content: start; }
.cell { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px 2px 6px; border-radius: 14px; background: var(--cell); box-shadow: 0 3px 0 var(--card-sh); min-height: 84px; }
.cell canvas { position: static; width: 100%; max-width: 84px; height: auto; aspect-ratio: 112 / 80; }
.cell.no canvas { filter: var(--sil); }
.cell .nm { font-size: 12px; font-weight: 900; line-height: 1.15; text-align: center; }
.cell .ct { position: absolute; right: 6px; top: 4px; font-size: 14px; font-weight: 900; padding: 0 6px; border-radius: 10px; background: var(--gold); color: #26304d; }
.cell.no .ct { display: none; }

/* スマホを横にしたとき: ボタンを みぎに */
@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; }
  .top { grid-column: 1 / -1; }
  .logo img { width: 32px; height: 32px; }
  .snd { height: 48px; width: 48px; }
  .tray { grid-column: 2; grid-row: 2; flex-direction: column; justify-content: center; gap: 10px; }
  .tb { min-width: 96px; min-height: 0; height: min(calc((100svh - 15vh - 90px) / 2), 72px); padding: 2px 8px; }
  .tb svg { width: 28px; height: 28px; }
  .maku { min-width: 96px; }
  .bk-grid { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); }
  .cell { min-height: 72px; }
  .bk-top h2 { display: none; }
}

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