/* Class notes — screen styles. Print styles live in print.css. */

:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --panel-2: #efeee9;
  --text: #1d1f22;
  --muted: #6b6f76;
  --line: #dddbd4;
  --focus: #2f5d8a;
  --accent: #2f5d8a;
  --danger: #a33a2c;

  --note: #6b6f76;
  --quote: #7a4b9a;
  --definition: #2f5d8a;
  --example: #2f7a4e;
  --question: #a3650f;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --panel: #1f2023;
    --panel-2: #2a2b2f;
    --text: #e8e6e1;
    --muted: #9a9ea6;
    --line: #34363b;
    --focus: #8fb6de;
    --accent: #8fb6de;
    --danger: #e08a7d;

    --note: #9a9ea6;
    --quote: #c09ae0;
    --definition: #8fb6de;
    --example: #86c9a0;
    --question: #e3b264;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

[hidden] { display: none !important; }

.print-doc { display: none; }

/* ---------- Buttons ---------- */

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: .45rem .8rem;
  cursor: pointer;
  line-height: 1.2;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); border-color: var(--line); }
.btn.danger:hover { color: var(--danger); }
.btn.small { padding: .25rem .55rem; font-size: .85rem; }

.chip {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: .3rem .75rem;
  font-size: .9rem;
  cursor: pointer;
  color: var(--muted);
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- Layout ---------- */

.app {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  min-height: 100%;
}

.library {
  border-right: 1px solid var(--line);
  padding: 1.25rem 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
}

.library-head { display: grid; gap: .1rem; }
.brand { font-size: 1.1rem; margin: 0; letter-spacing: .01em; }
.local-note { margin: 0; font-size: .8rem; color: var(--muted); }
.local-note::before { content: "●"; color: var(--example); margin-right: .35rem; font-size: .7rem; }

.new-subject { display: flex; gap: .4rem; }
.new-subject input {
  flex: 1; min-width: 0;
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 8px; padding: .45rem .6rem;
}

.subjects { display: grid; gap: 1rem; }
.subjects-empty { margin: 0; color: var(--muted); font-size: .88rem; }

.subject-head {
  display: flex; align-items: center; gap: .25rem;
  margin-bottom: .2rem;
}
.subject-name {
  flex: 1; min-width: 0;
  font-weight: 600; font-size: .95rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.subject-tools { display: flex; gap: .1rem; opacity: .0; transition: opacity .15s; }
.subject:hover .subject-tools, .subject:focus-within .subject-tools { opacity: 1; }
@media (hover: none) { .subject-tools { opacity: 1; } }
.icon-btn {
  border: 0; background: transparent; color: var(--muted);
  padding: .2rem .4rem; border-radius: 6px; cursor: pointer; font-size: .8rem;
}
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.icon-btn.danger:hover { color: var(--danger); }

.lecture-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.lecture-link {
  display: flex; justify-content: space-between; gap: .5rem; width: 100%;
  text-align: left; border: 0; background: transparent; cursor: pointer;
  padding: .4rem .55rem; border-radius: 7px; font-size: .92rem;
}
.lecture-link:hover { background: var(--panel-2); }
.lecture-link[aria-current="true"] { background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); }
.lecture-link .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lecture-link .d { color: var(--muted); font-size: .8rem; flex: none; font-variant-numeric: tabular-nums; }
.new-lecture { margin-top: .2rem; font-size: .88rem; color: var(--accent); }

.library-foot { margin: auto 0 0; font-size: .78rem; color: var(--muted); }

/* ---------- Lecture ---------- */

.lecture { min-width: 0; }

.empty-state {
  height: 100vh; height: 100dvh;
  display: grid; place-content: center; text-align: center; padding: 2rem;
  color: var(--muted);
}
.empty-title { font-size: 1.1rem; color: var(--text); margin: 0 0 .25rem; }
.empty-text { margin: 0; }

.editor {
  max-width: 820px;
  margin: 0 auto;
  min-height: 100vh; min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 1.25rem;
}

.lecture-head { padding: 1.1rem 0 .75rem; border-bottom: 1px solid var(--line); }
.lecture-top { display: flex; align-items: center; gap: .5rem; min-height: 1.8rem; }
.back { display: none; padding-left: 0; }
.lecture-subject { font-size: .85rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.save-state { margin-left: auto; font-size: .78rem; color: var(--muted); }
.save-state.error { color: var(--danger); font-weight: 600; }

.lecture-title {
  width: 100%;
  border: 0; background: transparent;
  font-size: 1.6rem; font-weight: 650; line-height: 1.25;
  padding: .2rem 0; margin: .1rem 0 .4rem;
}
.lecture-title::placeholder { color: var(--muted); opacity: .6; }
.lecture-title:focus-visible { outline: none; box-shadow: 0 2px 0 var(--focus); }

.lecture-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.date-field input {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: .3rem .5rem; font-size: .9rem;
}
.filters { display: flex; gap: .3rem; }
.spacer { flex: 1; }

/* Entries */

.entries {
  list-style: none; margin: 0; padding: 1rem 0;
  display: grid; gap: .6rem; align-content: start;
  flex: 1;
}
.entries-empty { color: var(--muted); text-align: center; padding: 2rem 0; margin: 0; flex: 1; }

.entry {
  --c: var(--note);
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--c);
  border-radius: var(--radius);
  padding: .55rem .8rem .6rem;
}
.entry.note { border-left-color: var(--line); }
.entry.quote { --c: var(--quote); }
.entry.definition { --c: var(--definition); }
.entry.example { --c: var(--example); }
.entry.question { --c: var(--question); }
.entry.answered { opacity: .62; }
.entry.flash { animation: flash .9s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 35%, transparent); } to { box-shadow: none; } }

