/* Layout concept: a printed weekly timetable, one column per weekday, with room codes as the loudest data. */
:root {
  --bg: #eef3f6;
  --surface: #ffffff;
  --ink: #12303d;
  --muted: #55707c;
  --line: #cbd9e0;
  --accent: #0b6e8a;
  --accent-ink: #ffffff;
  --mark: #ffc53d;
  --mark-ink: #3b2a00;
  --good: #137a4b;
  --bad: #b3372c;
  --soft: #dcebf1;
  --display: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --body: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1c23; --surface: #152a33; --ink: #e5f1f5; --muted: #9db6c1; --line: #2b4552;
    --accent: #55c2df; --accent-ink: #06222c; --mark: #ffcf5c; --mark-ink: #2f2200;
    --good: #5fd09b; --bad: #ff8f83; --soft: #1e3b47;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1c23; --surface: #152a33; --ink: #e5f1f5; --muted: #9db6c1; --line: #2b4552;
  --accent: #55c2df; --accent-ink: #06222c; --mark: #ffcf5c; --mark-ink: #2f2200;
  --good: #5fd09b; --bad: #ff8f83; --soft: #1e3b47;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.55 var(--body); }
h1, h2, h3, p { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.wrap {
  width: 100%; max-width: 1320px; margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.top { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top, 0px); }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; }
.brand { font-weight: 800; font-size: 18px; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.brand span { color: var(--accent); }

.btn { border: 1px solid transparent; border-radius: 6px; padding: 9px 15px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: .6; cursor: wait; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { background: var(--soft); }
.btn.small { padding: 5px 11px; font-size: 13px; }

.intro { display: grid; gap: 8px; padding-block: 30px 20px; max-width: 760px; }
.intro h1 { font: 800 clamp(25px, 4vw, 38px)/1.18 var(--display); letter-spacing: -.02em; text-wrap: balance; }
.intro p { color: var(--muted); font-size: 16px; max-width: 62ch; }

.controls { display: grid; gap: 12px; padding-bottom: 18px; }
.search input { width: 100%; padding: 13px 15px; font-size: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.days { display: flex; flex-wrap: wrap; gap: 6px; }
.day-btn { min-width: 46px; padding: 6px 11px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; font-weight: 600; font-size: 13px; cursor: pointer; }
.day-btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.filter-line { display: grid; grid-template-columns: 124px minmax(0, 1fr); align-items: center; gap: 8px; }
.filter-line > span { color: var(--muted); font-size: 13px; font-weight: 600; }
.day-btn.teacher-chip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.views { display: inline-flex; padding: 2px; gap: 2px; background: var(--soft); border-radius: 6px; }
.view-btn { padding: 4px 10px; background: transparent; border: 0; border-radius: 4px; font-size: 13px; font-weight: 600; cursor: pointer; }
.view-btn[aria-pressed="true"] { background: var(--surface); color: var(--accent); }
.empty-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.place { display: flex; flex-wrap: wrap; gap: 4px; }
.pill { padding: 1px 6px; background: var(--soft); border-radius: 3px; font-size: 11px; font-weight: 600; }
.pill.tag { background: transparent; border: 1px solid var(--line); color: var(--good); }
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-btn { padding: 5px 10px; background: transparent; border: 1px solid var(--line); border-radius: 5px; font-size: 13px; font-weight: 600; cursor: pointer; }
.tag-btn[aria-pressed="true"] { background: var(--soft); border-color: var(--accent); color: var(--accent); }
.meta-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; color: var(--muted); font-size: 13px; }
.meta-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(235px, 1fr)); gap: 12px; align-items: start; padding-bottom: 28px; }
.board.flat { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.col { display: grid; gap: 8px; min-width: 0; }
.col-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding-bottom: 6px; border-bottom: 2px solid var(--ink); }
.col-head h2 { font-size: 15px; font-weight: 800; }
.col-head span { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.col.today .col-head { border-bottom-color: var(--mark); }
.today-tag { background: var(--mark); color: var(--mark-ink); border-radius: 3px; padding: 0 5px; font-size: 11px; font-weight: 700; margin-left: 6px; }

.card { display: grid; gap: 7px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; min-width: 0; }
.card.doubtful { border-color: var(--bad); }
.card.expired { opacity: .62; }
.slot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-family: var(--mono); font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
.room { background: var(--soft); color: var(--ink); border-radius: 4px; padding: 2px 7px; overflow-wrap: anywhere; text-align: right; }
.teacher { font-weight: 700; font-size: 15px; line-height: 1.3; overflow-wrap: anywhere; }
.subject { color: var(--muted); font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
.next, .note, .by { font-size: 12px; overflow-wrap: anywhere; }
.next { font-weight: 600; color: var(--accent); }
.note { padding-top: 2px; }
.by { color: var(--muted); }
.flag { color: var(--bad); font-size: 12px; font-weight: 700; }
.card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; padding-top: 7px; border-top: 1px solid var(--line); }
.vote { padding: 3px 8px; font-size: 12px; font-weight: 600; background: transparent; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; font-variant-numeric: tabular-nums; }
.vote:hover { background: var(--soft); }
.vote.up[aria-pressed="true"] { color: var(--good); border-color: var(--good); }
.vote.down[aria-pressed="true"] { color: var(--bad); border-color: var(--bad); }
.del { margin-left: auto; padding: 3px 4px; background: none; border: 0; color: var(--bad); font-size: 12px; cursor: pointer; text-decoration: underline; }

.empty { display: grid; justify-items: start; gap: 10px; padding: 26px; margin-bottom: 28px; background: var(--surface); border: 1px dashed var(--line); border-radius: 6px; }
.empty h2 { font-size: 20px; font-weight: 800; }
.empty p { color: var(--muted); max-width: 58ch; }
.foot { padding-block: 16px 34px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; max-width: 80ch; }

dialog { width: min(680px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; }
dialog::backdrop { background: rgba(6, 20, 27, .6); }
#add-form { display: grid; gap: 15px; padding: 20px; }
.dlg-head, .dlg-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dlg-foot { justify-content: flex-end; }
.dlg-head h2 { font-size: 20px; font-weight: 800; }
.icon { width: 34px; height: 34px; background: none; border: 0; font-size: 24px; line-height: 1; cursor: pointer; }
.grid.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
#add-form label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; min-width: 0; }
#add-form input, #add-form textarea, #add-form select { width: 100%; min-width: 0; padding: 9px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; font-size: 16px; font-weight: 400; }
fieldset { display: grid; justify-items: start; gap: 10px; margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 6px; min-width: 0; }
legend { padding-inline: 5px; font-size: 13px; font-weight: 700; }
.rows { display: grid; gap: 10px; width: 100%; }
.row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) 32px; gap: 7px; align-items: end; }
.row-del { grid-column: 4; grid-row: 1 / 3; align-self: stretch; background: none; border: 1px solid var(--line); border-radius: 5px; cursor: pointer; color: var(--bad); }
.row-del:disabled { opacity: .3; cursor: default; }
.hp { position: absolute !important; left: -9999px; }
.form-error { color: var(--bad); font-weight: 600; font-size: 14px; }
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 20; max-width: calc(100vw - 32px); padding: 10px 16px; background: var(--ink); color: var(--bg); border-radius: 6px; font-weight: 600; font-size: 14px; }

@media (max-width: 560px) {
  .grid.two { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr 1fr; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
  .row-del { grid-column: 1 / -1; grid-row: auto; height: 34px; }
  .filter-line { grid-template-columns: 1fr; gap: 4px; }
  .board { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .vote, .day-btn { transition: background-color .12s, border-color .12s; }
}
