/* ==========================================================================
   AEON 100Years メタバース — デザインシステム
   ネオ・フューチャリズム × 子ども向け学習ツール。
   マゼンタは「塗り」ではなく「光」として使う。
   ========================================================================== */

:root {
  --ink: #0b0616;
  --ink-2: #150c26;
  --ink-3: #1e1333;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.2);
  --text: #f5eefc;
  --muted: #a99dc0;
  --muted-2: #7d7194;
  --magenta: #ae008e;
  --magenta-bright: #ff2fd0;
  --magenta-soft: rgba(255, 47, 208, 0.16);
  --red: #e60012;
  --lime: #b6ff3c;
  --cyan: #3ce0ff;
  --amber: #ffb03c;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.75);
  --font-display: 'M PLUS Rounded 1c', 'Zen Kaku Gothic New', 'Hiragino Maru Gothic ProN', system-ui, sans-serif;
  --font-body: 'Zen Kaku Gothic New', 'Hiragino Sans', 'Yu Gothic', system-ui, sans-serif;
  --font-mono: 'Roboto Mono', 'SFMono-Regular', Menlo, monospace;
}

* { box-sizing: border-box; }

/* display を持つクラスが hidden を打ち消さないようにする */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { overflow-x: hidden; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1.25;
  margin: 0;
  letter-spacing: 0.01em;
}

p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

button, input, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- 背景 */
.aurora {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(174, 0, 142, 0.35), transparent 60%),
    radial-gradient(90% 60% at 100% 100%, rgba(60, 224, 255, 0.12), transparent 65%),
    var(--ink);
}

.aurora__blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.55;
}

.aurora__blob--a {
  width: 46vw; height: 46vw;
  left: -12vw; top: -10vw;
  background: radial-gradient(circle, rgba(255, 47, 208, 0.55), transparent 70%);
  animation: drift-a 22s ease-in-out infinite;
}

.aurora__blob--b {
  width: 38vw; height: 38vw;
  right: -8vw; top: 12vh;
  background: radial-gradient(circle, rgba(174, 0, 142, 0.6), transparent 70%);
  animation: drift-b 27s ease-in-out infinite;
}

.aurora__blob--c {
  width: 34vw; height: 34vw;
  left: 28vw; bottom: -16vw;
  background: radial-gradient(circle, rgba(60, 224, 255, 0.28), transparent 70%);
  animation: drift-c 31s ease-in-out infinite;
}

@keyframes drift-a { 50% { transform: translate(6vw, 4vh) scale(1.12); } }
@keyframes drift-b { 50% { transform: translate(-5vw, 6vh) scale(1.08); } }
@keyframes drift-c { 50% { transform: translate(4vw, -5vh) scale(1.15); } }

/* ---------------------------------------------------------------- 画面 */
.screen { position: relative; z-index: 1; }
.screen[hidden] { display: none; }

.screen--lobby {
  min-height: 100vh;
  padding: clamp(20px, 4vw, 56px) clamp(16px, 5vw, 72px) 64px;
  display: flex;
  flex-direction: column;
  gap: clamp(24px, 4vw, 48px);
}

/* ---------------------------------------------------------------- ロゴ */
.logo { display: inline-flex; align-items: flex-end; gap: 10px; }

.logo__word {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(26px, 4vw, 40px);
  letter-spacing: 0.14em;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: #fff;
}

.logo__cube {
  width: 0.86em;
  height: 0.86em;
  display: inline-block;
  margin: 0 -0.02em;
  animation: cube-spin 6s linear infinite;
}

.logo__cube svg { width: 100%; height: 100%; display: block; }

@keyframes cube-spin { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-0.08em); } }

.logo__sub {
  font-family: var(--font-mono);
  font-size: clamp(9px, 1vw, 11px);
  letter-spacing: 0.42em;
  color: var(--magenta-bright);
  padding-bottom: 0.5em;
}

.logo--small .logo__word { font-size: 22px; }
.logo--small .logo__sub { display: none; }