.entry-bar { display: flex; align-items: center; gap: .4rem; min-height: 1.6rem; }
.entry-label {
  font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--c);
}
.entry.note .entry-label { color: var(--muted); }
.entry-time { font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.answered-tag { font-size: .72rem; color: var(--example); font-weight: 600; }

.entry-tools { margin-left: auto; display: flex; align-items: center; gap: .15rem; opacity: 0; transition: opacity .15s; }
.entry:hover .entry-tools, .entry:focus-within .entry-tools { opacity: 1; }
@media (hover: none) { .entry-tools { opacity: 1; } }

.type-select {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  font-size: .8rem; border-radius: 6px; padding: .1rem .2rem; cursor: pointer;
}
.type-select:hover { border-color: var(--line); color: var(--text); }

.answer-toggle {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .8rem; color: var(--muted); cursor: pointer; padding: .1rem .35rem;
  border-radius: 6px;
}
.answer-toggle:hover { background: var(--panel-2); color: var(--text); }
.entry.question .answer-toggle { opacity: 1; }

.entry-text {
  margin: .15rem 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.entry.quote .entry-text { font-style: italic; }
.entry.quote .entry-text::before { content: "“"; }
.entry.quote .entry-text::after { content: "”"; }
.entry.answered .entry-text { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--text) 40%, transparent); }

.entry-edit textarea {
  width: 100%; min-height: 3rem; resize: vertical;
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px;
  padding: .45rem .55rem; margin-top: .3rem; line-height: 1.5;
}
.entry-edit .row { display: flex; gap: .4rem; justify-content: flex-end; margin-top: .4rem; align-items: center; }
.entry-edit .hint { margin-right: auto; font-size: .75rem; color: var(--muted); }

/* Questions-filter: always show the answered toggle */
.entries.questions-only .entry-tools { opacity: 1; }

/* Composer */

.composer {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: .6rem 0 calc(.9rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.composer textarea {
  display: block;
  width: 100%;
  resize: none;
  min-height: 3.2rem;
  max-height: 40vh;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: .65rem .8rem;
  line-height: 1.5;
  font-size: 1.02rem;
}
.composer textarea:focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); }

