:root {
  --color-bg: #f3f4f6;
  --color-bg-soft: #e5e7eb;
  --color-surface: #ffffff;
  --color-surface-soft: #f9fafb;
  --color-accent: #2563eb;
  --color-accent-soft: rgba(37, 99, 235, 0.08);
  --color-border-subtle: #e5e7eb;
  --color-text-main: #111827;
  --color-text-muted: #6b7280;
  --color-danger: #dc2626;

  --radius-lg: 18px;
  --radius-full: 999px;
  --shadow-soft: 0 16px 35px rgba(15, 23, 42, 0.12);
}

/* ベース */

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

html {
  margin: 0;
  padding: 0;
  width: 100%;
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Helvetica Neue", Arial, sans-serif;
  color: var(--color-text-main);
  background: #ffffff;
  -webkit-font-smoothing: antialiased;
}

/* アプリ全体のラッパー */

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  width: 100%;
  position: relative;
}

.app-shell.input-active {
  height: 100vh;
  min-height: auto;
  overflow: hidden;
}

/* ヘッダー */

.app-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: #f5f5f7;
  border-bottom: 1px solid var(--color-border-subtle);
  width: 100%;
  position: relative;
  left: 0;
  right: 0;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.brand-title {
  font-size: 20px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0;
}

.brand-subtitle {
  margin: 0;
  font-size: 13px;
  color: var(--color-text-muted);
}

.header-description {
  display: none;
}

/* モード切り替え */

.mode-nav {
  display: flex;
  gap: 8px;
}

.mode-button {
  border: 1px solid var(--color-border-subtle);
  background: var(--color-surface);
  color: var(--color-text-muted);
  padding: 8px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition:
    background-color 0.18s ease,
    color 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.mode-button.is-active {
  background: var(--color-accent);
  color: #ffffff;
  border-color: var(--color-accent);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.mode-button:not(.is-active):hover {
  background: var(--color-surface-soft);
  color: var(--color-text-main);
  border-color: #d1d5db;
}

/* メイン */

.main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 16px 16px;
  flex: 1;
  min-height: 0;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  overflow-x: hidden;
}

.input-active .main {
  overflow: hidden;
}

.mode-panel {
  display: none;
  animation: fadeIn 0.2s ease-out;
}

.mode-panel.is-active {
  display: block;
}

/* 入力モード: 一画面完結 */
#input-mode.is-active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#input-mode > .card:first-of-type {
  flex-shrink: 0;
  margin-bottom: 8px;
}

#input-mode > .card:last-of-type {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  margin-bottom: 0;
}

#input-mode > .card:last-of-type .tab-panels {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#input-mode > .card:last-of-type .tab-panel.is-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#input-mode > .card:last-of-type #centuryEvents,
#input-mode > .card:last-of-type #categorizedEvents {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* セクション */

.card {
  margin-bottom: 16px;
}

.card-header {
  margin-bottom: 16px;
}

.card-title {
  margin: 0 0 4px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.card-subtitle {
  margin: 0;
  font-size: 14px;
  color: var(--color-text-muted);
}

/* フォーム */

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  gap: 12px 20px;
  margin-top: 12px;
  padding: 16px;
  background: var(--color-surface);
  border-radius: 18px;
  border: 1px solid var(--color-border-subtle);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-field-full {
  grid-column: 1 / -1;
}

.field-label {
  font-size: 12px;
  color: var(--color-text-muted);
}

.field-input {
  border-radius: 999px;
  border: 1px solid #d1d5db;
  background: var(--color-surface-soft);
  padding: 9px 12px;
  color: var(--color-text-main);
  font-size: 14px;
  outline: none;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    background 0.15s ease,
    transform 0.08s ease;
  min-height: 36px;
}

.field-input:focus {
  border-color: rgba(37, 99, 235, 0.9);
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.4);
}

