:root {
  --bg: #0b1020;
  --bg-2: #111831;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.09);
  --text: #e8ecf8;
  --muted: #94a0c0;
  --primary: hsl(248, 90%, 68%);
  --primary-2: hsl(190, 85%, 55%);
  --grad: linear-gradient(135deg, hsl(248, 90%, 66%), hsl(200, 90%, 56%));
  --success: hsl(152, 60%, 50%);
  --warn: hsl(38, 95%, 60%);
  --danger: hsl(352, 85%, 63%);
  --radius: 16px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  --font: 'Noto Sans JP', system-ui, sans-serif;
  --font-en: 'Outfit', 'Noto Sans JP', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  background-image:
    radial-gradient(900px 500px at 0% -10%, hsla(248, 90%, 60%, 0.18), transparent 60%),
    radial-gradient(800px 500px at 110% 10%, hsla(190, 90%, 50%, 0.12), transparent 60%);
  background-attachment: fixed;
}
a { color: hsl(200, 90%, 70%); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.35; margin: 0 0 .6em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
.en { font-family: var(--font-en); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-wrap; word-break: break-word; }
.hidden { display: none !important; }

/* ---------- boot / spinner ---------- */
.boot { height: 100vh; display: grid; place-items: center; }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: rgba(10, 14, 30, 0.75); backdrop-filter: blur(16px);
  border-right: 1px solid var(--border); padding: 22px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 11px; background: var(--grad);
  display: grid; place-items: center; font-size: 20px; box-shadow: 0 6px 20px hsla(248, 90%, 60%, .4);
}
.brand-name { font-family: var(--font-en); font-weight: 700; font-size: 1.15rem; letter-spacing: .02em; }
.brand-sub { font-size: .7rem; color: var(--muted); margin-top: -3px; }
.nav-label { font-size: .72rem; color: var(--muted); padding: 14px 12px 4px; letter-spacing: .08em; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
  color: var(--text); font-size: .92rem; transition: background .15s, transform .15s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-link:hover { background: var(--surface-2); text-decoration: none; transform: translateX(2px); }
.nav-link.active { background: linear-gradient(90deg, hsla(248, 90%, 66%, .28), hsla(200, 90%, 56%, .08)); box-shadow: inset 3px 0 0 var(--primary); }
.nav-link .ico { width: 20px; text-align: center; flex-shrink: 0; }
.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--grad); flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; font-size: .9rem;
}
.main { padding: 32px clamp(16px, 4vw, 48px) 60px; min-width: 0; animation: fadeUp .3s ease; }
.topbar { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; width: 270px; left: -280px; transition: left .25s; }
  .sidebar.open { left: 0; box-shadow: var(--shadow); }
  .topbar {
    display: flex; align-items: center; gap: 12px; padding: 12px 16px; position: sticky; top: 0; z-index: 40;
    background: rgba(10, 14, 30, .85); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
  }
  .main { padding-top: 20px; }
}

