:root {
  --bg-felt-dark: #0a2e1f;
  --bg-felt-mid: #124831;
  --bg-felt-light: #1a5e40;
  --gold-accent: #e5b84b;
  --gold-light: #fae094;
  --tile-ivory: #fcf8ee;
  --tile-border: #d4ccb8;
  --tile-back: #d68910;
  --tile-side: #b8730c;
  --text-light: #f4f6f5;
  --text-muted: #b6c9bf;
  --danger: #e53935;
  --success: #43a047;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', 'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
  background: radial-gradient(circle at center, var(--bg-felt-light) 0%, var(--bg-felt-mid) 55%, var(--bg-felt-dark) 100%);
  color: var(--text-light);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  user-select: none;
  overflow-x: hidden;
}

/* ヘッダー */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: rgba(7, 25, 17, 0.92);
  border-bottom: 2px solid rgba(229, 184, 75, 0.45);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  gap: 12px;
  flex-wrap: wrap;
  z-index: 100;
}

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

.brand-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 46px;
  background: var(--tile-ivory);
  color: #1b5e20;
  font-family: 'Yuji Boku', 'Klee One', 'HGSGyoshotai', 'HGKyokashotai', 'HGSeikaishotaiPRO', 'DFGyoshotai', serif;
  font-size: 24px;
  font-weight: 900;
  border-radius: 5px;
  border-bottom: 4px solid var(--tile-back);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
}

.brand-titles h1 {
  font-size: 1.2rem;
  color: var(--gold-light);
  letter-spacing: 0.05em;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.game-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-sep {
  width: 1px;
  height: 22px;
  background: rgba(229, 184, 75, 0.38);
  margin: 0 3px;
}

.nav-btn {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-light);
  border: 1px solid rgba(229, 184, 75, 0.35);
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-btn:hover {
  background: rgba(229, 184, 75, 0.22);
  border-color: var(--gold-accent);
}

.nav-btn.active {
  background: var(--gold-accent);
  color: #1a1a1a;
  border-color: var(--gold-light);
  box-shadow: 0 0 12px rgba(229, 184, 75, 0.5);
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.gamepad-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--text-muted);
}

.gamepad-badge.connected {
  color: #a5d6a7;
  border-color: #66bb6a;
}

.gp-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #777;
}

.gamepad-badge.connected .gp-dot {
  background: #4caf50;
  box-shadow: 0 0 8px #4caf50;
}

.tool-btn {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-light);
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

/* メイン領域 */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
  max-width: 1360px;
  width: 100%;
  margin: 0 auto;
}

/* タイトル画面 */
.title-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 12px 0 32px;
  width: 100%;
}

.title-hero {
  text-align: center;
  max-width: 860px;
}

.title-hero h2 {
  font-size: 2rem;
  color: var(--gold-light);
  margin-bottom: 8px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

.title-hero p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

.title-meta-row {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.title-author {
  color: #c5d8cf;
  letter-spacing: 0.03em;
}

.title-meta-sep {
  opacity: 0.45;
}

.title-ofuse-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.16);
  border: 1px solid rgba(245, 158, 11, 0.45);
  color: #fcd34d;
  text-decoration: none;
  font-size: 0.76rem;
  font-weight: 700;
  transition: all 0.18s ease;
}

.title-ofuse-pill:hover {
  background: rgba(245, 158, 11, 0.3);
  border-color: #fbbf24;
  color: #fffbeb;
  transform: translateY(-1px);
}

.title-footer {
  width: 100%;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid rgba(229, 184, 75, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.title-support-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  background: rgba(5, 20, 14, 0.55);
  border: 1px solid rgba(229, 184, 75, 0.25);
  border-radius: 10px;
  padding: 10px 18px;
  max-width: 880px;
}

.title-support-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.title-support-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #111318;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 5px 14px;
  border-radius: 999px;
  text-decoration: none;
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.3);
  transition: all 0.2s ease;
  white-space: nowrap;
}

.title-support-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.45);
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
}

.title-copyright {
  font-size: 0.76rem;
  color: rgba(182, 201, 191, 0.7);
}

.categories-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
}

.category-section {
  background: rgba(5, 20, 14, 0.45);
  border: 1px solid rgba(229, 184, 75, 0.25);
  border-radius: 14px;
  padding: 16px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.category-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  border-bottom: 1px solid rgba(229, 184, 75, 0.28);
  padding-bottom: 8px;
}

.category-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--gold-light);
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-desc {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.game-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  width: 100%;
}

.game-card {
  background: linear-gradient(155deg, rgba(16, 48, 33, 0.92), rgba(8, 28, 19, 0.96));
  border: 2px solid rgba(229, 184, 75, 0.4);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  position: relative;
}

.game-card:hover,
.game-card.focused {
  transform: translateY(-4px);
  border-color: var(--gold-light);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.55), 0 0 18px rgba(229, 184, 75, 0.35);
}

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

.game-card-title-box {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.game-card-title {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--gold-light);
}

.game-card-ver {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 1px 7px;
  border-radius: 4px;
  font-family: var(--font-mono, monospace);
  letter-spacing: 0.05em;
  display: inline-block;
  vertical-align: middle;
}

