:root {
  --bg: #14161a;
  --panel: #1c1f25;
  --panel-2: #22262e;
  --line: #2c313a;
  --text: #e8eaed;
  --text-dim: #93999f;
  --accent: #5fd1a8;
  --accent-dim: #2d5a4b;
  --danger: #e0645a;
  --radius: 10px;
  --radius-lg: 16px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============ トップバー ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn--header {
  width: 38px;
  height: 38px;
  font-size: 1rem;
}
.btn--header[data-hidden="true"] { display: none; }

.session-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--panel-2);
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot--off { background: #565c65; }
.dot--on { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

/* ============ 画面切り替え ============ */
.screen {
  flex: 1;
  display: none;
  overflow-y: auto;
  padding: 32px 20px 60px;
}
.screen[data-active="true"] { display: flex; }
#screen-connect[data-active="true"] { align-items: flex-start; justify-content: center; }
#screen-lobby[data-active="true"] { align-items: flex-start; justify-content: center; }
#screen-walk[data-active="true"] { padding: 0; position: relative; display: block; }
#screen-walk[data-active="true"] { display: block; }

/* ============ パネル共通 ============ */
.panel {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px;
}
.panel--wide { max-width: 880px; }

.panel-title {
  margin: 0 0 6px;
  font-size: 1.3rem;
  font-weight: 700;
}
.panel-sub {
  margin: 0 0 24px;
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ============ ボタン ============ */
.btn {
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 12px 18px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }

.btn--primary {
  background: var(--accent);
  color: #0d1512;
  width: 100%;
}
.btn--primary:hover { background: #74dab5; }

.btn--outline {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}
.btn--outline:hover { border-color: var(--accent); color: var(--accent); }

.btn--ghost {
  background: var(--panel-2);
  color: var(--text-dim);
}
.btn--ghost:hover { color: var(--text); }

.btn--small { padding: 7px 12px; font-size: 0.8rem; }
.btn--large { padding: 15px 24px; font-size: 1rem; width: 100%; }

.btn--round {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  padding: 0;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============ 接続画面 ============ */
.field-group { display: flex; flex-direction: column; gap: 16px; }

.or-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.78rem;
}
.or-divider::before, .or-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--line);
}
.or-divider span { padding: 0 12px; }

.join-row { display: flex; gap: 8px; }
.join-row input {
  flex: 1;
  min-width: 0;
  text-align: center;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-weight: 700;
}

input[type="text"], input[type="password"], select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 0.92rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: #5f656d; }

.hint-box {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.hint-box #apiKeyInput { width: 100%; margin-bottom: 10px; }
.hint-label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 600;
}
.hint-note {
  margin: 8px 0 0;
  font-size: 0.76rem;
  color: var(--text-dim);
}

/* ============ ロビー画面 ============ */
.lobby-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}
.code-chip {
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.1em;
}

.lobby-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.card-title {
  margin: 0 0 14px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.device-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.device-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel);
  border-radius: 8px;
  font-size: 0.85rem;
}
.device-item .badges { display: flex; gap: 4px; margin-left: auto; }
.badge {
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  white-space: nowrap;
}
.badge--host { background: #4a3a6b; color: #b39dff; }
.badge--monitor { background: #3a4a6b; color: #9dbaff; }
.device-empty {
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 8px 0;
}

/* ============ トグル ============ */
.toggle-row { margin-bottom: 6px; }
.toggle-row--role { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.toggle input { display: none; }
.toggle-track {
  width: 40px;
  height: 22px;
  background: var(--line);
  border-radius: 999px;
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s;
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.15s;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(18px); background: #0d1512; }
.toggle-label { font-size: 0.88rem; }

.sub-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 14px;
  padding-left: 2px;
}
.sub-options[data-hidden="true"], .position-select[data-hidden="true"] { display: none; }

.radio-chip {
  cursor: pointer;
}
.radio-chip input { display: none; }
.radio-chip span {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--text-dim);
  transition: all 0.15s;
}
.radio-chip input:checked + span {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.position-select { margin-bottom: 14px; }
.position-select select { width: 100%; }

.micro-note {
  margin: 6px 0 0;
  font-size: 0.76rem;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ============ スライダー ============ */
.slider-row {
  display: grid;
  grid-template-columns: 90px 1fr 48px;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.slider-row label { font-size: 0.82rem; color: var(--text-dim); }
.slider-val { font-size: 0.82rem; font-weight: 700; text-align: right; color: var(--accent); }

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: var(--line);
  border-radius: 999px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

.lobby-footer { margin-top: 24px; }

/* ============ センサー専用ビュー(モニター非提供端末) ============ */
.sensor-only-view {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  background: radial-gradient(circle at 50% 30%, var(--panel-2), var(--bg));
}
.sensor-only-view[data-active="true"] { display: flex; }

.sensor-only-stats {
  display: flex;
  gap: 40px;
}
.sensor-only-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.sensor-only-value {
  font-size: 3.2rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.sensor-only-unit {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.sensor-only-motion {
  width: min(320px, 80vw);
}

/* ============ 散歩画面 ============ */
#streetview {
  position: absolute;
  inset: 0;
  background: #0a0b0d;
}

.hud {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  pointer-events: none;
}
.hud-stat {
  background: rgba(20, 22, 26, 0.85);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 16px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.hud-stat-label { font-size: 0.7rem; color: var(--text-dim); }
.hud-stat-value { font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.hud-stat-unit { font-size: 0.75rem; color: var(--text-dim); }

.hud-motion {
  flex: 1;
  background: rgba(20, 22, 26, 0.85);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 16px;
  max-width: 260px;
}
.hud-motion-bar {
  width: 100%;
  height: 6px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 6px;
}
.hud-motion-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.12s ease-out;
}
.hud-motion-label { font-size: 0.72rem; color: var(--text-dim); }

.hud-motion-lr {
  display: none;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.hud-motion-lr[data-active="true"] { display: flex; }
.hud-motion-lr-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.hud-motion-lr-label {
  width: 14px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-dim);
  flex-shrink: 0;
}

.walk-controls {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
}

.role-badges {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}
.role-badges .badge {
  background: rgba(20, 22, 26, 0.85);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
}

/* ============ ミニマップ(通常モニター用) ============ */
.sv-minimap-wrap {
  position: absolute;
  bottom: 84px;
  right: 20px;
  width: 260px;
  height: 200px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  transform: scale(0.9) translateY(8px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.sv-minimap-wrap[data-open="true"] {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.sv-minimap-canvas { width: 100%; height: 100%; }
.sv-minimap-hint {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 6px 10px;
  background: rgba(20, 22, 26, 0.85);
  color: var(--text-dim);
  font-size: 0.7rem;
  text-align: center;
}

/* ============ VRメニューオーバーレイ(dom-overlay) ============ */
.vr-menu {
  display: none;
}
.vr-menu[data-open="true"] {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0;
  background: rgba(10, 11, 13, 0.92);
  padding: 40px;
  z-index: 10;
}
.vr-menu-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.vr-menu-tab {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.vr-menu-tab[data-active="true"] {
  color: var(--accent);
  border-color: var(--accent);
}
.vr-menu-body { flex: 1; display: flex; }
.vr-menu-panel { width: 100%; display: flex; flex-direction: column; }
.vr-menu-hint { color: var(--text-dim); font-size: 0.85rem; margin: 0 0 12px; }
.vr-map-canvas { flex: 1; border-radius: var(--radius); overflow: hidden; }
.vr-menu-close {
  align-self: center;
  margin-top: 16px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 24px;
  font-size: 0.85rem;
  cursor: pointer;
}

/* ============ 手のひらミニマップ(dom-overlay内、右手を上に向けると表示) ============
   vr-menu本体のdisplay:noneとは独立してfixed配置するため、position:fixedをここで指定する。
   実際の手位置追従はWebXRのワールド座標では行えない(dom-overlayはビューポート固定のDOM)ため、
   --palm-x/--palm-y/--palm-z (main.jsがpalm-poseイベントで更新するメートル単位の値)を
   簡易的に画面内オフセットへ変換して近似追従させる。 */
.palm-map {
  display: none;
}
.palm-map[data-open="true"] {
  display: block;
  position: fixed;
  width: 220px;
  height: 220px;
  left: calc(50% + (var(--palm-x, 0) * 160px));
  top: calc(55% - (var(--palm-y, 1) * 120px));
  transform: translate(-50%, -50%);
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--accent);
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.5);
  z-index: 20;
  pointer-events: auto;
  transition: opacity 0.15s ease;
}
.palm-map-canvas { width: 100%; height: 100%; }

/* ============ 設定/マップ ドロワー(ヘッダーからいつでも開閉) ============ */
.drawer {
  display: none;
}
.drawer[data-open="true"] {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 30;
}
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 11, 13, 0.6);
  backdrop-filter: blur(2px);
}
.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  box-shadow: -12px 0 32px rgba(0,0,0,0.4);
  animation: drawer-slide-in 0.18s ease;
}
@keyframes drawer-slide-in {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.drawer-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.drawer-restart-note {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.drawer-restart-note[data-hidden="true"] { display: none; }

.drawer-body--map {
  padding: 0;
}
.drawer-body--map .vr-menu-hint {
  padding: 14px 18px 0;
}
.header-map-canvas {
  flex: 1;
  margin: 12px 18px 18px;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 320px;
}

@media (max-width: 560px) {
  .drawer-panel { width: 100%; }
}

/* ============ レスポンシブ ============ */
@media (max-width: 560px) {
  .screen { padding: 20px 14px 50px; }
  .panel { padding: 20px; }
  .lobby-grid { grid-template-columns: 1fr; }
  .slider-row { grid-template-columns: 70px 1fr 42px; }
  .hud { flex-direction: column; align-items: stretch; }
  .hud-motion { max-width: none; }
}

/* ============ アクセシビリティ ============ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
