:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e3e6ee;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --today: #fff6d6;
  --selected: #2563eb;
  --sun: #d93636;
  --sat: #2563eb;
  --error-bg: #fdecec;
  --error-text: #9b1c1c;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141a;
    --surface: #1c1f27;
    --text: #e8eaf0;
    --muted: #9aa1b0;
    --border: #2e3340;
    --accent: #5b8cff;
    --today: #3a3420;
    --selected: #5b8cff;
    --sun: #ff7a7a;
    --sat: #7ea6ff;
    --error-bg: #3a1d1d;
    --error-text: #ffb4b4;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0; line-height: 1.3; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }

a { color: var(--accent); }

button, select { font: inherit; color: inherit; }

.wrap { width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* ---- header ---- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; }
.site-header h1 { font-size: 1.15rem; }
.class-picker { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.class-picker label { font-weight: 600; font-size: .9rem; }
.class-picker select {
  min-width: 12em;
  max-width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

/* ---- buttons ---- */
.btn-ghost, .btn-icon {
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 12px;
}
.btn-ghost { font-size: .85rem; }
.btn-icon { width: 40px; height: 40px; padding: 0; font-size: 1.4rem; line-height: 1; }
button:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- layout ---- */
main { padding-top: 16px; padding-bottom: 16px; }
.layout { display: grid; gap: 16px; }
.main-col, .side-col { display: grid; gap: 16px; align-content: start; min-width: 0; }
@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr) 340px; }
}
/* スマホでは「次回の授業」を先に */
@media (max-width: 959px) {
  .side-col { order: -1; }
  #access { order: 10; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.card > h2, .card > h3 { margin-bottom: 12px; }

.loading { color: var(--muted); }
.error { background: var(--error-bg); color: var(--error-text); padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; }
.hint { color: var(--muted); font-size: .8rem; margin: 10px 0 0; }

/* ---- calendar ---- */
.calendar-card { padding: 12px; }
.cal-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-nav h2 { flex: 1; text-align: center; font-size: 1.2rem; }

.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.cal-head { text-align: center; font-size: .8rem; font-weight: 600; color: var(--muted); padding: 4px 0; }
.cal-head.sun, .cal-day.sun .day-num { color: var(--sun); }
.cal-head.sat, .cal-day.sat .day-num { color: var(--sat); }

.cal-day {
  min-height: 52px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  text-align: left;
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
}
.cal-day.empty { border-color: transparent; background: transparent; cursor: default; }
.cal-day.is-today { background: var(--today); }
.cal-day.is-selected { border: 2px solid var(--selected); padding: 3px; }
.day-num { font-size: .85rem; font-weight: 600; }
.cal-day.is-today .day-num::after { content: "今日"; font-size: .6rem; margin-left: 3px; color: var(--muted); font-weight: 400; }

.chips { display: none; flex-direction: column; gap: 2px; }
.chip {
  display: block;
  background: var(--c);
  color: #fff;
  font-size: .7rem;
  border-radius: 4px;
  padding: 1px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip.is-cancelled { opacity: .45; text-decoration: line-through; }
.chip.is-tentative, .dot.is-tentative { opacity: .4; }
.chip.is-tentative.is-cancelled { opacity: .25; }

.dots { display: flex; flex-wrap: wrap; gap: 3px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.dot.is-cancelled { opacity: .35; }

@media (min-width: 640px) {
  .cal-day { min-height: 84px; }
  .chips { display: flex; }
  .dots { display: none; }
}

/* ---- lesson list ---- */
.lesson-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.lesson {
  border-left: 5px solid var(--c);
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 12px;
  display: grid;
  gap: 2px;
}
.lesson-time { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.lesson-date { font-weight: 600; color: var(--text); margin-right: 6px; }
.lesson-class { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.lesson-name { font-weight: 700; overflow-wrap: anywhere; }
.lesson.is-cancelled .lesson-name, .lesson.is-cancelled .lesson-time { text-decoration: line-through; opacity: .6; }
.badge { background: var(--error-bg); color: var(--error-text); font-size: .72rem; font-weight: 700; padding: 1px 6px; border-radius: 999px; }
.badge-tentative { background: var(--border); color: var(--muted); }
.lesson.is-tentative { opacity: .55; }
/* 固定ヘッダーに隠れないように */
.day-card { scroll-margin-top: 72px; }
.lesson-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: .85rem; align-items: center; }
.lesson-note { color: var(--muted); }
.lesson-actions { font-size: .82rem; margin-top: 2px; }
.map-link { white-space: nowrap; font-weight: 600; }
.empty-msg { color: var(--muted); font-size: .9rem; }

/* ---- access ---- */
.access-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.access-item { display: grid; gap: 2px; }
.access-address { font-size: .88rem; color: var(--muted); overflow-wrap: anywhere; }

/* ---- footer ---- */
.site-footer { color: var(--muted); font-size: .8rem; padding-bottom: 24px; }
