/* ===========================================================
   ココちゃんのハーモニカ配列表 — styles
   =========================================================== */

:root {
  color-scheme: light dark;

  --font: "Hiragino Maru Gothic ProN", "ヒラギノ丸ゴ ProN W4", "M PLUS Rounded 1c",
          "Quicksand", ui-rounded, "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;

  /* --- light palette (pastel) --- */
  --bg-a: #fff6f1;
  --bg-b: #f3f0ff;
  --bg-c: #eef8ff;
  --panel: rgba(255, 255, 255, .74);
  --panel-solid: #fffdfc;
  --ink: #4c3a44;
  --ink-soft: #8b7681;
  --line: rgba(120, 90, 105, .16);
  --accent: #e2503c;          /* ココちゃんの蝶ネクタイの赤 */
  --accent-soft: #ffe3dd;

  --blow-a: #ffe6d6;
  --blow-b: #ffd2bb;
  --blow-line: #f0a385;
  --blow-ink: #a44a26;

  --draw-a: #dcefff;
  --draw-b: #c3e2fb;
  --draw-line: #86bfe8;
  --draw-ink: #1d5c8a;

  --hole-a: #f3ecff;
  --hole-line: #cfbdec;
  --hole-ink: #6b4f96;

  --shadow-s: 0 1px 2px rgba(90, 60, 75, .10);
  --shadow-m: 0 6px 18px -8px rgba(90, 60, 75, .34);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-a: #2a1f2b;
    --bg-b: #221f33;
    --bg-c: #1d2531;
    --panel: rgba(58, 47, 62, .66);
    --panel-solid: #332836;
    --ink: #f6ecf1;
    --ink-soft: #b7a3b1;
    --line: rgba(255, 235, 245, .14);
    --accent: #ff7f6b;
    --accent-soft: #55322f;

    --blow-a: #6a4132;
    --blow-b: #56342a;
    --blow-line: #b9724f;
    --blow-ink: #ffd9c4;

    --draw-a: #2c4761;
    --draw-b: #24394f;
    --draw-line: #5b93c0;
    --draw-ink: #cfe8ff;

    --hole-a: #3c3050;
    --hole-line: #6b569a;
    --hole-ink: #dbcaff;

    --shadow-m: 0 6px 18px -8px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: clip;          /* 横スクロールは絶対に起こさない */
}

body {
  min-height: 100svh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(90rem 60rem at 12% -10%, var(--bg-a) 0%, transparent 60%),
    radial-gradient(70rem 50rem at 108% 8%, var(--bg-c) 0%, transparent 58%),
    var(--bg-b);
  background-attachment: fixed;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

/* ===================== topbar ===================== */

.topbar {
  position: sticky;
  isolation: isolate;
  top: 0;
  z-index: 20;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--panel-solid) 82%, transparent);
  backdrop-filter: saturate(1.5) blur(14px);
  -webkit-backdrop-filter: saturate(1.5) blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar__row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar__title {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.title {
  margin: 0;
  font-size: clamp(1.05rem, 4.6vw, 1.4rem);
  font-weight: 800;
  letter-spacing: .02em;
  line-height: 1.1;
}
.title span {
  display: inline-block;
  margin-left: .1em;
  color: var(--accent);
}

.keybadge {
  flex: 0 0 auto;
  font-size: clamp(1.15rem, 5.4vw, 1.5rem);
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}
.keybadge__sub {
  font-size: .62rem;
  color: var(--ink-soft);
  letter-spacing: .04em;
  white-space: nowrap;
}

/* --- key chips --- */
.keys {
  display: flex;
  gap: 7px;
  margin-top: 10px;
  padding: 3px 2px 6px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.keys::-webkit-scrollbar { display: none; }

.key {
  flex: 0 0 auto;
  scroll-snap-align: center;
  min-width: 46px;
  min-height: 40px;
  padding: 6px 12px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--panel-solid);
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: var(--shadow-s);
  cursor: pointer;
  transition: transform .16s cubic-bezier(.2, .9, .3, 1.4), background .16s, color .16s, border-color .16s;
  touch-action: manipulation;
}
.key:active { transform: scale(.93); }
.key[aria-pressed="true"] {
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 78%, #b3271a));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 12px -4px color-mix(in srgb, var(--accent) 70%, transparent);
}

/* --- toggles --- */
.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 5px 11px 5px 8px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: color .16s, border-color .16s, background .16s;
}
.toggle__dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid currentColor;
  background: transparent;
  transition: background .16s, box-shadow .16s;
}
.toggle[aria-pressed="true"] {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: var(--accent-soft);
}
.toggle[aria-pressed="true"] .toggle__dot {
  background: currentColor;
  box-shadow: inset 0 0 0 2px var(--accent-soft);
}

