/* ============ 基本 ============ */
* { box-sizing: border-box; }
:root {
  --bg: #0e0d12;
  --panel: #17161d;
  --panel-2: #1d1c25;
  --line: #2a2833;
  --text: #ece9f1;
  --muted: #9b96a8;
  --accent: #8b5cf6;
  --accent-soft: rgba(139, 92, 246, 0.16);
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --discord: #5865f2;
  --radius: 12px;
}
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Hiragino Sans",
    "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 15px;
  line-height: 1.65;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; }
code { background: var(--panel-2); padding: 2px 6px; border-radius: 6px; font-size: 13px; }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

.container { max-width: 1080px; margin: 0 auto; padding: 20px 16px 64px; }

/* ============ ヘッダー ============ */
.site-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 16px;
  background: rgba(14, 13, 18, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 12px;
}
.site-nav { display: flex; gap: 4px; flex: 1; }
.site-nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-size: 14px; }
.site-nav a:hover { color: var(--text); background: var(--panel-2); }
.site-nav a.on { color: var(--text); background: var(--accent-soft); }
.userchip { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.userchip-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { border-radius: 50%; background: var(--panel-2); }
.avatar-lg { width: 56px; height: 56px; }
.linklike {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 12px; padding: 4px; text-decoration: underline;
}
.linklike:hover { color: var(--text); }
.site-footer {
  border-top: 1px solid var(--line); color: var(--muted);
  text-align: center; font-size: 12px; padding: 24px 16px 40px;
}

/* ============ フラッシュメッセージ ============ */
.flash {
  position: sticky; top: 52px; z-index: 9;
  margin: 12px auto 0; max-width: 720px;
  background: var(--accent-soft); border: 1px solid var(--accent);
  color: var(--text); border-radius: var(--radius);
  padding: 10px 16px; font-size: 14px;
  transition: opacity 0.5s;
}

/* ============ ページ共通 ============ */
.page-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin: 8px 0 20px; }
.page-head h1 { flex: 1; }
.section-title { margin: 28px 0 12px; }
.section-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 28px; }
.section-head .section-title { margin: 0; flex: 1; }
.section-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.empty { color: var(--muted); padding: 32px 0; text-align: center; }
.hint { color: var(--muted); font-size: 13px; }

/* ============ ボタン・バッジ ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 18px; border-radius: 10px; border: 1px solid transparent;
  font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; font-weight: 500; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-discord { background: var(--discord); color: #fff; }
.btn-discord:hover { filter: brightness(1.1); }
.btn-ghost { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--muted); }
.btn-danger { background: transparent; color: var(--err); border-color: rgba(248, 113, 113, 0.4); }
.btn-danger:hover { background: rgba(248, 113, 113, 0.1); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; vertical-align: middle;
}
.badge-ok { background: rgba(52, 211, 153, 0.15); color: var(--ok); }
.badge-warn { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.badge-err { background: rgba(248, 113, 113, 0.15); color: var(--err); }
.badge-muted { background: var(--panel-2); color: var(--muted); }
.badge-role { background: rgba(88, 101, 242, 0.18); color: #a5b0ff; }
.badge-perk { background: rgba(139, 92, 246, 0.18); color: #c4b5fd; }
.badge-task { background: rgba(56, 189, 248, 0.15); color: #7dd3fc; }

.warn-box {
  background: rgba(251, 191, 36, 0.08); border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: var(--radius); padding: 12px 16px; font-size: 13.5px; margin: 12px 0;
}
.warn-box ul { margin: 6px 0 0; padding-left: 18px; }

/* ============ 動画グリッド ============ */
.search { display: flex; gap: 8px; }
.search input { min-width: 220px; }
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}
.grid-small { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; transition: transform 0.15s, border-color 0.15s;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); }
.thumb { position: relative; aspect-ratio: 16 / 9; background: #000; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 20px; background: rgba(0, 0, 0, 0.25); opacity: 0; transition: opacity 0.15s;
}
.card:hover .thumb-play { opacity: 1; }
.card-body { padding: 10px 12px 12px; }
.card-title {
  font-size: 14px; font-weight: 600; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ============ 視聴ページ ============ */
.watch { max-width: 860px; margin: 0 auto; }
.player-wrap {
  aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--line);
}
.player-wrap iframe, .player-wrap #player { width: 100%; height: 100%; display: block; }
.watch-title { margin-top: 16px; font-size: 20px; }
.watch-note { color: var(--muted); white-space: pre-wrap; }
.back { color: var(--muted); font-size: 13.5px; display: inline-block; margin-top: 8px; }
.back:hover { color: var(--text); }

