:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #e0e7ff;
  --accent: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --bg-color: #0f172a;
  --card-bg: #1e293b;
  --card-border: #334155;
  --text-main: #f8fafc;
  --text-sub: #94a3b8;
  --font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  background-image: radial-gradient(circle at 50% 0%, #1e1b4b 0%, #0f172a 75%);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12px;
  overflow-x: hidden;
}

.mobile-wrapper {
  width: 100%;
  max-width: 440px;
  min-height: calc(100vh - 24px);
  min-height: calc(100dvh - 24px);
  display: flex;
  flex-direction: column;
  position: relative;
}

/* 画面切り替え */
.screen-view {
  display: none;
  flex-direction: column;
  flex: 1;
  animation: fadeIn 0.25s ease-out;
}

.screen-view.active {
  display: flex;
}

/* バージョンバッジ */
.header-badge-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.version-tag {
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  border: 1px solid rgba(165, 180, 252, 0.3);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 9999px;
}

/* --- 画面1: スタート画面 --- */
.start-hero {
  text-align: center;
  margin-top: 20px;
  margin-bottom: 20px;
}

.hero-icon-box {
  font-size: 3rem;
  margin-bottom: 12px;
  display: flex;
  justify-content: center;
  gap: 12px;
}

.app-title {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 2.1rem;
  font-weight: 900;
  line-height: 1.25;
  color: #ffffff;
  letter-spacing: -0.5px;
}

.highlight-title {
  background: linear-gradient(90deg, #818cf8, #38bdf8, #34d399);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ボタンに見えないシンプルなテキストリスト */
.simple-rules-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 24px;
}

.rule-line {
  font-size: 1rem;
  font-weight: 700;
  color: #cbd5e1;
  letter-spacing: 0.5px;
}

/* プレイヤー名表示バー */
.player-profile-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  background: rgba(30, 41, 59, 0.6);
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.85rem;
  color: #94a3b8;
  margin-bottom: 20px;
  align-self: center;
}

.player-profile-row strong {
  color: #38bdf8;
}

.btn-text-link {
  background: none;
  border: none;
  color: #818cf8;
  font-size: 0.75rem;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

.btn-cta {
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: 18px;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 1.25rem;
  font-weight: 900;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 10px 25px -5px rgba(79, 70, 229, 0.5);
  transition: all 0.2s ease;
  margin-top: auto;
  margin-bottom: 16px;
}

.btn-cta:active {
  transform: scale(0.98);
  box-shadow: 0 5px 15px -3px rgba(79, 70, 229, 0.4);
}

/* --- 画面2: ゲームプレイ画面 --- */
.quiz-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.q-progress-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.q-badge {
  background: #312e81;
  color: #c7d2fe;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 9999px;
}

.btn-giveup-link {
  background: transparent;
  border: 1px solid #475569;
  color: #94a3b8;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-giveup-link:hover, .btn-giveup-link:active {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border-color: #ef4444;
}

.progress-track {
  width: 100%;
  height: 6px;
  background: #1e293b;
  border-radius: 9999px;
  overflow: hidden;
  margin-bottom: 14px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #38bdf8);
  border-radius: 9999px;
  transition: width 0.25s ease;
}

/* 鏡文字表示ボックス */
.mirror-box-container {
  width: 100%;
  margin-bottom: 12px;
}

.mirror-view-box {
  position: relative;
  background: #020617;
  border: 2px solid #334155;
  border-radius: var(--radius-md);
  height: 135px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.6);
  user-select: none;
  overflow: hidden;
}

.mirror-target-text {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 2.1rem;
  font-weight: 900;
  color: #38bdf8;
  text-shadow: 0 0 16px rgba(56, 189, 248, 0.5);
  letter-spacing: 3px;
  text-align: center;
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  word-break: break-all;
  transform-origin: center center;
}

/* 正常向き */
.mirror-target-text.normal {
  transform: none;
}

/* 上下反転（水面反射） */
.mirror-target-text.vertical {
  transform: scaleY(-1);
}

/* 左右反転（鏡文字） */
.mirror-target-text.horizontal {
  transform: scaleX(-1);
}

/* 画面中央カウントダウン（位置ズレなしの固定オーバーレイ） */
.center-countdown-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 150;
  pointer-events: none;
  animation: fadeIn 0.15s ease;
}

.center-countdown-card {
  background: rgba(15, 23, 42, 0.96);
  border: 2px solid #4338ca;
  border-radius: var(--radius-lg);
  padding: 16px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.7);
}

.center-cd-tag {
  background: #312e81;
  color: #c7d2fe;
  font-size: 0.85rem;
  font-weight: 800;
  padding: 3px 12px;
  border-radius: 9999px;
}