/* ---------------------------------------------------------------- ロビー */
.lobby__head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; justify-content: space-between; }

.lobby__tag {
  font-size: 13px;
  letter-spacing: 0.34em;
  color: var(--muted);
  text-transform: uppercase;
}

.lobby__hero { max-width: 900px; animation: rise 0.7s cubic-bezier(0.16, 1, 0.3, 1) both; }

.eyebrow {
  display: inline-block;
  font-size: 13px;
  letter-spacing: 0.24em;
  color: var(--lime);
  border: 1px solid rgba(182, 255, 60, 0.35);
  border-radius: 999px;
  padding: 4px 14px;
  margin-bottom: 20px;
}

.hero__title {
  font-size: clamp(34px, 6.2vw, 76px);
  letter-spacing: -0.01em;
  margin-bottom: 20px;
}

.hero__title em {
  font-style: normal;
  background: linear-gradient(96deg, var(--magenta-bright), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 46px rgba(255, 47, 208, 0.45);
}

.hero__lead { color: var(--muted); font-size: clamp(14px, 1.5vw, 17px); max-width: 720px; }

.lobby__choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: clamp(18px, 2.6vw, 32px);
  align-items: start;
}

/* ---------------------------------------------------------------- カード */
.card {
  position: relative;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(22px, 3vw, 34px);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.card--teacher { animation-delay: 0.08s; }
.card--student { animation-delay: 0.16s; }

.card::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(140deg, rgba(255, 47, 208, 0.6), transparent 40%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.card--student::before { background: linear-gradient(140deg, rgba(60, 224, 255, 0.55), transparent 40%); }

.card__badge {
  display: inline-block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--magenta-bright);
  border: 1px solid rgba(255, 47, 208, 0.45);
  background: var(--magenta-soft);
  border-radius: 999px;
  padding: 3px 14px;
  margin-bottom: 14px;
}

.card--student .card__badge { color: var(--cyan); border-color: rgba(60, 224, 255, 0.45); background: rgba(60, 224, 255, 0.12); }

.card__title { font-size: clamp(22px, 2.4vw, 30px); margin-bottom: 10px; }
.card__text { color: var(--muted); font-size: 14.5px; margin-bottom: 22px; }

/* ---------------------------------------------------------------- フォーム */
.form { display: flex; flex-direction: column; gap: 18px; }

.field { display: flex; flex-direction: column; gap: 8px; border: 0; padding: 0; margin: 0; }

.field__label { font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: 0.06em; }

.field__input {
  width: 100%;
  background: rgba(11, 6, 22, 0.65);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 16px;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
  outline: none;
}

.field__input::placeholder { color: var(--muted-2); }

.field__input:focus {
  border-color: var(--magenta-bright);
  box-shadow: 0 0 0 4px rgba(255, 47, 208, 0.16);
  background: rgba(11, 6, 22, 0.9);
}

.field__input--code {
  font-family: var(--font-mono);
  font-size: 26px;
  letter-spacing: 0.4em;
  text-align: center;
  padding: 12px 8px 12px 18px;
}

.field__input--area { resize: vertical; min-height: 76px; line-height: 1.6; }

.template-picker { display: flex; flex-wrap: wrap; gap: 8px; }

.template-picker__item {
  flex: 1 1 auto;
  min-width: 130px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: all 0.18s;
  font-family: var(--font-display);
}

.template-picker__item:hover { border-color: rgba(255, 47, 208, 0.5); background: rgba(255, 47, 208, 0.08); }

.template-picker__item.is-active {
  border-color: var(--magenta-bright);
  background: rgba(255, 47, 208, 0.18);
  box-shadow: 0 0 0 3px rgba(255, 47, 208, 0.14);
  color: #fff;
}

.color-picker { display: flex; flex-wrap: wrap; gap: 10px; }

.color-picker__item {
  width: 38px; height: 38px;
  border-radius: 12px;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  transition: transform 0.16s, box-shadow 0.16s;
}

.color-picker__item:hover { transform: translateY(-2px) scale(1.06); }

.color-picker__item.is-active {
  border-color: #fff;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.18);
  transform: scale(1.08);
}

/* ---------------------------------------------------------------- ボタン */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 15px 30px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s, background 0.2s, opacity 0.2s;
  min-height: 52px;
  text-decoration: none;
}

