:root {
  --accent: #1fb6ff;
  --accent2: #ff4f8b;
  --ink: #23324a;
  --muted: #7a8aa0;
  --panel: rgba(255, 255, 255, 0.82);
  --line: rgba(35, 50, 74, 0.1);
  --shadow: 0 8px 30px rgba(31, 120, 190, 0.18);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: 'M PLUS Rounded 1c', system-ui, sans-serif;
  background: #eef9ff;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }
kbd {
  display: inline-block; min-width: 1.6em; padding: 0 .35em; margin: 0 1px;
  border-radius: 6px; background: #fff; border: 1px solid var(--line); border-bottom-width: 2px;
  font-family: inherit; font-weight: 700; font-size: 11px; line-height: 1.6; text-align: center; color: var(--ink);
}

#app canvas { display: block; }
.label-layer { position: absolute; inset: 0; pointer-events: none; z-index: 1; overflow: hidden; }
.label-layer * { pointer-events: none; }

/* ---------- ロゴ ---------- */
.logo {
  margin: 0; font-weight: 800; letter-spacing: .12em;
  background: linear-gradient(90deg, #ff7a59, #ff4fa3 25%, #7c5cff 50%, #2bb3ff 75%, #3ccf6e);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---------- ログイン ---------- */
#login {
  position: fixed; inset: 0; display: grid; justify-items: center; align-items: start; overflow-y: auto;
  padding: max(16px, 8vh) 16px 16px; /* タブ切替で高さが変わってもカードが上下に動かないよう上寄せ */
  background: radial-gradient(ellipse at center, rgba(255,255,255,.35), rgba(220,242,255,.6));
  backdrop-filter: blur(3px); z-index: 10;
}
.card {
  width: min(640px, 100%); padding: 28px 28px 24px; border-radius: 28px;
  background: var(--panel); backdrop-filter: blur(16px);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,255,255,.8);
  text-align: center; animation: pop .5s cubic-bezier(.2,1.4,.4,1);
}
.logo-img { margin: 0; line-height: 0; }
.logo-img img { width: min(380px, 85%); height: auto; }
.tagline { margin: 8px 0 18px; color: var(--muted); font-weight: 700; }
.login-body { display: flex; gap: 20px; align-items: center; text-align: left; }
#preview {
  width: 220px; height: 220px; flex: none; border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #fff, #d8f1ff);
  box-shadow: inset 0 0 0 3px #fff, 0 6px 20px rgba(31,182,255,.2);
}
.fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.fields label { font-size: 12px; font-weight: 800; color: var(--muted); margin-top: 6px; }
.fields input {
  padding: 10px 14px; border-radius: 14px; border: 2px solid #d6ecfa; background: #fff; outline: none;
  font-weight: 700;
}
.fields input:focus { border-color: var(--accent); }
.type-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.type-btn {
  display: flex; align-items: center; justify-content: center; gap: 4px; padding: 7px 4px;
  border-radius: 12px; border: 2px solid transparent; background: #f1f8fd; cursor: pointer; font-weight: 700; font-size: 13px;
  transition: transform .15s;
}
.type-btn:hover { transform: translateY(-2px); }
.type-btn.active { border-color: var(--accent); background: #fff; }
.color-list { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line);
  transition: transform .15s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active { box-shadow: 0 0 0 3px var(--accent); }
.primary {
  margin-top: 20px; width: 100%; padding: 14px; border: 0; border-radius: 18px; cursor: pointer;
  background: linear-gradient(90deg, #2bb3ff, #7c5cff); color: #fff; font-size: 18px; font-weight: 800; letter-spacing: .2em;
  box-shadow: 0 6px 18px rgba(43,179,255,.4); transition: transform .15s, box-shadow .15s;
}
.primary:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(43,179,255,.5); }

@media (max-width: 600px) {
  .login-body { flex-direction: column; }
  #preview { width: 160px; height: 160px; }
  .logo-img img { width: min(280px, 90%); }
}

/* ---------- HUD 共通 ---------- */
#hud > * { position: fixed; z-index: 5; }
.pill {
  --c: var(--accent);
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 999px;
  background: #fff; font-weight: 800; font-size: 14px; box-shadow: var(--shadow);
  border: 2px solid var(--c);
}
.pill.ghost { border-color: transparent; color: var(--muted); }

#topbar { top: 16px; left: 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#topbar .logo-small { height: 36px; width: auto; margin-right: 4px; filter: drop-shadow(0 0 6px rgba(255,255,255,.95)) drop-shadow(0 2px 8px rgba(0,0,0,.15)); }

#minimap {
  width: 180px; height: 180px; border-radius: 50%; flex: none;
  box-shadow: var(--shadow), 0 0 0 4px #fff;
}

