:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --surface: #151821;
  --surface-2: #1c202b;
  --surface-3: #252a38;
  --line: rgba(255,255,255,.09);
  --text: #f7f8fb;
  --muted: #9aa3b6;
  --accent: #7b6cff;
  --accent-2: #a99fff;
  --danger: #ff667a;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); overscroll-behavior: none; }
body { touch-action: manipulation; }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(123,108,255,.55); outline-offset: 2px; }
.app-shell { width: 100%; min-height: 100dvh; background: radial-gradient(circle at 50% -10%, rgba(123,108,255,.15), transparent 28%), var(--bg); }
.topbar {
  height: calc(58px + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 14px 0;
  position: fixed; z-index: 30; inset: 0 0 auto 0;
  display: grid; grid-template-columns: 44px minmax(0,1fr) auto; align-items: center; gap: 8px;
  background: rgba(11,13,18,.88); backdrop-filter: blur(18px); border-bottom: 1px solid var(--line);
}
.icon-button, .round-button { border: 0; background: var(--surface-2); min-width: 44px; min-height: 44px; border-radius: 14px; font-weight: 800; }
.project-title { min-width: 0; border: 0; background: transparent; display: flex; align-items: center; gap: 7px; padding: 8px 4px; overflow: hidden; }
.project-title span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 800; font-size: 16px; }
.edit-mark { color: var(--muted); font-size: 13px; }
.save-state { font-size: 11px; color: var(--muted); white-space: nowrap; }
.main-area { padding-top: calc(58px + env(safe-area-inset-top, 0px)); padding-bottom: calc(82px + var(--safe-bottom)); }
.screen { display: none; min-height: calc(100dvh - 140px); padding: 18px 14px 28px; }
.screen.active { display: block; animation: screenIn .18s ease-out; }
@keyframes screenIn { from { opacity: .45; transform: translateY(4px); } }
.screen-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.eyebrow { margin: 0 0 3px; color: var(--accent-2); font-size: 11px; font-weight: 900; letter-spacing: .13em; }
h1 { margin: 0; font-size: 27px; line-height: 1.15; letter-spacing: -.03em; white-space: nowrap; }
h2 { margin: 0; }
.card { background: linear-gradient(180deg, rgba(255,255,255,.025), transparent), var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,.17); }
.capture-summary { display: grid; grid-template-columns: repeat(3,1fr); padding: 14px 12px; text-align: center; margin-bottom: 12px; }
.capture-summary > div:not(:last-child) { border-right: 1px solid var(--line); }
.capture-summary strong { display: block; font-size: 18px; margin-top: 4px; }
.summary-label, .field-label { color: var(--muted); font-size: 11px; font-weight: 700; }
.mode-segment { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 4px; margin-bottom: 12px; }
.segment { min-height: 42px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 800; }
.segment.active { background: var(--surface-3); color: var(--text); box-shadow: 0 3px 12px rgba(0,0,0,.18); }
.length-panel { padding: 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.length-chips { display: flex; gap: 5px; }
.length-chips button { min-width: 46px; min-height: 38px; padding: 0 8px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-2); font-size: 12px; font-weight: 800; }
.length-chips button.active { background: var(--accent); border-color: transparent; }
.particle-strip { min-height: 84px; padding: 12px; display: flex; align-items: stretch; gap: 7px; overflow-x: auto; scrollbar-width: none; }
.particle-strip::-webkit-scrollbar, .keyboard-viewport::-webkit-scrollbar { display: none; }
.particle-mini { flex: 0 0 auto; min-width: 50px; height: 58px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.particle-mini strong { font-size: 12px; }
.particle-mini span { color: var(--muted); font-size: 10px; }
.particle-mini.pitched { border-color: rgba(123,108,255,.55); background: rgba(123,108,255,.14); }
.strip-empty { color: var(--muted); font-size: 13px; align-self: center; width: 100%; text-align: center; }
.capture-zone { margin-top: 16px; }
.particle-button { width: 100%; min-height: 132px; border: 0; border-radius: 30px; background: radial-gradient(circle at 50% 15%, rgba(255,255,255,.22), transparent 32%), linear-gradient(145deg, #897cff, #6654ed); box-shadow: 0 16px 40px rgba(91,74,228,.35), inset 0 1px 0 rgba(255,255,255,.35); display: flex; flex-direction: column; align-items: center; justify-content: center; user-select: none; touch-action: none; transform: translateZ(0); }
.particle-button:active, .particle-button.holding { transform: scale(.982); filter: brightness(1.08); }
.particle-button-main { font-size: 37px; font-weight: 950; letter-spacing: .02em; }
.particle-button-sub { margin-top: 5px; font-size: 12px; font-weight: 700; opacity: .82; }
.capture-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 10px; }
.action-button, .small-button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 14px; min-height: 44px; padding: 0 13px; font-weight: 800; font-size: 13px; }
.small-button { min-height: 38px; border-radius: 12px; }
.small-button.accent { color: #d8d3ff; border-color: rgba(123,108,255,.35); background: rgba(123,108,255,.13); }
.danger-soft { color: #ff9aaa; background: rgba(255,102,122,.08); border-color: rgba(255,102,122,.2); }
.primary-wide { width: 100%; min-height: 54px; border: 0; border-radius: 16px; background: var(--text); color: #11131a; font-weight: 950; margin-top: 10px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.primary-wide span { font-size: 23px; line-height: 1; }
.pitch-head { margin-bottom: 12px; }
.counter-pill { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; font-weight: 800; font-size: 13px; }
.selected-particle { min-height: 92px; display: grid; grid-template-columns: 48px minmax(0,1fr) 48px; gap: 10px; align-items: center; padding: 10px; margin-bottom: 10px; }
.selected-center { text-align: center; display: flex; flex-direction: column; gap: 2px; }
.selected-center strong { font-size: 25px; white-space: nowrap; }
.selected-center span:last-child { color: var(--muted); font-size: 12px; }
.pitch-options { padding: 10px 12px; margin-bottom: 10px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.toggle-row > span { display: flex; flex-direction: column; gap: 2px; }
.toggle-row small { color: var(--muted); font-size: 10px; }
.toggle-row input { position: absolute; opacity: 0; }
.toggle-row i { width: 48px; height: 28px; border-radius: 999px; background: #343947; position: relative; flex: 0 0 auto; transition: .18s; }
.toggle-row i::after { content: ""; width: 22px; height: 22px; border-radius: 50%; background: white; position: absolute; top: 3px; left: 3px; transition: .18s; box-shadow: 0 2px 7px rgba(0,0,0,.3); }
.toggle-row input:checked + i { background: var(--accent); }
.toggle-row input:checked + i::after { transform: translateX(20px); }
.volume-row { border-top: 1px solid var(--line); padding-top: 10px; display: grid; grid-template-columns: auto minmax(0,1fr) 48px; gap: 10px; align-items: center; }
.volume-row label { font-size: 12px; font-weight: 800; }
.volume-row output { text-align: right; font-size: 12px; color: var(--accent-2); font-weight: 800; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.keyboard-card { overflow: hidden; margin-bottom: 10px; }
.keyboard-toolbar { min-height: 44px; padding: 6px 9px; display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; border-bottom: 1px solid var(--line); }
.keyboard-toolbar button:first-child { justify-self: start; }
.keyboard-toolbar button:last-child { justify-self: end; }
.keyboard-toolbar span { font-size: 12px; color: var(--muted); font-weight: 800; white-space: nowrap; }
.keyboard-viewport { width: 100%; overflow-x: auto; overscroll-behavior-x: contain; background: #090b0f; padding: 10px 12px 14px; }
.piano-keyboard { --white-width: 48px; position: relative; height: 178px; display: flex; width: max-content; padding-top: 1px; user-select: none; touch-action: pan-x; }
.piano-key { border: 0; padding: 0; position: relative; touch-action: none; }
.piano-key.white { width: var(--white-width); height: 172px; z-index: 1; border: 1px solid #b6bac1; border-left-width: 0; background: linear-gradient(90deg, #dadddf 0%, #ffffff 10%, #f8f8f6 72%, #d5d7d9 100%); box-shadow: inset 0 -9px 12px rgba(0,0,0,.12), 0 3px 0 #8f939a; border-radius: 0 0 8px 8px; color: #22252b; }
.piano-key.white:first-child { border-left-width: 1px; }
.piano-key.black { width: 30px; height: 106px; margin-left: -15px; margin-right: -15px; z-index: 3; border: 1px solid #050608; border-radius: 0 0 6px 6px; background: linear-gradient(90deg, #050609, #2a2e35 48%, #08090c 100%); box-shadow: inset 0 -6px 7px rgba(255,255,255,.06), 0 5px 5px rgba(0,0,0,.65); color: white; }
.piano-key.active.white { background: linear-gradient(180deg, #c9c3ff, #f4f1ff); transform: translateY(3px); box-shadow: inset 0 -4px 9px rgba(60,43,175,.18); }
.piano-key.active.black { background: linear-gradient(180deg, #7667e8, #302872); transform: translateY(3px); }
.piano-key.assigned.white { box-shadow: inset 0 -7px 0 rgba(123,108,255,.55), 0 3px 0 #8f939a; }
.piano-key.assigned.black { box-shadow: inset 0 -6px 0 rgba(123,108,255,.7), 0 5px 5px rgba(0,0,0,.65); }
.key-label { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); font-size: 10px; font-weight: 900; opacity: .75; pointer-events: none; }
.black .key-label { bottom: 7px; font-size: 8px; }
.pitch-footer { display: grid; grid-template-columns: .75fr 1.25fr; gap: 9px; }
.pitch-footer .primary-wide { margin-top: 0; }
.play-button { border: 0; min-height: 42px; border-radius: 14px; background: var(--accent); padding: 0 15px; font-weight: 900; }
.play-button.playing { background: var(--danger); }
.tempo-card { padding: 12px; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 12px; align-items: center; margin-bottom: 12px; }
.tempo-field { display: grid; grid-template-columns: auto minmax(0,1fr); gap: 4px 10px; align-items: center; }
.tempo-field label { font-size: 12px; font-weight: 800; }
.tempo-field output { grid-column: 1 / -1; color: var(--muted); font-size: 11px; }
.toggle-row.compact { min-height: 40px; }
.empty-state[hidden] { display: none; }
.empty-state { min-height: 150px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--text); }
.note-list { display: flex; flex-direction: column; gap: 9px; }
.note-card { display: grid; grid-template-columns: 44px minmax(0,1fr) auto; gap: 10px; align-items: center; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 17px; }
.note-index { width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); font-size: 12px; font-weight: 900; }
.note-main { min-width: 0; border: 0; background: transparent; color: var(--text); text-align: left; padding: 0; }
.note-main strong { font-size: 18px; }
.note-main span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.note-controls { display: grid; grid-template-columns: repeat(3,38px); gap: 5px; }
.note-controls button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-2); }
.note-length-row { grid-column: 2 / -1; display: grid; grid-template-columns: 42px minmax(0,1fr) 52px; gap: 8px; align-items: center; border-top: 1px solid var(--line); padding-top: 8px; }
.note-length-row label, .note-length-row output { color: var(--muted); font-size: 10px; }
.current-project-card { padding: 14px; }
.name-edit-row { margin-top: 8px; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; }
.name-edit-row input { min-width: 0; height: 46px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); border-radius: 13px; padding: 0 12px; font-weight: 800; }
.project-actions-grid { margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.section-title { font-size: 15px; margin: 18px 2px 9px; }
.project-list { display: flex; flex-direction: column; gap: 8px; }
.project-row { border: 1px solid var(--line); background: var(--surface); border-radius: 16px; padding: 12px; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; align-items: center; }
.project-row.current { border-color: rgba(123,108,255,.55); background: rgba(123,108,255,.09); }
.project-row button { text-align: left; border: 0; background: transparent; min-width: 0; padding: 0; }
.project-row strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-row span { display: block; color: var(--muted); font-size: 10px; margin-top: 4px; }
.project-row em { font-style: normal; color: var(--accent-2); font-size: 11px; font-weight: 800; }
.bottom-nav {
  position: fixed; z-index: 40; inset: auto 0 0 0; height: calc(70px + var(--safe-bottom)); padding: 6px 8px var(--safe-bottom); display: grid; grid-template-columns: repeat(4,1fr); gap: 4px;
  background: rgba(15,17,23,.93); backdrop-filter: blur(20px); border-top: 1px solid var(--line);
}
.nav-item { border: 0; background: transparent; color: var(--muted); border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; }
.nav-item span { font-size: 18px; line-height: 1; }
.nav-item b { font-size: 10px; white-space: nowrap; }
.nav-item.active { color: var(--text); background: rgba(123,108,255,.12); }
.modal-backdrop { position: fixed; z-index: 100; inset: 0; background: rgba(0,0,0,.68); display: flex; align-items: flex-end; padding: 16px 12px calc(16px + var(--safe-bottom)); }
.modal-backdrop[hidden] { display: none; }
.modal { width: 100%; max-width: 560px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 20px; box-shadow: 0 18px 60px rgba(0,0,0,.45); }
.modal h2 { font-size: 20px; margin-bottom: 10px; }
.modal p { margin: 8px 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.modal input { width: 100%; height: 48px; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: 13px; padding: 0 12px; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.modal-actions button { min-height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 900; }
.modal-actions .confirm { border-color: transparent; background: var(--accent); }
.toast { position: fixed; z-index: 120; left: 50%; bottom: calc(84px + var(--safe-bottom)); transform: translate(-50%, 18px); max-width: calc(100vw - 32px); background: #f4f5f8; color: #15171d; padding: 10px 14px; border-radius: 999px; font-size: 12px; font-weight: 800; opacity: 0; pointer-events: none; transition: .2s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 10px 30px rgba(0,0,0,.32); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 640px) {
  .app-shell { max-width: 560px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .topbar, .bottom-nav { left: 50%; width: 560px; transform: translateX(-50%); }
  .screen { padding-left: 20px; padding-right: 20px; }
}
@media (max-height: 700px) {
  .particle-button { min-height: 108px; }
  .piano-keyboard { height: 150px; }
  .piano-key.white { height: 144px; }
  .piano-key.black { height: 90px; }
}
