:root {
  color-scheme: dark;
  --bg-main: #0b1120;
  --bg-surface: #131c31;
  --bg-elevated: #1e293b;
  --bg-soft: rgba(255, 255, 255, 0.06);
  --border-color: rgba(148, 163, 184, 0.18);
  --text-main: #f8fafc;
  --text-sub: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-2: #ec4899;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.42);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --header-h: 64px;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg-main: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-elevated: #f8fafc;
  --bg-soft: rgba(15, 23, 42, 0.06);
  --border-color: rgba(15, 23, 42, 0.12);
  --text-main: #0f172a;
  --text-sub: #475569;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --shadow-lg: 0 12px 30px rgba(15, 23, 42, 0.12);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html {
  margin: 0;
  padding: 0;
  background: var(--bg-main);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  overscroll-behavior-x: none;
  overscroll-behavior-y: none;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-main);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  overflow-x: clip;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
  overscroll-behavior-x: none;
  overscroll-behavior-y: none;
}

button, input, select {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button:active:not(:disabled) {
  transform: scale(0.96);
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* === ヘッダー === */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 8px 14px;
  background: color-mix(in srgb, var(--bg-surface) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header-right {
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-title {
  font-weight: 800;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
}

.sync-dot {
  font-size: 0.68rem;
  color: var(--success);
}

.active-game-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-pill, .header-btn {
  min-height: 42px;
  height: 42px;
  min-width: 42px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--bg-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.header-btn.icon-only {
  width: 42px;
  padding: 0;
  font-size: 1.05rem;
}

.lobby-btn {
  border-color: rgba(99, 102, 241, 0.45);
  background: rgba(99, 102, 241, 0.14);
}

.badge {
  background: var(--accent-2);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 999px;
}

.account-pill {
  min-height: 42px;
  height: 42px;
  padding: 4px 12px 4px 6px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 160px;
  flex-shrink: 0;
}

.avatar-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  overflow: hidden;
  flex-shrink: 0;
}

.avatar-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-name-text {
  font-size: 0.82rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.g-badge {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #4285f4;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* === ホーム画面 === */
.home-container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 14px calc(36px + env(safe-area-inset-bottom, 0px));
}

.hero-card {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.22), rgba(236, 72, 153, 0.16));
  border: 1px solid rgba(129, 140, 248, 0.28);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}

.hero-chip {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.25);
  color: #c7d2fe;
  margin-bottom: 8px;
}

html[data-theme="light"] .hero-chip {
  color: #3730a3;
}

.hero-greeting h2 {
  margin: 0 0 6px;
  font-size: 1.32rem;
  line-height: 1.3;
}

.hero-greeting p {
  margin: 0 0 14px;
  font-size: 0.88rem;
  color: var(--text-sub);
  line-height: 1.5;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s, border-color 0.15s;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-google {
  background: #ffffff;
  color: #1e293b;
  border-color: rgba(148, 163, 184, 0.4);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.g-logo {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: conic-gradient(#ea4335 0deg 90deg, #fbbc05 90deg 180deg, #34a853 180deg 270deg, #4285f4 270deg 360deg);
  color: #fff;
  font-weight: 900;
  font-size: 0.78rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border-color);
}

.btn-ghost {
  background: var(--bg-soft);
  border-color: var(--border-color);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.35);
}

/* 再開バナー */
.continue-section {
  margin-bottom: 16px;
}

.section-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-sub);
  margin-bottom: 8px;
}

.continue-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.continue-list::-webkit-scrollbar { display: none; }

.continue-card {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--bg-surface);
  border: 1px solid rgba(16, 185, 129, 0.4);
  min-width: 210px;
}

/* カテゴリチップ */
.category-bar {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 2px 0 12px;
  margin-bottom: 12px;
  scrollbar-width: none;
}
.category-bar::-webkit-scrollbar { display: none; }

.cat-chip {
  flex: 0 0 auto;
  min-height: 42px;
  height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-sub);
}

.cat-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ゲームカード一覧 */
.games-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (min-width: 680px) {
  .games-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
  }
}

