/* ===========================
   Excel関数クイズ - スタイル
   =========================== */

:root {
  --green:       #217346;
  --green-light: #2e9c5e;
  --green-pale:  #e8f5ee;
  --green-dark:  #185c39;
  --accent:      #1D6F42;
  --gold:        #f5a623;
  --red:         #e74c3c;
  --red-pale:    #fdecea;
  --blue:        #2980b9;
  --blue-pale:   #ebf5fb;
  --gray-100:    #f5f6fa;
  --gray-200:    #e8eaf0;
  --gray-400:    #adb5bd;
  --gray-600:    #6c757d;
  --gray-800:    #343a40;
  --white:       #ffffff;
  --shadow-sm:   0 2px 8px rgba(0,0,0,.08);
  --shadow-md:   0 4px 20px rgba(0,0,0,.12);
  --shadow-lg:   0 8px 40px rgba(0,0,0,.15);
  --radius-sm:   8px;
  --radius-md:   14px;
  --radius-lg:   20px;
  --transition:  all .2s ease;
}

/* ===== リセット & ベース ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Noto Sans JP', 'Hiragino Kaku Gothic ProN', sans-serif;
  background: linear-gradient(135deg, #e8f5ee 0%, #f0f8f4 50%, #e4f2ff 100%);
  min-height: 100vh;
  color: var(--gray-800);
}

/* ===== ヘッダー ===== */
.app-header {
  background: linear-gradient(135deg, var(--green-dark) 0%, var(--green) 60%, var(--green-light) 100%);
  box-shadow: 0 2px 12px rgba(33,115,70,.4);
  position: sticky; top: 0; z-index: 100;
}
.header-inner {
  max-width: 760px; margin: 0 auto;
  padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 1.6rem; color: #7EE8A2; }
.logo-text { font-size: 1.25rem; font-weight: 900; color: var(--white); letter-spacing: .02em; }
.logo-accent { color: #7EE8A2; }
.header-score {
  background: rgba(255,255,255,.18); color: var(--white);
  padding: 5px 14px; border-radius: 20px;
  font-size: .95rem; font-weight: 700;
  display: flex; align-items: center; gap: 6px;
}
.header-score i { color: #FFD700; }

/* ===== コンテナ & 画面 ===== */
.container { max-width: 760px; margin: 0 auto; padding: 24px 16px 60px; }

.screen { display: none; animation: fadeIn .35s ease; }
.screen.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

/* ===== カード ===== */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
  border: 1px solid var(--gray-200);
}

/* ===== スタート画面 ===== */
.start-hero { text-align: center; padding: 32px 0 24px; }
.start-icon { font-size: 4rem; margin-bottom: 12px; animation: bounce 2s infinite; }
@keyframes bounce { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }

/* タイトル行（キャラ + タイトル + キャラ） */
.start-title-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0;
  margin-bottom: 10px;
}
.start-title {
  font-size: 2rem; font-weight: 900; color: var(--green-dark);
  margin-bottom: 0;
  flex-shrink: 0;
}
.title-char {
  width: 90px;
  height: auto;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.12));
}
.title-char-left {
  transform: translateY(10px);
  animation: charBobLeft 2.8s ease-in-out infinite;
}
.title-char-right {
  transform: translateY(10px);
  animation: charBobRight 2.8s ease-in-out infinite;
}
@keyframes charBobLeft {
  0%,100% { transform: translateY(10px) rotate(-3deg); }
  50%      { transform: translateY(2px)  rotate(0deg); }
}
@keyframes charBobRight {
  0%,100% { transform: translateY(10px) rotate(3deg); }
  50%      { transform: translateY(2px)  rotate(0deg); }
}

.start-desc { color: var(--gray-600); line-height: 1.7; font-size: .95rem; }

.settings-title {
  font-size: 1rem; font-weight: 700; color: var(--green-dark);
  margin-bottom: 18px; display: flex; align-items: center; gap: 8px;
}

.setting-group { margin-bottom: 18px; }
.setting-label { display: block; font-size: .85rem; font-weight: 700; color: var(--gray-600); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .06em; }

/* チップ */
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 16px; border-radius: 20px; border: 2px solid var(--gray-200);
  background: var(--white); color: var(--gray-600);
  font-size: .875rem; font-weight: 500; cursor: pointer;
  transition: var(--transition); font-family: inherit;
}
.chip:hover { border-color: var(--green); color: var(--green); }
.chip.active { background: var(--green); border-color: var(--green); color: var(--white); font-weight: 700; }

/* スタートボタン */
.btn-start {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 18px;
  background: linear-gradient(135deg, var(--green) 0%, var(--green-light) 100%);
  color: var(--white); border: none; border-radius: var(--radius-md);
  font-size: 1.15rem; font-weight: 900; cursor: pointer;
  box-shadow: 0 4px 16px rgba(33,115,70,.4);
  transition: var(--transition); font-family: inherit;
  margin-bottom: 24px;
}
.btn-start:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(33,115,70,.5); }
.btn-start:active { transform: translateY(0); }

