:root {
  --navy: #1f3a5f;
  --navy-2: #2c5282;
  --bg: #f5f6f8;
  --card: #fff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e2e5ea;
  --ok: #1e8e5a;
  --ok-bg: #e7f6ee;
  --warn: #b45309;
  --warn-bg: #fff7e6;
  --danger: #c53030;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 16px;
}
a { color: var(--navy-2); }
img { max-width: 100%; height: auto; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--navy); color: #fff;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.brand span { font-weight: 400; font-size: 13px; opacity: .85; margin-left: 4px; }
#nav { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
#nav a, #nav button {
  color: #fff; background: transparent; border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px; padding: 4px 12px; font-size: 13px; text-decoration: none; cursor: pointer; font-family: inherit;
}
#nav a.active { background: rgba(255,255,255,.18); }

main { max-width: 960px; margin: 0 auto; padding: 20px 16px 80px; }
main.wide { max-width: 1200px; }
h1 { font-size: 22px; margin: 4px 0 16px; line-height: 1.4; }
h2 { font-size: 18px; margin: 24px 0 10px; }
h3 { font-size: 16px; margin: 0; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.loading { color: var(--muted); text-align: center; padding: 40px 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card.narrow { max-width: 440px; margin: 24px auto; padding: 24px 20px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 18px; border-radius: 8px; border: 1px solid var(--navy);
  background: var(--navy); color: #fff; font-size: 15px; font-family: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; transition: opacity .15s;
}
.btn:hover { opacity: .9; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: #fff; color: var(--navy); }
.btn.ok { background: var(--ok); border-color: var(--ok); }
.btn.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.linklike { background: none; border: none; color: var(--navy-2); text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }

label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=url], select, textarea {
  width: 100%; padding: 10px 12px; font-size: 16px; font-family: inherit;
  border: 1px solid #cbd2db; border-radius: 8px; background: #fff; color: var(--text);
}
textarea { min-height: 220px; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: 20px; height: 20px; }
.field-hint { margin: -2px 0 6px; }
.form-actions { margin-top: 18px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 22px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.notice { padding: 12px 14px; border-radius: 8px; margin: 12px 0; font-size: 14px; }
.notice.ok { background: var(--ok-bg); color: #14532d; }
.notice.warn { background: var(--warn-bg); color: #7c2d12; }
.notice.error { background: #fdecec; color: #7f1d1d; }
.notice.dev { background: #eef2ff; color: #312e81; word-break: break-all; }

.progress { height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); border-radius: 999px; }
.progress-label { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 6px; }

.course-list { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .course-list { grid-template-columns: 1fr 1fr; } }
.course-card { display: block; text-decoration: none; color: inherit; }
.course-card h3 { font-size: 17px; margin-bottom: 10px; line-height: 1.5; }
.course-card:hover { border-color: var(--navy-2); }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: #eef1f6; color: var(--navy); margin-right: 4px; white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.gray { background: #f1f1f1; color: #666; }

.section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.section-title { padding: 12px 16px; background: #f0f3f7; font-weight: 700; font-size: 15px; }
.lecture-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; min-height: 52px; }
.lecture-row:first-of-type { border-top: none; }
a.lecture-row:hover { background: #fafbfc; }
.lecture-row.locked { color: #9aa1ab; }
.lecture-row .title { flex: 1; font-size: 15px; }
.mark { flex: none; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #cbd2db; display: grid; place-items: center; font-size: 13px; color: #fff; }
.mark.done { background: var(--ok); border-color: var(--ok); }
.mark.lock { border: none; color: #9aa1ab; font-size: 15px; }

.crumbs { font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.crumbs a { color: var(--muted); }
.video { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #0b0f17; border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: #cbd5e1; font-size: 14px; text-align: center; padding: 16px; }
.lecture-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin: 12px 0 20px; }
.lecture-body { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; overflow-wrap: anywhere; }
.lecture-body img, .lecture-body iframe, .lecture-body video { max-width: 100%; }
.lecture-body table { border-collapse: collapse; max-width: 100%; display: block; overflow-x: auto; }
.lecture-body td, .lecture-body th { border: 1px solid var(--line); padding: 4px 8px; }
.attachments { list-style: none; padding: 0; margin: 0; }
.attachments li { padding: 10px 0; border-top: 1px solid var(--line); }
.attachments li:first-child { border-top: none; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.pager > a, .pager > span { display: block; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; text-decoration: none; color: inherit; font-size: 14px; min-height: 64px; overflow-wrap: anywhere; }
.pager > span:empty { border: none; background: transparent; }
.pager > .next { text-align: right; }
.pager .lbl { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.pager > span { color: #aab0b9; }

/* 管理画面 */
.admin-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.admin-tabs a { padding: 6px 14px; border-radius: 999px; background: #fff; border: 1px solid var(--line); text-decoration: none; color: var(--text); font-size: 14px; }
.admin-tabs a.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 24px; }
.stat span { font-size: 13px; color: var(--muted); }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th, table.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.list th { background: #f0f3f7; font-weight: 600; white-space: nowrap; }
table.list tr:last-child td { border-bottom: none; }
table.list td.num { text-align: right; white-space: nowrap; }
.searchbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.searchbar input { flex: 1; min-width: 200px; }
.searchbar select { width: auto; min-width: 160px; }
.tree-section { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; margin-bottom: 12px; }
.tree-head { display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: #f0f3f7; flex-wrap: wrap; border-radius: var(--radius) var(--radius) 0 0; }
.tree-head .title { flex: 1; font-weight: 700; min-width: 160px; }
.tree-row { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.tree-row .title { flex: 1; min-width: 160px; }
.icon-btn { min-width: 34px; min-height: 34px; border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; font-size: 14px; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.attach-edit { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: #fafbfc; }
@media (min-width: 720px) { .attach-edit { grid-template-columns: 1fr 2fr auto; align-items: center; } }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input, .inline-form select { flex: 1; min-width: 160px; width: auto; }
.pagination { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #1d2330; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; width: max-content; text-align: center;
  opacity: 0; pointer-events: none; transition: all .2s; max-width: calc(100% - 32px); z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); }

.btn { white-space: nowrap; }
.td-label { display: none; }

/* スマホでは表をカード型に並べ替える */
@media (max-width: 640px) {
  table.list.stack thead { display: none; }
  table.list.stack, table.list.stack tbody, table.list.stack tr, table.list.stack td { display: block; width: 100%; }
  table.list.stack tr { padding: 10px 4px; border-bottom: 1px solid var(--line); }
  table.list.stack tr:last-child { border-bottom: none; }
  table.list.stack td { border: none; padding: 3px 10px; text-align: left; }
  table.list.stack td.num { text-align: left; }
  table.list.stack .td-label { display: inline; color: var(--muted); font-size: 12px; margin-right: 6px; }
  table.list.stack .inline-form input { min-width: 0; }
  #nav a, #nav button { padding: 3px 9px; font-size: 12px; }
  #nav { gap: 4px; }
}

@media (max-width: 480px) {
  h1 { font-size: 20px; }
  .brand span { display: none; }
  main { padding: 16px 12px 80px; }
  table.list th, table.list td { padding: 8px; }
}

/* 「HTMLを埋め込む」ブロックの囲い（高さは中身に合わせて app.js が決める） */
.lecture-body iframe.embed-frame { display: block; width: 100%; height: 200px; border: 0; margin: 12px 0; overflow: hidden; background: transparent; }
.lecture-body .embed-native-group { margin: 12px 0; }
.lecture-body .embed-native { position: relative; width: 100%; height: 0; overflow: hidden; margin-bottom: 8px; }
.lecture-body .embed-native iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.lecture-body iframe.embed-frame.empty { margin: 0; }