#teleport {
  top: 50%; left: 16px; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 1px; padding: 6px; border-radius: 14px;
  background: var(--panel); backdrop-filter: blur(10px); box-shadow: var(--shadow);
}
.nav-title { font-size: 9px; font-weight: 800; color: var(--muted); letter-spacing: .2em; padding: 0 5px 2px; }
#teleport button {
  --c: var(--accent);
  display: flex; align-items: center; gap: 5px; padding: 4px 8px 4px 5px; border: 0; border-radius: 8px;
  background: transparent; cursor: pointer; font-weight: 700; font-size: 11px; text-align: left;
  transition: background .15s, transform .15s;
}
#teleport button:hover { background: #fff; transform: translateX(3px); }
#teleport .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--c); flex: none; }

#chat { left: 16px; bottom: 16px; width: min(380px, calc(100vw - 32px)); }
#chat-log {
  max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
  padding: 8px 4px; scrollbar-width: none; mask-image: linear-gradient(to bottom, transparent, #000 25%);
}
.log-row {
  align-self: flex-start; max-width: 100%; padding: 5px 12px; border-radius: 14px;
  background: rgba(255,255,255,.88); font-size: 13px; box-shadow: 0 2px 8px rgba(31,120,190,.1);
  word-break: break-word;
}
.log-row b { margin-right: 8px; color: var(--accent); }
.log-row.me b { color: var(--accent2); }
.log-row.bot b { color: #9a7cff; }
.log-row.system { background: rgba(35,50,74,.55); color: #fff; font-size: 12px; font-weight: 700; }
#chat-form { display: flex; gap: 6px; margin-top: 6px; }
#chat-form input {
  flex: 1; min-width: 0; padding: 11px 16px; border-radius: 999px; border: 2px solid transparent;
  background: rgba(255,255,255,.92); box-shadow: var(--shadow); outline: none; font-weight: 700;
}
#chat-form input:focus { border-color: var(--accent); }
#chat-form button {
  padding: 0 18px; border: 0; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 800; cursor: pointer;
}

#emotes { bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; }
#emotes button {
  position: relative; width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer;
  background: #fff; box-shadow: var(--shadow); font-size: 24px; transition: transform .15s;
}
#emotes button:hover { transform: translateY(-4px) scale(1.06); }
#emotes kbd { position: absolute; right: -4px; bottom: -4px; }

#help {
  right: 16px; bottom: 16px; padding: 12px 16px; border-radius: 18px;
  background: var(--panel); backdrop-filter: blur(10px); box-shadow: var(--shadow); font-size: 12px;
}
.help-title { font-weight: 800; color: var(--muted); }
#help ul { margin: 6px 0 0; padding: 0; list-style: none; display: grid; gap: 4px; }
#help.collapsed ul { display: none; }

#banner {
  --c: var(--accent);
  top: 22%; left: 50%; transform: translate(-50%, -50%); text-align: center; pointer-events: none;
  opacity: 0;
}
#banner small { display: block; font-weight: 800; letter-spacing: .4em; color: var(--c); font-size: 13px; }
#banner strong {
  display: inline-block; margin-top: 6px; padding: 10px 28px; border-radius: 999px; background: #fff;
  font-size: 28px; font-weight: 800; box-shadow: var(--shadow); border: 3px solid var(--c);
}
#banner.show { animation: banner 2.8s ease forwards; }

