:root {
  --bg: #f5f7fa; --card: #fff; --line: #e2e8f0; --ink: #1a202c; --sub: #718096;
  --accent: #2b6cb0; --accent-d: #234e7d; --ok: #2f855a; --warn: #c05621; --danger: #c53030;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background: var(--bg); color: var(--ink); -webkit-text-size-adjust: 100%;
}
.env-badge {
  position: sticky; top: 0; z-index: 100; background: var(--warn); color: #fff;
  text-align: center; font-weight: 700; padding: 6px; font-size: 13px;
}
header {
  display: flex; align-items: center; justify-content: space-between;
  /* iOS ネイティブ/PWA でノッチ・ステータスバーに潜り込まないよう safe-area 分を確保 */
  padding: calc(12px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 12px calc(16px + env(safe-area-inset-left));
  background: var(--accent); color: #fff;
}
header h1 { font-size: 18px; margin: 0; }
header button { background: rgba(255,255,255,.2); color: #fff; border: 0; padding: 6px 12px; border-radius: 6px; cursor: pointer; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs button {
  flex: 1; padding: 12px; border: 1px solid var(--line); background: var(--card);
  border-radius: 8px; cursor: pointer; font-size: 15px; font-weight: 600; color: var(--sub);
}
.tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.btn { background: var(--accent); color: #fff; border: 0; padding: 11px 16px; border-radius: 8px; cursor: pointer; font-size: 15px; font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sec { background: #edf2f7; color: var(--ink); }
.btn.ok { background: var(--ok); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
input[type=file] { width: 100%; padding: 10px 0; }
textarea { width: 100%; min-height: 110px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-family: inherit; }
input[type=text], input[type=password], input[type=search] { width: 100%; padding: 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; }
#preview { max-width: 100%; max-height: 240px; border-radius: 8px; margin-top: 10px; display: none; }
.progress { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 10px 0; display: none; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.muted { color: var(--sub); font-size: 13px; }
.cand { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cand input[type=checkbox] { width: 20px; height: 20px; margin-top: 3px; }
.cand .w { font-weight: 700; }
.cand .pos { font-size: 11px; color: var(--sub); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; margin-left: 6px; }
.cand .m { width: 100%; margin-top: 4px; font-size: 13px; }
.cand.known { opacity: .55; }
.tag-known { font-size: 11px; color: var(--warn); margin-left: 6px; }
.wordrow { display: flex; align-items: flex-start; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.wordrow .main { flex: 1; }
.wordrow .word { font-weight: 700; font-size: 16px; }
.wordrow .meaning { font-size: 13px; color: var(--ink); margin-top: 3px; }
.wordrow.learned .word::after { content: " ✓"; color: var(--ok); }
.wordrow.learned { opacity: .6; }
.row-actions { display: flex; flex-direction: column; gap: 6px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .sp { flex: 1; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: #1a202c; color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: opacity .2s; z-index: 200; }
.toast.show { opacity: .95; }
.chk-section { margin-top: 12px; }
.chk-title { font-size: 13px; color: var(--sub); font-weight: 700; margin-bottom: 6px; }
.chk-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chk-group label, label.chk-inline {
  display: inline-flex; align-items: center; gap: 6px; margin: 0;
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 20px;
  font-size: 13px; color: var(--ink); cursor: pointer;
}
.chk-group input[type=checkbox] { width: 16px; height: 16px; margin: 0; }
.chk-group label.on { background: #ebf4ff; border-color: var(--accent); color: var(--accent-d); font-weight: 600; }
label.chk-inline { border: 0; padding: 0; gap: 8px; }
label.chk-inline select { margin-left: 4px; }
.login-wrap { max-width: 360px; margin: 60px auto; }
label { font-size: 13px; color: var(--sub); display: block; margin: 10px 0 4px; }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ===== eibun-app 追加スタイル ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-wrap .card { width: 100%; max-width: 360px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 6px; }
label { display: block; font-size: 13px; color: var(--sub); font-weight: 700; margin: 10px 0 4px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 0 0 auto; }
select, input[type=number] { padding: 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; background: #fff; }
.passage-item { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.passage-item .grow { flex: 1; cursor: pointer; }
.passage-item .t { font-weight: 700; }
.passage-item .sub { font-size: 12px; color: var(--sub); }
.sent { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.sent input[type=checkbox] { width: 20px; height: 20px; margin-top: 3px; flex: 0 0 auto; }
.sent .body { flex: 1; }
.sent .en { font-size: 14px; }
.sent .ja { font-size: 13px; color: var(--sub); margin-top: 3px; }
.sent .ja[contenteditable=true] { outline: 1px dashed var(--line); padding: 2px 4px; border-radius: 4px; }
.seq { color: var(--sub); font-size: 12px; min-width: 24px; }
.hint { background: #ebf8ff; border: 1px solid #bee3f8; color: #2c5282; padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }

/* ===== A4 問題プリント ===== */
.sheet {
  background: #fff; color: #000; width: 210mm; min-height: 297mm; margin: 0 auto 12px;
  padding: 18mm 16mm; box-shadow: 0 2px 12px rgba(0,0,0,.15); box-sizing: border-box;
}
.sheet h2 { margin: 0 0 2mm; font-size: 15pt; }
.sheet .meta { font-size: 9pt; color: #444; margin-bottom: 6mm; display: flex; justify-content: space-between; }
.sheet ol { margin: 0; padding-left: 9mm; }
.sheet li { margin-bottom: 5mm; font-size: 11pt; line-height: 1.5; page-break-inside: avoid; }
.sheet .q-prompt { }
.sheet .ans-line { border-bottom: 1px solid #999; height: 7mm; margin-top: 1.5mm; }
.sheet .ans-line.two { height: 14mm; }
.sheet.answers li { margin-bottom: 3mm; }
.sheet.answers .a { color: #000; }
.sheet .name-box { border: 1px solid #666; padding: 2mm 4mm; font-size: 9pt; }

@media print {
  body { background: #fff; }
  header, .tabs, .env-badge, .no-print, .toast { display: none !important; }
  main { max-width: none; margin: 0; padding: 0; }
  .sheet { box-shadow: none; margin: 0; width: auto; min-height: auto; padding: 0; }
  .sheet.answers { page-break-before: always; }
}
@page { size: A4; margin: 15mm; }