@media (min-width: 980px) {
  .games-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.game-card {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
  overflow: hidden;
}

.game-card:hover {
  border-color: rgba(129, 140, 248, 0.55);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.game-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.game-icon-box {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.65rem;
  flex-shrink: 0;
}

.game-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

.mini-tag {
  font-size: 0.66rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text-sub);
}

.mini-tag.mp {
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
}
html[data-theme="light"] .mini-tag.mp {
  color: #4338ca;
}

.mini-tag.save {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
}
html[data-theme="light"] .mini-tag.save {
  color: #047857;
}

.game-card h3 {
  margin: 2px 0 4px;
  font-size: 1.02rem;
  font-weight: 800;
}

.game-card p {
  margin: 0;
  font-size: 0.77rem;
  color: var(--text-sub);
  line-height: 1.38;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.game-card-stat {
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
  font-size: 0.74rem;
  color: var(--text-sub);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-highlight {
  font-weight: 700;
  color: var(--text-main);
}

/* === ゲームプレイビュー (スマホ縦横スクロール完全対応) === */
.game-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 12px calc(28px + env(safe-area-inset-bottom, 0px));
}

.game-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  column-gap: 14px;
  row-gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.game-mode-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.game-toolbar-right {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-left: auto;
  flex-shrink: 0;
}

.tool-chip {
  flex: 0 0 auto;
  min-height: 40px;
  min-width: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 0.83rem;
  font-weight: 700;
  white-space: nowrap;
}

.tool-chip:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tool-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.game-mount {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  user-select: none;
  -webkit-user-select: none;
  gap: 12px;
  padding: 8px 0 20px;
}

/* === 各ゲーム共通UIコンポーネント === */
.g-panel {
  width: 100%;
  max-width: 520px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 10px 12px;
}

.g-status-row {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.86rem;
  font-weight: 700;
  flex-shrink: 0;
}

.g-controls-row {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  flex-shrink: 0;
}

.g-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  font-weight: 700;
  font-size: 0.88rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.g-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.g-btn.active {
  background: rgba(99, 102, 241, 0.25);
  border-color: var(--accent);
  color: #a5b4fc;
}
html[data-theme="light"] .g-btn.active {
  color: var(--accent);
}

.no-touch-scroll {
  touch-action: none;
}

/* 数独専用グリッド & 数字キーパッド */
.sudoku-board {
  width: min(92vw, 46vh, 410px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  border: 2.5px solid var(--text-main);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-surface);
  flex-shrink: 0;
}

.sudoku-cell {
  border: 0.5px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1rem, 4.3vw, 1.35rem);
  font-weight: 700;
  cursor: pointer;
  position: relative;
  padding: 0;
  background: transparent;
}

.sudoku-cell.box-r { border-right: 2px solid var(--text-main); }
.sudoku-cell.box-b { border-bottom: 2px solid var(--text-main); }
.sudoku-cell.given { color: var(--text-main); font-weight: 800; }
.sudoku-cell.user-val { color: #60a5fa; }
html[data-theme="light"] .sudoku-cell.user-val { color: #2563eb; }
.sudoku-cell.related { background: rgba(99, 102, 241, 0.1); }
.sudoku-cell.same-num { background: rgba(99, 102, 241, 0.26); }
.sudoku-cell.selected { background: rgba(99, 102, 241, 0.45) !important; }
.sudoku-cell.conflict { background: rgba(239, 68, 68, 0.32) !important; color: #fca5a5; }

.sudoku-notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  font-size: clamp(0.46rem, 1.7vw, 0.62rem);
  line-height: 1;
  color: var(--text-sub);
  align-items: center;
  justify-items: center;
  pointer-events: none;
}

.sudoku-numpad {
  width: 100%;
  max-width: 430px;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 5px;
  flex-shrink: 0;
}

.numpad-key {
  height: clamp(44px, 6.8vh, 54px);
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  font-size: 1.18rem;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.numpad-key small {
  font-size: 0.58rem;
  color: var(--text-sub);
  font-weight: 600;
}

/* オセロ盤 */
.othello-board {
  width: min(92vw, 52vh, 420px);
  aspect-ratio: 1 / 1;
  background: #065f46;
  border: 4px solid #064e3b;
  border-radius: 12px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 2px;
  padding: 3px;
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
}

.othello-cell {
  background: #059669;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0;
  border: none;
}

.othello-disc {
  width: 80%;
  height: 80%;
  border-radius: 50%;
  transition: transform 0.24s ease, background 0.2s ease;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.45);
}

.othello-disc.black {
  background: radial-gradient(circle at 32% 30%, #475569, #090d16 70%);
}

.othello-disc.white {
  background: radial-gradient(circle at 32% 30%, #ffffff, #cbd5e1 78%);
  forced-color-adjust: none;
}

.othello-hint {
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.38);
}

.othello-last-dot {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f43f5e;
}

/* 2048 ボード */
.board-2048 {
  width: min(90vw, 50vh, 400px);
  aspect-ratio: 1 / 1;
  background: #334155;
  border-radius: 14px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 9px;
  touch-action: none;
  flex-shrink: 0;
}

.tile-2048 {
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: clamp(1.2rem, 5.5vw, 1.85rem);
  transition: transform 0.1s ease;
}

.tile-2048.pop {
  animation: popIn 0.16s ease;
}

@keyframes popIn {
  0% { transform: scale(0.7); }
  75% { transform: scale(1.07); }
  100% { transform: scale(1); }
}

/* 通信対戦プレイヤーバー & スタンプ */
.mp-room-banner {
  width: 100%;
  max-width: 520px;
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.2), rgba(236, 72, 153, 0.18));
  border: 1px solid rgba(129, 140, 248, 0.38);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.emoji-bar {
  display: flex;
  gap: 6px;
}

.emoji-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  font-size: 1.05rem;
  padding: 0;
}

.emoji-float-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
  overflow: hidden;
}

.floating-emoji {
  position: absolute;
  bottom: 85px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 1.05rem;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  animation: floatUp 2.2s ease-out forwards;
}

@keyframes floatUp {
  0% { opacity: 0; transform: translateY(20px) scale(0.8); }
  15% { opacity: 1; transform: translateY(0) scale(1); }
  85% { opacity: 1; transform: translateY(-110px) scale(1); }
  100% { opacity: 0; transform: translateY(-145px) scale(0.9); }
}

/* === モーダル (スマホではボトムシート表示) === */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-sheet {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  max-height: 88dvh;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (max-width: 600px) {
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .modal-sheet {
    max-width: 100%;
    max-height: 90dvh;
    border-radius: 22px 22px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

.modal-header {
  padding: 15px 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.02rem;
}

.modal-close {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-soft);
  font-size: 1rem;
}

.modal-body {
  padding: 16px 18px 22px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* フォーム・カード類 */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-sub);
  margin-bottom: 6px;
}

.input-box {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  font-size: 0.95rem;
}

.card-block {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}

.code-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.65rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-align: center;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg-main);
  border: 1px dashed var(--accent);
  margin: 8px 0;
  user-select: all;
  -webkit-user-select: all;
}