#lock-hint {
  top: 64%; left: 50%; transform: translateX(-50%); pointer-events: none; text-align: center;
  padding: 10px 20px; border-radius: 999px; background: rgba(35,50,74,.7); color: #fff; font-weight: 800; font-size: 14px;
  backdrop-filter: blur(6px); animation: pop .3s ease;
}
#lock-hint small { display: block; font-size: 11px; font-weight: 700; opacity: .8; }
body.locked #lock-hint, body.freelook #lock-hint { display: none; }
body.locked #chat-form input::placeholder { color: var(--muted); }

#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 20; }
#flash.on { animation: flash 1.8s ease; }

/* ---------- 3D ラベル ---------- */
.district-label {
  --c: var(--accent);
  display: flex; align-items: center; gap: 6px; padding: 6px 14px 6px 8px; border-radius: 999px;
  background: #fff; border: 3px solid var(--c); font-weight: 800; font-size: 15px; white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0,0,0,.08);
}
.district-label .icon {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--c); font-size: 15px;
}
.name-tag {
  padding: 2px 10px; border-radius: 999px; background: rgba(255,255,255,.92); font-size: 12px; font-weight: 800;
  white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.08); transition: opacity .2s;
}
.name-tag.me { background: var(--accent); color: #fff; }
.name-tag .badge {
  margin-left: 5px; padding: 0 5px; border-radius: 6px; background: #efeaff; color: #7c5cff; font-size: 9px; vertical-align: 1px;
}
.bubble {
  position: relative; max-width: 220px; padding: 8px 14px; border-radius: 16px; background: #fff;
  font-size: 13px; font-weight: 700; line-height: 1.45; text-align: center; word-break: break-word;
  box-shadow: 0 6px 18px rgba(31,120,190,.18); border: 2px solid #d6ecfa;
  opacity: 0; transform: translateY(6px) scale(.9); transition: opacity .25s, transform .25s;
}
.bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -7px;
  border: 7px solid transparent; border-top-color: #fff; border-bottom: 0;
}
.bubble.show { opacity: 1; transform: none; }
.heart { font-size: 22px; animation: floatUp 1.5s ease-out forwards; }

/* ---------- アニメーション ---------- */
@keyframes pop { from { opacity: 0; transform: scale(.9); } }
@keyframes floatUp { to { transform: translateY(-70px) scale(1.3); opacity: 0; } }
@keyframes flash { 0% { opacity: 0; } 40% { opacity: .85; } 100% { opacity: 0; } }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.9); }
  15%, 75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%); }
}

@media (max-height: 900px) {
  #chat-log { max-height: max(60px, calc(100vh - 460px)); }
  #teleport { top: 64px; transform: none; }
}

@media (max-width: 760px) {
  #teleport, #help { display: none; }
  #minimap { width: 120px; height: 120px; }
  #emotes { bottom: auto; top: 300px; left: auto; right: 16px; transform: none; flex-direction: column; }
}