.field-input::placeholder {
  color: #9ca3af;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

/* ボタン */

.primary-button,
.ghost-button {
  border-radius: 999px;
  border: none;
  outline: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition:
    background-color 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.08s ease;
}

.primary-button {
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #f9fafb;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.35);
}

.primary-button.subtle {
  box-shadow: none;
  background: #2563eb;
}

.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 36px rgba(37, 99, 235, 0.45);
}

.primary-button:active {
  transform: translateY(0);
  box-shadow: 0 6px 14px rgba(148, 163, 184, 0.6);
}

.ghost-button {
  background: #ffffff;
  color: var(--color-text-muted);
  border: 1px solid #d1d5db;
}

.ghost-button:hover {
  background: #f3f4f6;
  color: var(--color-text-main);
}

.ghost-button.small {
  padding: 5px 12px;
  font-size: 12px;
}

/* タブ（世紀別・カテゴリ別切り替え） */

.tabs {
  display: inline-flex;
  gap: 8px;
  margin-top: 8px;
}

.tab-button {
  border: 1px solid var(--color-border-subtle);
  background: var(--color-surface);
  color: var(--color-text-muted);
  padding: 8px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition:
    background-color 0.18s ease,
    color 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.tab-button.is-active {
  background: var(--color-accent);
  color: #ffffff;
  border-color: var(--color-accent);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.tab-button:not(.is-active):hover {
  background: var(--color-surface-soft);
  color: var(--color-text-main);
  border-color: #d1d5db;
}

.tab-panels {
  margin-top: 10px;
}

.tab-panel {
  display: none;
  animation: fadeInUp 0.18s ease-out;
}

.tab-panel.is-active {
  display: block;
}

/* 一覧コンテナのスクロール制限 */
#centuryEvents,
#categorizedEvents {
  max-height: 50vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 0;
}

/* グループ（タイムライン風・Apple風） */

.group {
  position: relative;
  background: transparent;
  margin-bottom: 0;
  padding-left: 28px;
}

/* タイムラインの縦線 */
.group::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(180deg, var(--color-border-subtle) 0%, #d1d5db 100%);
  border-radius: 1px;
}

/* 最初のグループは上部を丸く */
.group:first-child::before {
  top: 20px;
  border-radius: 1px 1px 0 0;
}

/* 最後のグループは下部を丸く */
.group:last-child::before {
  bottom: 20px;
  border-radius: 0 0 1px 1px;
}

.group-header {
  width: 100%;
  border: none;
  background: transparent;
  padding: 12px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  color: var(--color-text-main);
  position: relative;
}

/* タイムラインのドット */
.group-header::before {
  content: "";
  position: absolute;
  left: -24px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid var(--color-accent);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
  transition: all 0.2s ease;
}

.group.is-open .group-header::before {
  background: var(--color-accent);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.group-header-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.group-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-count {
  font-size: 12px;
  color: var(--color-text-muted);
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--color-surface-soft);
  border: 1px solid var(--color-border-subtle);
  flex-shrink: 0;
}

.group-chevron {
  font-size: 12px;
  color: var(--color-text-muted);
  transform: rotate(180deg);
  transition: transform 0.2s ease;
  padding: 4px;
}

.group-content {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  padding: 0;
  margin-left: 4px;
  border-left: 1px solid transparent;
  transition:
    max-height 0.25s ease,
    opacity 0.2s ease,
    padding 0.2s ease,
    border-color 0.2s ease;
}

.group.is-open .group-content {
  max-height: none;
  opacity: 1;
  padding: 0 0 16px 12px;
  border-left-color: var(--color-border-subtle);
}

.group.is-open .group-chevron {
  transform: rotate(0deg);
}

/* イベントリスト */

.event-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.event-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--color-surface);
  border-radius: 12px;
  border: 1px solid var(--color-border-subtle);
  transition: all 0.15s ease;
}

.event-item:hover {
  background: var(--color-surface-soft);
  border-color: #d1d5db;
}