/* ===================== stage ===================== */

.stage {
  padding: 14px;
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
  max-width: 1100px;
  margin: 0 auto;
}

.audio-hint {
  margin: 0 0 12px;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .8rem;
  font-weight: 700;
  text-align: center;
  animation: breathe 2.4s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { opacity: .75; }
  50%      { opacity: 1; }
}

/* ===================== chart grid =====================
   1つのDOMで2レイアウトを切り替える。
   --hole : 1..10 / --lane : 1=穴番号 2=吹 3=吸
   縦持ち  → 穴が「行」   (指が届く大きいタップ領域)
   横持ち・広い画面 → 穴が「列」(従来の配列表そのまま)
   ===================================================== */

.chart {
  display: grid;
  gap: 6px;
  /* portrait default */
  grid-template-columns: 2.9rem 1fr 1fr;
  grid-template-rows: auto;          /* 1行目はラベル行 */
  grid-auto-rows: minmax(58px, auto);
}
.chart .lane-label { grid-column: var(--lane); grid-row: 1; }
.chart .cell,
.chart .holenum { grid-column: var(--lane); grid-row: calc(var(--hole) + 1); }
.chart .holenum { grid-column: 1; }

@media (min-width: 700px), (orientation: landscape) and (min-height: 380px) and (min-width: 560px) {
  .chart {
    grid-template-columns: 3rem repeat(10, minmax(0, 1fr));
    grid-template-rows: auto auto auto;
    grid-auto-rows: auto;
    gap: 5px;
  }
  .chart .lane-label { grid-column: 1; grid-row: var(--lane); }
  .chart .cell,
  .chart .holenum { grid-column: calc(var(--hole) + 1); grid-row: var(--lane); }
  .chart .holenum { grid-row: 1; }
}

.lane-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  font-weight: 800;
  color: var(--ink-soft);
  letter-spacing: .06em;
}