/* トースト */
.toast-container {
  position: fixed;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 380px);
  pointer-events: none;
}

.toast {
  background: var(--bg-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
}

/* スマホ用Dパッド */
.mobile-dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(2, 50px);
  gap: 6px;
  justify-content: center;
  margin-top: 4px;
}

.dpad-btn {
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  font-size: 1.25rem;
  font-weight: 900;
}

/* カージャム・ミャウドク ステージ選択グリッド */
.cj-stage-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}

@media (min-width: 520px) {
  .cj-stage-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
  }
}

/* Meowdoku (ミャウドク) ボード & アニメーション */
.meow-board-wrap {
  position: relative;
  width: min(94vw, 56dvh, 436px);
  aspect-ratio: 1 / 1;
  flex-shrink: 0;
}

.meow-board {
  width: 100%;
  height: 100%;
  display: grid;
  border: 3px solid #0f172a;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: #0f172a;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.meow-board.drag-x-mode {
  touch-action: none;
}

.meow-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  cursor: pointer;
  border-style: solid;
  transition: filter 0.12s ease, transform 0.12s ease;
}

.meow-cell:active {
  filter: brightness(0.93);
}

.meow-cell.hint-pulse {
  animation: meowHintPulse 0.9s ease-in-out 2;
}

.meow-cell.shake-err {
  animation: meowShake 0.36s ease;
}

.meow-cat-icon {
  width: 78%;
  height: 78%;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: popIn 0.22s cubic-bezier(0.2, 1.3, 0.4, 1);
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(15, 23, 42, 0.32));
}

.meow-x-mark {
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  color: rgba(15, 23, 42, 0.48);
  font-size: clamp(0.85rem, 3.6vw, 1.18rem);
}

.meow-x-mark.wrong {
  color: #dc2626;
  font-size: clamp(0.95rem, 4vw, 1.28rem);
}

.meow-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.84);
  backdrop-filter: blur(4px);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px;
  text-align: center;
  z-index: 5;
}

