/* マフラー音シミュレーター — 夜のガレージ。金属のパイプと、熱で赤くなるエキマニ */
:root {
  --bg: #0b0c0f;
  --panel: #14161a;
  --panel2: #1b1e23;
  --edge: #2a2e35;
  --text: #f1f0eb;
  --sub: #969ba3;
  --dim: #5f646c;
  --hot: #ff6a21;
  --red: #e0261e;
  --heat: 0;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  overflow: hidden; overscroll-behavior: none;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
body {
  background: radial-gradient(130% 70% at 50% 30%, #181a1f 0%, var(--bg) 70%) fixed, var(--bg);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }

#app {
  position: fixed; inset: 0; margin: 0 auto; max-width: 520px;
  display: flex; flex-direction: column; gap: 8px;
  padding: max(4px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}

/* 上の行 */
.top { display: flex; align-items: center; justify-content: space-between; height: 44px; flex: none; gap: 8px; }
.title { margin: 0; font-size: 15px; font-weight: 800; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools { display: flex; gap: 0; flex: none; margin-right: -8px; }
.iconbtn { width: 44px; height: 44px; border: 0; background: none; padding: 10px; border-radius: 10px; cursor: pointer; }
.iconbtn svg { width: 24px; height: 24px; fill: var(--text); display: block; }
.iconbtn svg .w { fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn .off { display: none; }
.iconbtn[aria-pressed="true"] .on { display: none; }
.iconbtn[aria-pressed="true"] .off { display: block; }
.iconbtn:active { background: rgba(255,255,255,.06); }

/* 回転数と名前 */
.meter {
  flex: none; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; gap: 6px 14px; align-items: end;
  background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1px solid var(--edge); border-radius: 14px; padding: 10px 12px 10px;
}
.rpm { display: flex; align-items: baseline; gap: 4px; position: relative; min-width: 118px; }
.rpm b { font-size: 38px; line-height: 1; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.rpm small { font-size: 11px; color: var(--sub); font-weight: 700; letter-spacing: .08em; }
.cut { position: absolute; left: 0; top: -12px; font-size: 11px; font-weight: 900; letter-spacing: .04em; color: #fff; background: var(--red); border-radius: 4px; padding: 0 5px; line-height: 15px; opacity: 0; white-space: nowrap; }
.cut.on { opacity: 1; }
.name { display: flex; flex-direction: column; align-items: flex-end; text-align: right; min-width: 0; gap: 2px; padding-bottom: 2px; }
.name b { font-size: 15px; font-weight: 800; white-space: nowrap; }
.name span { font-size: 11px; color: var(--sub); line-height: 1.35; word-break: keep-all; height: 2.7em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.name b { height: 1.3em; overflow: hidden; }
.bar { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(32, 1fr); gap: 2px; height: 10px; }
.bar i { border-radius: 2px; background: #23262c; }
.bar i.on { background: #e9e7df; box-shadow: 0 0 6px rgba(255,255,255,.25); }
.bar i.red { background: #3a1513; }
.bar i.red.on { background: var(--red); box-shadow: 0 0 8px rgba(224,38,30,.7); }
.bar i.hi.on { background: var(--hot); box-shadow: 0 0 6px rgba(255,106,33,.6); }

/* 排気系の絵 */
.art-wrap { flex: none; position: relative; margin: 0 -6px; }
.art { display: block; width: 100%; height: auto; overflow: visible; }
.art .ground { stroke: #22252b; stroke-width: 1; }
.art .eng { fill: #2b2f36; stroke: #464c55; stroke-width: 1; }
.art .eng.back { fill: #22252b; }
.art .head { fill: #3a3f47; stroke: #555c66; stroke-width: 1; }
.art .plug, .art .rib { fill: #50565f; }
.art .fin { fill: #444a53; }
.art .pipe { fill: none; stroke: url(#gPipe); stroke-linecap: round; stroke-linejoin: round; }
.art .pipe.main, .art .pipe.tail { stroke: #8f98a3; }
.art .shine { fill: none; stroke: rgba(255,255,255,.55); stroke-width: 1.3; stroke-linecap: round; pointer-events: none; }
.art .pipe.coll { fill: url(#gPipe); stroke: #3c424a; stroke-width: .8; }
.art .pipe.back, .art .can.back, .art .tip.back, .art .tipend.back { opacity: .45; }
.art .glow { fill: none; stroke: var(--hot); stroke-linecap: round; stroke-linejoin: round; }
.art .glow.coll { fill: var(--hot); stroke: none; }
.art .hot { opacity: calc(var(--heat) * .85); mix-blend-mode: screen; filter: drop-shadow(0 0 3px rgba(255,90,20,.8)); pointer-events: none; }
.art .flow { fill: none; stroke: rgba(255,190,120,.55); stroke-width: 1.4; stroke-dasharray: 2 14; stroke-linecap: round; opacity: 0; pointer-events: none; }
.art .cat { fill: url(#gCat); stroke: #2d2615; stroke-width: 1; }
.art .hc { stroke: rgba(30,24,10,.55); stroke-width: 1.2; }
.art .hit { fill: transparent; }
.art .tag { font-size: 8px; fill: var(--dim); text-anchor: middle; font-weight: 700; }
.art .can { fill: url(#gCan); stroke: #2c3036; stroke-width: 1; }
.art .seam { stroke: rgba(30,34,40,.55); stroke-width: 1; fill: none; }
.art .seam.lite { stroke: rgba(255,255,255,.35); }
.art .perf { fill: rgba(20,22,26,.6); }
.art .tip { fill: url(#gCan); stroke: #2c3036; stroke-width: .8; }
.art .tipend { fill: #0c0d10; stroke: #dfe4ea; stroke-width: 1.2; }
.art .flame { opacity: 0; transform-box: fill-box; transform-origin: left center; pointer-events: none; }
.art .flame.pop { animation: flame .16s ease-out; }
@keyframes flame { 0% { opacity: 1; transform: scale(.6, .7); } 40% { opacity: 1; transform: scale(1.25, 1.1); } 100% { opacity: 0; transform: scale(1.5, .9); } }
.art .part { cursor: pointer; }
.art .part.sel .pipe:not(.back), .art .part.sel .can:not(.back), .art .part.sel .cat, .art .part.sel .eng:not(.back), .art .part.sel .tip:not(.back) { filter: drop-shadow(0 0 2.5px rgba(255,255,255,.55)); }

/* パーツ */
.builder { flex: none; display: flex; flex-direction: column; gap: 6px; }
.tabs { display: grid; grid-template-columns: repeat(6, minmax(44px, 1fr)) minmax(57px, 1.2fr); gap: 2px; } /* 5 文字の「パンパン音」だけ少し広く */
.tab {
  border: 1px solid var(--edge); background: var(--panel); border-radius: 10px; padding: 0; cursor: pointer; min-height: 44px;
  font-size: 11px; font-weight: 800; letter-spacing: -.07em; white-space: nowrap; color: var(--text); min-width: 0; overflow: hidden;
}
.tab[aria-selected="true"] { border-color: #e9e7df; background: #f1f0eb; color: #111; }
.tab.fixed { color: var(--dim); border-style: dashed; }
.tab.fixed[aria-selected="true"] { background: #2a2d33; color: var(--sub); border-color: var(--sub); }
.opts {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; touch-action: none; height: 46px; flex: none; /* どのタブでも同じ高さ（ペダルが動かない） */
  -webkit-overflow-scrolling: touch; padding: 1px;
}
.opts.fade-r { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent); }
.opts.fade-l { -webkit-mask-image: linear-gradient(90deg, transparent, #000 36px); mask-image: linear-gradient(90deg, transparent, #000 36px); }
.opts.fade-l.fade-r { -webkit-mask-image: linear-gradient(90deg, transparent, #000 36px, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(90deg, transparent, #000 36px, #000 calc(100% - 36px), transparent); }
.opts.pair { gap: 8px; overflow: visible; }
.opts.pair .grp { flex: 3 1 0; min-width: 0; gap: 4px; }
.opts.pair .grp + .grp { flex: 2.4 1 0; }
.opts.pair .grp-l { width: auto; font-size: 10px; letter-spacing: 0; line-height: 1.1; }
.opts.pair .opt { padding: 0 2px; font-size: 12px; letter-spacing: -.03em; }
.opts.strip { overflow: hidden; display: block; }
.opts .track { display: flex; gap: 6px; width: max-content; min-width: 100%; will-change: transform; }
.opts .track .opt { flex: none; }
.grp { display: flex; gap: 6px; align-items: center; }
.grp-l { flex: none; width: 34px; font-size: 11px; font-weight: 700; color: var(--sub); }
.grp .opt { flex: 1 1 0; min-width: 0; padding: 0 6px; }
.help { margin: 0; font-size: 11.5px; line-height: 1.45; color: var(--sub); height: 2.9em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; flex: none; }
.opts::-webkit-scrollbar { display: none; }
.opt {
  flex: 1 0 auto; min-width: 64px; height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid var(--edge); background: var(--panel);
  font-size: 13px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.opt[aria-checked="true"] { background: #f1f0eb; color: #111; border-color: #f1f0eb; }
.opt-sep { flex: none; width: 1px; background: var(--edge); margin: 6px 2px; }
.opts .note { align-self: center; font-size: 12px; color: var(--sub); padding: 0 4px; }

/* ペダル */
.pedal-wrap { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.status { margin: 4px 0 0; font-size: 12px; color: var(--sub); height: 17px; line-height: 17px; text-align: center; flex: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.status.warn { color: #ffd0b0; font-weight: 800; font-size: 13px; }
.status.flash { animation: flash .7s ease 2; }
@keyframes flash { 50% { color: #fff; text-shadow: 0 0 8px rgba(255,160,90,.9); } }
.pedal {
  position: relative; flex: 1 1 auto; width: min(70%, 270px); max-height: min(46vh, 380px); min-height: 110px; outline: none; cursor: pointer; touch-action: none;
  border-radius: 22px 22px 30px 30px; transform: perspective(500px) rotateX(14deg); transform-origin: 50% 100%;
  background: linear-gradient(180deg, #33373e, #1d2025 70%, #16181c); border: 1px solid #3d424a;
  box-shadow: 0 10px 0 #0a0b0d, 0 16px 26px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.12);
  transition: transform .06s, box-shadow .06s;
}
.pedal.down { transform: perspective(500px) rotateX(26deg) translateY(6px); box-shadow: 0 4px 0 #0a0b0d, 0 6px 12px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.08); }
.pedal .plate { position: absolute; inset: 16% 16% 26%; display: flex; flex-direction: column; justify-content: space-between; }
.pedal .plate i { display: block; height: 7px; border-radius: 4px; background: linear-gradient(180deg, #121417, #2b2f35); box-shadow: inset 0 1px 2px rgba(0,0,0,.8), 0 1px 0 rgba(255,255,255,.08); }
.pedal.down .plate i { background: linear-gradient(180deg, #2a1206, #5a2209); }
.pedal .ptext { position: absolute; left: 0; right: 0; bottom: 8%; text-align: center; font-size: 11px; color: var(--sub); font-weight: 700; line-height: 1.3; }
.pedal:focus-visible { box-shadow: 0 0 0 3px rgba(255,255,255,.35), 0 10px 0 #0a0b0d; }

.toast {
  position: absolute; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(241,240,235,.95); color: #111; font-size: 13px; font-weight: 700; padding: 10px 16px; border-radius: 20px; white-space: nowrap; pointer-events: none;
}

/* 遊び方 */
.sheet-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; z-index: 10; touch-action: pan-y; }
.sheet-wrap[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 520px; max-height: 86%; overflow-y: auto; background: #15171b; border: 1px solid var(--edge); border-bottom: 0;
  border-radius: 18px 18px 0 0; padding: 14px 18px calc(18px + env(safe-area-inset-bottom)); font-size: 14px; line-height: 1.7; -webkit-user-select: text; user-select: text;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet h2 { font-size: 15px; margin: 14px 0 4px; }
.sheet-head h2 { margin: 4px 0; }
.closebtn { border: 1px solid var(--edge); background: var(--panel); border-radius: 22px; min-height: 44px; padding: 0 18px; font-size: 13px; cursor: pointer; }
.linkbox { width: 100%; height: 44px; margin: 8px 0 4px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--edge); background: #0d0e11; color: var(--text); font-size: 13px; -webkit-user-select: text; user-select: text; }
.howto { padding-left: 1.3em; margin: 6px 0; }
.credit, .keys { color: #c9cbcf; margin: 6px 0; }
.keys { font-size: 12px; color: var(--sub); }
.foot { font-size: 11px; color: var(--dim); margin: 14px 0 0; }

/* 低い画面（375x667 など） */
@media (max-height: 700px) {
  #app { gap: 6px; }
  .meter { padding: 8px 11px; gap: 5px 12px; }
  .rpm b { font-size: 32px; }
  .tab { padding: 4px 2px 5px; }
  .help { font-size: 11px; }
}
/* 細い画面（320px など）: タイトルを小さく、タブは 2 段 */
@media (max-width: 359px) {
  .title { font-size: 13px; }
  .tabs { grid-template-columns: repeat(4, 1fr); gap: 3px; }
  .tab { font-size: 11px; letter-spacing: 0; }
  .name b { font-size: 14px; }
  .rpm { min-width: 100px; }
  .rpm b { font-size: 28px; }
}

/* 低くて細い画面（320x568 など）: 絵とメーターを詰めて、ペダルの場所を残す */
@media (max-height: 600px), (max-width: 359px) and (max-height: 700px) {
  #app { gap: 4px; }
  .top { height: 40px; }
  .meter { padding: 6px 10px; gap: 4px 10px; }
  .rpm b { font-size: 24px; }
  .art { height: 90px; width: auto; max-width: 100%; margin: 0 auto; }
  .help { font-size: 10.5px; line-height: 1.35; height: 2.7em; }
  .meter { grid-template-columns: auto 1fr; }
  .name span { font-size: 10px; line-height: 1.25; height: 2.45em; }
  .bar { height: 6px; }
  .status { height: 15px; line-height: 15px; font-size: 11px; margin-top: 2px; }
  .pedal .ptext { font-size: 10px; }
  .pedal { min-height: 80px; }
  .pedal-wrap { min-height: 0; }
  .pedal .plate { inset: 12% 16% 34%; }
}
