
@font-face{
  font-family: "Dragrace";
  src: url("fonts/Dragrace-MV4OY.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root{ 
  --ui-bg: rgba(255,255,255,.85); 
  --primary-color: #22c55e;
  --danger-color: #ef4444;
  --text-color: #333;
  --shadow-light: 0 1px 2px rgba(0,0,0,.12);
  --shadow-medium: 0 2px 8px rgba(0,0,0,.3);
}

html,body{
  margin:0;
  text-align:center;
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,"Noto Sans JP","Hiragino Kaku Gothic ProN",Meiryo,sans-serif;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
*{ -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; user-select:none; }

.app-title{
  position: fixed; inset: 0; display:flex; align-items:center; justify-content:center;
  pointer-events:none; font-size:clamp(28px,5vw,56px); font-weight:800; color:#999; 
  text-shadow:var(--shadow-light);
  z-index: 0 !important; margin:0; font-family:"Dragrace", system-ui;
}

/* === エラー表示 === */
.error-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  background: var(--danger-color); color: white; padding: 8px 16px;
  font-size: 14px; text-align: center;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}
.error-banner.show {
  transform: translateY(0);
}

/* === 下部UIコンテナ === */
.chainsaw-container{
  position: fixed; left:0; right:0; bottom: env(safe-area-inset-bottom, 0);
  display:flex; flex-direction:column; align-items:center; justify-content:flex-end; gap:10px;
  padding:10px 12px calc(10px + env(safe-area-inset-bottom, 0));
  background: var(--ui-bg); backdrop-filter: blur(4px); z-index:1000; isolation: isolate;
}

/* === 横並びエリア === */
#rowFit{
  display:flex; align-items:flex-end; flex-wrap:nowrap;
  gap:10px;
  transform-origin:center bottom;
  will-change: transform;
  z-index: 1001;
  --ratio-stage: 10;
  --ratio-switch: 1;
  --unit: 40px;
}

/* ラッパー幅を比率で固定 */
.chainsaw-stage{ 
  width: calc(var(--unit) * var(--ratio-stage)); 
  flex:0 0 auto; 
  position:relative; 
  --starter-left:66.5%; 
  --starter-bottom:41%; 
  --starter-width:8%; 
}
.switch-wrap{   
  width: calc(var(--unit) * var(--ratio-switch)); 
  flex:0 0 auto; 
  display:flex; 
  flex-direction:column; 
  align-items:center; 
  gap:6px; 
}

/* 画像はラッパー幅いっぱいに */
.chainsaw-body, .switch{
  width:100%; height:auto; display:block;
  pointer-events:none; -webkit-user-drag:none; touch-action:none;
  transition: filter 0.1s ease, transform 0.1s ease;
}

.switch{ 
  cursor:pointer; 
  pointer-events:auto;
  border-radius: 8px;
  transition: all 0.2s ease;
}
/*
.switch:hover:not(:active) {
  filter: brightness(1.05);
  transform: scale(1.02);
}
.switch:active {
  filter: brightness(1.1) drop-shadow(var(--shadow-medium));
  transform: scale(1.05);
}
*/
.switch:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.hit-layer{ 
  position:absolute; 
  inset:0; 
  z-index:1; 
  background:transparent; 
  touch-action:none; 
  cursor:default; 
}

.starter-wrap{
  position:absolute; 
  left:var(--starter-left); 
  bottom:var(--starter-bottom); 
  width:var(--starter-width);
  transform: translate(calc(-50% + var(--starter-tx, 0px)), var(--starter-ty, 0px));
  z-index:1003; 
  will-change: transform;
}

