/* style.css — 英単語800
   ・色だけで意味を伝えない（記号と文字を必ず添える）
   ・押せるところは最低 48px 四方
   ・スマホの縦画面と、タブレット・Chromebook の横画面のどちらでも崩れない  */

:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --ink: #1b1f24;
  --ink-sub: #5c6773;
  --line: #dfe3e8;
  --primary: #1f6feb;
  --primary-dark: #1558c0;

  /* 4つの状態の色（仕様書 §4.6） */
  --c-new: #c9ced6;
  --c-learning: #f2b705;
  --c-stable: #4cc3e0;
  --c-longterm: #35a35b;

  --ok: #1f8f4d;
  --maybe: #b57900;
  --ng: #c23b3b;
  --danger: #b3261e;

  /* 確認テストの採点マーク（先生の赤ペンの〇と、青ペンの×） */
  --maru: #e03131;
  --batsu: #1c6fd8;

  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --fs: 16px;
}

body[data-font="l"] { --fs: 19px; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181d; --card: #1c2127; --ink: #e8ecf1; --ink-sub: #9aa6b2;
    --line: #2c333b; --primary: #4d95ff; --primary-dark: #3a7fe0;
    --maru: #ff6b6b; --batsu: #5c9dff;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: var(--fs);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
               "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

/* ---------- 画面の切り替え ---------- */

.screen { display: none; }
.screen.is-active { display: block; }

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(28px + env(safe-area-inset-bottom));
}

/* 学習・確認テストの画面は「画面ぴったりの高さ」に閉じ込める。
   こうしないと、横向きのスマホや文字を大きくしたときに
   ⭕△❌ のボタンが画面の下に隠れてしまう（設計原則1「1操作1タップ」） */