/* ---------- components ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { margin: 0; }
.crumb { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; backdrop-filter: blur(10px); animation: fadeUp .3s ease both;
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

.course-card {
  position: relative; overflow: hidden; cursor: pointer; transition: transform .2s, border-color .2s, box-shadow .2s;
  color: var(--text); display: block;
}
.course-card:hover { transform: translateY(-3px); border-color: hsla(248, 90%, 70%, .5); box-shadow: var(--shadow); text-decoration: none; }
.course-card::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--grad);
}
.course-card .code { font-family: var(--font-en); font-size: .78rem; color: var(--muted); }
.course-card h3 { margin: 4px 0 8px; font-size: 1.05rem; }

.stat { display: flex; flex-direction: column; }
.stat .num { font-family: var(--font-en); font-size: 1.8rem; font-weight: 700; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 500; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap;
}
.badge.primary { background: hsla(248, 90%, 66%, .18); border-color: hsla(248, 90%, 66%, .35); color: hsl(248, 100%, 85%); }
.badge.success { background: hsla(152, 60%, 50%, .15); border-color: hsla(152, 60%, 50%, .35); color: hsl(152, 70%, 70%); }
.badge.warn { background: hsla(38, 95%, 60%, .15); border-color: hsla(38, 95%, 60%, .35); color: hsl(38, 100%, 72%); }
.badge.danger { background: hsla(352, 85%, 63%, .15); border-color: hsla(352, 85%, 63%, .35); color: hsl(352, 100%, 78%); }

.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--grad); border-radius: 99px; transition: width .6s ease; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; }
.tab {
  padding: 10px 16px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-size: .92rem;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: 10px; border: 1px solid var(--border); cursor: pointer;
  background: var(--surface-2); color: var(--text); font: inherit; font-size: .9rem; font-weight: 500;
  transition: transform .12s, box-shadow .2s, background .2s, opacity .2s; text-decoration: none !important; white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, .12); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--grad); border: none; color: #fff; box-shadow: 0 6px 20px hsla(248, 90%, 60%, .35); }
.btn.primary:hover { box-shadow: 0 8px 28px hsla(248, 90%, 60%, .5); }
.btn.danger { background: hsla(352, 85%, 63%, .15); border-color: hsla(352, 85%, 63%, .4); color: hsl(352, 100%, 80%); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 12px; font-size: .82rem; border-radius: 8px; }
.btn.block { width: 100%; }
.icon-btn { background: none; border: none; color: var(--text); font-size: 1.3rem; cursor: pointer; padding: 4px 8px; }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: .85rem; color: var(--muted); font-weight: 500; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 14px; }
input, select, textarea {
  font: inherit; color: var(--text); background: rgba(0, 0, 0, .25); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px; width: 100%; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px hsla(248, 90%, 66%, .25); }
textarea { resize: vertical; min-height: 90px; }
select option { background: var(--bg-2); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--primary); }
input[type=file] { padding: 7px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* table */
.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: rgba(255, 255, 255, .03); color: var(--muted); font-weight: 500; font-size: .8rem; position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255, 255, 255, .025); }
td.num, th.num { text-align: right; font-family: var(--font-en); }
td.wrap { white-space: normal; min-width: 200px; }