@keyframes meowShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  45% { transform: translateX(5px); }
  70% { transform: translateX(-4px); }
  88% { transform: translateX(3px); }
}

@keyframes meowHintPulse {
  0%, 100% { box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0); }
  50% { box-shadow: inset 0 0 0 5px #fff, inset 0 0 16px rgba(251, 191, 36, 0.9); }
}

/* Block Blast! (ブロックブラスト) */
.bb-stage-wrap {
  width: 100%;
  max-width: 444px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 0 auto;
}

.bb-hud-row {
  width: 100%;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 8px;
}

.bb-score-pill {
  flex: 1;
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.92), rgba(30, 41, 59, 0.88));
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 13px;
  padding: 6px 11px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 48px;
  box-shadow: 0 3px 10px rgba(2, 6, 23, 0.28);
}

.bb-score-pill .bb-lbl {
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 4px;
}

.bb-score-pill .bb-val {
  font-size: 1.18rem;
  font-weight: 900;
  line-height: 1.15;
  color: #f8fafc;
  font-variant-numeric: tabular-nums;
}

.bb-score-pill.best .bb-val {
  color: #fbbf24;
}

.bb-goal-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 900;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(96, 165, 250, 0.35);
  color: #e2e8f0;
}

.bb-goal-pill.done {
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(52, 211, 153, 0.65);
  color: #6ee7b7;
}

.bb-canvas-box {
  position: relative;
  width: max(284px, min(94vw, calc((100dvh - 198px) * 0.757), 432px));
  aspect-ratio: 400 / 528;
  flex-shrink: 0;
  user-select: none;
  -webkit-user-select: none;
}

.bb-canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 16px;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.bb-overlay {
  position: absolute;
  inset: 0;
  background: rgba(9, 14, 28, 0.84);
  backdrop-filter: blur(5px);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
  z-index: 6;
  animation: fadeIn 0.22s ease;
}

/* Magic Sort! (マジックソート) */
.ms-stage-wrap {
  width: 100%;
  max-width: 472px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 0 auto;
}

.ms-canvas-box {
  position: relative;
  width: min(95vw, 464px);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  user-select: none;
  -webkit-user-select: none;
}

.ms-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* ==========================================================
   Typing Battle (フリック＆ローマ字タイピング)
   ========================================================== */
.tp-wrap {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
}

.tp-hud-bar {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.tp-stat-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 11px;
  padding: 5px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.tp-stat-lbl {
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--text-sub);
  line-height: 1.1;
}

.tp-stat-val {
  font-size: 0.98rem;
  font-weight: 900;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}

.tp-race-box {
  width: 100%;
  max-height: 158px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tp-race-lane {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.76rem;
}

.tp-race-name {
  width: 108px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;
}

.tp-race-track {
  flex: 1;
  height: 10px;
  background: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.tp-race-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #22d3ee);
  border-radius: 999px;
  transition: width 0.18s ease;
}

.tp-race-fill.me {
  background: linear-gradient(90deg, #10b981, #34d399);
}

.tp-race-meta {
  width: 64px;
  flex-shrink: 0;
  text-align: right;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text-sub);
}

.tp-prompt-card {
  position: relative;
  width: 100%;
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  border-radius: 16px;
  padding: 12px 14px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transition: border-color 0.14s ease;
}

.tp-prompt-card.miss-shake {
  border-color: #ef4444;
  animation: meowShake 0.28s ease;
}

.tp-progress-strip {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(148, 163, 184, 0.16);
}

.tp-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #ec4899, #8b5cf6, #06b6d4);
  transition: width 0.12s linear;
}

.tp-prompt-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.73rem;
  color: var(--text-sub);
  margin-bottom: 4px;
}

.tp-word-jp {
  font-size: clamp(1.22rem, 4.8vw, 1.68rem);
  font-weight: 900;
  color: var(--text-main);
  line-height: 1.3;
  margin: 2px 0 5px;
  min-height: 1.4em;
  word-break: keep-all;
}

.tp-word-kana {
  font-size: clamp(0.95rem, 3.8vw, 1.16rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1.45;
  min-height: 1.5em;
}

.tp-kana-done {
  color: #10b981;
}

.tp-kana-cur {
  display: inline-block;
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.16);
  border-bottom: 2.5px solid #fbbf24;
  border-radius: 4px;
  padding: 0 2px;
}

