:root {
  --bg: #f4f5fb;
  --card: #ffffff;
  --ink: #1a1c2e;
  --muted: #6b6f86;
  --brand: #4f46e5;
  --brand-ink: #ffffff;
  --line: #e7e8f2;
  --accent: #eef0fe;
  --danger: #b42318;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(30, 32, 60, 0.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101018;
    --card: #1a1b28;
    --ink: #edeef6;
    --muted: #9a9db5;
    --brand: #8a86f2;
    --brand-ink: #12121c;
    --line: #2a2c3d;
    --accent: #24263a;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
}

.offline {
  background: #fff4e5;
  color: #7a4b00;
  text-align: center;
  font-size: 13px;
  padding: 8px;
  border-radius: 10px;
  margin: 10px 0 0;
}

/* ---- Hero ---- */
.hero {
  padding: calc(18px + env(safe-area-inset-top)) 0 14px;
}
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hero h1 { font-size: 20px; margin: 0; letter-spacing: .02em; }
.dateline { font-size: 28px; font-weight: 700; margin: 10px 0 16px; }
.dateline .wd { color: var(--brand); }

.speak {
  border: none;
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 700;
  font-size: 15px;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .08s ease, opacity .2s;
}
.speak:active { transform: scale(0.96); }
.speak.speaking { opacity: .6; }

/* ---- Main tabs（時間割/試験対策）---- */
.maintabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--accent);
  padding: 5px;
  border-radius: 14px;
  margin-bottom: 12px;
}
.mtab {
  border: none; background: transparent; color: var(--muted);
  font-weight: 700; font-size: 15px; padding: 9px 0;
  border-radius: 10px; cursor: pointer;
}
.mtab[aria-selected="true"] {
  background: var(--card); color: var(--brand); box-shadow: var(--shadow);
}
.dateline[hidden], .speak[hidden] { display: none; }

/* ---- 試験対策 ---- */
.exam-lead { margin: 0 0 4px; }
#examList { display: flex; flex-direction: column; gap: 10px; }
.exam-badge { font-size: 20px; }

/* ---- Year selector ---- */
.years {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: var(--accent);
  padding: 5px;
  border-radius: 14px;
}
.year {
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 15px;
  padding: 9px 0;
  border-radius: 10px;
  cursor: pointer;
}
.year[aria-selected="true"] {
  background: var(--card);
  color: var(--brand);
  box-shadow: var(--shadow);
}

/* ---- Content ---- */
.content { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.content[hidden] { display: none; }

.period {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 14px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.badge {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  background: var(--accent);
  color: var(--brand);
  border-radius: 12px;
  font-weight: 800;
  line-height: 1;
}
.badge small { display: block; font-size: 9px; font-weight: 600; opacity: .8; }
.badge b { font-size: 20px; }
.pmeta .subject { font-weight: 700; font-size: 17px; }
.pmeta .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.pmeta .sub span + span::before { content: "・"; margin: 0 2px; }

.notice {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 20px;
  text-align: center;
}
.notice .big { font-size: 40px; }
.notice .msg { font-weight: 700; font-size: 18px; margin-top: 8px; }
.notice.error .msg { color: var(--danger); }

.skeleton {
  height: 74px;
  border-radius: var(--radius);
  background: linear-gradient(100deg, var(--card) 30%, var(--accent) 50%, var(--card) 70%);
  background-size: 200% 100%;
  animation: sk 1.2s infinite;
}
@keyframes sk { to { background-position: -200% 0; } }

/* ---- Footer ---- */
.foot { display: flex; justify-content: center; gap: 20px; margin-top: 22px; }
.link {
  border: none; background: none; color: var(--muted);
  font-size: 14px; cursor: pointer; padding: 6px;
}
.link:active { color: var(--brand); }

/* ---- Dialog ---- */
.dialog {
  border: none; border-radius: var(--radius); padding: 20px;
  width: min(92vw, 420px); background: var(--card); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.dialog::backdrop { background: rgba(10,10,20,.5); }
.dialog h2 { margin: 0 0 4px; font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; }
.dialog textarea {
  width: 100%; margin: 12px 0; padding: 10px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font: inherit; resize: vertical;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.btn {
  border: none; background: var(--brand); color: var(--brand-ink);
  font-weight: 700; padding: 10px 18px; border-radius: 12px; cursor: pointer;
}
.btn.ghost { background: var(--accent); color: var(--ink); }

/* ---- Tappable period cards ---- */
.period.tappable {
  width: 100%; text-align: left; cursor: pointer; font: inherit; color: inherit;
  grid-template-columns: 46px 1fr auto;
}
.period.tappable:active { transform: scale(0.99); }
.pnote {
  display: flex; align-items: center; gap: 3px;
  color: var(--muted); font-size: 12px; opacity: .5;
}
.period.has-notes .pnote { opacity: 1; color: var(--brand); font-weight: 700; }
.pnote-c:empty { display: none; }

/* ---- Notes dialog ---- */
.notes-dialog { width: min(94vw, 480px); max-height: 88vh; }
.notes-dialog[open] { display: flex; flex-direction: column; }
.notes-head { display: flex; align-items: center; justify-content: space-between; }
.notes-head h2 { margin: 0; font-size: 18px; }
.notes-list { flex: 1; overflow-y: auto; margin: 10px 0; display: flex; flex-direction: column; gap: 10px; }
.note { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.note-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.note-meta b { color: var(--brand); }
.note-del { margin-left: auto; color: var(--danger) !important; font-size: 12px; }
.note-text { white-space: pre-wrap; word-break: break-word; }
.note-img { margin-top: 8px; max-width: 100%; max-height: 200px; border-radius: 10px; cursor: zoom-in; display: block; }

.note-form { border-top: 1px solid var(--line); padding-top: 10px; }
.note-form textarea {
  width: 100%; padding: 10px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit; resize: vertical;
}
.note-form-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.filebtn {
  background: var(--accent); color: var(--ink); padding: 8px 12px; border-radius: 10px;
  font-size: 14px; cursor: pointer; white-space: nowrap;
}
.note-form-row .btn { margin-left: auto; }
.note-preview { margin-top: 8px; max-width: 100%; max-height: 160px; border-radius: 10px; }
.note-preview:not([hidden]) { display: block; }

.img-dialog { width: min(96vw, 700px); }
.img-dialog img { max-width: 100%; max-height: 78vh; border-radius: 10px; display: block; margin: 0 auto; }

.dialog input[type="text"] {
  width: 100%; margin: 8px 0; padding: 10px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit;
}
