:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7785;
  --line: #d9dee5;
  --gold: #c9b77a;
  --accent: #2f7f6e;
  --danger: #c62828;
  --danger-soft: #fdecea;
  --ok: #2e7d32;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text); line-height: 1.6;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif;
}
body.detail-open { overflow: hidden; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 6px 0 0; }

/* ---- ヘッダー ---- */
.site-header, main, .site-footer { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.site-header { padding-top: 16px; }
.head-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: flex-end; }
.site-header h1 { margin: 0; font-size: 1.4rem; letter-spacing: 0.04em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }
.notice { margin: 10px 0 0; padding: 8px 12px; border-radius: 8px; background: #fff8e1; border: 1px solid #ffe082; font-size: 0.88rem; }
.notice.error { background: var(--danger-soft); border-color: #f5b5ae; }
.year-switch { display: flex; align-items: center; gap: 8px; }
.year-label { font-size: 0.85rem; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--gold); border-radius: 999px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 6px 14px; cursor: pointer; font: inherit; }
.seg button + button { border-left: 1px solid var(--gold); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.seg .count { display: inline-block; margin-left: 6px; min-width: 1.5em; padding: 0 5px; border-radius: 999px; background: rgba(0,0,0,.12); font-size: 0.75rem; }
.nav { display: flex; gap: 4px; margin: 14px 0 0; border-bottom: 1px solid var(--line); }
.nav a { padding: 8px 16px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; }
.nav a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.site-footer { color: var(--muted); font-size: 0.8rem; padding-top: 24px; padding-bottom: 24px; }
.view { padding-top: 16px; }

/* ---- フォーム部品 ---- */
input, select, button { font: inherit; }
input[type="search"], input[type="number"], select { padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-width: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 0.9rem; }
.btn { padding: 8px 16px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.link-btn { background: none; border: 0; color: var(--danger); cursor: pointer; padding: 2px 6px; }
.actions { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.warn { display: block; color: var(--danger); font-size: 0.85rem; }

/* ---- 科目一覧（カード） ---- */
.filters { display: grid; grid-template-columns: 2fr 1.4fr auto; gap: 8px; align-items: center; margin-bottom: 8px; }
@media (max-width: 700px) { .filters { grid-template-columns: 1fr; } }
.group-title {
  display: flex; align-items: center; gap: 10px; margin: 26px 0 12px; font-size: 1.05rem; color: var(--c);
}
.group-title::before, .group-title::after { content: ""; height: 1px; background: var(--gold); flex: 0 0 24px; }
.group-title::after { flex: 1; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px 14px; }
.card { display: flex; flex-direction: column; align-items: center; gap: 6px; text-decoration: none; }
.portrait {
  position: relative; width: 100%; aspect-ratio: 1 / 1; padding: 10px;
  border: 2px solid var(--gold); outline: 1px solid var(--gold); outline-offset: 3px;
  background: linear-gradient(160deg, #fff 0%, color-mix(in srgb, var(--c) 18%, #fff) 100%);
  display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover .portrait, .card:focus-visible .portrait { transform: translateY(-3px); box-shadow: 0 6px 16px rgba(0,0,0,.12); }
.card.planned .portrait { background: linear-gradient(160deg, color-mix(in srgb, var(--c) 30%, #fff) 0%, var(--c) 100%); color: #fff; }
.p-subject { position: absolute; top: 8px; left: 10px; font-size: 0.7rem; color: var(--c); }
.card.planned .p-subject { color: #fff; }
.p-name { font-size: 1.15rem; font-weight: 700; line-height: 1.3; color: var(--c); word-break: break-all; }
.p-name.long { font-size: 0.95rem; }
.card.planned .p-name { color: #fff; }
.p-meta { position: absolute; bottom: 8px; font-size: 0.75rem; opacity: 0.85; }
.p-years { position: absolute; top: 6px; right: 8px; font-size: 0.7rem; background: rgba(255,255,255,.9); color: var(--c); border-radius: 999px; padding: 0 7px; }
.card-name { color: var(--c); letter-spacing: 0.12em; font-size: 0.9rem; text-align: center; }
.card-teacher { color: var(--muted); font-size: 0.75rem; margin-top: -4px; }

/* ---- 詳細ページ ---- */
.detail { position: fixed; inset: 0; z-index: 50; overflow-y: auto; background: var(--bg); }
.detail-top {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.95); border-bottom: 1px solid var(--line); padding: 8px 12px;
}
.strip { display: flex; gap: 10px; overflow-x: auto; flex: 1; padding: 2px; scrollbar-width: thin; }
.chip { display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; flex: 0 0 auto; width: 62px; }
.chip .dot {
  width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--gold);
  display: grid; place-items: center; font-size: 0.8rem; font-weight: 700; color: var(--c); background: #fff;
}
.chip.current .dot { background: var(--c); color: #fff; box-shadow: 0 0 0 3px #fff, 0 0 0 4px var(--gold); }
.chip-name { font-size: 0.65rem; color: var(--muted); max-width: 62px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.close { flex: 0 0 auto; padding: 10px 14px; background: var(--c); color: #fff; text-decoration: none; border-radius: 6px; font-size: 0.85rem; }
.detail-body { max-width: 1000px; margin: 0 auto; padding: 0 16px 40px; }
.hero {
  margin: 0 -16px; padding: 28px 24px; display: grid; grid-template-columns: 220px 1fr; gap: 28px; align-items: center;
  background: linear-gradient(180deg, var(--bg) 0 30%, var(--c) 30% 100%); color: #fff;
}
@media (max-width: 700px) { .hero { grid-template-columns: 1fr; background: linear-gradient(180deg, var(--bg) 0 18%, var(--c) 18% 100%); } }
.hero-portrait, .hero-img {
  width: 220px; height: 220px; margin: 0 auto; border-radius: 50%; border: 3px solid var(--gold);
  box-shadow: 0 0 0 6px var(--c), 0 0 0 7px var(--gold); background: #fff; object-fit: cover;
  display: grid; place-items: center; padding: 20px; text-align: center;
}
.hero-portrait span { color: var(--c); font-size: 1.6rem; font-weight: 700; line-height: 1.3; word-break: break-all; }
.hero-text { align-self: end; }
.hero-subject { margin: 0; opacity: .85; font-size: 0.85rem; }
.hero-name { margin: 4px 0; font-size: 2.1rem; letter-spacing: 0.1em; font-weight: 600; }
.hero-teacher { margin: 0 0 10px; font-size: 1.1rem; letter-spacing: 0.05em; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; }
.pill { border: 1px solid rgba(255,255,255,.7); border-radius: 999px; padding: 1px 10px; font-size: 0.8rem; }
.divider { position: relative; height: 1px; background: var(--gold); margin: 22px 0; }
.divider::after { content: ""; position: absolute; left: 50%; top: -5px; width: 10px; height: 10px; background: var(--gold); transform: translateX(-50%) rotate(45deg); }
.detail-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 800px) { .detail-cols { grid-template-columns: 1fr; } }
dl.info { display: grid; grid-template-columns: 7.5em 1fr; gap: 8px 12px; margin: 0; }
dl.info dt { color: var(--muted); font-size: 0.88rem; }
dl.info dd { margin: 0; white-space: pre-wrap; letter-spacing: 0.03em; }
.pick { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.pick h3 { margin: 0; font-size: 1rem; color: var(--c); }
.pick-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.small-seg button { padding: 3px 10px; font-size: 0.8rem; }
.sec { display: grid; grid-template-columns: auto 1fr; gap: 0 8px; padding: 8px 10px; margin: 6px 0; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.sec.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 8%, #fff); }
.sec input { grid-row: span 3; margin-top: 5px; }
.sec-sub { color: var(--muted); font-size: 0.8rem; }
.credit-pick { display: block; margin-top: 10px; }
.mini { margin-top: 12px; display: grid; gap: 10px; }
.prevnext { display: flex; justify-content: space-between; margin-top: 28px; }
.prevnext a { color: var(--c); text-decoration: none; }

/* ---- 時間割（画面） ---- */
.view-title { font-size: 1.1rem; margin: 8px 0 10px; }
.tt-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .tt-pair { grid-template-columns: 1fr; } }
.tt-block { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
table.timetable { width: 100%; border-collapse: collapse; table-layout: fixed; background: #fff; }
.timetable th, .timetable td { border: 1px solid var(--line); padding: 3px; text-align: center; font-size: 0.78rem; }
.timetable th { background: #f1f3f6; }
.timetable th.period { width: 3.2em; }
.timetable td { height: 3em; word-break: break-all; }
.timetable td.blocked { background: repeating-linear-gradient(45deg, #eee 0 6px, #f8f8f8 6px 12px); }
.timetable td.fixed { background: #f3f0e4; color: var(--muted); }
.timetable td.preview { outline: 2px dashed var(--accent); outline-offset: -3px; background: #e7f3ef; }
.timetable td.conflict { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.timetable td.preview.conflict { outline-color: var(--danger); }
.checks { margin: 14px 0; }
.ck { margin: 4px 0; font-size: 0.9rem; }
.ck.err { color: var(--danger); }
.ck.warn-line { color: #8a6100; }
.ck.ok { color: var(--ok); }
.plan-table { width: 100%; border-collapse: collapse; background: #fff; font-size: 0.88rem; }
.plan-table th, .plan-table td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.plan-table .num { text-align: right; }
.totals { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 12px; }
.totals .strong { font-weight: 700; }
.err-text { color: var(--danger); font-weight: 600; }

/* ---- 帳票（画面プレビュー＋印刷） ---- */
.output-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.output-toolbar .hint { flex-basis: 100%; }
.sheet {
  background: #fff; color: #000; width: 210mm; max-width: 100%; margin: 0 auto 24px; padding: 10mm;
  box-shadow: 0 1px 6px rgba(0,0,0,.15); font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif; font-size: 10pt;
}
.f-title { display: flex; justify-content: space-between; align-items: baseline; }
.f-title h2 { margin: 0 0 4px; font-size: 15pt; }
.f-year { font-size: 11pt; border: 1px solid #000; padding: 0 8px; }
.f-head p { margin: 2px 0; }
.blank { display: inline-block; border-bottom: 1px solid #000; height: 1em; vertical-align: -2px; }
table.f-id { border-collapse: collapse; margin: 4px 0 8px; width: 99.5%; }
.f-id th, .f-id td { border: 1px solid #000; padding: 3px 6px; font-weight: normal; }
.f-id th { width: 5.5em; background: #eee; white-space: nowrap; }
table.f-tt { width: 99.5%; border-collapse: collapse; table-layout: fixed; margin: 8px 0; }
.f-tt th, .f-tt td { border: 1px solid #000; padding: 1px 3px; text-align: center; font-size: 8.5pt; height: 6.2mm; overflow: hidden; }
.f-tt thead th { background: #ddd; }
.f-tt .f-term { background: #222; color: #fff; width: 22mm; }
.f-tt .f-period { width: 8mm; }
.f-tt .f-kind { width: 14mm; font-weight: normal; }
.f-tt .r-abbr td { border-top: 1px dotted #888; }
.f-tt td.x { background: linear-gradient(to top right, transparent calc(50% - .6px), #000 50%, transparent calc(50% + .6px)), linear-gradient(to bottom right, transparent calc(50% - .6px), #000 50%, transparent calc(50% + .6px)); }
.f-tt td.dup { background: #ffd9d9; }
.f-tt .f-int-h { width: 24mm; }
.f-tt .f-int-empty { border: 0; }
.f-tt .f-credits { vertical-align: top; }
.f-credits-label { font-size: 8pt; font-weight: bold; border-bottom: 1px solid #000; }
.f-credits-val { font-size: 13pt; padding-top: 2px; }
.f-credits-val small { display: block; font-size: 7pt; }
.f-note { font-size: 8.5pt; margin: 4px 0; }
.f-checks h3 { font-size: 10pt; margin: 10px 0 4px; }
.f-checks ul { margin: 0; padding-left: 1em; list-style: none; font-size: 8.5pt; }
.f-checks li.err { color: #b00000; }
.p-flow { column-count: 4; column-gap: 4mm; margin-top: 6px; }
@media (max-width: 700px) { .p-flow { column-count: 1; } }
table.p-group { width: 99%; border-collapse: collapse; break-inside: avoid; margin-bottom: 2mm; font-size: 7pt; }
.p-group th, .p-group td { border: 1px solid #000; padding: 0 2px; line-height: 1.3; }
.p-group .p-gname { background: #ddd; text-align: left; padding-left: 4px; }
.p-group .p-mark { width: 3.5mm; text-align: center; }
.p-group .p-num { width: 5mm; text-align: center; }
.p-group .pg-name { letter-spacing: -0.03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 0; width: 100%; }
.p-group .p-val { font-weight: bold; }
.p-group tr.filled .pg-name { background: #f2f2f2; }
.p-foot { display: flex; flex-wrap: wrap; gap: 6mm; align-items: flex-start; margin-top: 4px; }
.p-sum { border-collapse: collapse; }
.p-sum th, .p-sum td { border: 1px solid #000; padding: 2px 8px; font-size: 9pt; text-align: center; font-weight: normal; }
.p-sum.big th { text-align: left; }
.p-sum.big td { min-width: 18mm; font-size: 12pt; font-weight: bold; }

@media print {
  @page { size: A4 portrait; margin: 8mm; }
  body { background: #fff; }
  .no-print, .output-toolbar { display: none !important; }
  main { max-width: none; padding: 0; }
  #view-output { display: block !important; padding: 0; }
  .sheet { box-shadow: none; margin: 0; padding: 0; width: auto; }
  body[data-print="timetable"] .sheet-plan, body[data-print="plan"] .sheet-timetable { display: none; }
  body:not([data-print]) .sheet + .sheet { break-before: page; }
  .p-group tr.filled .pg-name { background: #eee; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .f-tt thead th, .f-tt .f-term, .f-id th, .p-group .p-gname { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 600px) {
  .nav a { white-space: nowrap; padding: 8px 10px; font-size: 0.9rem; }
  .cards { grid-template-columns: repeat(3, 1fr); gap: 14px 8px; }
  .portrait { padding: 6px; outline-offset: 2px; }
  .p-name { font-size: 0.85rem; }
  .p-name.long { font-size: 0.72rem; }
  .p-subject, .p-years { display: none; }
  .p-meta { font-size: 0.65rem; bottom: 4px; }
  .card-name { font-size: 0.72rem; letter-spacing: 0.04em; }
  .hero-portrait, .hero-img { width: 150px; height: 150px; }
  .hero-portrait span { font-size: 1.1rem; }
  .hero-name { font-size: 1.6rem; }
}
.btn.secondary { background: #fff; color: var(--accent); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
