:root {
  --navy: #1e2a44;
  --navy-soft: #2a3856;
  --blue: #6db3f2;
  --blue-deep: #3f7fc4;
  --orange: #f2a65a;
  --paper: #fbfaf7;
  --ink: #23282f;
  --ink-soft: #5b636e;
  --line: #e7e3da;
  --ja-tint: #fff6ea;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Hiragino Kaku Gothic ProN", sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.8;
  padding-bottom: calc(64px + var(--safe-bot));
}

/* ---- トップバー ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--navy); color: #fff;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar .title { font-weight: 700; font-size: 17px; letter-spacing: .02em; }
.icon-btn { background: none; border: none; color: #fff; font-size: 20px; padding: 4px 8px; }

/* ---- ビュー ---- */
.view { display: none; padding: 16px; max-width: 720px; margin: 0 auto; }
.view.active { display: block; }

/* ---- 入力 ---- */
.loader { display: flex; flex-direction: column; gap: 12px; }
.seg { display: flex; background: #eee; border-radius: 12px; padding: 3px; }
.seg-btn { flex: 1; border: none; background: none; padding: 9px; border-radius: 9px; font-size: 14px; color: var(--ink-soft); }
.seg-btn.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.pane { display: none; flex-direction: column; gap: 10px; }
.pane.active { display: flex; }
input[type=url], textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; font-size: 16px; font-family: inherit; background: #fff; color: var(--ink);
}
textarea { resize: vertical; line-height: 1.6; }

button { font-family: inherit; cursor: pointer; }
.primary {
  background: var(--blue-deep); color: #fff; border: none;
  padding: 13px; border-radius: 12px; font-size: 16px; font-weight: 600;
}
.primary:active { background: #356aa5; }
.ghost {
  background: #fff; color: var(--ink); border: 1px solid var(--line);
  padding: 11px; border-radius: 12px; font-size: 15px;
}
.ghost.small { padding: 7px 12px; font-size: 13px; align-self: flex-start; }
.ghost.danger { color: #c0392b; border-color: #edcfca; }
.ghost.as-label { display: inline-block; text-align: center; }

/* ---- リーダー ---- */
.reader.hidden, .hidden { display: none; }
.ratio-bar {
  position: sticky; top: calc(44px + var(--safe-top)); z-index: 10;
  display: flex; align-items: center; gap: 10px;
  background: var(--paper); padding: 10px 2px; border-bottom: 1px solid var(--line); margin-bottom: 8px;
}
.ratio-label { font-size: 13px; color: var(--ink-soft); white-space: nowrap; }
.ratio-val { font-size: 13px; font-weight: 600; color: var(--blue-deep); width: 40px; text-align: right; }
#ratio { flex: 1; accent-color: var(--blue-deep); }
.art-title { font-size: 20px; line-height: 1.5; margin: 12px 0 4px; }
.art-body { font-size: 17px; }
.art-body p { margin: 0 0 14px; }
.hint { font-size: 12px; color: var(--ink-soft); background: #f3f1ec; padding: 10px 12px; border-radius: 10px; line-height: 1.6; }

/* ---- 文 ---- */
.sent { }
.sent .en { color: var(--ink); }
.sent .ja { color: var(--ink); }
.sent .ja.alt { display: inline; color: var(--ink-soft); font-size: .92em; background: var(--ja-tint); border-radius: 4px; padding: 0 3px; }
.sent .en.alt { color: var(--ink); }
/* 主表示が日本語の文はうっすら色地で「足場」だと分かる */
.sent[data-base="ja"] > .ja { background: var(--ja-tint); border-radius: 4px; padding: 0 2px; }
.w { }
.w:active { background: #d7e9fb; border-radius: 3px; }
.flip {
  border: 1px solid var(--line); background: #fff; color: var(--blue-deep);
  font-size: 10px; line-height: 1; padding: 2px 5px; border-radius: 6px; margin: 0 3px; vertical-align: 1px;
}

.load-status { text-align: center; color: var(--ink-soft); padding: 24px; font-size: 14px; }

/* ---- 空表示 ---- */
.empty { text-align: center; color: var(--ink-soft); padding: 40px 20px; }
.empty .sub { font-size: 13px; margin-top: 8px; }

/* ---- 復習 ---- */
.review-card { max-width: 560px; margin: 0 auto; }
.rc-progress { text-align: center; color: var(--ink-soft); font-size: 13px; margin-bottom: 16px; }
.rc-context { font-size: 18px; line-height: 1.9; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 16px; }
.rc-context b { color: var(--blue-deep); }
.rc-answer { text-align: center; margin-bottom: 16px; }
.rc-word { font-size: 24px; font-weight: 700; }
.rc-meaning { font-size: 18px; color: var(--blue-deep); margin-top: 4px; }
.rc-context-ja { font-size: 14px; color: var(--ink-soft); margin-top: 10px; line-height: 1.7; }
.rc-grades { display: flex; gap: 8px; margin-top: 10px; }
.grade { flex: 1; border: none; border-radius: 12px; padding: 14px 4px; font-size: 15px; font-weight: 600; color: #fff; }
.grade.again { background: #d9694f; }
.grade.hard { background: var(--orange); }
.grade.good { background: #4c9a63; }

/* ---- ためた語 ---- */
.saved-list { list-style: none; padding: 0; margin: 0; }
.saved-item { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.si-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.si-word { font-size: 17px; font-weight: 700; }
.si-meaning { color: var(--blue-deep); font-size: 15px; }
.si-context { font-size: 13px; color: var(--ink-soft); margin-top: 6px; line-height: 1.6; }
.si-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.si-due { font-size: 12px; color: var(--ink-soft); }
.si-del { background: none; border: none; color: #c0392b; font-size: 13px; }

/* ---- 下ナビ ---- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bot);
}
.nav-btn { flex: 1; border: none; background: none; padding: 12px 0; font-size: 13px; color: var(--ink-soft); position: relative; }
.nav-btn.active { color: var(--blue-deep); font-weight: 700; }
.badge {
  position: absolute; top: 6px; left: 50%; margin-left: 10px;
  background: #d9694f; color: #fff; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; line-height: 16px; border-radius: 8px; padding: 0 4px;
}

/* ---- シート ---- */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: #fff; border-radius: 18px 18px 0 0; padding: 20px 18px calc(20px + var(--safe-bot));
  display: flex; flex-direction: column; gap: 10px;
  max-width: 720px; margin: 0 auto;
  animation: slideup .18s ease;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.ws-word { font-size: 22px; font-weight: 700; }
.ws-meaning { font-size: 18px; color: var(--blue-deep); min-height: 26px; }
.ws-context { font-size: 14px; color: var(--ink-soft); line-height: 1.7; }
.ws-context b { color: var(--ink); }
.ws-actions { display: flex; gap: 10px; margin-top: 6px; }
.ws-actions .primary, .ws-actions .ghost { flex: 1; }
.set-note { font-size: 13px; color: var(--ink-soft); line-height: 1.7; }