.center-cd-num {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 4rem;
  font-weight: 900;
  color: #38bdf8;
  text-shadow: 0 0 20px rgba(56, 189, 248, 0.8);
  line-height: 1.1;
  animation: popNum 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* 入力エリア */
.quiz-input-area {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-row {
  display: flex;
  gap: 8px;
}

.quiz-input-field {
  flex: 1;
  background: #0f172a;
  border: 2px solid #475569;
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-size: 1.25rem;
  font-family: var(--font-family);
  font-weight: 700;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.2s ease;
}

.quiz-input-field:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

.btn-send {
  background: #6366f1;
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 18px;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.2s ease;
  white-space: nowrap;
}

.btn-send:active {
  background: #4f46e5;
  transform: scale(0.96);
}

.input-subnote {
  font-size: 0.75rem;
  color: var(--text-sub);
  text-align: center;
}

/* 判定トースト (⭕️/❌) */
.feedback-toast {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.7);
  background: rgba(15, 23, 42, 0.92);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-lg);
  padding: 16px 28px;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  backdrop-filter: blur(8px);
  z-index: 50;
  box-shadow: 0 15px 30px rgba(0,0,0,0.5);
  pointer-events: none;
}

.feedback-toast.show {
  display: flex;
  animation: popFeedback 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.feedback-icon {
  font-size: 2.8rem;
  line-height: 1;
}

.feedback-msg {
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
}

/* モーダル汎用 */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
  animation: fadeIn 0.2s ease;
}

.modal-dialog {
  background: #1e293b;
  border: 2px solid #475569;
  border-radius: var(--radius-md);
  padding: 24px 20px;
  width: 90%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

.modal-dialog h3 {
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
  margin-bottom: 6px;
}

.modal-dialog p {
  font-size: 0.85rem;
  color: #94a3b8;
  margin-bottom: 16px;
  line-height: 1.5;
}

.name-input-field {
  width: 100%;
  margin-bottom: 14px;
  text-align: center;
  font-size: 1.3rem;
}

.btn-primary-block {
  width: 100%;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.2s ease;
}

.btn-primary-block:hover {
  background: var(--primary-dark);
}

.modal-dialog-buttons {
  display: flex;
  gap: 10px;
}

.btn-modal-cancel {
  flex: 1;
  background: #334155;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px;
  font-weight: 700;
  cursor: pointer;
}

.btn-modal-danger {
  flex: 1;
  background: #ef4444;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px;
  font-weight: 700;
  cursor: pointer;
}

/* --- 画面3: 結果発表＆Xシェア画面 --- */
.result-header {
  text-align: center;
  margin-bottom: 14px;
}

.result-badge {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: #38bdf8;
  margin-bottom: 4px;
}

.result-header h2 {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 1.6rem;
  font-weight: 900;
  color: #fff;
}

.iq-card {
  background: linear-gradient(145deg, #1e1b4b 0%, #0f172a 100%);
  border: 2px solid #4338ca;
  border-radius: var(--radius-lg);
  padding: 20px 18px;
  margin-bottom: 18px;
  box-shadow: 0 15px 30px -5px rgba(0, 0, 0, 0.4);
}

.iq-card-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-bottom: 12px;
}

.iq-player-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: #38bdf8;
}

.iq-number-wrap {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.iq-prefix {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 1.8rem;
  font-weight: 900;
  color: #818cf8;
}

.iq-number {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 3.8rem;
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(90deg, #38bdf8, #fbbf24, #f472b6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 8px rgba(56, 189, 248, 0.4));
}

.rank-badge-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.rank-title {
  background: rgba(251, 191, 36, 0.15);
  color: #fbbf24;
  border: 1.5px solid rgba(251, 191, 36, 0.4);
  font-size: 1.05rem;
  font-weight: 800;
  padding: 6px 16px;
  border-radius: 9999px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: rgba(0, 0, 0, 0.25);
  padding: 10px;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.s-label {
  font-size: 0.7rem;
  color: #94a3b8;
  font-weight: 600;
}

.s-val {
  font-size: 0.95rem;
  font-weight: 800;
  color: #f1f5f9;
  font-family: 'M PLUS Rounded 1c', sans-serif;
}

.result-comment {
  font-size: 0.85rem;
  color: #cbd5e1;
  line-height: 1.5;
  background: rgba(255, 255, 255, 0.05);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

/* アクションボタン群 */
.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.btn-share-x {
  background: #000000;
  color: #ffffff;
  border: 1.5px solid #333333;
  border-radius: var(--radius-md);
  padding: 14px;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 1.05rem;
  font-weight: 800;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  transition: all 0.2s ease;
}

.btn-share-x:hover {
  background: #111111;
  border-color: #555555;
}

.btn-share-x:active {
  transform: scale(0.98);
}

.btn-restart {
  background: #1e293b;
  color: #cbd5e1;
  border: 1px solid #475569;
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-restart:hover {
  background: #334155;
  color: #fff;
}

.review-section {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 20px;
}

.review-section summary {
  font-size: 0.85rem;
  font-weight: 700;
  color: #94a3b8;
  cursor: pointer;
}

.review-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.8rem;
}

.review-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.review-item.correct {
  border-left: 3px solid #10b981;
}

.review-item.incorrect {
  border-left: 3px solid #ef4444;
}

#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 100;
}

.mobile-footer {
  text-align: center;
  font-size: 0.75rem;
  color: #64748b;
  padding: 12px 0 6px;
  margin-top: auto;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes popNum {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes popFeedback {
  0% { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
  60% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
