/* PicoPico Studio */
:root {
  --bg: #12141f;
  --panel: #1a1d2d;
  --panel2: #1f2335;
  --panel3: #272c47;
  --line: #343a5c;
  --line2: #464e7a;
  --deep: #0b0c14;
  --text: #eef0ff;
  --dim: #9097bf;
  --dim2: #646a90;
  --red: #ff4d5e;
  --yellow: #ffc83d;
  --blue: #4d8dff;
  --green: #3ddc84;
  --lcd: #0c1a13;
  --lcd-text: #8dffb8;
  --pix: 'Silkscreen', 'DotGothic16', ui-monospace, monospace;
  --jp: 'DotGothic16', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  --ui: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', 'Segoe UI', system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 13px/1.45 var(--ui);
  display: flex; flex-direction: column; overflow: hidden;
  user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, select:focus-visible, .dragnum:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
select {
  font: 12px var(--ui); color: var(--text); background: var(--panel3); border: 1px solid var(--line);
  border-radius: 6px; height: 28px; padding: 0 6px; cursor: pointer;
}
select:hover { border-color: var(--line2); }

/* ---------- 上のバー ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 14px; background: linear-gradient(#232741, #1a1d2d);
  border-bottom: 1px solid var(--deep); box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
  position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 9px; }
.logo-dots { display: grid; grid-template-columns: repeat(2, 9px); gap: 3px; transform: rotate(45deg); margin: 0 3px; }
.logo-dots i { width: 9px; height: 9px; border-radius: 50%; box-shadow: inset 0 -2px 0 rgba(0,0,0,.25); }
.logo-dots i:nth-child(1) { background: var(--blue); }
.logo-dots i:nth-child(2) { background: var(--red); }
.logo-dots i:nth-child(3) { background: var(--green); }
.logo-dots i:nth-child(4) { background: var(--yellow); }
.logo-text { font-family: var(--pix); font-weight: 700; font-size: 15px; letter-spacing: 1px; line-height: 1; }
.logo-text span { display: block; margin-top: 3px; font-size: 9px; font-weight: 400; color: var(--dim); letter-spacing: 4.5px; }

.transport { display: flex; align-items: center; gap: 10px; }
.play-btn {
  width: 46px; height: 46px; border-radius: 50%; border: none; padding: 0;
  display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #ff8a94, #ef3a48 55%, #c0202e);
  box-shadow: 0 3px 0 #7d1019, 0 6px 16px rgba(239,58,72,.3), inset 0 1px 0 rgba(255,255,255,.4);
  transition: transform .06s, box-shadow .06s;
}
.play-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #7d1019, 0 3px 8px rgba(239,58,72,.3), inset 0 1px 0 rgba(255,255,255,.4); }
.play-btn svg { width: 18px; height: 18px; fill: #fff; filter: drop-shadow(0 1px 0 rgba(0,0,0,.3)); }
.play-btn .i-stop { display: none; }
body.playing .play-btn .i-play { display: none; }
body.playing .play-btn .i-stop { display: block; }
body.playing .play-btn { animation: beat 0.9s ease-in-out infinite; }
@keyframes beat { 50% { box-shadow: 0 3px 0 #7d1019, 0 6px 26px rgba(239,58,72,.6), inset 0 1px 0 rgba(255,255,255,.4); } }

.rec-btn {
  height: 30px; padding: 0 10px; border-radius: 15px; display: flex; align-items: center; gap: 6px;
  font-family: var(--pix); font-size: 11px; color: var(--dim);
  background: var(--panel3); border: 1px solid var(--line); box-shadow: 0 2px 0 var(--deep);
}
.rec-btn i { width: 9px; height: 9px; border-radius: 50%; background: #5a2a33; }
.rec-btn.on { color: #fff; background: #5a1d27; border-color: #ff4d5e; }
.rec-btn.on i { background: var(--red); box-shadow: 0 0 8px var(--red); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .25; } }

.lcd {
  display: flex; align-items: stretch; gap: 10px; padding: 3px 10px 4px;
  background: var(--lcd); border: 2px solid #050a08; border-radius: 7px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,.7), 0 1px 0 rgba(255,255,255,.05);
}
.lcd-sep { width: 1px; background: #1d3a2a; }
.lcd label { display: block; font-family: var(--pix); font-size: 8px; color: #4c8a68; letter-spacing: 1px; line-height: 1.2; }
.lcd-val, .dragnum {
  font-family: var(--pix); font-size: 19px; line-height: 1.05; color: var(--lcd-text);
  text-shadow: 0 0 8px rgba(120,255,170,.45); min-width: 50px;
}
.dragnum { cursor: ns-resize; border-radius: 3px; }
.dragnum:hover, .dragnum.active { background: rgba(141,255,184,.08); }
.dragnum input {
  width: 56px; font: inherit; color: inherit; background: #081009; border: 1px solid #2c6a49;
  border-radius: 3px; padding: 0 2px;
}

.ctrls { display: flex; align-items: center; gap: 12px; }
.field { display: flex; align-items: center; gap: 6px; }
.field > span { font-size: 11px; color: var(--dim); white-space: nowrap; }
.toggle {
  height: 28px; padding: 0 10px; border-radius: 6px; white-space: nowrap;
  background: var(--panel3); border: 1px solid var(--line); box-shadow: 0 2px 0 var(--deep);
  font-family: var(--pix); font-size: 11px; color: var(--dim);
}
.toggle:hover { border-color: var(--line2); color: var(--text); }
.toggle.on { color: #1a1407; background: var(--yellow); border-color: #ffdc7a; box-shadow: 0 2px 0 #8a6a12, 0 0 12px rgba(255,200,61,.25); }
#ghostBtn { font-family: var(--jp); font-size: 12px; }

.scope {
  width: 120px; height: 34px; image-rendering: pixelated; image-rendering: crisp-edges;
  background: var(--lcd); border: 2px solid #050a08; border-radius: 7px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,.7);
}

.actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.icon-btn, .btn {
  height: 32px; min-width: 32px; padding: 0 8px; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  background: var(--panel3); border: 1px solid var(--line); box-shadow: 0 2px 0 var(--deep);
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover, .btn:hover, .btn.open { border-color: var(--line2); background: #2e3453; }
.icon-btn:active, .btn:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--deep); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.btn .caret { font-size: 9px; color: var(--dim); }
.icon-btn.help { font-family: var(--pix); font-weight: 700; color: var(--yellow); }

/* ---------- ノブ ---------- */
.knob { width: 30px; height: 30px; flex: none; cursor: ns-resize; touch-action: none; }
.knob svg { width: 100%; height: 100%; overflow: visible; }
.knob .kt { fill: none; stroke: #0e1019; stroke-width: 3.2; stroke-linecap: round; }
.knob .kv { fill: none; stroke: var(--c, var(--yellow)); stroke-width: 3.2; stroke-linecap: round; filter: drop-shadow(0 0 2px var(--c, var(--yellow))); }
.knob .kb { fill: #3a4064; stroke: #50587f; stroke-width: 1; }
.knob .kp { stroke: #fff; stroke-width: 2.2; stroke-linecap: round; }
.knob:hover .kb, .knob.active .kb { fill: #474e78; }
.knob.small { width: 26px; height: 26px; }
.tip {
  position: fixed; z-index: 90; pointer-events: none; padding: 3px 7px; border-radius: 5px;
  background: #0b0c14; border: 1px solid var(--line2); font-family: var(--pix); font-size: 10px;
  opacity: 0; transition: opacity .1s; white-space: nowrap;
}
.tip.show { opacity: 1; }

/* ---------- メイン ---------- */
.main { flex: 1; display: flex; min-height: 0; }
.layers {
  width: 272px; flex: none; display: flex; flex-direction: column; min-height: 0;
  background: #161827; border-right: 1px solid var(--deep);
}
.panel-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 14px 6px; font-size: 12px; color: var(--dim); font-family: var(--jp);
}
.count { font-family: var(--pix); font-size: 10px; color: var(--dim2); }
.layer-list { flex: 1; overflow-y: auto; padding: 2px 8px 8px; display: flex; flex-direction: column; gap: 6px; }
.layer-list::-webkit-scrollbar { width: 8px; }
.layer-list::-webkit-scrollbar-thumb { background: #2c3150; border-radius: 4px; }

.layer {
  position: relative; flex: none; border-radius: 9px; padding: 7px 8px 7px 13px; cursor: pointer;
  background: var(--panel2); border: 1px solid #2a2f4c;
  transition: background .12s, border-color .12s, box-shadow .12s, opacity .12s;
}
.layer::before {
  content: ''; position: absolute; left: -1px; top: -1px; bottom: -1px; width: 6px;
  border-radius: 9px 0 0 9px; background: var(--c);
}
.layer:hover { background: #242942; }
.layer.sel { background: #282e4d; border-color: var(--c); box-shadow: 0 0 0 1px var(--c), 0 6px 18px rgba(0,0,0,.35); }
.layer.silent .layer-name, .layer.silent .mini, .layer.silent .inst-chip { opacity: .4; }
.layer-top { display: flex; align-items: center; gap: 5px; min-width: 0; }
.led {
  width: 9px; height: 9px; flex: none; border-radius: 2px; background: #0e1019;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); transition: background .08s, box-shadow .08s;
}
.led.on { background: var(--c); box-shadow: 0 0 9px var(--c), inset 0 0 0 1px rgba(255,255,255,.4); transition: none; }
.layer-name {
  flex: 1; min-width: 0; font-family: var(--jp); font-size: 14px; line-height: 20px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.layer-name input {
  width: 100%; font: inherit; color: var(--text); background: #0e1019; border: 1px solid var(--c);
  border-radius: 4px; padding: 0 4px; outline: none;
}
.ms, .more {
  width: 23px; height: 21px; padding: 0; flex: none; border-radius: 5px;
  font-family: var(--pix); font-size: 10px; color: var(--dim);
  background: #2a2f4a; border: 1px solid #393f63; box-shadow: 0 1px 0 var(--deep);
}
.ms:hover, .more:hover, .more.open { color: var(--text); border-color: var(--line2); }
.ms.m.on { background: #ff8f40; border-color: #ffb27a; color: #2a1405; }
.ms.s.on { background: var(--yellow); border-color: #ffdc7a; color: #2a2005; }
.more { font-family: var(--ui); font-size: 13px; line-height: 1; }
.layer-mid { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.inst-chip {
  flex: 1; min-width: 0; height: 30px; display: flex; align-items: center; gap: 7px; padding: 0 8px;
  border-radius: 7px; background: #131522; border: 1px solid #333959; text-align: left;
}
.inst-chip:hover, .inst-chip.open { border-color: var(--c, var(--line2)); background: #171a2b; }
.inst-chip .glyph-svg { width: 28px; height: 14px; flex: none; color: var(--c, var(--text)); }
.inst-chip .iname { font-family: var(--pix); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inst-chip .caret { margin-left: auto; font-size: 9px; color: var(--dim); }
.mini { display: block; width: 100%; height: 22px; margin-top: 7px; border-radius: 5px; background: #111320; }

.add-layer {
  margin: 4px 8px 10px; height: 38px; flex: none; border-radius: 9px; font-family: var(--jp); font-size: 13px;
  color: var(--dim); background: transparent; border: 1px dashed #3a4166;
}
.add-layer:hover, .add-layer.open { color: var(--text); border-color: var(--green); background: rgba(61,220,132,.07); }

.editor { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.editor-head {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px; min-height: 44px;
  background: var(--panel); border-bottom: 1px solid var(--deep);
}
.swatch { width: 12px; height: 12px; flex: none; border-radius: 3px; background: var(--c); box-shadow: 0 0 10px var(--c); }
.ed-name { font-family: var(--jp); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30%; }
.ed-inst { flex: none; max-width: 200px; }
.spacer { flex: 1; }
.ed-tools { display: flex; align-items: center; gap: 8px; }
.seg { display: flex; align-items: center; height: 28px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel3); box-shadow: 0 2px 0 var(--deep); overflow: hidden; }
.seg button { height: 100%; min-width: 28px; padding: 0 8px; border: none; background: transparent; font-size: 13px; }
.seg button:hover { background: #343a5c; }
.seg span, .seg #zoomFit { font-family: var(--pix); font-size: 10px; padding: 0 6px; color: var(--dim); }
.seg #zoomFit { font-family: var(--jp); font-size: 12px; color: var(--text); border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.roll-wrap { flex: 1; position: relative; min-height: 0; overflow: hidden; }
.roll-canvas { position: absolute; left: 0; top: 0; touch-action: none; }

.status {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 4px 12px; min-height: 28px; background: #0f111b; border-top: 1px solid var(--deep);
  font-size: 12px; color: var(--dim); white-space: nowrap; overflow: hidden;
}
.hint { overflow: hidden; text-overflow: ellipsis; }
.hint b { color: var(--text); font-weight: 600; }
.status-right { font-family: var(--pix); font-size: 10px; color: var(--dim); flex: none; }
kbd {
  font-family: var(--pix); font-size: 10px; color: var(--text); padding: 0 4px; border-radius: 4px;
  background: var(--panel3); border: 1px solid var(--line); border-bottom-width: 2px;
}

/* ---------- ポップオーバー ---------- */
.popover {
  position: fixed; z-index: 50; padding: 10px; border-radius: 12px;
  background: #1c2034; border: 1px solid #3c4370; box-shadow: 0 18px 44px rgba(0,0,0,.6);
  animation: pop .12s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }
.picker { width: 430px; max-width: calc(100vw - 16px); }
.picker-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 2px 4px 10px; }
.picker-head b { font-family: var(--jp); font-size: 14px; font-weight: 400; }
.picker-head span { font-size: 11px; color: var(--dim); }
.picker-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tile {
  display: grid; grid-template-columns: 46px 1fr; grid-template-rows: auto auto; column-gap: 9px; align-items: center;
  padding: 8px; border-radius: 9px; text-align: left; background: #252a43; border: 1px solid #343a5c;
}
.tile:hover { background: #2c3252; border-color: #56608f; }
.tile:active { transform: translateY(1px); }
.tile.cur { background: #2d3458; border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }
.tile .glyph { grid-row: span 2; width: 46px; height: 32px; border-radius: 7px; display: grid; place-items: center; background: #111320; color: var(--c, var(--text)); }
.tile .glyph-svg { width: 34px; height: 18px; }
.tile b { font-family: var(--pix); font-size: 11px; font-weight: 400; line-height: 1.2; }
.tile small { font-size: 11px; color: var(--dim); line-height: 1.3; }
.menu { min-width: 210px; padding: 6px; }
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: none; border-radius: 7px;
  background: transparent; text-align: left; font-size: 13px;
}
.menu button:hover { background: #2c3252; }
.menu button .ic { width: 16px; text-align: center; color: var(--dim); }
.menu button.danger { color: #ff8a94; }
.menu hr { border: none; border-top: 1px solid #30365a; margin: 5px 4px; }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; padding: 6px 10px 8px; }
.swatches i { width: 18px; height: 18px; border-radius: 5px; cursor: pointer; box-shadow: inset 0 -2px 0 rgba(0,0,0,.25); }
.swatches i:hover, .swatches i.cur { outline: 2px solid #fff; outline-offset: 1px; }

/* ---------- ヘルプ ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px;
  background: rgba(5,6,12,.62); backdrop-filter: blur(3px);
}
.modal-card {
  width: min(780px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: #1c2034; border: 1px solid #3c4370; border-radius: 14px; padding: 18px 22px 16px;
  box-shadow: 0 24px 60px rgba(0,0,0,.6); user-select: text;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.modal-head h2 { margin: 0; font-family: var(--jp); font-weight: 400; font-size: 20px; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 26px; }
.help-grid h3 { font-family: var(--pix); font-size: 12px; color: var(--yellow); margin: 12px 0 6px; letter-spacing: 1px; }
.help-grid dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 12.5px; }
.help-grid dt { color: var(--text); white-space: nowrap; }
.help-grid dd { margin: 0; color: var(--dim); }
.help-foot { margin: 16px 0 0; font-size: 12px; color: var(--dim); }

.toast {
  position: fixed; left: 50%; bottom: 46px; z-index: 80; transform: translate(-50%, 16px);
  padding: 9px 16px; border-radius: 9px; background: #2a3050; border: 1px solid #4a5384;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); font-size: 13px; opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.drop-hint::after {
  content: '.json をドロップして開く'; position: fixed; inset: 10px; z-index: 95; display: grid; place-items: center;
  border: 3px dashed var(--green); border-radius: 16px; background: rgba(10,20,15,.75);
  font-family: var(--jp); font-size: 22px; color: var(--green); pointer-events: none;
}

/* ---------- 画面が狭いとき ---------- */
@media (max-width: 1240px) {
  .ctrls .field > span, .master > span { display: none; }
  .scope { width: 84px; }
  #scale { width: 86px; }
}
@media (max-width: 1100px) {
  .topbar { gap: 10px; padding: 7px 10px; }
  .ctrls { gap: 8px; }
  .logo-text { display: none; }
  .layers { width: 240px; }
  .help-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .scope, .master, .brand, .lcd-sep, .lcd-cell + .lcd-sep + .lcd-cell { display: none; }
  .ed-tools .oct { display: none; }
  .layers { width: 212px; }
  .layer .knob[data-k="pan"] { display: none; }
}
@media (max-width: 720px) {
  #redoBtn, .rec-btn { font-size: 0; }
  #redoBtn { display: none; }
  .layers { width: 172px; }
  .inst-chip .iname { display: none; }
  .zoom #zoomFit { display: none; }
  .ed-inst .iname { display: inline; }
}