.btn:hover:not(:disabled) { transform: translateY(-2px); }
.btn:active:not(:disabled) { transform: translateY(0) scale(0.985); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--primary {
  background: linear-gradient(100deg, var(--magenta-bright), var(--magenta));
  color: #fff;
  box-shadow: 0 14px 34px -12px rgba(255, 47, 208, 0.85);
}

.btn--primary:hover:not(:disabled) { box-shadow: 0 20px 44px -12px rgba(255, 47, 208, 1); }

.btn--secondary {
  background: linear-gradient(100deg, var(--cyan), #1b8fd6);
  color: #04121c;
  box-shadow: 0 14px 34px -12px rgba(60, 224, 255, 0.8);
}

.btn--ghost {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line-strong);
  color: var(--text);
}

.btn--ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); }

.btn--danger {
  background: rgba(230, 0, 18, 0.14);
  border-color: rgba(230, 0, 18, 0.55);
  color: #ff8f96;
}

.btn--danger:hover:not(:disabled) { background: rgba(230, 0, 18, 0.24); }

.btn--block { width: 100%; }
.btn--small { padding: 10px 20px; font-size: 14px; min-height: 42px; }
.btn__arrow { transition: transform 0.2s; }
.btn:hover .btn__arrow { transform: translateX(4px); }

.lobby__foot { color: var(--muted-2); font-size: 13px; max-width: 780px; border-top: 1px solid var(--line); padding-top: 20px; }

/* ---------------------------------------------------------------- トップバー */
.screen--teacher { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px clamp(14px, 3vw, 32px);
  background: rgba(11, 6, 22, 0.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
  flex-wrap: wrap;
}

.tabs { display: flex; gap: 6px; background: rgba(255, 255, 255, 0.04); border-radius: 999px; padding: 4px; }

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.18s;
}

.tab:hover { color: var(--text); }
.tab.is-active { background: linear-gradient(100deg, var(--magenta-bright), var(--magenta)); color: #fff; box-shadow: 0 8px 22px -10px rgba(255, 47, 208, 0.9); }

.topbar__right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.conn { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 10px var(--lime); }
.conn[data-state="off"] i { background: var(--amber); box-shadow: 0 0 10px var(--amber); }
.conn[data-state="down"] i { background: var(--red); box-shadow: 0 0 10px var(--red); }

.teacher__body { padding: clamp(16px, 3vw, 32px); flex: 1; }

.tabpanel { display: none; }
.tabpanel.is-active { display: block; animation: rise 0.45s cubic-bezier(0.16, 1, 0.3, 1) both; }

/* ---------------------------------------------------------------- コードヒーロー */
.code-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: clamp(18px, 3vw, 40px);
  align-items: center;
  background: linear-gradient(120deg, rgba(255, 47, 208, 0.18), rgba(174, 0, 142, 0.06) 45%, transparent);
  border: 1px solid rgba(255, 47, 208, 0.3);
  border-radius: var(--radius);
  padding: clamp(22px, 3vw, 40px);
  margin-bottom: clamp(18px, 2.6vw, 28px);
  position: relative;
  overflow: hidden;
}

.code-hero::after {
  content: '';
  position: absolute;
  width: 420px; height: 420px;
  right: -120px; top: -180px;
  background: radial-gradient(circle, rgba(255, 47, 208, 0.35), transparent 65%);
  pointer-events: none;
}

.code-hero__label { font-size: 13px; letter-spacing: 0.3em; color: var(--magenta-bright); font-weight: 700; }

.code-hero__code {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(52px, 11vw, 108px);
  line-height: 1;
  letter-spacing: 0.1em;
  margin: 8px 0 6px;
  color: #fff;
  text-shadow: 0 0 44px rgba(255, 47, 208, 0.7);
}