.event-main {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.event-year {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 60px;
}

.event-name {
  font-size: 14px;
  color: var(--color-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* クイズ */

.quiz-settings {
  margin-top: 12px;
}

/* プログレスバー（Instagram風セグメント式） */

.progress-container {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.progress-bar {
  display: flex;
  gap: 2px;
  flex: 1;
  height: 6px;
  min-width: 0;
  overflow: hidden;
}

.progress-segment {
  flex: 1 1 0;
  border-radius: 3px;
  transition: background-color 0.3s ease;
  min-width: 2px;
}

.progress-segment.correct {
  background: #22c55e;
}

.progress-segment.wrong {
  background: #ef4444;
}

.progress-segment.current {
  background: #2563eb;
  animation: pulse 1.5s ease-in-out infinite;
}

.progress-segment.pending {
  background: #e5e7eb;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

.progress-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.progress-count {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.progress-accuracy {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  font-size: 12px;
  min-width: 80px;
  text-align: center;
}

.progress-accuracy.good {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #059669;
}

.progress-accuracy.bad {
  background: #fef2f2;
  border-color: #fecaca;
  color: #dc2626;
}

.quiz-area {
  margin-top: 16px;
  padding: 20px;
  background: var(--color-surface);
  border-radius: 18px;
  border: 1px solid var(--color-border-subtle);

  height: calc(100vh - 280px);
  min-height: 400px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  gap: 16px;

  overflow: hidden;
}

.quiz-label {
  font-size: 13px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin: 0 0 4px;
}

.quiz-question-block {
  flex-shrink: 0;
}

/* メインレイアウト: 左（問題・入力・画像）+ 右（解答履歴） */

.quiz-main-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.quiz-left-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

.quiz-history {
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: 16px;
  padding: 12px;
  min-height: 0;
  overflow-y: auto;
}

.quiz-history-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.quiz-history-title {
  margin: 0;
  font-size: 15px;
  font-weight: bold;
  color: var(--color-text-main);
}

.quiz-restart-btn {
  margin-top: 8px;
  width: 100%;
}

.quiz-history-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.quiz-history-item {
  padding: 10px;
  border-bottom: 1px solid #e5e7eb;
  font-size: 14px;
}

.quiz-history-item:last-child {
  border-bottom: none;
}

.quiz-history-item.correct {
  background: #ecfdf5; /* 緑：正解 */
  border-left: 3px solid #34d399;
}

.quiz-history-item.wrong {
  background: #fef2f2; /* 赤：不正解 */
  border-left: 3px solid #f87171;
}

.quiz-history-question {
  font-weight: bold;
  color: var(--color-text-main);
}

.quiz-history-answer {
  font-size: 13px;
  color: var(--color-text-muted);
}

.quiz-question-text {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.quiz-note {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--color-text-muted);
  min-height: 1.4em;
}

.quiz-answer-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  flex-shrink: 0;
}

.quiz-answer-row .field-input {
  flex: 1 1 130px;
  min-width: 0;
}

.quiz-feedback {
  min-height: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
  margin-top: 8px;
}

.quiz-result {
  margin: 0;
  font-size: 15px;
}

.quiz-score {
  margin: 0;
  font-size: 14px;
  color: var(--color-text-muted);
}

.quiz-image-title {
  position: absolute;
  top: 8px;
  left: 8px;
  margin: 0;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 8px;

  font-size: 14px;
  font-weight: bold;
  color: var(--color-text-main);

  z-index: 20;
}

.quiz-image-container {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: 16px;
  overflow-y: auto;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: center;
}

#quiz-image {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: auto;
  object-fit: contain;
  display: none;
}

#quiz-image.is-visible {
  animation: imgFadeIn 0.4s ease;
}

@keyframes imgFadeIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

.quiz-image-column {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  margin-top: 12px;
}

.quiz-caption {
  margin: 6px 4px 0;
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.5;
  min-height: 1.5em;
  flex-shrink: 0;
}

/* 画像拡大モーダル */

.image-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: fadeIn 0.2s ease-out;
  padding: 20px;
}

.image-modal-content {
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.image-modal-content img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.image-modal-caption {
  color: #ccc;
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  max-width: 600px;
}

#quiz-image {
  cursor: zoom-in;
}

/* 確認モーダル */

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}

.confirm-dialog {
  background: var(--color-surface);
  border-radius: 16px;
  padding: 24px 28px;
  max-width: 340px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.confirm-message {
  margin: 0 0 20px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text-main);
  white-space: pre-line;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* リサイズハンドル（デフォルトは非表示） */
.resize-handle {
  display: none;
}

/* ========================================
   クイズ終了画面
   ======================================== */

.quiz-end {
  display: none;
  animation: fadeIn 0.3s ease-out;
}

.quiz-end-content {
  max-width: 560px;
  margin: 0 auto;
  padding: 40px 20px;
  text-align: center;
}

.quiz-end-summary {
  margin-bottom: 32px;
}

.quiz-end-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 20px;
}

.quiz-end-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  margin-bottom: 8px;
}

