/* Homework ม.5/2: warm paper, emerald, brick red for quizzes and แจกใหม่. Light mode only. */
:root {
  --bg: #f7f0e4;
  --text: #1a1310;
  --muted: #58514b;
  --line: #e6dccb;
  --card: #fffbf4;
  --cardline: #dccdb6;
  --field: #8c8580;
  --white: #ffffff;
  --accent: #1a7558;
  --accent-soft: #e3efe9;
  --accent-deep: #124a38;
  --on-accent: #fffbf4;
  --link: #1a664d;
  --red: #a8432f;
  --serif: "Noto Serif Thai", Georgia, serif;
  --sans: "Sarabun", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.6;
}
a { color: var(--link); text-underline-offset: 3px; }
a:hover { color: var(--accent-deep); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.wrap { max-width: 600px; margin: 0 auto; padding: 0 20px 64px; }

/* ---------- header ---------- */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 26px 0 20px; }
.top h1 { margin: 0; font-family: var(--serif); font-size: 28px; line-height: 1.3; font-weight: 700; }
.top p { margin: 2px 0 0; font-size: 15px; color: var(--muted); }
.top a { font-size: 17px; font-weight: 600; padding: 4px 0; white-space: nowrap; }

h2.section-title { margin: 0 0 8px; font-family: var(--serif); font-size: 22px; line-height: 1.3; font-weight: 600; }

/* ---------- day circles (student tabs and admin date picker) ---------- */
.days { display: flex; align-items: center; justify-content: space-between; gap: 2px; }
.days-tabs { padding: 0 0 18px; border-bottom: 1px solid var(--line); }
.day {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-height: 62px; padding: 0; border: 0; background: transparent; cursor: pointer;
}
.day-abbr { font-size: 15px; color: var(--muted); }
.day-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 999px;
  font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.day.is-today .day-num { color: var(--link); box-shadow: inset 0 0 0 1.5px var(--link); }
.day[aria-pressed="true"] .day-num { background: var(--accent); color: var(--on-accent); box-shadow: none; }
.week-btn {
  flex: none; width: 36px; height: 44px; padding: 0; border: 0; background: transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ---------- timetable ---------- */
.timetable { padding: 24px 0 8px; }
.period {
  display: grid; grid-template-columns: 104px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.period-when { display: flex; flex-direction: column; line-height: 1.35; }
.period-when b { font-size: 16px; font-weight: 600; }
.period-when span { font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; }
.period-name { font-size: 19px; line-height: 1.35; overflow-wrap: anywhere; }
.period-name.is-free { color: var(--muted); }
.period-name.is-now { font-weight: 700; }
.period-name small { display: block; font-size: 14px; font-weight: 600; color: var(--link); }
.period-count { font-size: 16px; font-weight: 600; white-space: nowrap; }

/* ---------- select ---------- */
.select-wrap { position: relative; }
.select-wrap select {
  appearance: none; -webkit-appearance: none; width: 100%; min-height: 50px;
  padding: 10px 44px 10px 14px; border: 1px solid var(--field); border-radius: 8px;
  background: var(--white); font-size: 18px; cursor: pointer;
}
.select-wrap svg { position: absolute; right: 14px; top: 50%; margin-top: -9px; pointer-events: none; }

/* ---------- student work list ---------- */
.work { padding: 36px 0 0; scroll-margin-top: 12px; }
.field-label { display: block; font-size: 16px; color: var(--muted); margin-bottom: 4px; }
.work .select-wrap { margin-bottom: 20px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 16px; }
.pager-label { text-align: center; line-height: 1.35; min-width: 0; }
.pager-label b { display: block; font-size: 18px; }
.pager-label span { font-size: 15px; color: var(--muted); }
.pager-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; flex: none;
  border: 1px solid var(--field); border-radius: 8px; background: var(--card); cursor: pointer;
}
.pager-btn:disabled { opacity: 0.35; cursor: default; }

.groups { display: flex; flex-direction: column; gap: 16px; }
.date-head { margin: 8px 0 -4px; font-size: 17px; font-weight: 700; color: var(--muted); }
.subject-card { background: var(--card); border: 1px solid var(--cardline); border-radius: 12px; padding: 18px 18px 4px; }
.subject-card h3 { margin: 0; font-family: var(--serif); font-size: 22px; line-height: 1.3; font-weight: 700; }
.subject-card .meta { margin: 2px 0 0; font-size: 15px; color: var(--muted); }
.task { margin-top: 14px; padding: 14px 0 16px; border-top: 1px solid var(--line); }
.task-type { margin: 0; font-size: 16px; font-weight: 700; color: var(--muted); }
.task-type.is-quiz { color: var(--red); }
.task-topic { margin: 2px 0 0; font-size: 20px; line-height: 1.45; font-weight: 600; overflow-wrap: anywhere; }
.task-books-label { margin: 10px 0 2px; font-size: 16px; color: var(--muted); }
.task-books { margin: 0; padding-left: 22px; }
.task-books li { padding: 1px 0; overflow-wrap: anywhere; }
.new-tag { color: var(--red); font-weight: 700; white-space: nowrap; }
.task-submit { margin: 10px 0 0; }
.task-link { margin: 8px 0 0; }
.task-link a { display: inline-block; padding: 6px 0; font-weight: 600; }

.older-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; min-height: 50px; margin-top: 20px;
  border: 1px solid var(--field); border-radius: 8px; background: var(--card); font-size: 18px; font-weight: 600; cursor: pointer;
}
.empty { margin: 0; padding: 8px 0; color: var(--muted); }
.notice { margin: 16px 0; padding: 12px 14px; border-radius: 8px; background: var(--card); border: 1px solid var(--red); }