/* ランキング */
.ranking-section {}
.ranking-list { display: flex; flex-direction: column; gap: 10px; }
.ranking-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--gray-100);
  border-radius: var(--radius-sm);
}
.rank-badge {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: .9rem; flex-shrink: 0;
}
.rank-1 { background: #FFD700; color: #7a5800; }
.rank-2 { background: #C0C0C0; color: #555; }
.rank-3 { background: #CD7F32; color: #fff; }
.rank-other { background: var(--gray-200); color: var(--gray-600); }
.rank-name { flex: 1; font-weight: 600; font-size: .95rem; }
.rank-score { font-weight: 900; color: var(--green); font-size: 1rem; }
.rank-meta { font-size: .75rem; color: var(--gray-400); }
.no-data { color: var(--gray-400); text-align: center; font-size: .9rem; padding: 16px; }

/* ハイスコアリスト */
.highscore-list { display: flex; flex-direction: column; gap: 10px; }
.highscore-list .ranking-item { background: var(--gray-100); }
.highscore-list .rank-score { font-weight: 900; color: var(--blue); font-size: 1.1rem; }

/* ===== クイズ画面 ===== */
.progress-wrap { margin-bottom: 18px; }
.progress-info { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.question-num { font-weight: 700; color: var(--green-dark); font-size: .95rem; }
.timer { display: flex; align-items: center; gap: 5px; font-weight: 700; font-size: .95rem; color: var(--gray-600); }
.timer.warning { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }

.progress-bar-track {
  height: 8px; background: var(--gray-200);
  border-radius: 4px; overflow: hidden; margin-bottom: 10px;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--green-light));
  border-radius: 4px; transition: width .4s ease;
}

.level-badge-row { display: flex; gap: 8px; }
.level-badge, .category-badge {
  padding: 3px 12px; border-radius: 12px;
  font-size: .78rem; font-weight: 700; letter-spacing: .04em;
}
.level-badge { background: var(--green-pale); color: var(--green-dark); }
.level-badge.初級 { background: #e8f5ee; color: #1a7a3c; }
.level-badge.中級 { background: #fff8e1; color: #b8860b; }
.level-badge.上級 { background: #fdecea; color: #c0392b; }
.category-badge { background: var(--blue-pale); color: var(--blue); }

/* 問題カード */
.question-card { margin-bottom: 16px; }
.question-text { font-size: 1.05rem; font-weight: 500; line-height: 1.8; color: var(--gray-800); }
.code-block {
  margin-top: 14px; background: #1e1e2e; border-radius: var(--radius-sm);
  padding: 16px; overflow-x: auto;
}
.code-block pre { color: #a6e3a1; font-size: .9rem; font-family: 'Courier New', monospace; line-height: 1.6; white-space: pre-wrap; }

/* 選択肢 */
.options-grid { display: grid; gap: 12px; margin-bottom: 16px; }
.option-btn {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 20px; background: var(--white);
  border: 2px solid var(--gray-200); border-radius: var(--radius-md);
  cursor: pointer; text-align: left; transition: var(--transition);
  width: 100%; font-family: inherit;
}
.option-btn:hover:not(:disabled) { border-color: var(--green); background: var(--green-pale); transform: translateX(4px); }
.option-key {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--gray-100); color: var(--gray-600);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: .9rem; flex-shrink: 0;
  transition: var(--transition);
}
.option-text { font-size: .95rem; font-weight: 500; color: var(--gray-800); line-height: 1.5; }
.option-btn.selected .option-key { background: var(--blue); color: var(--white); }
.option-btn.correct { border-color: var(--blue); background: var(--blue-pale); }
.option-btn.correct .option-key { background: var(--blue); color: var(--white); }
.option-btn.wrong { border-color: var(--red); background: var(--red-pale); }
.option-btn.wrong .option-key { background: var(--red); color: var(--white); }
.option-btn:disabled { cursor: not-allowed; opacity: .85; transform: none !important; }

/* 解説 */
.explanation-box {
  background: var(--white); border-radius: var(--radius-md);
  border: 2px solid var(--blue); overflow: hidden;
  box-shadow: var(--shadow-sm); margin-bottom: 16px;
  animation: slideUp .3s ease;
}
@keyframes slideUp { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:translateY(0)} }
.explanation-header {
  padding: 14px 20px; display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1rem;
  background: var(--blue); color: var(--white);
}
.explanation-header.wrong-header { background: var(--red); border-color: var(--red); }
.explanation-box.correct-box { border-color: var(--blue); }
.explanation-header.wrong-header + .explanation-text { border-color: var(--red); }
.explanation-box.wrong-box { border-color: var(--red); }
.explanation-text { padding: 16px 20px; font-size: .92rem; line-height: 1.75; color: var(--gray-800); border-top: 1px solid var(--gray-200); }

.btn-next {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: calc(100% - 40px); margin: 0 20px 18px;
  padding: 13px; background: var(--green); color: var(--white);
  border: none; border-radius: var(--radius-sm);
  font-size: 1rem; font-weight: 700; cursor: pointer;
  transition: var(--transition); font-family: inherit;
}
.btn-next:hover { background: var(--green-dark); }

/* ===== 結果画面 ===== */
.result-hero { text-align: center; padding: 32px 0 20px; }
.result-emoji { font-size: 5rem; margin-bottom: 12px; animation: bounce 1.5s infinite; }
.result-title { font-size: 1.8rem; font-weight: 900; color: var(--green-dark); margin-bottom: 6px; }
.result-subtitle { color: var(--gray-600); font-size: 1rem; }

.result-stats {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px;
  text-align: center;
}
.stat-item { padding: 12px; }
.stat-value { font-size: 2rem; font-weight: 900; color: var(--green); margin-bottom: 4px; }
.stat-label { font-size: .8rem; color: var(--gray-600); font-weight: 500; }

.name-entry h3 { font-size: 1rem; font-weight: 700; color: var(--gray-800); margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.name-input-row { display: flex; gap: 10px; }
.name-input {
  flex: 1; padding: 11px 14px; border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm); font-size: .95rem; font-family: inherit;
  transition: var(--transition);
}
.name-input:focus { outline: none; border-color: var(--green); }
.btn-save {
  padding: 11px 18px; background: var(--gold); color: var(--white);
  border: none; border-radius: var(--radius-sm);
  font-weight: 700; font-size: .9rem; cursor: pointer; transition: var(--transition); font-family: inherit;
  display: flex; align-items: center; gap: 6px;
}
.btn-save:hover { background: #e09415; }
.save-feedback { font-size: .85rem; margin-top: 8px; color: var(--green); font-weight: 600; min-height: 20px; }

/* 振り返り */
.review-section h3 { font-size: 1rem; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.review-list { display: flex; flex-direction: column; gap: 10px; }
.review-item {
  padding: 14px 16px; border-radius: var(--radius-sm);
  border-left: 4px solid; font-size: .88rem; line-height: 1.6;
}
.review-item.correct { border-color: var(--green); background: var(--green-pale); }
.review-item.wrong { border-color: var(--red); background: var(--red-pale); }
.review-q { font-weight: 600; margin-bottom: 4px; }
.review-answer { display: flex; gap: 14px; font-size: .83rem; }
.review-your { color: var(--gray-600); }
.review-correct { color: var(--green); font-weight: 700; }
.review-wrong-ans { color: var(--red); font-weight: 700; }

.result-btns { display: flex; gap: 12px; }
.btn { padding: 13px 20px; border-radius: var(--radius-sm); font-size: .95rem; font-weight: 700; cursor: pointer; border: none; transition: var(--transition); font-family: inherit; display: flex; align-items: center; justify-content: center; gap: 8px; flex: 1; }
.btn-primary { background: var(--green); color: var(--white); }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { background: var(--gray-100); color: var(--gray-800); border: 2px solid var(--gray-200); }
.btn-secondary:hover { border-color: var(--green); color: var(--green); }

/* ===== ローディング ===== */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(255,255,255,.85);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 200; gap: 16px; font-weight: 600; color: var(--green);
}
.loading-spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--green);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== トースト ===== */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--gray-800); color: var(--white);
  padding: 12px 24px; border-radius: 24px;
  font-size: .9rem; font-weight: 600;
  box-shadow: var(--shadow-md);
  transition: transform .3s ease, opacity .3s ease;
  opacity: 0; pointer-events: none; z-index: 300; white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ===== スコアアップアニメ ===== */
@keyframes scorePopup {
  0%   { transform: scale(1.6); opacity: 0; }
  40%  { transform: scale(1); opacity: 1; }
  80%  { transform: scale(1); opacity: 1; }
  100% { transform: scale(.8); opacity: 0; }
}
.score-popup {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2.5rem; font-weight: 900;
  color: var(--gold); text-shadow: 0 2px 8px rgba(0,0,0,.3);
  pointer-events: none; animation: scorePopup 1.2s ease forwards;
  z-index: 400;
}

/* ===== レスポンシブ ===== */
/* ===== フッター ===== */
.app-footer {
  text-align: center;
  padding: 16px 0 20px;
  background: linear-gradient(135deg, var(--green-dark) 0%, var(--green) 60%, var(--green-light) 100%);
}
.footer-account {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: rgba(255,255,255,.85);
  font-size: .88rem;
  font-weight: 600;
  letter-spacing: .04em;
}
.footer-account i {
  font-size: 1rem;
  color: #fff;
}

@media (max-width: 480px) {
  .start-title { font-size: 1.5rem; }
  .title-char  { width: 66px; }
  .result-stats { grid-template-columns: repeat(2,1fr); }
  .chip { font-size: .8rem; padding: 6px 12px; }
  .option-text { font-size: .88rem; }
  .question-text { font-size: .98rem; }
}