.quiz-end-correct {
  font-size: 56px;
  font-weight: 800;
  line-height: 1;
  color: var(--color-accent);
}

.quiz-end-separator {
  font-size: 32px;
  font-weight: 300;
  color: var(--color-text-muted);
}

.quiz-end-total {
  font-size: 32px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.quiz-end-rate {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--color-text-muted);
}

.quiz-end-rate.good {
  color: #059669;
}

.quiz-end-rate.bad {
  color: #dc2626;
}

.quiz-end-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 32px;
}

.quiz-end-wrong-list {
  text-align: left;
}

.quiz-end-wrong-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border-subtle);
}

.quiz-end-wrong-list ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.quiz-end-wrong-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border-subtle);
  font-size: 14px;
}

.quiz-end-wrong-event {
  flex: 1;
}

.quiz-end-wrong-answer {
  color: #dc2626;
  margin-right: 12px;
  font-size: 13px;
}

.quiz-end-wrong-correct {
  font-weight: 600;
  white-space: nowrap;
}

/* 空状態 */

.empty-text {
  font-size: 13px;
  color: var(--color-text-muted);
  padding: 6px 2px 2px;
}

/* フッター */

.app-footer {
  padding: 8px 16px;
  text-align: center;
  font-size: 11px;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

/* アニメーション */

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

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

/* レスポンシブ */

@media (min-width: 720px) {
  .app-shell {
    padding: 0;
  }

  .app-header {
    padding: 22px 24px 22px;
  }

  .card {
    padding: 20px 22px 18px;
  }

  .form-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .form-field-full {
    grid-column: span 3;
  }

  .form-actions {
    justify-content: flex-end;
  }
}

/*解答後の解答欄色*/
.answer-correct {
  background-color: #d1fae5 !important; /* 淡い緑 */
  border-color: #10b981 !important;
  transition: background-color 0.3s, border-color 0.3s;
}

.answer-wrong {
  background-color: #fee2e2 !important; /* 淡い赤 */
  border-color: #ef4444 !important;
  transition: background-color 0.3s, border-color 0.3s;
}

/* ========================================
   クイズ選択画面（カテゴリカード）
   ======================================== */

.quiz-select {
  animation: fadeIn 0.3s ease;
}

/* Apple風アニメーション */
.quiz-select .card-header {
  opacity: 0;
  transform: translateY(30px);
  animation: slideUpFadeIn 0.6s ease forwards;
}

.quiz-select .card-title {
  opacity: 0;
  transform: translateY(20px);
  animation: slideUpFadeIn 0.5s ease 0.1s forwards;
}

.quiz-select .card-subtitle {
  opacity: 0;
  transform: translateY(20px);
  animation: slideUpFadeIn 0.5s ease 0.2s forwards;
}

/* カテゴリカードのアニメーション */
.category-card {
  opacity: 0;
  transform: translateY(40px) scale(0.95);
}

.category-card.animate-in {
  animation: cardSlideIn 0.5s ease forwards;
}

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

@keyframes cardSlideIn {
  from {
    opacity: 0;
    transform: translateY(40px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ========================================
   入力モード Apple風アニメーション
   ======================================== */

#input-mode .card {
  opacity: 0;
  transform: translateY(30px);
}

#input-mode .card.animate-in {
  animation: slideUpFadeIn 0.5s ease forwards;
}

#input-mode .card-title {
  opacity: 0;
  transform: translateY(20px);
}

#input-mode .card-title.animate-in {
  animation: slideUpFadeIn 0.4s ease forwards;
}