/* =========================================================
   Admin
   ========================================================= */
.status { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 0 18px; border-bottom: 1px solid var(--line); }
.status p { margin: 0; font-size: 15px; line-height: 1.45; color: var(--muted); }
.status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 4px; background: var(--field); margin-right: 8px; vertical-align: 2px; }
.status.is-live .dot { background: var(--accent); }
.status.is-error .dot { background: var(--red); }
.text-btn {
  min-height: 44px; padding: 0 4px; border: 0; background: transparent; cursor: pointer;
  color: var(--link); font-size: 16px; font-weight: 600;
}
.text-btn.is-plain { color: var(--text); font-weight: 400; }
.text-btn.is-danger { color: var(--red); font-weight: 400; }
.status .text-btn { flex: none; text-decoration: underline; text-underline-offset: 3px; }

.form-card {
  margin-top: 20px; background: var(--card); border: 1px solid var(--cardline); border-radius: 12px;
  padding: 20px 18px 22px; display: flex; flex-direction: column; gap: 24px;
}
.form-card h2 { margin: 0; font-family: var(--serif); font-size: 22px; line-height: 1.3; font-weight: 600; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.label, legend.label { display: block; padding: 0; font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.label small { font-weight: 400; font-size: 15px; color: var(--muted); }
.input {
  width: 100%; min-height: 50px; padding: 10px 14px; border: 1px solid var(--field); border-radius: 8px;
  background: var(--white); font-size: 18px;
}
.date-line { margin: 6px 0 0; font-size: 16px; }
.quick-title { margin: 10px 0 6px; font-size: 15px; color: var(--muted); }
.quick { display: flex; flex-wrap: wrap; gap: 8px; }
.quick button {
  min-height: 44px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--cardline);
  background: var(--white); font-size: 16px; cursor: pointer;
}
.quick button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-deep); font-weight: 700; }

.checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.check {
  position: relative; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 14px;
  border: 1px solid var(--field); border-radius: 8px; background: var(--white); cursor: pointer;
}
.check input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.box {
  display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; flex: none;
  border-radius: 4px; border: 1.5px solid var(--field); background: var(--white);
}
.box svg { visibility: hidden; }
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-deep); font-weight: 700; }
.check:has(input:checked) .box { border-color: var(--accent); background: var(--accent); }
.check:has(input:checked) .box svg { visibility: visible; }
.check:has(input:focus-visible), .radio:has(input:focus-visible), .seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.books { display: flex; flex-direction: column; gap: 14px; }
.book { display: flex; flex-direction: column; gap: 8px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.book-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.seg { display: inline-flex; border: 1px solid var(--field); border-radius: 8px; overflow: hidden; }
.seg label { position: relative; display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; background: var(--white); font-size: 16px; cursor: pointer; }
.seg label + label { border-left: 1px solid var(--field); }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg label:has(input:checked) { background: var(--muted); color: var(--on-accent); font-weight: 700; }
.seg label.is-new:has(input:checked) { background: var(--red); }

.radios { display: flex; flex-direction: column; border: 1px solid var(--field); border-radius: 8px; overflow: hidden; background: var(--white); }
.radio { position: relative; display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 14px; cursor: pointer; }
.radio + .radio { border-top: 1px solid var(--line); }
.radio input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.ring {
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; flex: none;
  border-radius: 11px; border: 1.5px solid var(--field); background: var(--white);
}
.radio:has(input:checked) { background: var(--accent-soft); font-weight: 700; }
.radio:has(input:checked) .ring { border-color: var(--accent); }
.radio:has(input:checked) .ring::after { content: ""; width: 10px; height: 10px; border-radius: 5px; background: var(--accent); }

.btn-main {
  width: 100%; min-height: 54px; border: 0; border-radius: 8px; background: var(--accent); color: var(--on-accent);
  font-size: 19px; font-weight: 700; cursor: pointer;
}
.btn-main:disabled { opacity: 0.6; cursor: progress; }
.btn-line {
  width: 100%; min-height: 50px; border: 1px solid var(--field); border-radius: 8px; background: var(--card);
  font-size: 18px; cursor: pointer;
}
.form-error { margin: 0; color: var(--red); font-weight: 600; }
.form-error:empty { display: none; }

.posted { padding: 40px 0 0; }
.posted-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.posted-head h2 { margin: 0; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 15px; color: var(--muted); min-height: 44px; cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.post { padding: 14px 0 6px; border-top: 1px solid var(--line); }
.post.is-archived { opacity: 0.6; }
.post.is-editing { background: var(--accent-soft); margin: 0 -12px; padding-left: 12px; padding-right: 12px; border-radius: 8px; }
.post-topic { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.45; overflow-wrap: anywhere; }
.post-meta { margin: 2px 0 0; font-size: 15px; color: var(--muted); }
.post-actions { display: flex; gap: 20px; }
.hint { margin: 8px 0 0; font-size: 15px; color: var(--muted); }

dialog {
  border: 1px solid var(--cardline); border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px));
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(26, 19, 16, 0.45); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
dialog h2 { margin: 0; font-family: var(--serif); font-size: 22px; font-weight: 600; }
dialog p, dialog ol { margin: 0; font-size: 16px; color: var(--muted); }
dialog ol { padding-left: 22px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog-actions { display: flex; flex-direction: column; gap: 8px; }
.dialog-more { display: flex; flex-wrap: wrap; gap: 4px 20px; border-top: 1px solid var(--line); padding-top: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 10;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 8px;
  font-size: 17px; max-width: calc(100vw - 32px);
}
