:root {
  --brand: #2563eb;
  --brand-d: #1d4ed8;
  --line: #06c755;
  --bg: #f1f5f9;
  --card: #fff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
}
* {
  box-sizing: border-box;
}
/* Material Symbols を自己ホスト（外部fonts.googleapis.com/gstatic依存を排除し、SRI/CSPを簡潔化） */
@font-face {
  font-family: 'Material Symbols Outlined';
  font-style: normal;
  font-weight: 100 700;
  font-display: block;
  src: url('assets/fonts/material-symbols-outlined.woff2') format('woff2');
}
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined';
  font-weight: normal;
  font-style: normal;
  font-size: 20px;
  line-height: 1;
  letter-spacing: normal;
  white-space: nowrap;
  direction: ltr;
  display: inline-block;
  vertical-align: middle;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}
.material-symbols-outlined.filled {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}
.material-symbols-outlined.big {
  font-size: 44px;
}
body {
  margin: 0;
  font-family:
    system-ui, -apple-system, 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.muted {
  color: var(--muted);
}
.sm {
  font-size: 12px;
}
.err {
  color: var(--danger);
}

/* 認証カード */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.06);
}
.auth-card {
  width: 100%;
  max-width: 380px;
}
.logo {
  text-align: center;
  margin-bottom: 18px;
}
.logo .mark {
  font-size: 40px;
}
.logo h1 {
  margin: 4px 0 2px;
  color: var(--brand);
}

.field {
  margin-bottom: 12px;
}
.field label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
}
.field textarea {
  resize: vertical;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brand);
}

/* お知らせ */
.notice {
  margin-bottom: 12px;
  cursor: pointer;
}
.notice.unread {
  border-color: var(--brand);
}
.notice-title {
  font-weight: 700;
}
.notice-body {
  margin-top: 8px;
  white-space: pre-wrap;
  font-size: 14px;
}
.dot-new {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--brand);
  flex: 0 0 auto;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 15px;
  font-weight: 700;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
}
.btn:hover {
  background: var(--brand-d);
}
.btn.full {
  width: 100%;
}
.btn.line {
  background: var(--line);
  margin-top: 8px;
}
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn.danger {
  background: var(--danger);
}
.btn.sm {
  padding: 7px 10px;
  font-size: 13px;
}

.or {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 14px 0;
}
.gbtn {
  display: flex;
  justify-content: center;
  min-height: 40px;
}
.auth-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
}
.link {
  background: none;
  border: none;
  color: var(--brand);
  cursor: pointer;
  font-size: 13px;
}
.api-hint {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  margin: 14px 0 0;
}
.qr-note {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

.steps {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 14px;
}
.dot {
  width: 28px;
  height: 5px;
  border-radius: 3px;
  background: var(--border);
}
.dot.on {
  background: var(--brand);
}

/* ログイン後シェル（サイドバー＋コンテンツ＋下部ナビ） */
.shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 220px;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  /* PC: side-nav はスクロール対象外（画面に固定） */
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.side-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.snav {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  border: none;
  background: transparent;
  padding: 11px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}
.snav:hover {
  background: var(--bg);
}
.snav.on {
  background: #eff6ff;
  color: var(--brand);
  font-weight: 700;
}
.snav .ico {
  font-size: 16px;
}
.main-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.hdr-title {
  font-size: 18px;
  margin: 0;
}
.brand {
  font-weight: 800;
  color: var(--brand);
}
/* サブ画面ヘッダ: 長いタイトルは省略表示し、戻るボタンを押し出さない（狭幅対策） */
.topbar #topBack {
  flex: 0 0 auto;
  white-space: nowrap;
}
.topbar .brand {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}
.content {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  gap: 16px;
}
.bottom-nav {
  display: none;
}

/* 狭い画面: サイドバー→下部ナビへ */
@media (max-width: 720px) {
  .sidebar {
    display: none;
  }
  .content {
    /* 下部固定ナビと最下部ボタン（ログアウト/削除）が重ならない余白＋端末のセーフエリア */
    padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  }
  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    border-top: 1px solid var(--border);
    z-index: 50;
  }
  .nav-item {
    flex: 1;
    border: none;
    background: transparent;
    padding: 9px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    color: var(--muted);
    font-size: 11px;
  }
  .nav-item.on {
    color: var(--brand);
  }
  .nav-ico {
    font-size: 18px;
  }
}
.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chips {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
/* アカウント等の list-row（プロトタイプ準拠） */
.section-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  margin: 18px 2px 8px;
}
.card.list {
  padding: 0;
  overflow: hidden;
}
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 13px 16px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
}
button.list-row {
  cursor: pointer;
}
button.list-row:hover {
  background: var(--bg);
}
.list-row:last-child {
  border-bottom: 0;
}
.lr-main {
  min-width: 0;
}
.lr-title {
  font-weight: 700;
}
.lr-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}
.chip.on {
  background: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}