#input-mode .card-subtitle {
  opacity: 0;
  transform: translateY(20px);
}

#input-mode .card-subtitle.animate-in {
  animation: slideUpFadeIn 0.4s ease forwards;
}

#input-mode .form-grid {
  opacity: 0;
  transform: translateY(20px) scale(0.98);
}

#input-mode .form-grid.animate-in {
  animation: cardSlideIn 0.5s ease forwards;
}

#input-mode .tabs {
  opacity: 0;
  transform: translateY(15px);
}

#input-mode .tabs.animate-in {
  animation: slideUpFadeIn 0.4s ease forwards;
}

#input-mode #centuryEvents,
#input-mode #categorizedEvents {
  opacity: 0;
  transform: translateY(20px) scale(0.98);
}

#input-mode #centuryEvents.animate-in,
#input-mode #categorizedEvents.animate-in {
  animation: cardSlideIn 0.5s ease forwards;
}

/* ========================================
   クイズ準備画面
   ======================================== */

/* クイズ準備画面表示中は一画面完結・ヘッダー非表示 */
.quiz-ready-active {
  overflow: hidden;
}

.quiz-ready-active .app-header {
  display: none;
}

.quiz-ready-active .app-footer {
  display: none;
}

.quiz-ready-active .main {
  height: 100vh;
  height: 100dvh;
  max-width: none;
  padding: 0;
  margin: 0;
  overflow: hidden;
}

.quiz-ready {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  animation: fadeIn 0.3s ease;
  padding: 20px;
  box-sizing: border-box;
}

.quiz-ready-header {
  position: absolute;
  top: 12px;
  left: 16px;
}

.quiz-ready-content {
  text-align: center;
  max-width: 400px;
  padding: 40px;
  margin-top: -15vh;
}

.ready-category-icon {
  width: 120px;
  height: 120px;
  margin: 0 auto 24px;
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.8);
  animation: readyIconIn 0.5s ease 0.1s forwards;
}

.ready-category-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 24px;
}

.ready-title {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--color-text-main);
  opacity: 0;
  transform: translateY(20px);
  animation: slideUpFadeIn 0.5s ease 0.2s forwards;
}

.ready-subtitle {
  font-size: 16px;
  color: var(--color-text-muted);
  margin: 0 0 32px;
  opacity: 0;
  transform: translateY(20px);
  animation: slideUpFadeIn 0.5s ease 0.3s forwards;
}

.ready-info {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  margin-bottom: 32px;
  opacity: 0;
  transform: translateY(20px);
  animation: slideUpFadeIn 0.5s ease 0.4s forwards;
}

.ready-count {
  font-size: 64px;
  font-weight: 700;
  color: var(--color-accent);
  line-height: 1;
}

.ready-label {
  font-size: 24px;
  color: var(--color-text-muted);
}

.ready-start-btn {
  padding: 14px 48px;
  font-size: 16px;
  opacity: 0;
  transform: translateY(20px);
  animation: slideUpFadeIn 0.5s ease 0.5s forwards;
}