/* ---------- ボイスチャット ---------- */
#vc {
  width: 100%; padding: 10px; border-radius: 18px;
  background: var(--panel); backdrop-filter: blur(10px); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px; font-size: 12px;
}
.vc-head { font-weight: 800; color: var(--muted); text-align: center; }
.vc-join {
  padding: 9px 8px; border: 0; border-radius: 12px; cursor: pointer; font-weight: 800; font-size: 13px;
  background: linear-gradient(90deg, #2ecc71, #1fb6ff); color: #fff; box-shadow: 0 4px 12px rgba(46,204,113,.35);
}
.vc-controls { display: none; gap: 6px; }
.vc-controls button {
  border: 0; border-radius: 12px; cursor: pointer; font-weight: 800; font-size: 12px; padding: 8px 8px;
}
#vc-mute { flex: 1; display: flex; align-items: center; gap: 4px; background: #e6f9ee; color: #1e8f4f; }
#vc-mute.muted { background: #ffe9ee; color: #d6385e; }
#vc-mute:disabled { cursor: default; opacity: .8; }
#vc-mute kbd { margin-left: auto; }
#vc-leave { background: #eef2f6; color: var(--muted); }
.vc-range { display: none; text-align: center; color: #1e8f4f; font-weight: 700; font-size: 11px; }
#vc.active .vc-join { display: none; }
#vc.active .vc-controls { display: flex; }
#vc.active .vc-range { display: block; }

/* 名札の VC 表示 */
.name-tag.vc::before { content: '🔊'; margin-right: 4px; font-size: 10px; }
.name-tag.vc.muted::before { content: '🔇'; }
.name-tag.vc.far::before { opacity: .35; }
.name-tag.speaking { box-shadow: 0 0 0 3px #2ecc71, 0 0 14px rgba(46,204,113,.7); }

@media (max-width: 760px) {
  #right-col { width: 160px; }
  #world-panel .astro { flex-direction: column; }
}

/* ---------- 右カラム：ワールドタイム / ミニマップ / VC ---------- */
#right-col {
  top: 16px; right: 16px; width: 200px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
}
#world-panel {
  width: 100%; padding: 10px 12px; border-radius: 18px;
  background: var(--panel); backdrop-filter: blur(10px); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 3px;
}
.clock-row { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
#clock-time { font-size: 24px; font-weight: 800; letter-spacing: .02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
#clock-period { font-size: 12px; font-weight: 800; color: var(--muted); white-space: nowrap; }
#world-panel .sub { font-size: 11px; font-weight: 700; color: var(--muted); }
#world-panel .place { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
#locate {
  border: 0; border-radius: 8px; padding: 2px 6px; background: #eef6fc; cursor: pointer;
  font-size: 10px; font-weight: 800; color: var(--accent); white-space: nowrap;
}
#world-panel .astro { display: flex; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.skin-switch {
  display: grid; grid-template-columns: 1fr 1fr; margin-top: 5px; padding: 3px; border-radius: 11px; background: #eef2f6;
}
.skin-switch button {
  border: 0; border-radius: 8px; padding: 5px 0; background: transparent; cursor: pointer;
  font-size: 12px; font-weight: 800; color: var(--muted);
}
.skin-switch button.active { background: #fff; color: var(--ink); box-shadow: 0 2px 6px rgba(31,120,190,.18); }

/* リアルワールド生成中の表示 */
#skin-loading {
  position: fixed; left: 50%; top: 45%; transform: translate(-50%, -50%); z-index: 30;
  display: none; align-items: center; gap: 10px; padding: 12px 22px; border-radius: 999px;
  background: rgba(20, 28, 40, 0.8); color: #fff; font-weight: 800; font-size: 14px; backdrop-filter: blur(8px);
}
#skin-loading.show { display: flex; }
#skin-loading .spinner {
  width: 16px; height: 16px; border-radius: 50%; border: 3px solid rgba(255,255,255,.3); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- ロゴ以外を非表示（U キー） ---------- */
#hud > *, #topbar > *, .label-layer { transition: opacity .25s; }
body.ui-hidden #hud > *:not(#topbar):not(#ui-hint):not(#elevator):not(#touch-actions):not(#joy), /* エレベーターの階選択・スマホの操作（スティック・ボタン）は非表示中も出す */
body.ui-hidden #topbar > *:not(.logo-small),
body.ui-hidden .label-layer {
  opacity: 0 !important; pointer-events: none !important;
}
#ui-hint {
  top: 60px; left: 16px; padding: 6px 12px; border-radius: 999px;
  background: rgba(20, 28, 40, 0.7); color: #fff; font-size: 12px; font-weight: 800;
  opacity: 0; pointer-events: none;
}
#ui-hint.show { opacity: 1; }

