:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #000000;
  --sub: #8e8e93;
  --line: rgba(60, 60, 67, .14);
  --grid: rgba(60, 60, 67, .10);
  --stage: #ffffff;
  --accent: #007aff;
  --danger: #ff3b30;
  --fill: rgba(120, 120, 128, .12);
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 8px 24px rgba(0, 0, 0, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #ffffff;
    --sub: #8e8e93;
    --line: rgba(235, 235, 245, .16);
    --grid: rgba(235, 235, 245, .08);
    --stage: #1c1c1e;
    --accent: #0a84ff;
    --danger: #ff453a;
    --fill: rgba(120, 120, 128, .24);
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  max-width: 960px;
  margin: 0 auto;
}

/* 上のバー */
.bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
}
.title {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 6px 8px;
  outline: none;
}
.title:focus { background: var(--fill); }
.icon {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 20px;
  color: var(--accent);
  flex: none;
}
.icon:active { background: var(--fill); }
.icon:disabled { color: var(--sub); opacity: .5; }
.icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon svg .fill { fill: currentColor; stroke: none; }
.icon.accent { background: var(--accent); color: #fff; width: 44px; height: 44px; border-radius: 22px; margin-left: 4px; }
.icon.accent:active { opacity: .8; }
.icon .stop { display: none; }
body.playing .icon .play { display: none; }
body.playing .icon .stop { display: block; }

/* ステージ */
.stageWrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 16px;
}
#stage {
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.st-floor { fill: var(--stage); filter: drop-shadow(0 1px 2px rgba(0,0,0,.06)); }
.st-grid { stroke: var(--grid); stroke-width: .02; }
.st-center { stroke: var(--line); stroke-width: .03; }
.st-mark { fill: var(--sub); font-size: .28px; text-anchor: middle; font-weight: 500; }
.st-front { fill: var(--sub); font-size: .3px; text-anchor: middle; font-weight: 600; letter-spacing: .08px; }
.st-front-line { stroke: var(--sub); stroke-width: .04; stroke-linecap: round; opacity: .5; }
.ghost { fill: none; stroke-width: .035; stroke-dasharray: .08 .07; opacity: .55; }
.trail { stroke-width: .035; opacity: .45; stroke-linecap: round; }
.dancer { cursor: grab; }
.dancer circle { stroke: rgba(0,0,0,.12); stroke-width: .02; }
.dancer text { fill: #fff; font-size: .36px; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.dancer.sel .ring { fill: none; stroke: var(--accent); stroke-width: .05; }
.dancer.dragging { cursor: grabbing; }
body.playing .dancer { cursor: default; }

/* フォーメーションの帯 */
.strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 10px 16px 14px;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.strip::-webkit-scrollbar { display: none; }
.thumb {
  flex: none;
  width: 76px;
  scroll-snap-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--sub);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.thumb svg {
  width: 76px; height: 50px;
  background: var(--card);
  border-radius: 10px;
  box-shadow: var(--shadow);
  outline: 2px solid transparent;
  outline-offset: 1px;
  transition: outline-color .15s;
}
.thumb.on { color: var(--accent); }
.thumb.on svg { outline-color: var(--accent); }
.thumb.add svg { background: var(--fill); box-shadow: none; }
.thumb.add path { stroke: var(--accent); stroke-width: .5; stroke-linecap: round; }

/* シート */
.sheetBack {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .25);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 10;
  animation: fade .2s;
}
.sheetBack[hidden] { display: none; }
.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--bg);
  border-radius: 14px 14px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
  animation: up .25s cubic-bezier(.2, .8, .2, 1);
}
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 4px; }
.nameInput {
  font: inherit; font-size: 17px;
  color: var(--text);
  background: var(--card);
  border: 0; border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}
.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; padding: 4px 8px; justify-items: center; }
.swatch { width: 40px; height: 40px; border-radius: 20px; position: relative; }
.swatch.on::after { content: ""; position: absolute; inset: -4px; border-radius: 24px; border: 2.5px solid var(--accent); }
.group { display: flex; flex-direction: column; background: var(--card); border-radius: 10px; overflow: hidden; }
.group .rowBtn { border-radius: 0; }
.group .rowBtn + .rowBtn { border-top: .5px solid var(--line); }
.rowBtn {
  background: var(--card);
  border-radius: 10px;
  padding: 14px;
  font-size: 17px;
  color: var(--accent);
  text-align: center;
}
.rowBtn:active { background: var(--fill); }
.rowBtn.danger { color: var(--danger); }
.rowBtn:disabled { color: var(--sub); }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }

/* 共有リンクで見ているとき */
.view-only { display: none; }
body.viewing .view-only { display: grid; }
body.viewing .edit-only { display: none; }
body.viewing .dancer { cursor: default; }

.rowBtn[hidden] { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 16px;
  border-radius: 20px;
  background: rgba(30, 30, 32, .92);
  color: #fff;
  font-size: 15px;
  z-index: 20;
  animation: fade .2s;
}
.toast[hidden] { display: none; }