.book {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-top: 8px;
}
.book-title {
  font-weight: 700;
}
.book-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
/* お気に入り一覧の右側: 解除星ボタン＋矢印 */
.fav-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}
.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
}
.icon-btn.fav-on {
  color: #f59e0b;
}
.book-head {
  display: flex;
  align-items: center;
  gap: 14px;
}
/* 書籍カバー（420:595。画像は全体表示=contain／無い時はグラデ＋教科名） */
.book-cover {
  aspect-ratio: 420 / 595;
  /* 書籍画像は角丸なし・裏の背景は白（画像の四隅を加工せず、余白は白で見せる） */
  border-radius: 0;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  background-color: #fff;
  display: flex;
  align-items: flex-end;
  padding: 6px;
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  flex: 0 0 auto;
}
/* プレースホルダー（画像が無い場合のグラデ）は従来どおり角丸を維持 */
.book-cover.grad {
  background-size: cover;
  border-radius: 8px;
}
.book-cover.sm {
  width: 46px;
  font-size: 9px;
  padding: 4px;
}
.book-cover.md {
  width: 92px;
}
.book-cover.card {
  width: 64px;
}

/* マイ書籍（プロトタイプ準拠のカードグリッド） */
.addbook-bar {
  display: flex;
  justify-content: flex-end;
}
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.book-card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  cursor: pointer;
}
.book-card:hover {
  background: var(--bg);
}
.book-card.is-expired {
  opacity: 0.6;
  cursor: not-allowed;
}
.book-card.is-expired:hover {
  background: #fff;
}
.bc-main {
  min-width: 0;
}
.bc-title {
  font-weight: 700;
}
.bc-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
/* 閲覧期限。期限なし(移行ライセンスに多い)でも「無期限」と必ず表示する */
.bc-term {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 6px;
  margin-top: 6px;
}
.term-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  background: #eef2f9;
  color: #475569;
  border: 1px solid #cbd5e1;
  white-space: nowrap;
}
.term-badge.is-unlimited {
  background: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}
.term-badge.is-free {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}
.term-badge.is-expired {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}
.term-date {
  font-size: 11.5px;
  color: var(--muted);
}
.dev {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
/* 端末情報側は縮小可に（長い端末名/バッジで押し出されないように） */
.dev > div {
  min-width: 0;
  flex: 1 1 auto;
}
.dev .actions {
  flex: 0 0 auto;
}
/* 狭い画面（〜430px）は操作ボタンを情報の下に全幅で並べる */
@media (max-width: 430px) {
  .dev {
    align-items: flex-start;
  }
  .dev .actions {
    width: 100%;
  }
  .dev .actions .btn {
    flex: 1 1 0;
  }
}

/* 視聴系 */
.row-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-top: 8px;
  cursor: pointer;
}
.row-link:hover {
  background: var(--bg);
}
/* 行リンク: タイトルは縮小・折り返し、右側の本数/％＋矢印は改行させない（狭幅対策） */
.row-link > :first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}
.row-link > :last-child {
  flex: 0 0 auto;
  white-space: nowrap;
  margin-left: 8px;
}
/* 320〜380px の極狭幅: ヘッダ余白と文字を詰める */
@media (max-width: 380px) {
  .topbar {
    padding: 12px 10px;
  }
  .topbar .brand {
    font-size: 15px;
  }
  .content {
    padding: 14px 12px;
  }
}
.redeem {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}
.redeem input {
  flex: 1;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
}
.video-frame {
  position: relative;
  padding-top: 56.25%;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}
.video-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge.on {
  background: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}

/* トースト */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 9999;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

/* ===================================================================
 * 動画再生画面（app.js の openVideo）専用のレイアウト
 * -------------------------------------------------------------------
 * 既存の .content / .card / .video-frame の宣言は 1 行も変更していない。
 * openVideo() が出す <main class="content video-page"> のときだけ効く
 * 修飾子として、このファイルの末尾に追記している。
 * 詳細度 (0,2,0) なので、上方の @media 内にある .content (0,1,0) には
 * 記述位置に関係なく勝つ。
 *
 * ねらい: 動画を .card の padding(24px)+border(1px) の外に出し、画面端から
 * 8px まで広げる。iPhone SE(375px) で実効幅 301px → 359px（面積 1.42 倍）。
 *
 * ★ 触るときの注意 ─ 幅は .video-frame ではなく .content 側で変える
 * .video-frame の高さは padding-top:56.25% で作られている。パーセンテージ
 * padding は「自分の幅」ではなく「包含ブロックの幅」に対して解決されるので、
 * 包含ブロック（.content の内容ボックス）を動かせば幅も高さも追従して 16:9
 * が保たれる。.video-frame 自身に max-width を掛けると幅だけ縮んで高さが
 * 据え置かれ、縦横比が 2.0 台に崩れる。
 *
 * ★ Vimeo の操作バーについて（このCSSでは解決できない）
 * 操作バーはプレーヤーの幅だけで折り返しを決める。実測した閾値は 430px
 * （414px = 音量・字幕・画質(歯車)・速度・PiP・全画面がバーの外に出て「‹」の
 * 奥に格納される / 430px = 全アイコンが並ぶ）。iPhone 縦持ちのビューポートは
 * 375〜430px なので、左右の余白を 0 にしても届かない。全幅化しても歯車は
 * 露出しないため、app.js の VIDEO_QUALITY_NOTE 末尾で「‹」を案内している。
 * =================================================================== */