/* list */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.list-item .ico {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0;
  background: var(--surface-2); font-size: 1.1rem;
}
.list-item .body { flex: 1; min-width: 0; }
.list-item .title { font-weight: 500; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty .big { font-size: 2.2rem; display: block; margin-bottom: 6px; }

/* lessons */
.lesson { padding: 0; overflow: hidden; }
.lesson-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; cursor: pointer; user-select: none; }
.lesson-head:hover { background: rgba(255, 255, 255, .02); }
.lesson-no {
  font-family: var(--font-en); font-weight: 700; font-size: .85rem; min-width: 44px; height: 30px; padding: 0 8px; border-radius: 8px;
  display: grid; place-items: center; background: hsla(248, 90%, 66%, .18); color: hsl(248, 100%, 85%);
}
.lesson-body { padding: 0 20px 16px; border-top: 1px solid var(--border); }
.lesson.collapsed .lesson-body { display: none; }
.chev { transition: transform .2s; color: var(--muted); }
.lesson.collapsed .chev { transform: rotate(-90deg); }
.viewer { margin-top: 10px; border-radius: 12px; overflow: hidden; background: #000; }
.viewer video, .viewer iframe { width: 100%; aspect-ratio: 16/9; display: block; border: 0; }
.viewer iframe.pdf { aspect-ratio: auto; height: 75vh; background: #fff; }
.text-material { background: rgba(0, 0, 0, .2); padding: 14px; border-radius: 10px; margin-top: 10px; }

/* quiz */
.question { margin-bottom: 16px; }
.question .qno { font-family: var(--font-en); font-weight: 700; color: var(--primary-2); }
.choice {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-top: 8px; border-radius: 10px;
  border: 1px solid var(--border); background: rgba(0, 0, 0, .15); cursor: pointer; transition: border-color .15s, background .15s;
}
.choice:hover { border-color: hsla(248, 90%, 70%, .5); }
.choice:has(input:checked) { border-color: var(--primary); background: hsla(248, 90%, 66%, .14); }
.choice.correct { border-color: var(--success); background: hsla(152, 60%, 50%, .12); }
.choice.wrong { border-color: var(--danger); background: hsla(352, 85%, 63%, .12); }
.timer {
  position: sticky; top: 12px; z-index: 5; float: right; font-family: var(--font-en); font-weight: 700; font-size: 1.1rem;
  padding: 8px 16px; border-radius: 12px; background: rgba(10, 14, 30, .85); border: 1px solid var(--border); backdrop-filter: blur(10px);
}
.timer.low { color: var(--danger); border-color: var(--danger); }
.score-big { font-family: var(--font-en); font-size: 3rem; font-weight: 700; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; line-height: 1.1; }
.qedit { border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 14px; background: rgba(0, 0, 0, .15); }
.choice-edit { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }

/* attendance */
.att-select { width: auto; padding: 4px 6px; font-size: .82rem; border-radius: 6px; }
.att-present { color: var(--success); }
.att-late { color: var(--warn); }
.att-absent { color: var(--danger); }
.att-excused { color: var(--muted); }
.code-display { font-family: var(--font-en); font-size: 2.6rem; font-weight: 700; letter-spacing: .3em; text-align: center; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.qr-stage { display: flex; align-items: center; justify-content: center; gap: 28px; flex-wrap: wrap; padding: 8px 0; }
.qr-box { background: #fff; padding: 12px; border-radius: 16px; box-shadow: var(--shadow); line-height: 0; }
.qr-box svg { display: block; border-radius: 6px; }
.preview-frame { width: 100%; height: 420px; border: 1px solid var(--border); border-radius: 10px; background: #fff; margin: 10px 0 14px; }
.preview-img { max-width: 100%; max-height: 420px; border-radius: 10px; border: 1px solid var(--border); margin: 10px 0 14px; display: block; }

/* login */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero {
  position: relative; overflow: hidden; padding: 60px; display: flex; flex-direction: column; justify-content: flex-end;
  background:
    radial-gradient(600px 400px at 20% 20%, hsla(248, 90%, 60%, .55), transparent 60%),
    radial-gradient(500px 400px at 80% 70%, hsla(190, 90%, 50%, .4), transparent 60%),
    #0a0e1f;
}
.login-hero .orb { position: absolute; border-radius: 50%; filter: blur(2px); opacity: .5; animation: float 9s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-24px) scale(1.04); } }
.login-hero h1 { font-family: var(--font-en); font-size: clamp(2rem, 4vw, 3.2rem); margin-bottom: .2em; position: relative; }
.login-hero p { color: #c5cce6; max-width: 460px; position: relative; }
.login-features { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; position: relative; }
.login-panel { display: grid; place-items: center; padding: 40px 24px; }
.login-box { width: 100%; max-width: 380px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .8rem; margin: 18px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
@media (max-width: 900px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-hero { min-height: 240px; padding: 32px; }
}

/* modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(3, 6, 15, .65); backdrop-filter: blur(4px); z-index: 100;
  display: grid; place-items: center; padding: 20px; animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 18px; padding: 24px; box-shadow: var(--shadow); animation: fadeUp .2s ease;
}
.modal.wide { max-width: 860px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* toast */
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--border); box-shadow: var(--shadow);
  animation: fadeUp .2s ease; max-width: 360px; border-left: 4px solid var(--success);
}
.toast.error { border-left-color: var(--danger); }

.member-picker { max-height: 380px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; padding: 6px; }
.member-picker .check { padding: 5px 8px; border-radius: 6px; }
.member-picker .check:hover { background: var(--surface-2); }