.code-hero__hint { color: var(--muted); font-size: 14px; }
.code-hero__actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.code-hero__link { font-family: var(--font-mono); font-size: 12px; color: var(--muted-2); margin-top: 10px; word-break: break-all; }

.code-hero__qr { text-align: center; }
.code-hero__qr img { border-radius: 14px; background: #fff; padding: 8px; width: clamp(120px, 16vw, 200px); height: auto; display: block; }
.code-hero__qr p { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ---------------------------------------------------------------- グリッド & パネル */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: clamp(14px, 2vw, 22px); align-items: start; }

.panel {
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.015));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(18px, 2.4vw, 26px);
  backdrop-filter: blur(14px);
}

.panel--players { grid-row: span 2; }

.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel__title { font-size: 18px; }
.panel__hint { font-size: 13px; color: var(--muted); margin-bottom: 12px; }

.pill {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--magenta-soft);
  color: var(--magenta-bright);
  border: 1px solid rgba(255, 47, 208, 0.35);
}

.stack { display: flex; flex-direction: column; gap: 12px; }

/* 参加者リスト */
.player-list { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow-y: auto; padding-right: 4px; }

.player-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid transparent;
  transition: background 0.18s, border-color 0.18s;
}

.player-row:hover { background: rgba(255, 255, 255, 0.07); border-color: var(--line-strong); }
.player-row.is-teacher { border-color: rgba(255, 47, 208, 0.35); }

.player-row__dot { width: 14px; height: 14px; border-radius: 5px; box-shadow: 0 0 12px currentColor; }

.player-row__name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }

.player-row__tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 47, 208, 0.18);
  color: var(--magenta-bright);
}

.player-row__blocks { font-family: var(--font-mono); font-size: 13px; color: var(--lime); }
.player-row__kick { border: 1px solid var(--line-strong); background: transparent; border-radius: 999px; font-size: 12px; padding: 5px 12px; cursor: pointer; color: var(--muted); transition: all 0.18s; }
.player-row__kick:hover { border-color: rgba(230, 0, 18, 0.6); color: #ff8f96; }

.empty { color: var(--muted-2); font-size: 14px; padding: 12px 0; }

/* お題クイック */
.quick-missions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.quick-missions button {
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.18s;
}

.quick-missions button:hover { color: var(--text); border-color: var(--magenta-bright); background: var(--magenta-soft); }

/* トグル */
.toggle-row { display: flex; align-items: center; gap: 16px; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.toggle-row__title { font-weight: 700; font-size: 15px; }
.toggle-row__hint { font-size: 12.5px; color: var(--muted); }

.switch { width: 56px; height: 30px; border-radius: 999px; border: 1px solid var(--line-strong); background: rgba(255, 255, 255, 0.08); position: relative; cursor: pointer; transition: background 0.2s, border-color 0.2s; flex: 0 0 auto; }
.switch span { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform 0.24s cubic-bezier(0.34, 1.56, 0.64, 1); }
.switch[aria-checked="true"] { background: linear-gradient(100deg, var(--magenta-bright), var(--magenta)); border-color: transparent; }
.switch[aria-checked="true"] span { transform: translateX(26px); }

/* 見学 */
.spectate { display: flex; flex-direction: column; gap: 16px; }
.spectate__bar { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.spectate__title { font-family: var(--font-display); font-weight: 800; font-size: 22px; }
.spectate__hint { font-size: 13px; color: var(--muted); max-width: 780px; }

.spectate__stage {
  position: relative;
  aspect-ratio: 16 / 9;
  min-height: 340px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: #05030c;
}

.spectate__placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 24px;
}

.spectate__placeholder-icon { font-size: 48px; color: var(--magenta-bright); opacity: 0.6; }

/* 統計 */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }

.stat-card {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.015));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-card__label { font-size: 12.5px; color: var(--muted); letter-spacing: 0.1em; }
.stat-card__value { font-family: var(--font-mono); font-size: 34px; font-weight: 700; color: #fff; line-height: 1.2; }
.stat-card__unit { font-size: 14px; color: var(--muted); margin-left: 4px; }

.rank-list { display: flex; flex-direction: column; gap: 8px; }

.rank-row { display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: rgba(255, 255, 255, 0.035); }
.rank-row__no { font-family: var(--font-mono); color: var(--muted); font-size: 14px; }
.rank-row__name { font-weight: 700; font-size: 14.5px; }
.rank-row__value { font-family: var(--font-mono); font-size: 14px; color: var(--lime); }

/* ---------------------------------------------------------------- 3D画面 */
.screen--game { position: fixed; inset: 0; z-index: 40; background: #05030c; }

#game-canvas { display: block; width: 100%; height: 100%; }

.hud { position: absolute; inset: 0; pointer-events: none; }
.hud > * { pointer-events: auto; }

.hud__topleft { position: absolute; top: 14px; left: 14px; display: flex; flex-direction: column; gap: 8px; max-width: min(46vw, 420px); }
.hud__topright { position: absolute; top: 14px; right: 14px; display: flex; align-items: center; gap: 8px; }

.hud-card {
  background: rgba(11, 6, 22, 0.72);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  backdrop-filter: blur(14px);
}

.hud-card--mission { border-color: rgba(255, 47, 208, 0.4); box-shadow: 0 0 30px -12px rgba(255, 47, 208, 0.9); }
.hud-card__label { font-size: 10.5px; letter-spacing: 0.22em; color: var(--magenta-bright); font-weight: 700; }
.hud-card__value { font-size: 14.5px; font-weight: 700; line-height: 1.5; }
.hud-card__value--mono { font-family: var(--font-mono); letter-spacing: 0.2em; }

.hud-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(11, 6, 22, 0.72);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  backdrop-filter: blur(14px);
}

.hud-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 10px var(--lime); }