.starter{ 
  display:block; 
  width:100%; 
  height:auto; 
  touch-action:none; 
  -webkit-user-drag:none; 
  cursor:grab;
  transition: filter 0.1s ease, transform 0.1s ease;
}
.starter:active{ 
  cursor:grabbing;
  filter: brightness(1.1) drop-shadow(var(--shadow-medium));
  transform: scale(1.02);
}
.starter:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* ロープを回転で斜めにする */
.rope{
  position:absolute; 
  width:3px; 
  height:0; 
  background: linear-gradient(to bottom, #333 0%, #666 100%);
  box-shadow: 1px 0 2px rgba(0,0,0,0.3);
  transform-origin:top center; 
  z-index:1002;
  transition: width 0.1s ease;
}

.engine-hint{
  white-space:pre-line; 
  text-align:center; 
  font-size:14px; 
  color: var(--text-color); 
  line-height:1.45;
  padding-top:2px; 
  padding-bottom:18vh;
  transition: color 0.3s ease;
}

/* 音声ゲート */
.audio-gate{
  position:fixed; 
  inset:0; 
  display:grid; 
  place-items:center; 
  background:rgba(0,0,0,.55);
  backdrop-filter: blur(8px);
  color:#fff; 
  z-index:10000; 
  font-size:clamp(18px,4vw,24px); 
  line-height:1.6; 
  padding:24px; 
  user-select:none;
  transition: opacity 0.5s ease-out;
}
.audio-gate button{ 
  margin-top:12px; 
  padding:12px 24px; 
  border:0; 
  border-radius:12px; 
  font-weight:800; 
  cursor:pointer; 
  background: var(--primary-color); 
  color:#fff;
  transition: all 0.2s ease;
  font-size: 16px;
}
.audio-gate button:hover {
  background: #16a34a;
  transform: scale(1.05);
}
.audio-gate button:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}

.gate-btn{ display:inline-flex; }
.gate-loading{ display:none; align-items:center; gap:10px; margin-top:10px; position: relative; }
.audio-gate.is-loading .gate-btn{ display:none; }
.audio-gate.is-loading .gate-loading{ display:flex; align-items:center; gap:10px; }

/* バッテリー節約モード */
.battery-saver .chainsaw-body,
.battery-saver .starter,
.battery-saver .switch {
  transition: none;
}
.battery-saver .rope {
  transition: none;
}

/* スマホの長押しメニュー等を予防 */
html, body, .chainsaw-container, .chainsaw-stage, .hit-layer,
.starter, .switch, .engine-hint, #audioGate, button, img {
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
}

/* 追記：操作対象はダブルタップズーム無効（スクロールは不要なUIなので抑止OK） */
.chainsaw-container,
.chainsaw-stage,
#hitLayer,
#starterHandle,
#killSwitch {
  touch-action: manipulation; /* ダブルタップズーム無効・タップ反応を速く */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* iOSのテキスト自動拡大を抑止（連打で拡大する副作用の低減） */
html, body { -webkit-text-size-adjust: 100%; }
/* % 表示の文字だけ中央に大きく */
#audioGate #gateText { display: inline !important; opacity: 1 !important; }

#audioGate #gateText {
  /* 最小14px〜最大28pxの範囲で可変 */
  font-size: clamp(12px, 4.2vw, 14px);
  font-weight: 700;
  letter-spacing: .02em;
}

/* アクセシビリティ改善 */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 767px){
  .engine-hint{ padding-bottom: 1vh; }
  html, body { overscroll-behavior: none; }
}
/* 追加: スマホ横向きだけ 0vh にする（順番はこのブロックを下に） */
@media (max-width: 767px) and (orientation: landscape){
  .engine-hint{ padding-bottom: 0vh; }
}

/* ダークモード対応 */
@media (prefers-color-scheme: dark) {
  :root {
    --ui-bg: rgba(31, 41, 55, .85);
    --text-color: #e5e7eb;
  }
  .app-title {
    color: #9ca3af;
  }
}

/* === ローディングは「文言＋％」だけにする（緑バーを無効化） === */
.audio-gate .gate-loading::before,
.audio-gate
/* くるくるも消す */

html, body, .app-title, .chainsaw-container, .chainsaw-stage,
#hitLayer, #starterHandle, #killSwitch {
  touch-action: manipulation;
}
.app-title {
  touch-action: manipulation;
}