/* ---------- アカウント ---------- */
.auth-tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; margin: 0 auto 14px;
  max-width: 360px; border-radius: 14px; background: #eef2f6;
}
.auth-tabs button {
  border: 0; border-radius: 10px; padding: 8px 0; background: transparent; cursor: pointer; font-weight: 800; color: var(--muted);
}
.auth-tabs button.active { background: #fff; color: var(--ink); box-shadow: 0 2px 6px rgba(31,120,190,.18); }
.auth-panel { display: flex; flex-direction: column; gap: 8px; max-width: 360px; margin: 0 auto; text-align: left; }
.auth-panel input {
  padding: 11px 14px; border-radius: 14px; border: 2px solid #d6ecfa; background: #fff; outline: none; font-weight: 700;
}
.auth-panel input:focus { border-color: var(--accent); }
.auth-panel .primary { margin-top: 6px; }
.auth-error { min-height: 1.2em; color: #d6385e; font-size: 12px; font-weight: 800; }
.account-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 14px; padding: 8px 12px;
  border-radius: 12px; background: #eef6fc; font-size: 13px; font-weight: 700; text-align: left;
}
.account-bar b { word-break: break-all; }
.account-bar button {
  border: 0; border-radius: 10px; padding: 6px 12px; background: #fff; color: var(--muted); font-weight: 800; cursor: pointer; flex: none;
}
.custom-avatar .custom-row { display: flex; gap: 6px; flex-wrap: wrap; }
.custom-avatar button {
  border: 0; border-radius: 10px; padding: 8px 12px; cursor: pointer; font-weight: 800; font-size: 12px;
  background: linear-gradient(90deg, #2bb3ff, #7c5cff); color: #fff;
}
.custom-avatar #avatar-remove { background: #eef2f6; color: var(--muted); }
.avatar-status { min-height: 1.2em; font-size: 11px; font-weight: 700; color: var(--muted); }
.avatar-status.error { color: #d6385e; }
.guest-note { margin: 6px 0 0; font-size: 11px; font-weight: 700; color: var(--muted); }

/* 建物に出入りするときの暗転 */
#space-fade {
  position: fixed; inset: 0; z-index: 25; background: #0b0f16; opacity: 0; pointer-events: none;
  transition: opacity .3s ease;
}
#space-fade.on { opacity: 1; }

/* ---------- 視点切替（F キー） ---------- */
#view-toast {
  top: 40%; left: 50%; transform: translate(-50%, -50%); padding: 8px 18px; border-radius: 999px;
  background: rgba(20, 28, 40, 0.72); color: #fff; font-weight: 800; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
#view-toast.show { opacity: 1; }
#crosshair {
  top: 50%; left: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 2px rgba(0,0,0,.35); pointer-events: none; display: none;
}
body.first-person #crosshair { display: block; }
body.first-person #lock-hint { top: 58%; }

/* お店のスタッフ */
.name-tag .badge.staff { background: #fff1e0; color: #d9731a; }
.admin-link { margin-left: auto; font-size: 12px; font-weight: 800; color: var(--accent); text-decoration: none; white-space: nowrap; }
.admin-link:hover { text-decoration: underline; }

/* ---------- エレベーターの階選択 ---------- */
#elevator {
  left: 50%; bottom: 130px; transform: translateX(-50%); padding: 12px 16px; border-radius: 16px;
  background: var(--panel); backdrop-filter: blur(12px); box-shadow: var(--shadow); text-align: center; min-width: 220px;
}
#elevator .ev-head { font-weight: 800; font-size: 14px; }
#elevator .ev-now { margin-left: 6px; font-size: 12px; color: var(--muted); }
#elevator .ev-floors { display: flex; gap: 10px; justify-content: center; margin: 10px 0 6px; }
#elevator button {
  width: 64px; height: 64px; border-radius: 50%; border: 2px solid #c9a25a; background: #23272e; color: #ffb13b;
  font-family: inherit; font-weight: 800; font-size: 20px; cursor: pointer; transition: transform .15s, box-shadow .15s;
}
#elevator button:hover:not(:disabled) { transform: scale(1.06); box-shadow: 0 0 0 4px rgba(255, 177, 59, 0.3); }
#elevator button.current { background: #ffb13b; color: #23272e; cursor: default; }
#elevator small { color: var(--muted); font-size: 11px; }