.hud-btn {
  width: 42px; height: 42px;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  background: rgba(11, 6, 22, 0.72);
  backdrop-filter: blur(14px);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
  transition: all 0.16s;
  display: grid;
  place-items: center;
}

.hud-btn:hover { background: rgba(255, 47, 208, 0.25); border-color: var(--magenta-bright); }
.hud-btn--exit:hover { background: rgba(230, 0, 18, 0.3); border-color: var(--red); }
.hud-btn.is-active { background: linear-gradient(100deg, var(--magenta-bright), var(--magenta)); border-color: transparent; }

.crosshair {
  position: absolute;
  left: 50%; top: 50%;
  width: 22px; height: 22px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.crosshair::before, .crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.9);
}

.crosshair::before { left: 50%; top: 0; width: 2px; height: 100%; transform: translateX(-50%); }
.crosshair::after { top: 50%; left: 0; height: 2px; width: 100%; transform: translateY(-50%); }

.hud__announce { position: absolute; top: 74px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(90vw, 620px); pointer-events: none; }

.announce-toast {
  background: linear-gradient(100deg, rgba(255, 47, 208, 0.95), rgba(174, 0, 142, 0.95));
  color: #fff;
  border-radius: 14px;
  padding: 12px 22px;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 18px 40px -16px rgba(255, 47, 208, 0.95);
  animation: drop 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
  text-align: center;
}

@keyframes drop { from { opacity: 0; transform: translateY(-18px) scale(0.96); } to { opacity: 1; transform: none; } }

.hud__bottomleft { position: absolute; left: 14px; bottom: 14px; }

