: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;
}
.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);
}
