:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --fg: #1c2333;
  --muted: #6b7280;
  --accent: #4f6df5;
  --accent-weak: #e8ecfe;
  --good: #16a34a;
  --bad: #dc2626;
  --border: #e2e5ee;
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--fg);
}
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand {
  border: none; background: none; font-size: 18px; font-weight: 700;
  cursor: pointer; color: var(--fg); padding: 0;
}
.brand .badge {
  font-size: 10px; font-weight: 600; color: var(--accent);
  background: var(--accent-weak); border-radius: 999px; padding: 2px 8px;
  vertical-align: middle; margin-left: 6px;
}
#progress-summary { font-size: 13px; color: var(--muted); }
.view { max-width: 860px; margin: 0 auto; padding: 20px 16px 60px; }
.hidden { display: none !important; }

.hero h1 { margin: 18px 0 6px; font-size: 26px; }
.hero .sub { margin: 0 0 22px; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.stage-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; cursor: pointer; transition: transform .08s, box-shadow .08s;
}
.stage-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(30,40,90,.08); }
.stage-card h3 { margin: 0 0 6px; font-size: 17px; }
.stage-card p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.6; }

.back {
  border: 1px solid var(--border); background: var(--card); color: var(--fg);
  border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 13px; margin-bottom: 14px;
}
.back:hover { background: var(--accent-weak); }

.tabs { display: flex; gap: 6px; margin: 14px 0; }
.tab {
  border: 1px solid var(--border); background: var(--card); padding: 8px 16px;
  border-radius: 999px; cursor: pointer; font-size: 14px;
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tabpane { margin-top: 6px; }

.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.unit-item, .deck-item {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer;
}
.unit-item:hover, .deck-item:hover { border-color: var(--accent); }
.unit-item .num, .deck-item .num {
  display: inline-block; min-width: 34px; font-weight: 700; color: var(--accent);
  font-size: 13px; margin-right: 8px;
}
.unit-item .t { font-weight: 600; }
.deck-item .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.deck-actions { display: flex; gap: 8px; margin-top: 10px; }
.deck-actions button {
  flex: 1; border: none; border-radius: 9px; padding: 7px 0; cursor: pointer;
  font-size: 13px; font-weight: 600;
}
.btn-flash { background: var(--accent-weak); color: var(--accent); }
.btn-quiz { background: #fff3e0; color: #d97706; }
.deck-actions button:hover { filter: brightness(.96); }

/* 教科書ビュー */
.doc {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px 26px; line-height: 1.75; font-size: 15px;
}
.doc h1 { font-size: 22px; margin: 4px 0 10px; }
.doc h2 { font-size: 17px; margin: 26px 0 8px; padding-left: 10px; border-left: 4px solid var(--accent); }
.doc h3 { font-size: 15px; margin: 18px 0 6px; }
.doc blockquote {
  margin: 8px 0 14px; padding: 8px 14px; background: var(--bg);
  border-radius: 8px; color: var(--muted); font-size: 13px;
}
.doc table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13.5px; }
.doc th, .doc td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.doc th { background: var(--bg); }
.doc code { background: var(--bg); border-radius: 5px; padding: 1px 6px; font-size: 13px; }
.doc li { margin: 4px 0; }
.doc ol li { margin: 8px 0; }

/* フラッシュカード */
.flash-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; color: var(--muted); margin-bottom: 8px;
}
.progress { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 20px; }
.bar { height: 100%; width: 0%; background: var(--accent); transition: width .25s; }
.card {
  background: var(--card); border: 2px solid var(--border); border-radius: 18px;
  min-height: 220px; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 30px; cursor: pointer; user-select: none;
}
.card.flipped { border-color: var(--accent); }
#card-face .word { font-size: 40px; font-weight: 700; letter-spacing: .01em; }
#card-face .reading { font-size: 22px; margin-top: 12px; color: var(--fg); }
#card-face .pos-tag {
  display: inline-block; font-size: 11px; color: var(--accent); background: var(--accent-weak);
  border-radius: 999px; padding: 2px 10px; margin-bottom: 12px;
}
#card-face .ex { margin-top: 16px; font-size: 14px; color: var(--muted); line-height: 1.6; }
#card-face .ex b { color: var(--accent); }
.flash-controls { margin-top: 20px; text-align: center; }
.flash-controls button {
  border: none; border-radius: 12px; padding: 12px 22px; margin: 0 4px;
  font-size: 15px; font-weight: 700; cursor: pointer;
}
#btn-show { background: var(--accent); color: #fff; width: 60%; max-width: 320px; }
#btn-again { background: #fee2e2; color: var(--bad); }
#btn-ok { background: #dcfce7; color: var(--good); }
#btn-easy { background: #e0f2fe; color: #0369a1; }
#btn-speak { background: var(--bg); color: var(--muted); border: 1px solid var(--border) !important; }