.holenum {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 12px;
  background: var(--hole-a);
  border: 1.5px solid var(--hole-line);
  color: var(--hole-ink);
  font-size: clamp(.85rem, 3.4vw, 1rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* --- note cell --- */
.cell {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 7px 6px;
  border-radius: var(--radius);
  border: 1.5px solid;
  box-shadow: var(--shadow-s);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  /* 縦スクロールはブラウザに任せ、横方向のドラッグをグリッサンドに使う */
  touch-action: pan-y;
  -webkit-touch-callout: none;
  transition: transform .11s cubic-bezier(.2, .9, .3, 1.4), box-shadow .18s, filter .18s;
}
.cell--blow {
  background: linear-gradient(160deg, var(--blow-a), var(--blow-b));
  border-color: var(--blow-line);
  color: var(--blow-ink);
}
.cell--draw {
  background: linear-gradient(160deg, var(--draw-a), var(--draw-b));
  border-color: var(--draw-line);
  color: var(--draw-ink);
}
.cell.is-on {
  transform: scale(.965);
  filter: saturate(1.35) brightness(1.06);
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 34%, transparent),
              var(--shadow-m);
}

.cell__note {
  font-size: clamp(1.15rem, 5.6vw, 1.6rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: .01em;
  white-space: nowrap;
}
.cell__note .oct {
  font-size: .52em;
  font-weight: 700;
  opacity: .62;
  vertical-align: super;
  margin-left: .08em;
}

/* --- bend badges --- */
.bends {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin-top: 1px;
}
.bend {
  min-width: 34px;
  min-height: 26px;
  padding: 3px 7px;
  border-radius: 8px;
  border: 1.5px dashed color-mix(in srgb, currentColor 46%, transparent);
  background: color-mix(in srgb, var(--panel-solid) 62%, transparent);
  color: inherit;
  font-family: inherit;
  font-size: .68rem;
  font-weight: 800;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  touch-action: pan-y;
  -webkit-touch-callout: none;
}
.bend .arrow { opacity: .6; font-size: .85em; }
.bend.is-on {
  border-style: solid;
  background: color-mix(in srgb, currentColor 22%, var(--panel-solid));
  transform: scale(.94);
}

/* --- ripple --- */
.ripple {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: currentColor;
  opacity: .3;
  pointer-events: none;
  animation: ripple .55s cubic-bezier(.15, .7, .3, 1) forwards;
}
@keyframes ripple {
  to { transform: scale(18); opacity: 0; }
}

/* ===================== legend / foot ===================== */

.legend {
  margin: 16px 2px 0;
  font-size: .76rem;
  line-height: 1.75;
  color: var(--ink-soft);
  text-align: center;
}
.legend__chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1.5px solid;
  font-weight: 800;
}
.legend__chip--blow {
  background: var(--blow-a); border-color: var(--blow-line); color: var(--blow-ink);
}
.legend__chip--draw {
  background: var(--draw-a); border-color: var(--draw-line); color: var(--draw-ink);
}

.foot {
  margin: 22px 0 0;
  text-align: center;
  font-size: .72rem;
  color: var(--ink-soft);
}
.foot p { margin: 0; }

/* ===================== ココちゃん =====================
   配列表の上に重ならないよう、ヘッダーに常駐させる
   ===================================================== */

.coco {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  line-height: 0;
}

.coco__sprite {
  flex: 0 0 auto;
  width: clamp(50px, 15vw, 66px);
  aspect-ratio: 192 / 208;
  padding: 0;
  border: 0;
  background-color: transparent;
  background-image: url("assets/coco.webp");
  background-repeat: no-repeat;
  background-size: 800% 900%;              /* 8列 × 9行 */
  background-position: 0% 0%;
  cursor: pointer;
  touch-action: manipulation;
  filter: drop-shadow(0 4px 7px rgba(80, 50, 65, .26));
  transition: transform .18s cubic-bezier(.2, .9, .3, 1.4);
  will-change: background-position, transform;
}
.coco__sprite:active { transform: scale(.92); }
.coco.is-hop .coco__sprite { animation: hop .42s cubic-bezier(.3, .8, .4, 1); }
@keyframes hop {
  0%   { transform: translateY(0) scale(1); }
  35%  { transform: translateY(-9px) scale(1.06, .95); }
  70%  { transform: translateY(0) scale(.96, 1.04); }
  100% { transform: translateY(0) scale(1); }
}

/* ふきだしはヘッダー内に重ねて出す（本文レイアウトに一切影響させない） */
.coco__bubble {
  position: absolute;
  left: calc(max(14px, env(safe-area-inset-left)) + clamp(50px, 15vw, 66px) + 8px);
  top: calc(env(safe-area-inset-top) + 8px);
  z-index: 5;
  pointer-events: none;
  max-width: min(64vw, 300px);
  padding: 7px 13px;
  border-radius: 4px 16px 16px 16px;
  background: var(--panel-solid);
  border: 1.5px solid var(--accent);
  box-shadow: var(--shadow-m);
  color: var(--ink);
  font-size: .76rem;
  font-weight: 700;
  line-height: 1.45;
  opacity: 0;
  transform: translateX(-6px) scale(.92);
  transform-origin: 0 0;
  transition: opacity .18s, transform .26s cubic-bezier(.2, .9, .3, 1.4);
}
.coco__bubble.is-show {
  opacity: 1;
  transform: translateX(0) scale(1);
}

/* 横持ちで画面が低いときは、ヘッダーを固定しないで縦の余裕を作る */
@media (orientation: landscape) and (max-height: 500px) {
  .topbar { position: static; padding-top: calc(env(safe-area-inset-top) + 8px); padding-bottom: 8px; }
  .keys { margin-top: 7px; padding-bottom: 4px; }
  .keybadge__sub { display: none; }
  .stage { padding-top: 10px; }
  .coco__sprite { width: 48px; }
}

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