/* Pinball Maker — Copyright (c) 2026 FUJIYAMA2236 — MIT License (see LICENSE) */
/* ピンボールメーカー エディタ */

/* 2言語の文章ブロック：表示中の言語のものだけ見せる */
html[lang="ja"] [data-lang="en"], html[lang="en"] [data-lang="ja"] { display: none !important; }

:root {
  --bg: #0d1020;
  --panel: #151a2e;
  --panel2: #1c2240;
  --panel3: #252c50;
  --line: #2b3256;
  --text: #e8ebff;
  --muted: #8d95bd;
  --accent: #36e0ff;
  --accent2: #ff3d81;
  --ok: #7dff6a;
  --warn: #ffd23f;
  --radius: 10px;
  --font: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 13px/1.5 var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
kbd {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 4px;
  background: var(--panel3); border: 1px solid var(--line); border-bottom-width: 2px;
  font: 600 11px/18px var(--font); text-align: center;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
svg .fill { fill: currentColor; stroke: none; }

/* ------------------------------------------------------------ 上部バー */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: linear-gradient(180deg, #181d36, #12162a);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto; min-width: 0; overflow-x: auto; scrollbar-width: none;
}
.topbar::-webkit-scrollbar { display: none; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 900; font-size: 15px; white-space: nowrap; margin-right: 6px; }
.logo {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 15%, #c9d4ff 30%, #5b6aa8 75%, #2a3060);
  box-shadow: 0 0 10px rgba(54, 224, 255, .6);
}
.tb-group { display: flex; gap: 4px; padding-left: 10px; border-left: 1px solid var(--line); }
.tb {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  border: 1px solid transparent; border-radius: 8px; background: transparent; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.tb:hover { background: var(--panel3); }
.tb:active { transform: translateY(1px); }
.tb.icon { width: 34px; padding: 0; justify-content: center; }
.tb:disabled { opacity: .35; pointer-events: none; }
.tb.play { background: linear-gradient(90deg, #1fc8ec, #2f8cff); color: #fff; font-weight: 800; box-shadow: 0 4px 14px rgba(47, 140, 255, .35); }
.tb.play:hover { filter: brightness(1.1); }
.tb.export { background: linear-gradient(90deg, #ff3d81, #ff7a45); color: #fff; font-weight: 800; box-shadow: 0 4px 14px rgba(255, 61, 129, .3); }
.tb.export:hover { filter: brightness(1.1); }
.title-input {
  min-width: 120px; width: 220px; height: 34px; padding: 0 12px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--panel2);
  font-weight: 800; letter-spacing: .03em;
}
.title-input:focus { outline: none; border-color: var(--accent); }
.spacer { flex: 1; }

/* ------------------------------------------------------------ レイアウト */
.main { flex: 1; min-height: 0; display: grid; grid-template-columns: 196px 1fr 300px; }
.palette, .inspector { background: var(--panel); overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--panel3) transparent; }
.palette { border-right: 1px solid var(--line); padding: 10px 10px 16px; }
.inspector { border-left: 1px solid var(--line); }
.panel-title { font-size: 11px; font-weight: 800; letter-spacing: .15em; color: var(--muted); margin: 2px 2px 8px; }

/* パレット */
.parts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.part-cat { grid-column: 1 / -1; font-size: 11px; color: var(--muted); font-weight: 700; margin: 8px 2px 0; }
.part-cat:first-child { margin-top: 0; }
.part {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px 7px; border-radius: var(--radius);
  background: var(--panel2); border: 1px solid var(--line);
  cursor: grab; touch-action: pan-x; user-select: none; -webkit-user-select: none;
  transition: border-color .15s, background .15s, transform .1s;
}
.part:hover { border-color: var(--accent); background: var(--panel3); }
.part:active { cursor: grabbing; transform: scale(.97); }
.part canvas { width: 52px; height: 52px; pointer-events: none; }
.part span { font-size: 11px; font-weight: 700; white-space: nowrap; pointer-events: none; }
.palette-hint { color: var(--muted); font-size: 11px; text-align: center; margin: 12px 0 0; line-height: 1.6; }
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 100; pointer-events: none;
  width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 12px;
  background: rgba(21, 26, 46, .9); border: 2px solid var(--accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5); display: grid; place-items: center;
}
.drag-ghost canvas { width: 52px; height: 52px; }
.drag-ghost.over { opacity: 0; }

/* ステージ */
.stage-wrap {
  position: relative; min-width: 0; min-height: 0; overflow: hidden;
  background-color: #0a0c18;
  background-image: radial-gradient(rgba(255, 255, 255, .06) 1px, transparent 1px);
  background-size: 22px 22px;
}
#stage { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.stage-tools {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px; padding: 4px;
  background: rgba(21, 26, 46, .92); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4); backdrop-filter: blur(6px); white-space: nowrap;
}
.stage-tools button { height: 30px; min-width: 32px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; font-weight: 800; }
.stage-tools button:hover { background: var(--panel3); }
.stage-tools .divider { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.chk { display: inline-flex; align-items: center; gap: 5px; padding: 0 8px; height: 30px; border-radius: 8px; cursor: pointer; user-select: none; }
.chk:hover { background: var(--panel3); }
.chk input { accent-color: var(--accent); margin: 0; }

/* ステータスバー */
.statusbar {
  flex: 0 0 auto; display: flex; gap: 16px; padding: 5px 14px; padding-bottom: max(5px, env(safe-area-inset-bottom));
  font-size: 12px; color: var(--muted); background: #10132a; border-top: 1px solid var(--line);
}
.statusbar .status { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.statusbar .credit { flex: 0 0 auto; opacity: .6; white-space: nowrap; }
.statusbar b { color: var(--text); }
.tb.lang { border-color: var(--line); }

/* ------------------------------------------------------------ インスペクタ */
.insp-head { display: flex; gap: 12px; align-items: center; padding: 14px 16px 12px; border-bottom: 1px solid var(--line); background: var(--panel2); position: sticky; top: 0; z-index: 2; }
.insp-head canvas { width: 46px; height: 46px; flex: 0 0 auto; border-radius: 10px; background: var(--bg); }
.insp-name { font-size: 16px; font-weight: 900; }
.insp-desc { font-size: 12px; color: var(--muted); line-height: 1.5; margin-top: 2px; }
.sec { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sec h3 { margin: 0 0 10px; font-size: 11px; letter-spacing: .12em; color: var(--muted); font-weight: 800; }
.sec details summary { cursor: pointer; font-size: 11px; letter-spacing: .12em; color: var(--muted); font-weight: 800; list-style: none; }
.sec details summary::before { content: "▸ "; }
.sec details[open] summary::before { content: "▾ "; }
.sec details[open] summary { margin-bottom: 10px; }
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field > label, .field-label { display: block; font-weight: 700; margin-bottom: 5px; font-size: 12px; }
.field .help { display: block; font-weight: 400; font-size: 11px; color: var(--muted); line-height: 1.4; }
.field .mixed { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 999px; background: rgba(255,210,63,.16); color: #ffd23f; font-size: 10px; font-weight: 700; vertical-align: 1px; }
.range-row { display: flex; align-items: center; gap: 8px; }
.range-row input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.num {
  width: 66px; height: 28px; padding: 0 6px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); text-align: right; font-variant-numeric: tabular-nums;
}
.num:focus, .txt:focus { outline: none; border-color: var(--accent); }
.txt { width: 100%; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); resize: vertical; }
.xy { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 6px; align-items: center; }
.xy .num { width: 100%; }
.xy span { color: var(--muted); font-weight: 700; }
.swatches { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.sw {
  width: 24px; height: 24px; border-radius: 7px; border: 2px solid transparent; padding: 0;
  background: var(--c); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .15);
}
.sw:hover { transform: scale(1.12); }
.sw.on { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.sw.auto { width: auto; padding: 0 7px; font-size: 11px; font-weight: 800; background: var(--panel3); }
.picker { position: relative; width: 24px; height: 24px; border-radius: 7px; overflow: hidden; border: 1px dashed var(--muted); background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); }
.picker input { position: absolute; inset: -6px; width: 40px; height: 40px; opacity: 0; cursor: pointer; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 3px; padding: 3px; border-radius: 9px; background: var(--bg); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 6px; font-weight: 700; min-width: 32px; }
.seg button:hover { background: var(--panel3); }
.seg button.on { background: var(--accent); color: #002230; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 700; }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.theme {
  height: 46px; border-radius: 9px; border: 2px solid transparent; position: relative; overflow: hidden;
  font-size: 11px; font-weight: 800; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 3px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
}
.theme::before { content: ""; position: absolute; left: 20%; right: 20%; top: 10px; height: 3px; border-radius: 3px; background: var(--w); box-shadow: 0 0 6px var(--w); }
.theme:hover { border-color: var(--muted); }
.theme.on { border-color: var(--accent); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.keycfg { display: grid; gap: 7px; }
.keyrow { display: grid; grid-template-columns: 92px 1fr; gap: 8px; align-items: center; }
.keyname { font-weight: 700; font-size: 11.5px; line-height: 1.3; }
.keychips { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.keychip { display: inline-flex; align-items: center; gap: 1px; padding: 2px 1px 2px 3px; border-radius: 6px; background: var(--panel3); }
.keychip kbd { background: var(--bg); color: var(--text); border-color: var(--line); }
.keyx { width: 18px; height: 18px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: var(--muted); line-height: 1; }
.keyx:hover { color: #ff8aa8; background: rgba(255, 61, 129, .15); }
.keyadd { height: 24px; padding: 0 8px; border: 1px dashed var(--line); border-radius: 6px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; }
.keyadd:hover { color: var(--text); border-color: var(--accent); }
.keyadd.capturing { border-style: solid; border-color: var(--accent); color: var(--accent); animation: keyblink .7s infinite alternate; }
@keyframes keyblink { to { opacity: .45; } }
.keyfoot { margin-top: 4px; }
.bg-thumb { height: 96px; margin-bottom: 8px; border-radius: 8px; border: 1px solid var(--line); background: #000 center / cover no-repeat; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel2); font-weight: 700; white-space: nowrap;
}
.btn:hover { background: var(--panel3); border-color: #3a4372; }
.btn.danger { color: #ff8aa8; }
.btn.danger:hover { background: rgba(255, 61, 129, .15); border-color: var(--accent2); }
.btn.primary { background: linear-gradient(90deg, #1fc8ec, #2f8cff); border: 0; color: #fff; }
.btn.big { height: 44px; font-size: 15px; padding: 0 28px; }
.btn.wide { grid-column: 1 / -1; }
.warns { margin: 0; padding: 0; list-style: none; }
.warns li { padding: 7px 10px; border-radius: 8px; background: rgba(255, 210, 63, .1); border: 1px solid rgba(255, 210, 63, .35); color: var(--warn); font-size: 12px; margin-bottom: 6px; }
.warns li.good { background: rgba(125, 255, 106, .08); border-color: rgba(125, 255, 106, .3); color: var(--ok); }
.counts { display: flex; flex-wrap: wrap; gap: 5px; }
.counts span { padding: 2px 8px; border-radius: 999px; background: var(--panel3); font-size: 11px; }
.note { font-size: 11px; color: var(--muted); margin: 6px 0 0; line-height: 1.5; }

/* ------------------------------------------------------------ モーダル */
.modal {
  position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center;
  padding: 20px; background: rgba(4, 6, 16, .72); backdrop-filter: blur(4px);
}
.modal.show { display: flex; }
.dialog {
  width: min(520px, 100%); max-height: 100%; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6); padding: 18px 22px 22px;
}
.dialog.wide { width: min(860px, 100%); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-head h2 { margin: 0; font-size: 19px; }
.x { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--panel2); font-size: 20px; line-height: 1; }
.x:hover { background: var(--panel3); }
.dlg-lead { color: var(--muted); margin: 6px 0 16px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dlg-actions { display: flex; justify-content: center; margin: 18px 0 6px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.tpl {
  display: flex; flex-direction: column; text-align: left; padding: 10px; gap: 8px;
  border-radius: 14px; border: 2px solid var(--line); background: var(--panel2);
  transition: border-color .15s, transform .15s;
}
.tpl:hover { border-color: var(--accent); transform: translateY(-2px); }
.tpl canvas { width: 100%; aspect-ratio: 560 / 1000; border-radius: 8px; background: #000; }
.tpl b { font-size: 14px; }
.tpl small { color: var(--muted); line-height: 1.45; }
.file-row { display: flex; align-items: center; gap: 6px; }
.file-row input { flex: 1; height: 38px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); font-weight: 700; }
.file-row input:focus { outline: none; border-color: var(--accent); }
.file-row span { color: var(--muted); font-weight: 700; }
.tips { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--panel2); }
.tips h3 { margin: 0 0 6px; font-size: 13px; }
.tips ul { margin: 0; padding-left: 18px; color: var(--muted); }
.tips li { margin: 3px 0; }
.help { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 10px; }
.help h3 { font-size: 14px; margin: 14px 0 4px; color: var(--accent); }
.help h3:first-child { margin-top: 0; }
.help p { margin: 0; color: #c6cbe8; }
.keys { width: 100%; border-collapse: collapse; }
.keys td { padding: 4px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.keys td:first-child { color: #c6cbe8; padding-right: 10px; white-space: nowrap; }
.about { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); color: #c6cbe8; }
.about h3 { font-size: 14px; margin: 0 0 6px; color: var(--accent); }
.about p { margin: 0 0 8px; }
.about summary { cursor: pointer; font-weight: 700; color: var(--muted); }
.license { margin: 8px 0 0; padding: 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line);
  font: 11px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; white-space: pre-wrap; color: var(--muted); }

/* テストプレイ */
.play-modal { flex-direction: column; padding: 0; background: rgba(4, 6, 16, .94); align-items: stretch; justify-content: flex-start; }
.play-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.play-tip { color: var(--muted); font-size: 12px; }
.play-area { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.device { position: relative; background: #000; }
.device iframe { border: 0; display: block; width: 100%; height: 100%; background: #04050c; }
.play-area.pc .device { position: absolute; inset: 0; }
.play-area.phone .device {
  width: 390px; height: 844px; flex: 0 0 auto; border-radius: 34px; overflow: hidden;
  box-shadow: 0 0 0 10px #22263a, 0 0 0 12px #3a4060, 0 30px 80px rgba(0, 0, 0, .7);
  transform-origin: center center;
}

/* コンテキストメニュー・トースト */
.ctxmenu {
  position: fixed; z-index: 80; display: none; min-width: 210px; padding: 5px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .55);
}
.ctxmenu.show { display: block; }
.ctxmenu button { display: flex; width: 100%; justify-content: space-between; gap: 18px; padding: 7px 10px; border: 0; border-radius: 6px; background: transparent; text-align: left; }
.ctxmenu button:hover { background: var(--panel3); }
.ctxmenu button.danger { color: #ff8aa8; }
.ctxmenu kbd { background: transparent; border: 0; color: var(--muted); font-weight: 400; }
.ctxmenu .sep { height: 1px; background: var(--line); margin: 4px 6px; }
.toast {
  position: fixed; left: 50%; bottom: 48px; z-index: 90; transform: translate(-50%, 20px);
  padding: 10px 18px; border-radius: 999px; background: #f2f4ff; color: #12162a; font-weight: 800;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #ff3d81; color: #fff; }

/* ------------------------------------------------------------ 狭い画面（タブレット・スマホ） */
@media (max-width: 1080px) {
  .main { grid-template-columns: 176px 1fr 270px; }
  .tb span { display: none; }
  .tb { padding: 0 9px; }
  .tb.play span, .tb.export span, .tb.lang span { display: inline; }
}
@media (max-width: 820px) {
  .brand-name { display: none; }
  .title-input { width: 140px; }
  .tb.play span, .tb.export span, .tb.lang span { display: none; }
  .main { display: flex; flex-direction: column; }
  .palette { flex: 0 0 auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px 8px; overflow-x: auto; overflow-y: hidden; }
  .palette .panel-title, .palette-hint, .part-cat { display: none; }
  .parts { display: flex; gap: 6px; width: max-content; }
  .part { width: 66px; padding: 4px 2px 5px; }
  .part canvas { width: 40px; height: 40px; }
  .part span { font-size: 10px; }
  .stage-wrap { flex: 1; min-height: 240px; }
  .inspector { flex: 0 0 auto; max-height: 36vh; border-left: 0; border-top: 1px solid var(--line); }
  .insp-head { padding: 10px 14px; }
  .help { grid-template-columns: 1fr; }
  .play-tip { display: none; }
  .statusbar { display: none; }
}
@media (max-width: 600px) {
  .brand, .title-input, .tb.lang span { display: none; }
  .topbar { gap: 4px; padding-left: 8px; padding-right: 8px; }
  .tb-group { padding-left: 4px; gap: 2px; }
  .tb { padding: 0 8px; }
}