/* ---------- 表示モード（デスクトップ / VR） ---------- */
.mode-switch {
  display: grid; grid-template-columns: 1fr 1fr; margin-top: 5px; padding: 3px; border-radius: 11px; background: #eef2f6;
}
.mode-switch button {
  border: 0; border-radius: 8px; padding: 5px 0; background: transparent; cursor: pointer;
  font-size: 12px; font-weight: 800; color: var(--muted);
}
.mode-switch button.active { background: #fff; color: var(--ink); box-shadow: 0 2px 6px rgba(31,120,190,.18); }
.mode-switch button.unsupported { opacity: .5; }

/* =====================================================================
   スマホ・タブレット（タッチ操作）  body.touch は touch.js が付ける
   ===================================================================== */
body.touch { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
body.touch input { -webkit-user-select: text; user-select: text; }
body.touch #app canvas { touch-action: none; }
body.touch #help, body.touch #lock-hint, body.touch kbd { display: none !important; }

/* 上：ロゴ・エリア名（左）と メニュー・ミニマップ（右） */
body.touch #topbar { top: calc(8px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left)); gap: 6px; max-width: calc(100vw - 150px); }
body.touch #topbar .logo-small { height: 26px; }
body.touch .pill { font-size: 11px; padding: 4px 10px; border-width: 2px; }
body.touch #topbar { flex-wrap: nowrap; }
body.touch #area { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; display: inline-block; }
/* 幅の狭いスマホでは人数表示はメニューの中へ */
@media (max-width: 560px) { body.touch #topbar #online { display: none; } }
body.touch #right-col {
  top: calc(8px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right));
  width: auto; flex-direction: row; align-items: flex-start; gap: 8px;
}
body.touch #minimap { width: 84px; height: 84px; box-shadow: var(--shadow), 0 0 0 3px #fff; }
#menu-btn {
  width: 44px; height: 44px; border: 0; border-radius: 14px; background: var(--panel); backdrop-filter: blur(10px);
  box-shadow: var(--shadow); font-size: 22px; font-weight: 800; color: var(--ink); cursor: pointer;
}
#menu-btn.on { background: var(--accent); color: #fff; }

/* ☰ メニュー（時計・スキン・表示モード・VC・ワープ） */
#m-menu {
  top: calc(8px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right));
  width: min(300px, calc(100vw - 20px)); max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto; padding: 12px; border-radius: 20px; z-index: 12 !important;
  background: rgba(245, 250, 255, 0.95); backdrop-filter: blur(14px); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
}
#m-menu .m-head { display: flex; align-items: center; justify-content: space-between; font-size: 14px; }
#m-menu .m-close { width: 36px; height: 36px; border: 0; border-radius: 12px; background: #eef2f6; font-size: 20px; cursor: pointer; }
#m-menu #world-panel, #m-menu #vc { box-shadow: none; background: #fff; }
#m-menu #teleport { display: flex; position: static; transform: none; box-shadow: none; background: #fff; }
#m-menu #teleport button { font-size: 14px; padding: 9px 10px; }
#m-menu .m-tools { display: flex; gap: 8px; }
#m-menu .m-tools button { flex: 1; padding: 10px 8px; border: 0; border-radius: 12px; background: #fff; font-weight: 800; font-size: 13px; cursor: pointer; }

/* チャット：ログは左上に小さく。入力欄は 💬 を押したときだけ（キーボードに隠れないよう上に出す） */
body.touch #chat { top: calc(44px + env(safe-area-inset-top)); bottom: auto; left: calc(10px + env(safe-area-inset-left)); width: min(320px, 62vw); }
body.touch #chat-log { max-height: 22vh; font-size: 11px; }
body.touch #chat-form { display: none; }
body.touch.chat-open #chat-form { display: flex; }

/* 左下：移動スティック */
#joy {
  left: calc(22px + env(safe-area-inset-left)); bottom: calc(22px + env(safe-area-inset-bottom));
  width: 124px; height: 124px; border-radius: 50%; touch-action: none;
  background: rgba(255, 255, 255, 0.28); border: 2px solid rgba(255, 255, 255, 0.85); backdrop-filter: blur(4px);
  box-shadow: 0 6px 20px rgba(31, 120, 190, 0.18);
}
#joy .knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%;
  background: #fff; box-shadow: 0 4px 12px rgba(31, 120, 190, 0.35); pointer-events: none;
}
#joy.on .knob { background: var(--accent); }

