/* 共通の画面UI（HUD・下部バー・パネル・スタート画面・スマホ用スティック）
   必要な要素の id は engine/README.md を参照 */
:root {
  --panel: rgba(13, 11, 26, 0.78);
  --line: rgba(255, 255, 255, 0.16);
  --text: #f4f4f2;
  --muted: #b6bccb;
  --accent: #f6c95b;
  --on: #3c6aa8;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0d0b1a; color: var(--text);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; touch-action: none; -webkit-touch-callout: none;
}
#view {
  position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block;
  image-rendering: pixelated; image-rendering: crisp-edges;
}
.hidden { display: none !important; }
.box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
#hud-tl { position: fixed; top: 12px; left: 12px; padding: 8px 12px; font-size: 13px; line-height: 1.6; pointer-events: none; }
#hud-tl .title { font-weight: 700; font-size: 15px; letter-spacing: 0.04em; }
#hud-tl .ver { font-size: 10px; color: var(--muted); font-weight: 400; margin-left: 4px; }
#bar {
  position: fixed; left: 50%; bottom: calc(12px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 6px;
  max-width: calc(100vw - 24px);
}
#bar .group { display: flex; align-items: center; gap: 2px; padding: 2px; border-radius: 6px; background: rgba(255,255,255,0.05); }
#bar button, #panel button, #start button, #prompt {
  font: inherit; font-size: 12px; color: var(--text); background: transparent; border: 0;
  padding: 5px 9px; border-radius: 5px; cursor: pointer; white-space: nowrap;
}
#bar button:hover { background: rgba(255,255,255,0.1); }
#bar button.on { background: var(--on); }
#bar input[type=range] { width: 120px; accent-color: var(--accent); }
#bar .time label { font-size: 12px; font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }
#help { position: fixed; left: 12px; top: 80px; max-width: min(520px, 45vw); font-size: 11px; line-height: 1.6; color: var(--muted); padding: 4px 8px; pointer-events: none; } /* 左上の場所表示の下（下部バーと重ならないように） */
#prompt {
  position: fixed; left: 50%; top: 62%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--accent); font-size: 14px; padding: 8px 14px;
}
#prompt kbd { background: var(--accent); color: #1b1a33; border-radius: 3px; padding: 0 5px; margin-right: 6px; font-family: ui-monospace, monospace; }
#toast { position: fixed; left: 50%; top: 18%; transform: translateX(-50%); padding: 8px 14px; font-size: 14px; pointer-events: none; }
#panel, #start { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(13,11,26,0.45); padding: 16px; }
#panel .card, #start .card { max-width: 440px; width: 100%; padding: 20px 22px; line-height: 1.75; font-size: 14px; }
#panel h2, #start h1 { margin: 2px 0 8px; font-size: 20px; }
#panel .tag { display: inline-block; font-size: 11px; color: #1b1a33; background: var(--accent); border-radius: 3px; padding: 0 6px; }
#panel p, #start p { margin: 6px 0; color: #e2e4ea; }
#panel #p-close { margin-top: 10px; border: 1px solid var(--line); }
#start .btns { display: flex; gap: 8px; margin: 14px 0 8px; flex-wrap: wrap; }
#start .btns button { background: var(--on); font-size: 14px; padding: 9px 14px; }
#start .btns button.sub { background: rgba(255,255,255,0.1); }
#start small { color: var(--muted); font-size: 12px; }
/* スマホ用スティック：待機中は左下にうっすら表示、触れた位置に移動して追従する */
#joy { position: fixed; left: 24px; top: calc(100dvh - 300px - env(safe-area-inset-bottom)); width: 120px; height: 120px; border-radius: 50%; border: 2px solid var(--line); background: rgba(13,11,26,0.3); pointer-events: none; opacity: 0.45; transition: opacity 0.15s; }
#joy.active { opacity: 1; transition: none; }
#joy-knob { position: absolute; left: 36px; top: 36px; width: 48px; height: 48px; border-radius: 50%; background: rgba(246,201,91,0.8); }
#joy-label { position: absolute; left: -20px; right: -20px; top: -20px; text-align: center; font-size: 11px; color: var(--muted); }
#joy.active #joy-label { display: none; }
#s-pause, #o-more { display: none; }
#s-pause.show { display: inline-block; }
/* 書き出しパネル（下部バーの上）と録画中の表示 */
#export { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(118px + env(safe-area-inset-bottom)); width: min(440px, calc(100vw - 24px)); padding: 10px 12px; font-size: 13px; }
#export .ex-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
#export .ex-head span { flex: 1; font-size: 11px; color: var(--muted); }
#export .ex-row { display: flex; gap: 6px; flex-wrap: wrap; }
#export button { font: inherit; font-size: 13px; color: var(--text); background: rgba(255,255,255,0.08); border: 1px solid var(--line); border-radius: 5px; padding: 7px 10px; cursor: pointer; }
#export button:hover { background: rgba(255,255,255,0.16); }
#export .ex-head button { background: transparent; border: 0; padding: 2px 6px; }
#export .ex-note { margin-top: 8px; font-size: 11px; color: var(--muted); line-height: 1.6; word-break: break-all; }
#export .ex-note a { color: var(--accent); margin-left: 4px; }
#rec { position: fixed; left: 50%; transform: translateX(-50%); top: calc(12px + env(safe-area-inset-top)); display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 13px; font-variant-numeric: tabular-nums; }
#rec .rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #e06a4f; animation: rec-blink 1s steps(2) infinite; }
#rec button { font: inherit; font-size: 12px; color: var(--text); background: rgba(255,255,255,0.1); border: 1px solid var(--line); border-radius: 5px; padding: 3px 8px; cursor: pointer; }
@keyframes rec-blink { 50% { opacity: 0.2; } }
/* 風景を優先するUI：小さな丸いドックと設定メニュー。操作がないと .fade の要素は消える */
.fade { transition: opacity 0.5s ease; }
body.ui-idle .fade { opacity: 0; pointer-events: none; }
body.ui-idle #joy.fade:not(.active) { opacity: 0; } /* 待機中のスティックの目印も消す（触れれば出る） */
#bar.dock { left: 50%; transform: translateX(-50%); bottom: calc(14px + env(safe-area-inset-bottom)); width: auto; max-width: none; flex-wrap: nowrap; gap: 2px; padding: 4px; border-radius: 999px; }
#bar.dock button { width: 40px; height: 40px; padding: 0; font-size: 18px; border-radius: 50%; }
#bar.dock #o-more { display: inline-block; } /* ドックでは設定ボタンを常に出す */
#bar.dock .sep { width: 1px; align-self: stretch; margin: 6px 3px; background: var(--line); }
#menu { position: fixed; left: 50%; transform: translateX(-50%); width: min(420px, calc(100vw - 24px)); padding: 10px 12px; font-size: 13px; }
#menu .row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
#menu .row > span { min-width: 56px; font-size: 11px; color: var(--muted); }
#menu button { font: inherit; font-size: 13px; color: var(--text); background: rgba(255,255,255,0.08); border: 1px solid var(--line); border-radius: 5px; padding: 6px 9px; cursor: pointer; }
#menu button:hover { background: rgba(255,255,255,0.16); }
#menu button.on { background: var(--on); border-color: transparent; }
#menu input[type=range] { flex: 1; accent-color: var(--accent); }
#menu label { font-variant-numeric: tabular-nums; min-width: 44px; }
#hud-tl.chip { padding: 4px 10px; font-size: 12px; }
#prompt.small { font-size: 13px; padding: 6px 12px; top: auto; bottom: calc(76px + env(safe-area-inset-bottom)); }
@media (pointer: coarse) {
  body.ui-idle #bar.dock { opacity: 1; pointer-events: auto; } /* スマホは常にドックを出す（ホバーで呼び出せないため） */
  #bar.dock button { width: 46px; height: 46px; }
}
@media (max-width: 640px) {
  #hud-tl { top: calc(8px + env(safe-area-inset-top)); left: 8px; padding: 5px 9px; font-size: 12px; }
  #hud-tl .title { display: none; }
  #help { display: none; }
  #bar { gap: 4px; padding: 4px; width: calc(100vw - 16px); }
  #bar input[type=range] { width: 0; flex: 1; }
  #bar .time { flex: 1; min-width: 150px; }
  #bar button { padding: 8px 9px; font-size: 13px; }
  #o-more { display: inline-block; }
  #bar .opts { display: none; width: 100%; justify-content: space-around; }
  #bar.open .opts { display: flex; }
  #prompt { top: auto; bottom: calc(150px + env(safe-area-inset-bottom)); font-size: 15px; padding: 12px 18px; }
  #prompt kbd { display: none; }
  #toast { top: calc(120px + env(safe-area-inset-top)); }
  #export { bottom: calc(150px + env(safe-area-inset-bottom)); }
}