.type-buttons {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: .4rem;
  margin-top: .5rem;
}
.type-btn {
  --c: var(--note);
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: .5rem .3rem;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 600;
  color: var(--c);
  border-bottom: 3px solid var(--c);
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.type-btn:hover { background: var(--panel-2); }
.type-btn:active { transform: translateY(1px); }
.t-note { --c: var(--note); }
.t-quote { --c: var(--quote); }
.t-definition { --c: var(--definition); }
.t-example { --c: var(--example); }
.t-question { --c: var(--question); }

/* Toast */

.toast {
  position: fixed; left: 50%; bottom: calc(8.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  border-radius: 999px; padding: .45rem .5rem .45rem 1rem;
  display: flex; align-items: center; gap: .6rem;
  font-size: .9rem; box-shadow: 0 6px 20px rgb(0 0 0 / .18);
  z-index: 10; max-width: calc(100vw - 2rem);
}
.toast-btn {
  border: 0; background: transparent; color: inherit; font-weight: 700;
  padding: .2rem .6rem; border-radius: 999px; cursor: pointer; text-decoration: underline;
}

.noscript { padding: 2rem; text-align: center; }

/* ---------- Phone / narrow ---------- */

@media (max-width: 800px) {
  .app { display: block; }
  .library { position: static; height: auto; min-height: 100vh; min-height: 100dvh; border-right: 0; }
  .app[data-view="library"] .lecture { display: none; }
  .app[data-view="lecture"] .library { display: none; }
  .back { display: inline-block; }
  .editor { padding: 0 .85rem; }
  .lecture-title { font-size: 1.35rem; }
  .lecture-head .spacer { display: none; }
  .lecture-meta .btn { font-size: .88rem; }
  .type-btn { font-size: .82rem; padding: .6rem .15rem; }
  .library-foot { margin-top: 1rem; }
}

@media (max-width: 420px) {
  .type-buttons { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .type-btn { grid-column: span 2; }
  .type-btn.t-example, .type-btn.t-question { grid-column: span 3; }
  .save-state { display: none; }
}

/* ---------- Overflow guards ---------- */
.entries { grid-template-columns: minmax(0, 1fr); }
.entry { min-width: 0; }
.entry-bar { flex-wrap: wrap; row-gap: .1rem; }
.lecture-link .t { flex: 1; min-width: 0; }

/* ---------- v1.1: missed markers, topics, rearranging, prefixes ---------- */
:root { --missed: #b4232a; }
@media (prefers-color-scheme: dark) { :root { --missed: #f0857f; } }

.entry.missed {
  --c: var(--missed);
  border-style: dashed;
  border-left-style: solid;
  background: color-mix(in srgb, var(--missed) 5%, var(--panel));
}
.entry-text.placeholder { font-style: italic; color: var(--muted); }

.entry.topic {
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--text);
  border-radius: 0;
  padding: 1rem 0 .3rem;
  margin-top: .4rem;
}
.entries > .entry.topic:first-child { margin-top: 0; padding-top: .2rem; }
.topic-title { margin: 0; font-size: 1.15rem; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.entry.topic .entry-bar { align-items: baseline; }

.drag-handle {
  border: 0; background: transparent; color: var(--muted);
  cursor: grab; touch-action: none;
  padding: .1rem .2rem; margin-left: -.35rem; border-radius: 6px;
  font-size: 1rem; line-height: 1; opacity: .45;
}
.entry:hover .drag-handle, .drag-handle:focus-visible { opacity: 1; }
.drag-handle:hover { background: var(--panel-2); color: var(--text); }
@media (hover: none) { .drag-handle { opacity: .8; font-size: 1.2rem; padding: .25rem .35rem; } }
.entry.dragging {
  box-shadow: 0 8px 24px rgb(0 0 0 / .18);
  position: relative; z-index: 2;
  opacity: 1;
}
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; }

.composer { position: sticky; }
.composer[data-type] textarea { border-color: var(--tc); box-shadow: 0 0 0 1px var(--tc); }
.composer[data-type="note"] { --tc: var(--note); }
.composer[data-type="quote"] { --tc: var(--quote); }
.composer[data-type="definition"] { --tc: var(--definition); }
.composer[data-type="example"] { --tc: var(--example); }
.composer[data-type="question"] { --tc: var(--question); }
.composer[data-type="missed"] { --tc: var(--missed); }
.composer[data-type="topic"] { --tc: var(--text); }
.detected {
  position: absolute; right: .6rem; top: .25rem; transform: translateY(-50%);
  background: var(--tc, var(--text)); color: var(--bg);
  font-size: .72rem; font-weight: 700; padding: .1rem .5rem; border-radius: 999px;
  pointer-events: none;
}

.composer-extra { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-top: .45rem; }
.mini-btn {
  border: 1px dashed var(--line); background: transparent; border-radius: 8px;
  padding: .3rem .65rem; font-size: .85rem; cursor: pointer; color: var(--muted);
}
.mini-btn:hover { color: var(--text); border-color: var(--muted); }
.mini-btn.t-missed { color: var(--missed); border-color: color-mix(in srgb, var(--missed) 45%, transparent); }
.prefix-hint { margin: 0 0 0 auto; font-size: .75rem; color: var(--muted); }
.prefix-hint kbd {
  font: inherit; font-weight: 700; color: var(--text);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 .25rem; background: var(--panel);
}
@media (max-width: 800px) {
  .prefix-hint { display: none; }
  .mini-btn { flex: 1; padding: .45rem .5rem; }
}

/* ---------- v1.2: lists ---------- */
:root { --list: #2b7a86; }
@media (prefers-color-scheme: dark) { :root { --list: #7cc7d1; } }

.entry.list { --c: var(--list); }
.list-title { margin: .15rem 0 .1rem; font-weight: 650; overflow-wrap: anywhere; }
.elist { margin: .15rem 0 0; padding-left: 1.4rem; }
.elist .elist { margin: .1rem 0; padding-left: 1.3rem; }
.elist li { margin: .1rem 0; }
.elist-text { white-space: pre-wrap; overflow-wrap: anywhere; }
ul.elist-l0 { list-style: disc; }
ul.elist-l1 { list-style: circle; }
ul.elist-l2 { list-style: square; }

.mini-btn.t-list { color: var(--list); border-color: color-mix(in srgb, var(--list) 45%, transparent); }
.composer[data-type="list"] { --tc: var(--list); }
.composer[data-mode="list"] .type-buttons,
.composer[data-mode="list"] .composer-extra { display: none; }
.composer[data-mode="list"] textarea { white-space: pre-wrap; tab-size: 4; }

.list-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-top: .5rem; }
.list-bar .mini-btn { border-style: solid; }
.list-hint { font-size: .75rem; color: var(--muted); margin-right: auto; }
.list-save { border-color: var(--list); color: var(--list); font-weight: 700; }
@media (max-width: 800px) {
  .list-hint { display: none; }
  .list-bar { display: grid; grid-template-columns: 1fr 1fr 2fr; }
  .list-bar .mini-btn, .list-bar .btn { padding: .55rem .4rem; font-size: .9rem; }
  #exitListBtn { grid-column: span 1; }
  .list-save { grid-column: span 2; }
}

/* ---------- v1.3: sync ---------- */
.sync-box {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: .6rem .7rem; display: grid; gap: .45rem; margin-top: auto;
}
.sync-line { margin: 0; font-size: .82rem; display: flex; align-items: center; gap: .45rem; }
.sync-dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--muted); flex: none; }
.sync-dot[data-state="ok"], .sync-dot[data-state="idle"] { background: var(--example); }
.sync-dot[data-state="syncing"] { background: var(--definition); }
.sync-dot[data-state="offline"] { background: var(--question); }
.sync-dot[data-state="login"], .sync-dot[data-state="denied"], .sync-dot[data-state="notready"], .sync-dot[data-state="error"] { background: var(--missed); }
.sync-hint { margin: -.2rem 0 0; font-size: .75rem; color: var(--muted); overflow-wrap: anywhere; }
.sync-hint:empty { display: none; }
.sync-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.library-foot { margin-top: 0; }

