/* =========================================
1. 変数・基本設定
========================================= */
:root {
  --bg-ink: #07111f;
  --bg-deep: #0f1d2d;
  --panel: rgba(8, 18, 31, 0.78);
  --panel-strong: rgba(9, 23, 39, 0.92);
  --line: rgba(173, 196, 220, 0.16);
  --line-strong: rgba(229, 196, 115, 0.35);
  --text-main: #f2f7fb;
  --text-muted: #a7b7ca;
  --text-soft: #d7e3ef;
  --accent: #18b46b;
  --accent-strong: #109057;
  --accent-warm: #e5c473;
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.12);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  color-scheme: dark;
  --bg-ink: #07111f;
  --bg-deep: #0f1d2d;
}

* {
  box-sizing: border-box;
  outline: none !important;
  -webkit-tap-highlight-color: transparent !important;
}

html {
  background-color: #07111f;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  color: var(--text-main);
  font-family:
    "Yu Gothic UI", "BIZ UDPGothic", "Hiragino Sans", Meiryo, sans-serif;
  background:
    radial-gradient(
      circle at top left,
      rgba(24, 180, 107, 0.2),
      transparent 30%
    ),
    radial-gradient(
      circle at top right,
      rgba(229, 196, 115, 0.18),
      transparent 28%
    ),
    linear-gradient(160deg, #07111f 0%, #0b1726 52%, #13253a 100%);
  display: flex;
  justify-content: center;
  align-items: center;
}

body::before {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), transparent 85%);
  content: "";
  pointer-events: none;
}

/* =========================================
2. 全体レイアウト
========================================= */
.app-shell {
  width: min(600px, calc(100% - 12px));
  height: 90dvh;
  margin: auto;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

.hero-card,
.panel {
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.hero-card {
  text-align: center;
  background:
    linear-gradient(135deg, rgba(24, 180, 107, 0.15), transparent 45%),
    linear-gradient(155deg, rgba(229, 196, 115, 0.12), transparent 60%),
    var(--panel);
  padding: 8px 12px;
}

.version-info {
  font-size: 0.7rem;
  color: #888;
  line-height: 1.4;
  margin: 0 auto;
  margin-top: 3px;
  width: fit-content;
  cursor: pointer;
}

.version-alert {
  color: var(--accent-warm);
  border: none;
  background: none;
}

.panel-main {
  background:
    linear-gradient(180deg, rgba(24, 180, 107, 0.08), transparent 28%),
    var(--panel-strong);
}

.hero-copy h1 {
  margin: 0;
  font-family: "Yu Mincho", "BIZ UDPMincho", Georgia, serif;
  font-weight: 700;
  letter-spacing: 0.03em;
  font-size: clamp(1.2rem, 4vw, 1.6rem);
}
.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-warm);
  letter-spacing: 0.28em;
  font-size: 0.65rem;
  font-weight: 700;
}
.subtitle {
  margin: 4px 0 0;
  color: var(--text-soft);
  line-height: 1.4;
  font-size: 0.75rem;
}

/* =========================================
3. 伸縮エリアの制御（★最重要ポイント★）
========================================= */
#gameContent {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  gap: 8px;
}

#gameplayArea {
  flex: 0 0 auto;
  padding: 8px 12px;
}

#gameContent > section:nth-of-type(2) {
  flex: 1 1 0;
  min-height: 0;
  padding: 6px;
}

#actionArea {
  flex: 0 0 auto;
  padding: 8px 12px;
}

/* =========================================
4. 成績ボード
========================================= */
.score-board {
  display: flex;
  justify-content: space-around;
  padding: 6px 16px;
  background: var(--panel-strong);
  border-radius: var(--radius-md);
  border: 1px solid var(--line-strong);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}
.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.score-item .label {
  font-size: 0.65rem;
  color: var(--accent-warm);
  letter-spacing: 0.15em;
  margin-bottom: 2px;
}
.score-item .value {
  font-size: 1.2rem;
  font-weight: 800;
  font-family: "Arial", sans-serif;
  color: #fff;
}

/* =========================================
5. コンポーネント
========================================= */
button,
select,
input[type="text"] {
  font: inherit;
  outline: none;
}

button.primary,
button.danger {
  border: none;
  border-radius: var(--radius-md);
  padding: 8px 12px;
  cursor: pointer;
  transition: transform 0.1s ease;
  font-weight: bold;
  white-space: nowrap;
  flex-shrink: 0;
}

button.primary:active,
button.danger:active {
  transform: scale(0.96);
}

button.primary {
  background: linear-gradient(
    135deg,
    var(--accent) 0%,
    var(--accent-strong) 100%
  );
  color: #f4fff9;
  box-shadow: 0 8px 16px rgba(24, 180, 107, 0.2);
}
button.danger {
  color: var(--danger);
  border: 1px solid rgba(255, 107, 107, 0.28);
  background: var(--danger-soft);
}

button.primary:disabled,
select:disabled {
  background: rgba(255, 255, 255, 0.05);
  color: #5c6a79;
  border: 1px solid var(--line);
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.8;
}

select,
input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(4, 13, 24, 0.7);
  color: var(--text-main);
  font-size: 16px;
}
select:focus,
input[type="text"]:focus {
  border-color: rgba(24, 180, 107, 0.7);
}