@keyframes readyIconIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.quiz-play {
  animation: fadeIn 0.3s ease;
}

/* クイズ解答中は一画面完結 */
.quiz-play-active {
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

.quiz-play-active .app-shell {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.quiz-play-active .app-header {
  display: none;
}

.quiz-play-active .main {
  height: 100vh;
  height: 100dvh;
  max-width: none;
  padding: 0;
  margin: 0;
  gap: 0;
  overflow: hidden;
}

.quiz-play-active .app-footer {
  display: none;
}

.quiz-play-active .mode-panel {
  height: 100%;
}

.quiz-play-active #quiz-play {
  height: 100%;
}

.quiz-play-active #quiz-play > .card {
  height: 100%;
  margin: 0;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.quiz-play-active .quiz-play-header {
  margin-bottom: 8px;
  flex-shrink: 0;
}

.quiz-play-active .quiz-area {
  flex: 1;
  height: auto;
  max-height: none;
  min-height: 0;
  margin: 0;
  overflow: hidden;
}

.quiz-play-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}

.quiz-play-header .card-title {
  margin: 0;
  font-size: 24px;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
  margin-top: 16px;
}

.category-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.category-card:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.category-card:active {
  transform: scale(0.98);
}

.category-card-image {
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.category-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

/* カテゴリごとのグラデーション背景（画像がない場合のフォールバック） */
.category-card-image.gradient-ancient {
  background: linear-gradient(135deg, #fef3c7 0%, #fcd34d 100%);
}
.category-card-image.gradient-asia1 {
  background: linear-gradient(135deg, #fce7f3 0%, #f9a8d4 100%);
}
.category-card-image.gradient-asia2 {
  background: linear-gradient(135deg, #fed7aa 0%, #fb923c 100%);
}
.category-card-image.gradient-islam {
  background: linear-gradient(135deg, #d1fae5 0%, #34d399 100%);
}
.category-card-image.gradient-medieval {
  background: linear-gradient(135deg, #dbeafe 0%, #60a5fa 100%);
}
.category-card-image.gradient-early-modern {
  background: linear-gradient(135deg, #fce7f3 0%, #f472b6 100%);
}
.category-card-image.gradient-modern1 {
  background: linear-gradient(135deg, #e0e7ff 0%, #818cf8 100%);
}
.category-card-image.gradient-modern2 {
  background: linear-gradient(135deg, #fee2e2 0%, #f87171 100%);
}
.category-card-image.gradient-modern3 {
  background: linear-gradient(135deg, #f3e8ff 0%, #a78bfa 100%);
}
.category-card-image.gradient-other {
  background: linear-gradient(135deg, #f3f4f6 0%, #9ca3af 100%);
}
.category-card-image.gradient-all {
  background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
}

.category-card-info {
  padding: 12px 14px;
}

.category-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-main);
  margin: 0 0 4px;
  line-height: 1.3;
}

.category-card-count {
  font-size: 12px;
  color: var(--color-text-muted);
  margin: 0;
}

/* 全カテゴリカード */
.category-card.category-card-all {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
}

.category-card-all .category-card-image {
  width: 80px;
  height: 80px;
  flex-shrink: 0;
  border-radius: 12px;
  margin: 12px;
}

.category-card-all .category-card-info {
  flex: 1;
  padding: 12px 16px 12px 0;
}

.category-card-all .category-card-name {
  font-size: 16px;
}

.category-card-all .category-card-count {
  font-size: 13px;
}

/* ========================================
   PC版レイアウト（768px以上）
   ======================================== */

@media (min-width: 768px) {
  .app-header {
    gap: 24px;
    padding: 12px 32px;
  }

  /* メインを全幅に */
  .main {
    padding: 24px 32px 40px;
    max-width: 1400px;
  }

  /* 入力モード: 2カラム・一画面完結レイアウト */
  #input-mode.is-active {
    display: grid;
    grid-template-columns: var(--input-col-width, 40%) 8px 1fr;
    gap: 0;
    align-items: stretch;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  #input-mode > .card {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* 左カラムに右マージン */
  #input-mode > .card:first-of-type {
    margin-right: 12px;
  }

  /* 右カラムに左マージン */
  #input-mode > .card:last-of-type {
    margin-left: 12px;
  }

  /* リサイズハンドル */
  .resize-handle {
    display: block;
    width: 8px;
    cursor: col-resize;
    background: transparent;
    position: relative;
    transition: background 0.15s ease;
  }

  .resize-handle::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 40px;
    background: var(--color-border-subtle);
    border-radius: 2px;
    transition: background 0.15s ease, height 0.15s ease;
  }

  .resize-handle:hover::before,
  .resize-handle.is-dragging::before {
    background: var(--color-accent);
    height: 60px;
  }

  .resize-handle.is-dragging {
    background: var(--color-accent-soft);
  }

  /* 入力フォームカード */
  #input-mode > .card:first-child .form-grid {
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  /* 入力フォームを縦積みに（2カラムレイアウト時） */
  #input-mode .form-grid {
    grid-template-columns: 1fr;
  }

  #input-mode .form-field-full {
    grid-column: 1;
  }

  /* 一覧カードの高さ調整 */
  #input-mode > .card:last-child {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  #input-mode > .card:last-child .tab-panels {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }

  #input-mode > .card:last-child .tab-panel.is-active {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }

  #input-mode > .card:last-child #centuryEvents,
  #input-mode > .card:last-child #categorizedEvents {
    flex: 1;
    max-height: none;
    min-height: 0;
    overflow-y: auto;
  }

  /* クイズエリア: 1画面完結 */
  .quiz-area {
    height: calc(100vh - 320px);
    min-height: 500px;
    max-height: none;
  }

  /* 2カラムレイアウト（左:画像+問題、右:履歴） */
  .quiz-main-row {
    grid-template-columns: 1fr 280px;
    gap: 20px;
  }

  /* 解答履歴の幅固定 */
  .quiz-history {
    width: 280px;
  }

  /* プログレスバーの調整 */
  .progress-container {
    padding: 12px 0;
    margin-bottom: 12px;
  }

  .progress-bar {
    gap: 4px;
    height: 8px;
  }

  .progress-segment {
    border-radius: 4px;
  }

  .progress-info {
    font-size: 14px;
    gap: 16px;
  }

  .progress-accuracy {
    font-size: 13px;
    padding: 3px 10px;
  }

}

/* ========================================
   大画面PC版レイアウト（1024px以上）
   ======================================== */

@media (min-width: 1024px) {
  .main {
    padding: 24px 48px 40px;
    max-width: 1600px;
  }

  /* 入力モード: gap広げる */
  #input-mode {
    gap: 32px;
  }

  .quiz-area {
    height: calc(100vh - 300px);
    min-height: 550px;
    padding: 24px;
  }

  .quiz-main-row {
    grid-template-columns: 1fr 360px;
    gap: 32px;
  }

  .quiz-history {
    width: 360px;
    padding: 20px;
  }

  .quiz-question-text {
    font-size: 20px;
  }

  .category-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 24px;
  }
}

/* ========================================
   超大画面PC版レイアウト（1440px以上）
   ======================================== */

@media (min-width: 1440px) {
  .main {
    padding: 32px 64px 48px;
    max-width: 1800px;
  }

  .app-header {
    padding: 14px 64px;
  }

  /* 入力モード: gap広げる */
  #input-mode {
    gap: 40px;
  }

  .quiz-area {
    padding: 32px;
  }

  .quiz-main-row {
    grid-template-columns: 1fr 400px;
    gap: 40px;
  }

  .quiz-history {
    width: 400px;
  }

  .category-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 28px;
  }

  .category-card-image {
    height: 160px;
  }
}