/* ═══════════════════════════════════════════════
   common.css  全ページ共通スタイル
   白ベース・かわいい寄り・iPad/スマホ両対応
   ═══════════════════════════════════════════════ */

/* ── CSS変数 ── */
:root {
  --bg:        #fdf6ff;
  --surface:   #ffffff;
  --surface2:  #f8f0ff;
  --border:    #e8d8f8;
  --accent:    #8b5cf6;
  --accent-lt: #ede9fe;
  --accent2:   #f472b6;
  --accent3:   #34d399;
  --yellow:    #fbbf24;
  --red:       #f87171;
  --blue:      #60a5fa;
  --text:      #2d1b69;
  --text-sub:  #7c6ea0;
  --text-hint: #b8a8d0;
  --correct:   #34d399;
  --wrong:     #f87171;
  --correct-bg: rgba(52,211,153,.1);
  --wrong-bg:   rgba(248,113,113,.1);
  --shadow-sm:  0 2px 8px rgba(139,92,246,.1);
  --shadow:     0 4px 16px rgba(139,92,246,.15);
  --radius:     16px;
  --radius-sm:  10px;
}

/* ── 基本リセット ── */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans JP', sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  /* iPad対応：フォントサイズを端末に合わせる */
  -webkit-text-size-adjust: 100%;
}

/* ── ページヘッダー ── */
.page-header {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: 14px 18px 13px;
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 2px 12px rgba(139,92,246,.08);
}
.page-header .back {
  font-size: 24px; cursor: pointer;
  color: var(--accent); padding: 4px 6px;
  text-decoration: none; display: flex;
  border-radius: 50%; transition: background .15s;
}
.page-header .back:active { background: var(--accent-lt); }
.page-header h2 {
  font-family: 'Nunito', sans-serif;
  font-size: 18px; font-weight: 800;
  color: var(--text); flex: 1;
  letter-spacing: -.3px;
}
.page-header .hd-right {
  font-size: 13px; color: var(--text-sub);
  font-weight: 600;
}

/* ── プログレスバー ── */
.prog-wrap {
  background: var(--surface2); height: 5px;
}
.prog-fill {
  height: 5px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 0 3px 3px 0;
  transition: width .4s ease;
}

