:root {
  --bg: #0b0f14; --panel: #121922; --panel2: #18212c; --line: #243140; --text: #dce6ee; --muted: #8aa0b2;
  --accent: #2fd6c3; --accent2: #20b8a5; --warn: #ffc04d; --ok: #4be38a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif; font-size: 14px; }
button { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button:hover { border-color: #3a5166; }
button:active { background: #223041; }
button.primary { background: var(--accent2); border-color: var(--accent2); color: #04110f; font-weight: 600; }
a { color: var(--accent); }

.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: #0e141b; }
.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.logo { border-radius: 6px; }
.tag { color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }
.icon-btn { width: 32px; height: 32px; border-radius: 50%; padding: 0; font-weight: 700; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; padding: 6px 12px; }
.seg button.on { background: var(--accent2); color: #04110f; font-weight: 600; }
.seg.small button { padding: 4px 9px; font-size: 12px; }

.layout { display: grid; gap: 8px; padding: 8px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: minmax(300px, 1fr) auto auto; grid-template-areas: "v3 echo" "ctrl ctrl" "views views";
  height: calc(100vh - 49px - 34px); min-height: 640px; }
.pane { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; position: relative; min-width: 0; }
.pane3d { grid-area: v3; overflow: hidden; }
.paneEcho { grid-area: echo; display: flex; flex-direction: column; overflow: hidden; background: #000; }
.paneCtrl { grid-area: ctrl; padding: 8px 10px; }
.paneViews { grid-area: views; padding: 8px; }
.view3d { position: absolute; inset: 0; touch-action: none; }
.view3d canvas { display: block; touch-action: none; }
.overlay-tl { position: absolute; left: 8px; top: 8px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.overlay-tr { position: absolute; right: 8px; top: 8px; }
.chip { padding: 4px 9px; font-size: 12px; background: rgba(24,33,44,.85); }
.layers { background: rgba(18,25,34,.92); border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; font-size: 13px; max-width: 220px; }
.layers summary { cursor: pointer; padding: 3px 0; color: var(--muted); }
.layers label { display: flex; gap: 6px; align-items: center; padding: 2px 0; }
.hint3d { position: absolute; left: 8px; bottom: 6px; right: 8px; font-size: 11px; color: var(--muted); pointer-events: none; text-shadow: 0 1px 2px #000; }

.echo-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; }
#echo { max-width: 100%; max-height: 100%; aspect-ratio: 640 / 500; width: auto; height: 100%; object-fit: contain; display: block; }
.echo-bar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 6px 10px; background: #0b1016; border-top: 1px solid var(--line); }
.view-name { position: absolute; right: 10px; top: 8px; color: #9fd8cf; font-size: 13px; text-align: right; pointer-events: none; text-shadow: 0 1px 2px #000; }
.row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.row span { min-width: 3.2em; }
.row input[type=range] { flex: 1; min-width: 90px; accent-color: var(--accent2); }
.row output { min-width: 3.4em; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.chk { font-size: 12px; color: var(--muted); display: flex; gap: 5px; align-items: center; }
.success { position: absolute; top: 46px; left: 50%; transform: translateX(-50%); background: rgba(40,190,110,.92); color: #03140a; font-weight: 800; font-size: 20px; padding: 6px 18px; border-radius: 999px; box-shadow: 0 0 24px rgba(75,227,138,.6); animation: pop .35s ease-out; }
@keyframes pop { from { transform: translateX(-50%) scale(.6); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

.ctrl-grid { display: grid; grid-template-columns: auto 1fr 1.3fr 1.6fr; gap: 10px 18px; align-items: start; }
.ctrl-group h3 { margin: 0 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.dpad { display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 34px); gap: 3px; }
.dpad button { padding: 0; font-size: 11px; line-height: 1.1; }
.dpad [data-act="z+"] { grid-column: 2; grid-row: 1; }
.dpad [data-act="th-"] { grid-column: 1; grid-row: 2; }
.dpad [data-act="th+"] { grid-column: 3; grid-row: 2; }
.dpad [data-act="z-"] { grid-column: 2; grid-row: 3; }
.btnrow { display: flex; gap: 6px; margin-bottom: 4px; }
.btnrow button { flex: 1; font-size: 12px; padding: 6px 4px; }
.practice { background: var(--panel2); border-radius: 10px; padding: 8px 10px; min-height: 196px; }
.guide { min-height: 72px; }
.muted { color: var(--muted); font-size: 12px; margin: 4px 0; }
.match { display: flex; align-items: center; gap: 10px; }
.meter { flex: 1; height: 10px; background: #0c1218; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.meter > i { display: block; height: 100%; background: linear-gradient(90deg, #d9534f, var(--warn), var(--ok)); transition: width .15s; }
.pct { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right; }
.guide { list-style: none; margin: 6px 0; padding: 0; }
.guide li { padding: 3px 0; font-size: 13px; display: flex; gap: 8px; }
.guide li b { color: var(--warn); width: 1.2em; text-align: center; }
.prow { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.views { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.views .grp { color: var(--muted); font-size: 11px; margin: 0 2px 0 8px; }
.views .grp:first-child { margin-left: 0; }
.views button { font-size: 12.5px; padding: 6px 9px; }
.views button.target { border-color: var(--warn); color: var(--warn); }
.views button.cur { background: #1f3a37; border-color: var(--accent2); }

.foot { height: 34px; display: flex; gap: 16px; align-items: center; padding: 0 14px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); overflow: hidden; white-space: nowrap; }
.foot .credit { margin-left: auto; }

.loading { position: fixed; inset: 0; background: rgba(8,12,16,.94); display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; z-index: 50; color: var(--muted); }
.spinner { width: 38px; height: 38px; border: 3px solid #23313f; border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; max-width: 640px; width: calc(100% - 32px); padding: 18px 22px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { font-size: 15px; margin: 10px 0 6px; }
dialog ul { padding-left: 18px; margin: 0; } dialog li { margin: 4px 0; font-size: 13px; }
.small { font-size: 12px; line-height: 1.6; }

@media (max-width: 1100px) {
  .ctrl-grid { grid-template-columns: auto 1fr 1fr; }
  .practice { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .topbar { padding: 6px 10px; gap: 6px; flex-wrap: wrap; }
  .topbar h1 { font-size: 15px; }
  .tag { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: 46vh auto auto auto; grid-template-areas: "v3" "echo" "views" "ctrl"; height: auto; min-height: 0; padding: 6px; }
  .paneEcho { min-height: 0; }
  .echo-wrap { height: auto; }
  #echo { width: 100%; height: auto; }
  .ctrl-grid { grid-template-columns: 1fr 1fr; }
  .ctrl-group:first-child { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; }
  .dpad { grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 40px); }
  .foot { height: auto; flex-direction: column; align-items: flex-start; white-space: normal; padding: 8px 12px; gap: 4px; }
  .foot .credit { margin-left: 0; }
  .hint3d { display: none; }
  .overlay-tr { top: 46px; }
}
@media (max-width: 480px) { .ctrl-grid { grid-template-columns: 1fr; } }