.help { background: rgba(11, 6, 22, 0.68); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; backdrop-filter: blur(14px); max-width: 260px; }
.help__title { font-size: 10.5px; letter-spacing: 0.22em; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.help__list { display: flex; flex-direction: column; gap: 3px; }
.help__list li { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; }
.help__list b { color: var(--text); font-family: var(--font-mono); font-size: 11.5px; min-width: 74px; }

.hud__bottom { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; }

.hotbar { display: flex; gap: 6px; padding: 7px; background: rgba(11, 6, 22, 0.72); border: 1px solid var(--line); border-radius: 16px; backdrop-filter: blur(14px); }

.hotbar__slot {
  width: 46px; height: 46px;
  border-radius: 10px;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  transition: transform 0.14s, border-color 0.14s;
  box-shadow: inset 0 -10px 16px -10px rgba(0, 0, 0, 0.8);
}

.hotbar__slot:hover { transform: translateY(-3px); }
.hotbar__slot.is-active { border-color: #fff; transform: translateY(-4px) scale(1.06); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.16); }
.hotbar__slot span { position: absolute; bottom: 1px; right: 4px; font-family: var(--font-mono); font-size: 9px; color: rgba(0, 0, 0, 0.65); font-weight: 700; }

.hotbar__name { font-size: 12.5px; font-weight: 700; color: var(--text); text-shadow: 0 2px 8px #000; }

/* タッチ操作 */
.touch { position: absolute; inset: 0; pointer-events: none; }
.touch > * { pointer-events: auto; }

.joystick {
  position: absolute;
  left: 22px; bottom: 96px;
  width: 132px; height: 132px;
  border-radius: 50%;
  background: rgba(11, 6, 22, 0.5);
  border: 2px solid var(--line-strong);
  backdrop-filter: blur(8px);
  touch-action: none;
}

.joystick__knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 56px; height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--magenta-bright), var(--magenta));
  box-shadow: 0 6px 20px -6px rgba(255, 47, 208, 0.9);
}

.touch__right { position: absolute; right: 18px; bottom: 96px; display: flex; flex-direction: column; gap: 12px; align-items: flex-end; }

.touch-btn {
  border: 2px solid var(--line-strong);
  background: rgba(11, 6, 22, 0.6);
  color: var(--text);
  border-radius: 999px;
  padding: 14px 22px;
  font-weight: 700;
  font-size: 14px;
  backdrop-filter: blur(8px);
  min-height: 54px;
}

.touch-btn--mode { border-color: rgba(182, 255, 60, 0.6); color: var(--lime); }