.content.video-page {
  /* 動画・注意書き・情報カードの左右インセットを決める唯一の調整点 */
  --video-gutter: 8px;
  /* ショートハンド(padding:)で書くと @media(max-width:720px) の padding-bottom と
     @media(max-width:380px) の padding まで巻き込んでしまうので、必ず longhand で
     書くこと。padding-top / padding-bottom は既存の値をそのまま継承させる。 */
  padding-left: var(--video-gutter);
  padding-right: var(--video-gutter);
  gap: 12px;
}

/* 動画: カードの外に出した分だけ角丸を広い面に合わせる。
   padding-top:56.25% / background:#000 / overflow:hidden は既存定義のまま。 */
.content.video-page > .video-frame {
  border-radius: 12px;
}

/* 注意書き: 白カードの外＝背景色 --bg の上に直接置く */
.content.video-page > .video-note {
  /* .content は display:grid。<p> の既定 margin は gap と相殺されず加算される */
  margin: 0;
  /* 「※」をぶら下げ、2 行目以降を本文の頭に揃える */
  padding-left: calc(var(--video-gutter) + 1em);
  padding-right: var(--video-gutter);
  text-indent: -1em;
  /* --muted(#64748b) は背景 --bg(#f1f5f9) の上だと 4.34:1 で WCAG AA に届かない。
     #475569 は .term-badge で既に使っている色で、同じ背景で 6.92:1。 */
  color: #475569;
  font-size: 12.5px;
  /* body に line-height の指定が無く、既定値のままだと和文が詰まって読めない */
  line-height: 1.6;
}

/* 情報カード: 共通の .card は変更せず、この画面のときだけ余白を詰める。
   ★ .card の共通スタイルを変えても、padding はこの画面だけ追随しない。 */
.content.video-page > .card.video-info {
  padding: 14px 16px;
}
.content.video-page .v-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.45;
  /* 長い英数字が続く書籍名でも横スクロールを出さない */
  overflow-wrap: anywhere;
}
.content.video-page .v-meta {
  margin-top: 4px;
  font-size: 12.5px;
  line-height: 1.5;
  /* 白カードの上なら --muted でも 4.76:1 で AA を満たす */
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* ===================================================================
 * サブ画面ヘッダの固定表示
 * -------------------------------------------------------------------
 * 対象は動画再生・動画一覧・書籍詳細・各設定など、showShell() を通らない
 * 画面。これらには .bottom-nav が描画されないため、画面上の操作手段は
 * topbar() が出す「← 戻る」ただ1つしかない。
 * ところが .topbar は position 指定が無く(294行 = static)、スクロールすると
 * 一緒に流れて消える。消えた時点で生徒は画面から出られなくなる。
 *
 * 発生条件(実測): Safari のページズームを上げると文字が大きくなって
 * 書籍名・セクション名の折り返しが増え、ページが縦に伸びる。
 * iPhone 390px 縦持ちの動画再生画面で計測すると
 *   100% → スクロール余地 0px(そもそもスクロールできない)
 *   150% → 5px
 *   175% → 166px。ヘッダは完全に画面外、動画の上端も 66px 切れる
 * ズームは Safari がサイトごとに記憶するため、一度上げた端末では
 * 再現し続ける。「毎回ではない」のはこれと文字量の組み合わせによる。
 *
 * ★ セレクタを子結合子に限定している理由
 * showShell() のヘッダは #root > .shell > .main-col > header.topbar なので
 * このセレクタには一致しない。あちらは .bottom-nav(349行)が position:fixed で
 * 常に画面に残るため固定は不要で、PC 表示の見た目も変えたくない。
 * サブ画面は root().innerHTML = topbar(...) + '<main>' の形なので
 * header.topbar が #root の直接の子になり、こちらだけに一致する。
 * 詳細度 (1,1,0) なので既存の .topbar (0,1,0) と
 * @media(max-width:380px) 内の .topbar(653行)に、記述位置に関係なく勝つ。
 *
 * ★ z-index は消さないこと
 * .video-frame は position:relative(676行)で DOM 順が後ろのため、
 * z-index が無いとスクロール時にヘッダが動画の下に潜り、
 * 「戻る」が押せなくなる(実測: z-index 無しだと画面左上の座標が
 * IFRAME#vplayer を返す。40 を付けると BUTTON#topBack が返る)。
 *
 * ★ 既知の副作用
 * ズーム時にスクロールすると、固定されたヘッダが動画の上端に少し被る。
 * 「動画の上が切れて操作手段が何も無い」状態よりは良い、という判断。
 * =================================================================== */
#root > .topbar {
  position: sticky;
  top: 0;
  z-index: 40;
}