/* ── セクション区切り ── */
.sec-div {
  padding: 9px 18px 6px;
  font-size: 11px; font-weight: 800;
  letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--accent); background: var(--surface2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

/* ── 単語問題行 ── */
.q-row {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
  transition: background .15s;
}
.q-row.ok { background: var(--correct-bg); }
.q-row.ng { background: var(--wrong-bg); }

.q-num {
  font-family: 'Nunito', sans-serif;
  font-size: 13px; color: var(--accent);
  min-width: 28px; font-weight: 800;
  background: var(--accent-lt);
  border-radius: 50%; width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.q-ja { font-size: 16px; flex: 1; line-height: 1.4; }
.q-mark { font-size: 18px; min-width: 24px; text-align: center; }
.q-corr { font-size: 12px; color: var(--correct); font-weight: 700; }

/* ── 英文問題行 ── */
.sq-row {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  transition: background .15s;
}
.sq-row.ok { background: var(--correct-bg); }
.sq-row.ng { background: var(--wrong-bg); }

.sq-top { display: flex; gap: 10px; }
.sq-num {
  font-family: 'Nunito', sans-serif;
  font-size: 13px; color: var(--accent2); font-weight: 800;
  min-width: 26px; width: 26px; height: 26px;
  background: #fff0f8; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 2px;
}
.sq-body { flex: 1; }
.sq-ja {
  font-size: 16px; line-height: 1.5;
  margin-bottom: 8px; color: var(--text);
}
.sq-result {
  display: flex; align-items: center;
  gap: 6px; margin-top: 8px; flex-wrap: wrap;
}
.sq-corr {
  color: var(--correct); font-weight: 700;
  font-size: 14px; font-family: 'Nunito', sans-serif;
}
.sq-explain {
  display: none; margin-top: 10px;
  padding: 10px 12px;
  background: #fffbeb;
  border-left: 4px solid var(--yellow);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 12px; color: #92400e; line-height: 1.8;
}
.sq-explain.show { display: block; }
.sq-explain .ep {
  font-size: 10px; font-weight: 800; color: var(--yellow);
  display: block; margin-bottom: 4px; letter-spacing: 1px;
}

/* ── 入力フォーム（共通） ── */
/* iPad/スマホ両対応：font-size:16px以上でiOSのズームを防ぐ */
.test-inp {
  border: none;
  border-bottom: 2.5px solid var(--border);
  background: transparent; outline: none;
  font-family: 'Nunito', sans-serif;
  font-size: 16px;           /* iOS zoom防止 */
  color: var(--text);
  cursor: pointer;
  caret-color: var(--accent);
  transition: border-color .2s;
  padding: 4px 8px; min-width: 120px;
  border-radius: 0;
  /* iPad Scribble対応：readonlyをJSで制御 */
}
.test-inp:focus,
.test-inp.inp-focused {
  border-bottom-color: var(--accent);
  background: var(--accent-lt);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  outline: none;
}
.test-inp.inp-ok { border-bottom-color: var(--correct); color: var(--correct); }
.test-inp.inp-ng { border-bottom-color: var(--wrong);   color: var(--wrong); }

.sq-full-inp {
  width: 100%;
  border: 2px solid var(--border);
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 16px;           /* iOS zoom防止 */
  font-family: 'Nunito', sans-serif;
  color: var(--text); outline: none;
  cursor: pointer;
  caret-color: var(--accent);
  transition: border-color .2s, background .2s;
  margin-top: 4px;
  -webkit-appearance: none; /* iOS styling reset */
}
.sq-full-inp:focus,
.sq-full-inp.inp-focused {
  border-color: var(--accent);
  background: var(--accent-lt);
  outline: none;
}
.sq-full-inp.inp-ok { border-color: var(--correct); color: var(--correct); background: var(--correct-bg); }
.sq-full-inp.inp-ng { border-color: var(--wrong);   color: var(--wrong);   background: var(--wrong-bg); }

/* ── 採点バー（固定下部） ── */
.grade-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 140;
  display: flex; gap: 10px; align-items: center;
  box-shadow: 0 -4px 20px rgba(139,92,246,.1);
}
.grade-btn {
  flex: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; border: none;
  border-radius: var(--radius);
  padding: 15px;
  font-size: 16px; font-weight: 800;
  font-family: 'Nunito', sans-serif;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(139,92,246,.3);
  transition: opacity .15s, transform .1s;
}
.grade-btn:active { opacity: .85; transform: scale(.98); }
.reset-btn {
  background: var(--surface2); color: var(--text-sub);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  font-size: 14px; font-weight: 700;
  font-family: 'Nunito', sans-serif;
  cursor: pointer; white-space: nowrap;
}

/* ── 英字専用キーボード ── */
#keyboard {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #cdd0da;
  border-top: 1px solid #aeb3c0;
  padding: 10px 5px 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  z-index: 150; display: none;
  user-select: none; -webkit-user-select: none;
}
#keyboard.kb-visible { display: block; }
.kb-row { display: flex; justify-content: center; gap: 5px; margin-bottom: 6px; }
.kb-key {
  background: #ffffff;
  border: none; border-radius: 10px;
  box-shadow: 0 3px 0 #8f95a3;
  min-width: 30px; height: 46px; flex: 1; max-width: 36px;
  font-size: 17px; font-weight: 600;
  color: #1a1a2e;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .08s;
  font-family: 'Nunito', sans-serif;
  letter-spacing: 0;
}
.kb-key:active {
  background: #bfc4d0;
  transform: translateY(2px);
  box-shadow: 0 1px 0 #8f95a3;
}
.kb-shift {
  background: #e4e7ef;
  color: #1a1a2e;
  font-size: 16px;
}
.kb-shift.on {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 3px 0 #6d3fd4;
}
.kb-wide {
  max-width: 54px; flex: 1.8;
  font-size: 14px; font-weight: 700;
  background: #e4e7ef;
}
.kb-space {
  max-width: 200px; flex: 5;
  font-size: 13px; font-weight: 600;
  color: #4a4a6a;
  background: #ffffff;
  letter-spacing: .5px;
}
.kb-done {
  background: var(--accent);
  color: #fff;
  max-width: 58px; flex: 2;
  font-size: 12px; font-weight: 800;
  box-shadow: 0 3px 0 #6d3fd4;
}