/* 右下：操作ボタン */
#touch-actions {
  right: calc(16px + env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(3, 54px); gap: 10px;
}
#touch-actions button {
  width: 54px; height: 54px; border: 0; border-radius: 50%; touch-action: none; cursor: pointer;
  background: rgba(255, 255, 255, 0.88); box-shadow: var(--shadow); font-size: 22px; line-height: 1;
}
#touch-actions button.on { background: var(--accent); color: #fff; }

/* エモート：😊 を押すと操作ボタンの上に出る */
body.touch #emotes { display: none; top: auto; left: auto; transform: none; flex-direction: row; right: calc(16px + env(safe-area-inset-right)); bottom: calc(150px + env(safe-area-inset-bottom)); }
body.touch.emotes-open #emotes { display: flex; }

/* エレベーターの階選択は、スティックとボタンに重ならない高さに */
body.touch #elevator { bottom: auto; top: 36%; }
body.touch #banner strong { font-size: 22px; }

/* ログイン画面（スマホ） */
@media (max-width: 600px) {
  #login { padding-top: max(12px, env(safe-area-inset-top)); }
  .card { padding: 18px 16px 16px; border-radius: 22px; }
  .tagline { margin: 4px 0 12px; font-size: 13px; }
}

/* 縦向きのときの「横向きにしてください」 */
#rotate-hint {
  display: none; inset: 0; z-index: 40 !important; padding: 24px; text-align: center;
  flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: rgba(11, 15, 22, 0.88); color: #fff; backdrop-filter: blur(6px);
}
@media (orientation: portrait) { body.touch #rotate-hint:not(.dismissed) { display: flex; } }
#rotate-hint .rot-icon { font-size: 64px; animation: rot-phone 2.2s ease-in-out infinite; }
@keyframes rot-phone { 0%, 20% { transform: rotate(0); } 50%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
#rotate-hint b { font-size: 18px; }
#rotate-hint p { margin: 0; font-size: 13px; line-height: 1.7; opacity: .85; }
#rotate-hint button {
  margin-top: 10px; padding: 10px 20px; border: 0; border-radius: 999px; cursor: pointer;
  background: rgba(255, 255, 255, 0.18); color: #fff; font-weight: 800; font-size: 13px;
}

/* 横向き（高さの低い画面）では、操作部品を少し小さくして景色を広く */
@media (max-height: 500px) {
  body.touch #joy { width: 108px; height: 108px; left: calc(18px + env(safe-area-inset-left)); bottom: calc(14px + env(safe-area-inset-bottom)); }
  body.touch #touch-actions { grid-template-columns: repeat(3, 48px); gap: 8px; right: calc(14px + env(safe-area-inset-right)); bottom: calc(14px + env(safe-area-inset-bottom)); }
  body.touch #touch-actions button { width: 48px; height: 48px; font-size: 20px; }
  body.touch #minimap { width: 72px; height: 72px; }
  body.touch #menu-btn { width: 40px; height: 40px; font-size: 20px; }
  body.touch #chat { width: min(300px, 40vw); }
  body.touch #chat-log { max-height: 30vh; }
  body.touch #emotes { bottom: calc(126px + env(safe-area-inset-bottom)); }
  body.touch #elevator { top: 18%; }
}

/* 自分のアバター（VRM / GLB）を使っている間は、プリセットのタイプ・カラーは選べない */
.type-list.locked, .color-list.locked { opacity: .4; filter: grayscale(.6); pointer-events: none; }
.type-list.locked button, .color-list.locked button { cursor: not-allowed; }
.preset-lock { margin: 6px 0 0; font-size: 11px; font-weight: 700; color: var(--muted); line-height: 1.5; }

/* スマホ：UI を隠している間も移動・ジャンプなどの操作はそのまま使える。チャット欄は隠れるのでチャットボタンだけ隠す（位置はそのまま） */
body.ui-hidden #touch-actions button[data-act=chat] { visibility: hidden; }
body.touch #emotes, body.touch.emotes-open #emotes { display: none; }

/* 下段は「ダッシュ・飛ぶ」の 2 つ。飛ぶボタンは親指で押しやすい右下の角に */
#touch-actions button[data-act=run] { grid-column: 2; }