.ver-v1 {
  background: rgba(229, 184, 75, 0.22);
  color: var(--gold-light);
  border: 1px solid rgba(229, 184, 75, 0.6);
  box-shadow: 0 0 8px rgba(229, 184, 75, 0.2);
}

.ver-v05 {
  background: rgba(255, 255, 255, 0.1);
  color: #c4d3cb;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.game-card-tag {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
}

.tag-mouse {
  background: rgba(33, 150, 243, 0.25);
  border: 1px solid #64b5f6;
  color: #bbdefb;
}

.tag-pad {
  background: rgba(156, 39, 176, 0.28);
  border: 1px solid #ba68c8;
  color: #f3e5f5;
}

.game-card-preview {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 10px;
}

.game-card-preview .mj-tile {
  width: 44px;
  height: 58px;
}

.game-card-desc {
  font-size: 0.9rem;
  color: #dce7e1;
  line-height: 1.55;
  flex: 1;
}

.game-card-controls {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 8px 10px;
  border-radius: 6px;
}

.game-card-play {
  margin-top: 4px;
  background: linear-gradient(180deg, #f3ca63, #d19b26);
  color: #1b1300;
  font-weight: 800;
  border: none;
  padding: 10px;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
}

/* 共通麻雀牌スタイル */
.mj-tile {
  position: relative;
  width: 48px;
  height: 64px;
  background: var(--tile-ivory);
  border: 1px solid var(--tile-border);
  border-radius: 6px;
  box-shadow:
    1px 1px 0 var(--tile-side),
    2px 3px 0 var(--tile-back),
    3px 4px 6px rgba(0, 0, 0, 0.45);
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
  overflow: hidden;
  user-select: none;
}

.mj-tile-face {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #fffdf9 0%, #f5efe0 100%);
  border-radius: 5px;
}

.mj-tile.selected {
  outline: 3px solid #ff9800;
  box-shadow: 0 0 14px rgba(255, 152, 0, 0.95), 2px 3px 0 var(--tile-back);
  transform: translateY(-3px);
}

.mj-tile.hint {
  outline: 3px solid #00e5ff;
  box-shadow: 0 0 16px rgba(0, 229, 255, 0.95);
  animation: pulseHint 0.8s infinite alternate;
}

.mj-tile.blocked {
  filter: brightness(0.76) saturate(0.85);
}

.mj-tile.petrified {
  background: #78909c;
  filter: grayscale(0.75) contrast(1.1);
}

.mj-tile.petrified .mj-tile-face {
  background: linear-gradient(180deg, #cfd8dc 0%, #90a4ae 100%);
}

@keyframes pulseHint {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

/* ゲーム共通ツールバー・ステータスパネル */
.game-shell {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  flex: 1;
}

.game-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: rgba(6, 22, 15, 0.82);
  border: 1px solid rgba(229, 184, 75, 0.35);
  border-radius: 10px;
  padding: 10px 16px;
}

.hud-stats {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.hud-stat {
  display: flex;
  flex-direction: column;
}

.hud-stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.hud-stat-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--gold-light);
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-btn {
  background: rgba(229, 184, 75, 0.16);
  color: var(--gold-light);
  border: 1px solid rgba(229, 184, 75, 0.5);
  padding: 7px 13px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.hud-btn:hover:not(:disabled) {
  background: var(--gold-accent);
  color: #151515;
}

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

.hud-select {
  background: #0d2b1d;
  color: var(--text-light);
  border: 1px solid rgba(229, 184, 75, 0.5);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
}

/* モーダル・オーバーレイ */
.game-overlay {
  position: absolute;
  inset: 0;
  background: rgba(4, 15, 10, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50000;
  border-radius: 12px;
}

.overlay-box {
  background: linear-gradient(160deg, #133b28, #092116);
  border: 2px solid var(--gold-accent);
  border-radius: 14px;
  padding: 28px 36px;
  text-align: center;
  max-width: 460px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.7);
}

.overlay-box h3 {
  font-size: 1.7rem;
  color: var(--gold-light);
  margin-bottom: 10px;
}

.overlay-box p {
  margin-bottom: 18px;
  color: #e0ece6;
  line-height: 1.5;
}

.rule-modal-box {
  max-width: 580px;
  text-align: left;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.rule-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(229, 184, 75, 0.4);
  padding-bottom: 10px;
  margin-bottom: 14px;
}

.rule-modal-header h3 {
  font-size: 1.35rem;
  color: var(--gold-light);
  margin-bottom: 0;
}

.rule-modal-body {
  overflow-y: auto;
  padding-right: 8px;
  font-size: 0.9rem;
  line-height: 1.65;
  color: #e2ede7;
}

.rule-section {
  margin-bottom: 14px;
}

.rule-section-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--gold-accent);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.rule-section ul {
  padding-left: 20px;
  margin-top: 4px;
}

.rule-section li {
  margin-bottom: 3px;
}

.rule-key-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: monospace;
  color: #fff;
  margin: 0 2px;
}

.rule-modal-footer {
  margin-top: 16px;
  text-align: center;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 12px;
}

/* 仮想コントローラーパッド（落雀・紫禁城用） */
.virtual-pad {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 10px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
}

.dpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(2, 42px);
  gap: 5px;
}

.pad-btn {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}

.pad-btn:active {
  background: var(--gold-accent);
  color: #111;
}