.tp-kana-pending {
  display: inline-block;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.2);
  border-bottom: 2.5px solid #38bdf8;
  border-radius: 4px;
  padding: 0 3px;
}

.tp-kana-rest {
  color: var(--text-sub);
}

.tp-romaji-line {
  margin-top: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(0.92rem, 3.4vw, 1.12rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  min-height: 1.4em;
}

.tp-rom-done {
  color: #10b981;
}

.tp-rom-cur {
  color: #38bdf8;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.tp-rom-rest {
  color: var(--text-muted);
}

/* 専用12キー・フリックキーボード */
.tp-flick-wrap {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.tp-flick-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1.15fr)) minmax(0, 0.9fr);
  grid-template-rows: repeat(4, minmax(52px, 60px));
  gap: 6px;
  width: 100%;
  touch-action: none;
}

@media (max-height: 700px) {
  .tp-flick-grid {
    grid-template-rows: repeat(4, 48px);
    gap: 5px;
  }
}

.tp-fkey {
  position: relative;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2px;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(2, 6, 23, 0.35);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.06s ease, background 0.08s ease, border-color 0.1s ease;
}

.tp-fkey.util {
  background: var(--bg-surface);
}

.tp-fkey.pressing {
  background: rgba(99, 102, 241, 0.28);
  border-color: var(--accent);
  transform: scale(0.97);
}

.tp-fkey.mod-glow {
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.45), 0 0 12px rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.16);
}

.tp-fkey-main {
  font-size: 1.18rem;
  font-weight: 900;
  line-height: 1.1;
  pointer-events: none;
}

.tp-fkey-sub {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  line-height: 1.05;
  margin-top: 2px;
  pointer-events: none;
}

/* 5方向十字フリックポップアップ */
.tp-flick-popup {
  position: fixed;
  width: 126px;
  height: 126px;
  pointer-events: none;
  z-index: 90;
  transform: translate(-50%, -62%);
}

.tp-flick-petal {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: rgba(15, 23, 42, 0.94);
  border: 1.5px solid rgba(148, 163, 184, 0.42);
  color: #e2e8f0;
  font-size: 1.12rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  transition: transform 0.06s ease, background 0.06s ease;
}

.tp-flick-petal.active {
  background: linear-gradient(135deg, #6366f1, #ec4899);
  border-color: #ffffff;
  color: #ffffff;
  transform: scale(1.16);
  z-index: 2;
}

.tp-flick-petal.dir-center { top: 43px; left: 43px; }
.tp-flick-petal.dir-up     { top: 0px;  left: 43px; }
.tp-flick-petal.dir-down   { top: 86px; left: 43px; }
.tp-flick-petal.dir-left   { top: 43px; left: 0px;  }
.tp-flick-petal.dir-right  { top: 43px; left: 86px; }

/* PC ローマ字ミニキーボードビジュアル */
.tp-qwerty-box {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
}

.tp-qrow {
  display: flex;
  gap: 4px;
  justify-content: center;
  width: 100%;
}

.tp-qkey {
  width: clamp(24px, 7.2vw, 36px);
  height: 34px;
  border-radius: 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--text-sub);
  transition: background 0.08s ease, color 0.08s ease, transform 0.06s ease;
}

.tp-qkey.next-hint {
  border-color: #38bdf8;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.14);
}

.tp-qkey.hit {
  background: #10b981;
  border-color: #34d399;
  color: #ffffff;
  transform: translateY(1px);
}

/* レスポンシブ表示制御 */
.show-xs-flex { display: none; }

@media (max-width: 560px) {
  .app-header {
    padding-left: 12px;
    padding-right: 12px;
    gap: 10px;
  }
  .header-left, .header-right {
    gap: 9px;
  }
  .user-name-text {
    display: none;
  }
  .account-pill {
    padding: 4px 7px;
    min-width: 42px;
    justify-content: center;
  }
  .lobby-btn {
    padding: 0 11px;
  }
}

@media (max-width: 520px) {
  .hide-xs { display: none !important; }
  .hide-mobile-sm { display: none !important; }
  .show-xs-flex { display: inline-flex; }
  .hero-card { padding: 16px; }
  .hero-greeting h2 { font-size: 1.12rem; }
  .hero-actions .btn { width: 100%; }
}

@media (max-width: 760px) {
  .hide-sm { display: none !important; }
}