/* ドロワー */
.drawer {
  position: absolute;
  right: 14px;
  top: 70px;
  width: min(88vw, 340px);
  max-height: min(72vh, 560px);
  background: rgba(11, 6, 22, 0.92);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
  animation: rise 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.drawer[hidden] { display: none; }
.drawer__head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer__head h3 { font-size: 15px; }
.drawer__close { border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.drawer__close:hover { color: #fff; }
.drawer__note { font-size: 11.5px; color: var(--muted-2); padding: 10px 18px 16px; }

.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; padding: 14px 18px; overflow-y: auto; }

.palette__item {
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
  transition: transform 0.14s, border-color 0.14s;
}

.palette__item:hover { transform: translateY(-2px); }
.palette__item.is-active { border-color: var(--magenta-bright); box-shadow: 0 0 0 3px rgba(255, 47, 208, 0.2); }
.palette__swatch { height: 38px; width: 100%; box-shadow: inset 0 -12px 18px -12px rgba(0, 0, 0, 0.9); }
.palette__label { font-size: 10.5px; padding: 4px 2px; text-align: center; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat__list { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; min-height: 140px; }
.chat__item { font-size: 13.5px; line-height: 1.5; }
.chat__item b { font-family: var(--font-display); margin-right: 6px; }
.chat__item--teacher b { color: var(--magenta-bright); }
.chat__form { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.chat__input { flex: 1; background: rgba(11, 6, 22, 0.7); border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px 12px; font-size: 14px; outline: none; }
.chat__input:focus { border-color: var(--magenta-bright); }

/* スタートゲート */
.startgate { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5, 3, 12, 0.72); backdrop-filter: blur(10px); z-index: 5; }
.startgate[hidden] { display: none; }

.startgate__card {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 47, 208, 0.35);
  border-radius: var(--radius);
  padding: 36px 40px;
  text-align: center;
  max-width: min(90vw, 460px);
  box-shadow: var(--shadow);
}

.startgate__label { font-size: 12px; letter-spacing: 0.28em; color: var(--lime); font-weight: 700; }
.startgate__title { font-size: 30px; margin: 10px 0 12px; }
.startgate__text { color: var(--muted); font-size: 14px; margin-bottom: 24px; }

.loading { position: absolute; inset: 0; display: grid; place-items: center; gap: 16px; background: #05030c; z-index: 8; }
.loading[hidden] { display: none; }
.loading p { color: var(--muted); font-size: 14px; }
.loading__spin { width: 44px; height: 44px; border-radius: 50%; border: 3px solid rgba(255, 47, 208, 0.25); border-top-color: var(--magenta-bright); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* トースト */
.toast-stack { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 10px; align-items: center; pointer-events: none; }

.toast {
  background: rgba(11, 6, 22, 0.95);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow);
  animation: drop 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.toast--ok { border-color: rgba(182, 255, 60, 0.5); color: var(--lime); }
.toast--err { border-color: rgba(230, 0, 18, 0.6); color: #ff8f96; }
.toast--info { border-color: rgba(255, 47, 208, 0.5); color: var(--magenta-bright); }

@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- レスポンシブ */
@media (max-width: 900px) {
  .code-hero { grid-template-columns: 1fr; }
  .code-hero__qr { justify-self: start; }
  .code-hero__code { font-size: clamp(44px, 16vw, 72px); }
  .panel--players { grid-row: auto; }
}

@media (max-width: 640px) {
  .lobby__choices { grid-template-columns: 1fr; }
  .topbar { gap: 10px; padding: 10px 12px; }
  .tabs { order: 3; width: 100%; justify-content: space-between; }
  .tab { flex: 1; padding: 8px 6px; font-size: 12.5px; }
  .hud__bottomleft { display: none; }
  .hud-card--room { display: none; }
  .hud__topleft { max-width: 60vw; }
  .hotbar__slot { width: 40px; height: 40px; }
  .drawer { top: auto; bottom: 12px; right: 12px; left: 12px; width: auto; max-height: 62vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}


/* Phase 2: experience modes and story */
.mode-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mode-picker__item { border: 1px solid var(--line-strong); border-radius: 12px; padding: 12px 10px; background: rgba(255,255,255,.035); color: var(--muted); text-align: left; font-family: var(--font-display); font-size: 12px; font-weight: 700; line-height: 1.4; cursor: pointer; transition: all .18s; }
.mode-picker__item:hover { border-color: rgba(255,176,60,.7); color: var(--text); transform: translateY(-2px); }
.mode-picker__item.is-active { border-color: var(--amber); background: rgba(255,176,60,.13); color: #fff; box-shadow: 0 0 0 3px rgba(255,176,60,.12); }
.room-mode { display: inline-block; margin: 7px 0 0; color: var(--amber); font-size: 13px; font-weight: 700; letter-spacing: .05em; }
.story-panel { border-color: rgba(255,176,60,.35); background: linear-gradient(150deg, rgba(255,176,60,.1), rgba(255,255,255,.03)); }
.story-panel__character { color: var(--amber); font-size: 12px; font-weight: 700; margin: 2px 0 6px; }
.story-panel__title { font-size: 20px; margin: 0 0 8px; }
.story-panel__mission { border-left: 3px solid var(--amber); padding-left: 10px; color: #ffe2ac; font-size: 13px; line-height: 1.6; }
.story-panel__complete { color: var(--lime); font-size: 13px; font-weight: 700; }
.pill--story { color: var(--amber); border-color: rgba(255,176,60,.4); }
.btn--story { background: linear-gradient(100deg, #ffb03c, #d76a1b); color: #1b0d03; box-shadow: 0 14px 34px -12px rgba(255,176,60,.8); }
.hud-card--mode { border-color: rgba(255,176,60,.32); }
.hud-card--story { max-width: min(360px, 42vw); border-color: rgba(255,176,60,.45); background: rgba(38, 19, 4, .78); }
.hud-card__story-title { font-size: 15px; font-weight: 800; margin-top: 4px; }
.hud-card__story-body { color: var(--muted); font-size: 12px; line-height: 1.5; margin-top: 4px; }
@media (max-width: 640px) { .mode-picker { grid-template-columns: 1fr; } .hud-card--mode { display: none; } .hud-card--story { max-width: 82vw; } }


/* Student controls: clear, low-friction touch actions */
.touch__hint { position: absolute; left: 50%; bottom: 68px; transform: translateX(-50%); padding: 7px 12px; border: 1px solid rgba(255,255,255,.16); border-radius: 999px; background: rgba(11,6,22,.62); color: var(--muted); font-size: 11px; white-space: nowrap; backdrop-filter: blur(8px); }
.touch-btn--respawn { border-color: rgba(60,224,255,.55); color: #9ceeff; font-size: 12px; padding: 11px 17px; min-height: 44px; }
.touch-btn[aria-pressed="true"] { background: rgba(230,0,18,.18); }
@media (min-width: 641px) { .touch__hint { display: none; } }
@media (max-width: 640px) { .touch__right { bottom: 112px; } .touch__hint { bottom: 78px; } }

.hud-card__story-progress { margin-top: 8px; padding-top: 7px; border-top: 1px solid rgba(255,176,60,.25); color: #ffcf7a; font-family: var(--font-mono); font-size: 11px; font-weight: 700; }
.story-panel__progress { margin: 10px 0; padding: 8px 10px; border-radius: 8px; background: rgba(255,176,60,.1); color: #ffcf7a; font-family: var(--font-mono); font-size: 11px; font-weight: 700; }

.drawer--reference { width: min(420px, calc(100vw - 24px)); max-height: min(82vh, 760px); overflow: auto; }
.reference-figure { margin: 10px 0; border: 1px solid rgba(255,255,255,.13); border-radius: 10px; overflow: hidden; background: rgba(0,0,0,.18); }
.reference-figure img { display: block; width: 100%; height: auto; max-height: 250px; object-fit: cover; }
.reference-figure:nth-of-type(2) img { object-fit: contain; background: #f5f2ed; }
.reference-figure figcaption { padding: 7px 9px; color: var(--muted); font-size: 11px; }
.drawer__source { color: var(--muted); font-size: 11px; }
.drawer__source a { color: #9ceeff; }

.hud-card__story-condition { margin-top: 6px; color: var(--lime); font-size: 11.5px; font-weight: 700; }
.hotbar__action { font-size: 11px; color: var(--muted); text-shadow: 0 2px 8px #000; }
.hotbar__slot-name { position: absolute; left: 2px; right: 2px; bottom: 2px; display: block; font-size: 8px; line-height: 1.1; color: #fff; text-shadow: 0 1px 3px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hotbar__key { position: absolute; top: 2px; right: 4px; font-family: var(--font-mono); font-size: 9px; color: rgba(0,0,0,.68); font-weight: 700; }
.palette-search { margin: 12px 18px 0; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: rgba(255,255,255,.06); color: var(--text); outline: none; }
.palette-search:focus { border-color: var(--magenta-bright); }
.touch-actions { display: flex; gap: 8px; }
.touch-btn--place { border-color: rgba(182,255,60,.65); color: var(--lime); }
.touch-btn--break { border-color: rgba(230,0,18,.65); color: #ff8f96; }
.touch-btn--place.is-active { background: rgba(182,255,60,.2); box-shadow: 0 0 0 2px rgba(182,255,60,.25); }
.touch-btn--break.is-active { background: rgba(230,0,18,.2); box-shadow: 0 0 0 2px rgba(230,0,18,.25); }
@media (max-width: 700px) { .hotbar__slot-name { font-size: 7px; } .hotbar__slot { width: 42px; height: 42px; } }

.hotbar { max-width: calc(100vw - 24px); overflow-x: auto; }