/* ---- 課題カード ---- */
.assignment {
  margin: 18px 0 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.assignment-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.assignment-text { white-space: pre-wrap; margin: 10px 0 12px; }
.assignment-form {
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line);
}
.check-inline {
  display: flex; align-items: center; gap: 8px;
  color: var(--text); font-size: 14px; margin: 0; cursor: pointer;
}
.check-inline input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

/* ============ ログイン・案内 ============ */
.hero { display: flex; justify-content: center; padding: 48px 0; }
.hero-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 40px 36px; max-width: 460px; width: 100%; text-align: center;
}
.hero-logo {
  width: 64px; height: 64px; border-radius: 18px; background: var(--accent);
  color: #fff; font-size: 24px; display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.hero-sub { color: var(--muted); font-size: 14px; margin: 12px 0 24px; }
.hero-note { color: var(--muted); font-size: 12.5px; margin-top: 20px; }
.dev-login { margin-top: 16px; }

/* ============ マイページ ============ */
.profile { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.profile-name { font-size: 17px; font-weight: 700; }
.profile-sub { color: var(--muted); font-size: 13px; }
.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-label { color: var(--muted); font-size: 12.5px; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat-sub { color: var(--muted); font-size: 12.5px; }

.perk-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.perk {
  background: var(--panel); border: 1px dashed var(--accent); border-radius: var(--radius);
  padding: 16px;
}
.perk-used, .perk-revoked { border-color: var(--line); opacity: 0.65; }
.perk-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.perk-desc { color: var(--muted); font-size: 13px; margin: 8px 0; }
.perk-code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 22px; letter-spacing: 2px; text-align: center;
  background: var(--panel-2); border-radius: 8px; padding: 10px; margin: 10px 0;
}
.perk-meta { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.perk-error { color: var(--err); font-size: 12.5px; }

/* ============ フォーム ============ */
input[type="text"], input[type="search"], input[type="number"], select, textarea {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); padding: 8px 12px; font-size: 14px; font-family: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label input, label select, label textarea { margin-top: 4px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13.5px; }
label.check input { width: auto; margin: 0; }
.form-row { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.form-row input, .form-row select { width: auto; min-width: 180px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 20px 20px; margin-bottom: 8px;
}
.panel .section-title { margin-top: 4px; }
.reward-form button[type="submit"] { margin-top: 6px; }

/* ============ テーブル ============ */
.tablewrap {
  overflow-x: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius);
}
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; white-space: nowrap; }
.row-muted { opacity: 0.55; }
.cell-user { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cell-sub { color: var(--muted); font-size: 12px; }
.cell-sub a { text-decoration: underline; }
.cell-thumb img { border-radius: 6px; display: block; }
.cell-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.cell-actions form { display: inline; }

.w-bar { width: 140px; min-width: 100px; }
.bar { background: var(--panel-2); border-radius: 999px; height: 8px; overflow: hidden; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #c084fc); border-radius: 999px; }

/* ============ 管理タブ ============ */
.admin-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.admin-tabs a { padding: 8px 14px; color: var(--muted); font-size: 14px; border-bottom: 2px solid transparent; }
.admin-tabs a:hover { color: var(--text); }
.admin-tabs a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.period-tabs { display: inline-flex; background: var(--panel-2); border-radius: 8px; padding: 3px; gap: 2px; }
.period-tabs a { padding: 4px 10px; border-radius: 6px; font-size: 12.5px; color: var(--muted); }
.period-tabs a.on { background: var(--accent); color: #fff; }

.edit-details { display: inline-block; }
.edit-details summary { list-style: none; display: inline-flex; }
.edit-details summary::-webkit-details-marker { display: none; }
.edit-details[open] { display: block; width: 100%; }
.edit-form {
  margin-top: 10px; padding: 12px; background: var(--panel-2);
  border-radius: 8px; max-width: 420px;
}

/* ============ モバイル ============ */
@media (max-width: 640px) {
  .site-header { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .site-nav { order: 3; width: 100%; }
  .userchip-name { max-width: 90px; }
  .container { padding: 16px 12px 48px; }
  .hero-card { padding: 28px 20px; }
}