/* ── 結果画面 ── */
.result-hero {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  padding: 36px 20px 30px; text-align: center;
  border-bottom: 1px solid var(--border);
  position: relative; overflow: hidden;
}
.result-hero::before {
  content: '🌟';
  position: absolute; font-size: 120px; opacity: .08;
  top: -20px; right: -20px;
}
.result-label {
  font-family: 'Nunito', sans-serif;
  font-size: 11px; letter-spacing: 3px;
  color: rgba(255,255,255,.7); margin-bottom: 8px;
  text-transform: uppercase;
}
.result-big {
  font-family: 'Nunito', sans-serif;
  font-size: 84px; font-weight: 900; color: #fff; line-height: 1;
}
.result-big .denom { font-size: 32px; color: rgba(255,255,255,.65); font-weight: 600; }
.result-grade { font-size: 44px; margin: 8px 0 4px; }
.result-msg { font-size: 15px; color: rgba(255,255,255,.85); margin-bottom: 18px; font-weight: 600; }
.result-parts { display: flex; gap: 1px; }
.rpart { flex: 1; background: rgba(255,255,255,.18); padding: 12px; text-align: center; }
.rpart:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.rpart:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.rpart .pt { font-family: 'Nunito', sans-serif; font-size: 26px; font-weight: 800; color: #fff; }
.rpart .lb { font-size: 10px; color: rgba(255,255,255,.65); margin-top: 2px; }

.result-section { padding: 16px; }
.result-section h3 {
  font-size: 11px; font-weight: 800; letter-spacing: 1.5px;
  color: var(--text-sub); margin-bottom: 12px;
  border-bottom: 2px solid var(--border); padding-bottom: 6px;
  text-transform: uppercase;
}

/* ── 間違いリスト ── */
.wrong-item {
  background: var(--surface); border: 2px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 8px;
  display: flex; gap: 10px;
  box-shadow: var(--shadow-sm);
}
.wi-body { flex: 1; font-size: 13px; }
.wi-q { color: var(--text); font-weight: 600; }
.wi-ans { color: var(--correct); font-weight: 800; font-size: 13px; margin-top: 4px; font-family: 'Nunito', sans-serif; }
.wi-yours { color: var(--wrong); font-size: 12px; margin-top: 2px; }

/* ── 共有カード ── */
.share-card {
  background: var(--surface); border: 2px solid var(--border);
  border-radius: var(--radius); overflow: hidden; margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.share-hd {
  background: var(--surface2); padding: 10px 14px;
  font-size: 12px; font-weight: 800; color: var(--text-sub);
  border-bottom: 1px solid var(--border);
}
.share-ta {
  width: 100%; padding: 12px;
  font-size: 12px; font-family: monospace;
  border: none; outline: none;
  background: var(--surface); color: var(--text);
  min-height: 100px; resize: none; line-height: 1.7;
}

/* ── 結果ボタン ── */
.res-btn {
  display: block; width: 100%; border: none;
  border-radius: var(--radius); padding: 15px;
  font-size: 15px; font-weight: 800;
  font-family: 'Nunito', sans-serif;
  cursor: pointer; text-align: center; margin-bottom: 10px;
  text-decoration: none; transition: opacity .15s, transform .1s;
}
.res-btn:active { opacity: .85; transform: scale(.98); }
.res-btn.green   { background: #25d366; color: #fff; box-shadow: 0 4px 12px rgba(37,211,102,.3); }
.res-btn.flash   { background: linear-gradient(135deg,var(--yellow),#f97316); color: #fff; box-shadow: 0 4px 12px rgba(251,191,36,.3); }
.res-btn.outline { background: transparent; color: var(--text-sub); border: 2px solid var(--border); }

/* ── フッター ── */
.footer-note {
  padding: 18px 16px; text-align: center;
  font-size: 12px; color: var(--text-hint);
  border-top: 1px solid var(--border);
}

/* ── ボトムナビ ── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(16px);
  border-top: 2px solid var(--border);
  display: flex; z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -4px 20px rgba(139,92,246,.08);
}
.nav-item {
  flex: 1; padding: 10px 4px;
  display: flex; flex-direction: column; align-items: center;
  gap: 3px; cursor: pointer; text-decoration: none;
  transition: transform .1s;
}
.nav-item:active { transform: scale(.9); }
.nav-item .ni { font-size: 22px; }
.nav-item .nl {
  font-size: 9px; color: var(--text-hint);
  font-weight: 700; letter-spacing: .5px;
}
.nav-item.active .ni { filter: drop-shadow(0 0 4px rgba(139,92,246,.5)); }
.nav-item.active .nl { color: var(--accent); }

/* ── iPad対応：レイアウト調整 ── */
@media (min-width: 768px) {
  body { padding-bottom: 20px; }

  /* iPadでは中央寄せ・幅制限 */
  #test-content, .flash-wrap,
  .result-hero, .result-section,
  .wrong-section {
    max-width: 680px; margin-left: auto; margin-right: auto;
  }

  /* 問題行を広く */
  .q-row { padding: 14px 24px; }
  .sq-row { padding: 16px 24px; }

  /* 入力フォームを少し大きく */
  .test-inp { font-size: 17px; min-width: 160px; }
  .sq-full-inp { font-size: 17px; padding: 14px 16px; }

  /* ヘッダー */
  .page-header { padding: 16px 24px 14px; }
  .page-header h2 { font-size: 20px; }

  /* キーボードは非表示（iPadはシステムキーボード） */
  #keyboard { display: none !important; }

  /* 採点バー調整 */
  .grade-bar { padding: 14px 24px; }
  .grade-btn { font-size: 17px; padding: 16px; }

  /* ボトムナビ非表示（iPadはタップ可） */
  .bottom-nav { display: none; }
}

/* ── アニメーション ── */
@keyframes pop-in {
  0%   { transform: scale(.8) translateY(10px); opacity: 0; }
  70%  { transform: scale(1.03); }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
@keyframes slide-up {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes correct-flash {
  0%   { background: var(--correct-bg); }
  50%  { background: rgba(52,211,153,.25); }
  100% { background: var(--correct-bg); }
}
@keyframes wrong-shake {
  0%,100% { transform: translateX(0); }
  25%     { transform: translateX(-4px); }
  75%     { transform: translateX(4px); }
}
.anim-pop     { animation: pop-in .35s cubic-bezier(.34,1.56,.64,1); }
.anim-slide   { animation: slide-up .25s ease; }
.anim-correct { animation: correct-flash .4s ease; }
.anim-wrong   { animation: wrong-shake .3s ease; }