/* クイズ */
.qtext {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; font-size: 19px; text-align: center; font-weight: 600;
}
.choices { display: grid; gap: 10px; margin-top: 16px; }
.choices button {
  border: 2px solid var(--border); background: var(--card); border-radius: 12px;
  padding: 14px; font-size: 15px; cursor: pointer; text-align: left;
}
.choices button:hover:not(:disabled) { border-color: var(--accent); }
.choices button.correct { border-color: var(--good); background: #f0fdf4; }
.choices button.wrong { border-color: var(--bad); background: #fef2f2; }
.feedback { min-height: 44px; margin-top: 12px; font-size: 13.5px; line-height: 1.55; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.quiz-controls { text-align: center; margin-top: 8px; }
.quiz-controls button {
  border: none; background: var(--accent); color: #fff; border-radius: 12px;
  padding: 12px 28px; font-size: 15px; font-weight: 700; cursor: pointer;
}
@media (max-width: 560px) {
  #card-face .word { font-size: 30px; }
  .qtext { font-size: 16px; }
}

/* ---------- 同期UI ---------- */
.topbar { gap: 10px; flex-wrap: wrap; }
.sync-btn {
  border: 1px solid var(--border); background: var(--bg); color: var(--fg);
  border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 13px;
}
.sync-btn:hover { background: var(--accent-weak); }
.sync-status {
  font-size: 12px; color: var(--muted);
}
.sync-status.sync-on { color: var(--good); font-weight: 600; }

.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20,25,40,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-box {
  background: var(--card); border-radius: 18px; padding: 24px 26px;
  max-width: 420px; width: 100%; box-shadow: 0 18px 50px rgba(0,0,0,.22);
}
.modal-box h3 { margin: 0 0 8px; }
.modal-box p { margin: 6px 0; font-size: 13.5px; line-height: 1.6; }
.modal-note { color: var(--muted); font-size: 12.5px !important; }
.code-display {
  font-family: ui-monospace, monospace; font-size: 26px; font-weight: 700;
  letter-spacing: .12em; text-align: center;
  background: var(--accent-weak); color: var(--accent);
  border-radius: 10px; padding: 10px; margin: 8px 0;
}
#sync-link-area input {
  width: 100%; box-sizing: border-box; font-size: 20px;
  text-align: center; letter-spacing: .1em; text-transform: uppercase;
  border: 2px solid var(--border); border-radius: 10px; padding: 9px; margin: 6px 0 10px;
}
#sync-link-area input:focus { outline: none; border-color: var(--accent); }
#btn-create-code, #btn-link-code, #btn-unlink {
  border: none; border-radius: 10px; padding: 10px 18px;
  font-size: 14px; font-weight: 700; cursor: pointer;
}
#btn-create-code, #btn-link-code { background: var(--accent); color: #fff; }
#btn-unlink.danger { background: #fee2e2; color: var(--bad); margin-top: 10px; }
#btn-create-code:hover, #btn-link-code:hover { filter: brightness(1.06); }
.modal-close {
  display: block; width: 100%; margin-top: 18px;
  border: 1px solid var(--border); background: none; border-radius: 10px;
  padding: 9px; cursor: pointer; color: var(--muted);
}

#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(80px);
  background: var(--fg); color: var(--bg); font-size: 13.5px;
  border-radius: 999px; padding: 10px 20px; opacity: 0;
  transition: transform .25s, opacity .25s; z-index: 200; pointer-events: none;
  max-width: 90vw;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