.wrap-study {
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- 共通のパーツ ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.title { font-size: 1.5em; margin: 8px 0 4px; }
.title.small { font-size: 1.15em; margin: 0; }
.card-title { font-size: .95em; color: var(--ink-sub); margin: 0 0 10px; font-weight: 600; }
.lead { color: var(--ink-sub); margin: 0 0 16px; }
.hint { color: var(--ink-sub); font-size: .85em; line-height: 1.6; }
.center { text-align: center; }
.error { color: var(--danger); font-weight: 600; margin: 4px 0 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 12px 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 1em;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn-block { display: flex; width: 100%; }
.btn-big { min-height: 60px; font-size: 1.1em; }
.btn + .btn { margin-top: 10px; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { border-color: var(--line); color: var(--ink); }
.btn-danger { border-color: var(--line); color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

.link-btn {
  background: none;
  border: 0;
  color: var(--ink-sub);
  font: inherit;
  font-size: .9em;
  cursor: pointer;
  padding: 12px 8px 12px 0;
  min-height: 44px;
}

.icon-btn {
  background: none;
  border: 0;
  color: var(--ink-sub);
  font: inherit;
  font-size: 1.05em;
  cursor: pointer;
  min-width: 48px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.icon-btn span { font-size: .8em; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.who { margin: 0; font-size: .8em; color: var(--ink-sub); }
.who .badge {
  display: inline-block;
  background: var(--c-learning);
  color: #3a2b00;
  border-radius: 999px;
  padding: 2px 10px;
  font-weight: 700;
  margin-right: 6px;
}

.divider { display: flex; align-items: center; gap: 12px; color: var(--ink-sub); font-size: .8em; margin: 22px 0 14px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- 入力 ---------- */

.form .field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: .85em; color: var(--ink-sub); margin-bottom: 4px; font-weight: 600; }
.form input {
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  font-size: 1.05em;
  font-family: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.form input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.radios { display: flex; flex-direction: column; gap: 2px; }
.radios label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 4px 2px;
  cursor: pointer;
}
.radios input { width: 22px; height: 22px; accent-color: var(--primary); }

.setting-line { margin: 4px 0 10px; font-size: .9em; color: var(--ink-sub); }

/* ---------- ホーム ---------- */

.card-today { text-align: center; }
.today-count { font-size: 1.05em; margin: 0 0 14px; }
.today-count strong { font-size: 1.9em; color: var(--primary); }
.today-count .sep { color: var(--ink-sub); margin: 0 6px; }

.trophy { margin: 0 0 10px; font-size: 1.05em; }
.trophy strong { font-size: 1.4em; color: var(--c-longterm); }

.bar {
  display: flex;
  height: 16px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--c-new);
  border: 1px solid var(--line);
}
.bar-seg { display: block; height: 100%; transition: width .3s; }
.seg-new { background: var(--c-new); }
.seg-learning { background: var(--c-learning); }
.seg-stable { background: var(--c-stable); }
.seg-longterm { background: var(--c-longterm); }

.legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 0;
  margin: 10px 0 0;
  font-size: .82em;
  color: var(--ink-sub);
}
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.legend b { color: var(--ink); }

.week { display: flex; gap: 4px; justify-content: space-between; align-items: flex-end; }
.week .day { flex: 1; text-align: center; font-size: .78em; color: var(--ink-sub); }
.week .day .mark { display: block; font-size: 1.4em; line-height: 1.2; color: var(--c-new); }
.week .day.on .mark { color: var(--c-longterm); }
.week .day.today { font-weight: 700; color: var(--ink); }
.week-total { align-self: center; font-weight: 700; padding-left: 8px; white-space: nowrap; }
.week-streak { margin: 10px 0 0; font-size: .88em; color: var(--ink-sub); }

.pending { text-align: center; font-size: .8em; color: var(--ink-sub); margin: 0; }

/* ---------- 学習 ---------- */

.study-top { display: flex; align-items: center; justify-content: space-between; }
.counter { color: var(--ink-sub); font-size: .9em; font-variant-numeric: tabular-nums; margin: 0; }

.word-card {
  flex: 1 1 auto;
  min-height: 0;              /* 縮められるようにする（これが無いと下がはみ出す） */
  overflow-y: auto;           /* 例文が長いときはカードの中だけがスクロールする */
  display: flex;
  flex-direction: column;
  justify-content: center;
  justify-content: safe center;   /* 古いブラウザは上の center が効く */
  text-align: center;
  padding: 20px 16px;
}
.word-head { display: flex; align-items: center; justify-content: center; gap: 8px; }
.word {
  font-size: 2.3em;
  font-weight: 700;
  margin: 0;
  word-break: break-word;
  letter-spacing: .01em;
}
.pos { color: var(--ink-sub); font-size: .85em; margin: 2px 0 14px; }
.prompt { color: var(--ink-sub); font-size: .95em; margin: 16px 0 0; }

.meaning { font-size: 1.5em; font-weight: 700; margin: 6px 0; }
.kana { color: var(--ink-sub); font-size: .9em; margin: 2px 0; }
.note {
  font-size: .85em;
  color: var(--ink-sub);
  margin: 8px auto 0;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  max-width: 90%;
}
.example { font-size: .9em; margin: 10px 0 0; color: var(--ink); }
.example-ja { font-size: .85em; margin: 2px 0 0; color: var(--ink-sub); }

.actions { flex: 0 0 auto; padding-top: 12px; }

/* 横向きのスマホなど、縦が短いとき */
@media (max-height: 520px) {
  .word { font-size: 1.7em; }
  .meaning { font-size: 1.25em; }
  .word-card { padding: 12px 16px; }
  .actions.grade { grid-template-columns: repeat(3, 1fr); }
  .actions.grade .btn { justify-content: center; padding-left: 12px; min-height: 52px; }
}
.actions.grade { display: grid; grid-template-columns: 1fr; gap: 10px; }
.actions.grade .btn { margin-top: 0; min-height: 56px; justify-content: flex-start; padding-left: 22px; }
.actions.grade .mark { font-size: 1.2em; min-width: 1.6em; }

.btn-ok { border-color: var(--ok); color: var(--ok); }
.btn-maybe { border-color: var(--maybe); color: var(--maybe); }
.btn-ng { border-color: var(--ng); color: var(--ng); }

@media (min-width: 620px) {
  .actions.grade { grid-template-columns: repeat(3, 1fr); }
  .actions.grade .btn { justify-content: center; padding-left: 12px; flex-direction: column; gap: 2px; min-height: 76px; }
}

/* ---------- 確認テスト ---------- */

.choices { display: grid; gap: 10px; }
.choices .btn { margin-top: 0; text-align: left; justify-content: flex-start; min-height: 56px; }
.choices .btn .num {
  min-width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .85em; color: var(--ink-sub);
}
.choices .btn.is-correct { border-color: var(--ok); background: rgba(31, 143, 77, .1); color: var(--ok); }
.choices .btn.is-wrong { border-color: var(--ng); background: rgba(194, 59, 59, .1); color: var(--ng); }
.check-msg { text-align: center; font-weight: 600; margin: 14px 0 0; font-size: 1.15em; }
.check-msg.is-correct { color: var(--maru); }
.check-msg.is-wrong { color: var(--batsu); }

/* ---------- 採点マーク（〇と×） ---------- */

/* 単語のまわりに余白を作って、その枠にぴったり〇を描く */
/* 単語を inline-block で包み、その枠にぴったり〇を描く。
   flex の中で直接 fit-content を使うと幅が 0 に潰れる端末があるので、
   いったん普通のブロック（.mark-line）で中央寄せしてから包む */
.mark-line { text-align: center; }
.mark-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  padding: 18px 40px;
}
.mark-wrap .word { position: relative; z-index: 2; margin: 0; display: inline-block; }

/* 正解 — 英単語を囲む赤い〇 */
.mark-o {
  position: absolute;
  inset: 0;
  z-index: 3;
  border: 7px solid var(--maru);
  border-radius: 50%;
  pointer-events: none;
  animation: mark-pop .28s cubic-bezier(.2, 1.5, .4, 1);
}

/* 不正解 — 英単語の後ろに出る大きな青い× */
.mark-x {
  position: absolute;
  inset: -10% -6%;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--batsu);
  font-size: 5.5em;
  font-weight: 400;
  line-height: 1;
  opacity: .8;
  pointer-events: none;
  animation: mark-pop .28s cubic-bezier(.2, 1.5, .4, 1);
}

.mark-o[hidden], .mark-x[hidden] { display: none; }

@keyframes mark-pop {
  from { transform: scale(.55); opacity: 0; }
  to   { transform: scale(1); }
}

@media (max-height: 520px) {
  .mark-wrap { padding: 12px 28px; }
  .mark-x { font-size: 4em; }
  .mark-o { border-width: 5px; }
}

@media (min-width: 620px) { .choices { grid-template-columns: 1fr 1fr; } }

/* ---------- 終了 ---------- */

.done-main { text-align: center; font-size: 1.05em; margin: 0 0 10px; }
.done-main strong { font-size: 1.8em; color: var(--primary); }
.done-list { list-style: none; padding: 0; margin: 0; }
.done-list li { display: flex; justify-content: space-between; padding: 6px 0; border-top: 1px solid var(--line); }
.done-list b { font-variant-numeric: tabular-nums; }

/* ---------- 読み込み中 ---------- */

.boot { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.boot-logo { font-size: 1.5em; font-weight: 700; letter-spacing: .04em; }
.boot-msg { color: var(--ink-sub); font-size: .9em; margin: 0; }

/* ---------- 確認ダイアログ・お知らせ ---------- */

.modal {
  position: fixed; inset: 0;
  background: rgba(16, 24, 40, .5);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.modal[hidden] { display: none; }
.modal-box { background: var(--card); border-radius: var(--radius); padding: 20px; max-width: 420px; width: 100%; }
.modal-title { font-size: 1.1em; margin: 0 0 8px; }
.modal-text { color: var(--ink-sub); font-size: .92em; margin: 0 0 18px; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }
.modal-actions .btn { margin-top: 0; }

@media (min-width: 520px) {
  .modal-actions { flex-direction: row-reverse; }
  .modal-actions .btn { flex: 1; }
}

.toast {
  position: fixed;
  left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 999px;
  font-size: .88em; z-index: 60;
  max-width: 90vw; text-align: center;
}
.toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