.category-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
  justify-content: center;
}
.category-buttons button {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  border: 1px solid var(--line);
  padding: 6px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
}
.category-buttons button.active {
  border-color: rgba(24, 180, 107, 0.65);
  background: linear-gradient(
    135deg,
    rgba(24, 180, 107, 0.28),
    rgba(255, 255, 255, 0.03)
  );
  color: #fff;
}
.category-buttons button.locked {
  opacity: 0.5;
  background: #1a1a1a;
  cursor: not-allowed;
  border-style: dashed;
  border-color: #555;
}
.lock-message {
  text-align: center;
  font-size: 0.7rem;
  color: var(--danger);
  margin-top: 6px;
  font-weight: bold;
}

.question-builder,
.flex-between {
  display: flex;
  flex-direction: row !important;
  gap: 8px;
  align-items: center;
}

.question-builder {
  background: rgba(0, 0, 0, 0.2);
  padding: 6px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.rule-help {
  background: none;
  border: 1px solid var(--accent-warm);
  color: var(--accent-warm);
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 11px;
  cursor: pointer;
  margin-left: 6px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* =========================================
6. 競馬新聞風パーツ
========================================= */
.history-area {
  background-color: #f4ece1;
  border: 3px solid #111;
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  flex: 1 1 100%;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  font-family: "Yu Mincho", "BIZ UDPMincho", "Hiragino Mincho ProN", serif;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1);
  -webkit-overflow-scrolling: touch;
}
.history-area::-webkit-scrollbar {
  width: 8px;
}
.history-area::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 4px;
}
.history-area::-webkit-scrollbar-track {
  background: #dcd7cd;
  border-left: 1px solid #111;
}

.history-placeholder {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  min-height: 100%;
  width: 100%;
  text-align: center;
  color: #333;
  font-size: 0.9rem;
  font-weight: 700;
}
.log-item {
  display: flex;
  align-items: stretch;
  border-bottom: 2px solid #111;
  color: #111;
  font-weight: 700;
  animation: rise 0.2s ease;
  min-height: 48px;
  font-size: 0.9rem;
}

.umaban {
  width: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.15rem;
  font-weight: 900;
  border-right: 2px solid #111;
  flex-shrink: 0;
  font-family: Arial, sans-serif;
}
.qa-content {
  padding: 4px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0;
}

.waku-1 .umaban {
  background-color: #ffffff;
  color: #111;
}
.waku-2 .umaban {
  background-color: #333333;
  color: #fff;
}
.waku-3 .umaban {
  background-color: #d32f2f;
  color: #fff;
}
.waku-4 .umaban {
  background-color: #1976d2;
  color: #fff;
}
.waku-5 .umaban {
  background-color: #fbc02d;
  color: #111;
}
.waku-6 .umaban {
  background-color: #388e3c;
  color: #fff;
}
.waku-7 .umaban {
  background-color: #f57c00;
  color: #fff;
}
.waku-8 .umaban {
  background-color: #f48fb1;
  color: #111;
}

.log-item span.yes {
  color: #d32f2f;
  font-size: 1rem;
}
.log-item span.yes::before {
  content: "◎ ";
}
.log-item span.no {
  color: #111;
  font-size: 1rem;
}
.log-item span.no::before {
  content: "× ";
}

/* =========================================
7. 結果表示
========================================= */
#resultArea {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: 1 1 0;
  min-height: 0;
  background:
    linear-gradient(
      135deg,
      rgba(229, 196, 115, 0.08),
      rgba(24, 180, 107, 0.08)
    ),
    var(--panel);
  text-align: center;
}
.result-panel.success {
  border-color: rgba(24, 180, 107, 0.42);
}
.result-panel.gameover {
  border-color: rgba(255, 107, 107, 0.42);
}
.result-name {
  font-family: "Yu Mincho", "BIZ UDPMincho", Georgia, serif;
  font-size: clamp(1.4rem, 6vw, 2.2rem);
  font-weight: 700;
  margin-bottom: 8px;
}
.result-desc {
  line-height: 1.5;
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  margin-bottom: 12px;
  width: 70%;
  flex: 1 1 0;
  overflow-y: auto;
  min-height: 0;
}

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

/* =========================================
8. 極小画面向け調整（スマホ用）
========================================= */
@media (max-width: 480px) {
  .log-item {
    min-height: 42px;
    font-size: 0.8rem;
  }
  .umaban {
    width: 34px;
    font-size: 1rem;
  }
  .qa-content {
    padding: 2px 8px;
  }
  .log-item span.yes,
  .log-item span.no {
    font-size: 0.9rem;
  }
  .history-placeholder {
    font-size: 0.8rem;
  }
}

/* =========================================
9. フッター（AI免責事項）
========================================= */
.ai-disclaimer {
  flex-shrink: 0;
  margin: 0px auto;
  margin-top: 5px;
  max-width: 600px;
  text-align: center;
  opacity: 0.6;
  padding-bottom: 4px;
}

.ai-disclaimer .divider {
  height: 1px;
  background: linear-gradient(
    to right,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  margin-bottom: 5px;
}

.ai-disclaimer p {
  font-size: 0.5rem;
  color: #888;
  line-height: 1.4;
  margin: 0;
}

/* =========================================
10. エラー報告リンク
========================================= */
.report-error {
  font-size: 0.5rem;
  color: #888;
  line-height: 1.6;
  margin-top: 4px;
}

.report-error a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: #555;
  transition: color 0.2s ease;
  padding: 4px;
  display: inline-block;
}

.report-error a:hover {
  color: #ccc;
  text-decoration-color: #ccc;
}
