:root {
  --bg: #f7f7fb; --panel: #ffffff; --text: #1d1d2c; --muted: #6b6b80;
  --border: #e3e3ee; --accent: #5b5bd6; --accent-2: #eeeefd; --accent-text: #fff;
  --ok: #1f9d55; --ok-bg: #e6f6ec; --bad: #d64545; --bad-bg: #fdecec;
  --radius: 12px; --shadow: 0 1px 3px rgba(20,20,50,.06), 0 4px 16px rgba(20,20,50,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12121a; --panel: #1b1b26; --text: #ececf4; --muted: #9a9ab0;
    --border: #2c2c3c; --accent: #8b8bff; --accent-2: #26264a; --accent-text: #0f0f1a;
    --ok: #4ade80; --ok-bg: #173323; --bad: #f87171; --bad-bg: #3a1c1c;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: .75rem; padding: .7rem 1rem; background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: .4rem; }
.logo { color: var(--accent); }
.pill { font-size: .75rem; padding: .15rem .55rem; border-radius: 99px; background: var(--accent-2); color: var(--accent); margin-left: auto; }
.icon-btn { background: none; border: 0; color: var(--text); font-size: 1.2rem; cursor: pointer; padding: .25rem .4rem; border-radius: 8px; }
.icon-btn:hover { background: var(--accent-2); }

.layout { display: grid; grid-template-columns: 270px 1fr; min-height: calc(100vh - 53px); }
.sidebar { border-right: 1px solid var(--border); padding: 1rem; background: var(--panel); }
.main { padding: 1.5rem clamp(1rem, 4vw, 3rem); max-width: 960px; width: 100%; }
.list-title { margin: 1.25rem 0 .5rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.note-list { list-style: none; margin: 0; padding: 0; }
.note-list li { padding: .55rem .65rem; border-radius: 8px; cursor: pointer; }
.note-list li:hover { background: var(--accent-2); }
.note-list li.active { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.note-list .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-list .m { font-size: .75rem; color: var(--muted); }
.only-mobile { display: none; }

.btn { border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: .55rem 1rem; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin: 1.25rem 0 1rem; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: .6rem .9rem; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.field { display: block; margin: .9rem 0; font-weight: 500; }
input[type=text], input[type=url], input[type=password], input[type=number], textarea {
  width: 100%; margin-top: .35rem; padding: .6rem .75rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel); color: var(--text); font: inherit; }
input[type=number] { width: 5rem; margin: 0 .4rem; }
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin: .75rem 0; }
.row.end { justify-content: flex-end; }
.row input[type=text] { flex: 1; margin: 0; }
.check { display: flex; align-items: center; gap: .35rem; color: var(--muted); }

.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.25rem; text-align: center; background: var(--panel); margin: .75rem 0; }
.drop.over { border-color: var(--accent); background: var(--accent-2); }
.qr-reader { max-width: 420px; margin: .5rem 0; border-radius: var(--radius); overflow: hidden; }

.note-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.markdown { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.5rem; box-shadow: var(--shadow); }
.markdown h2 { font-size: 1.15rem; margin: 1.2rem 0 .4rem; }
.markdown h2:first-child { margin-top: 0; }
.source { margin-top: 1rem; }
.source pre { white-space: pre-wrap; max-height: 300px; overflow: auto; background: var(--panel); padding: 1rem; border-radius: var(--radius); border: 1px solid var(--border); font-size: .85rem; }

.quiz-q { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin: .75rem 0; box-shadow: var(--shadow); }
.quiz-q .opts { display: grid; gap: .4rem; margin-top: .6rem; }
.quiz-q .opt { text-align: left; }
.opt.right { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.opt.wrong { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.explain { margin-top: .5rem; font-size: .9rem; color: var(--muted); }
.score { font-weight: 600; margin: 1rem 0; }

.card-stage { display: flex; flex-direction: column; align-items: center; gap: .75rem; margin-top: 1rem; }
.flashcard { width: min(520px, 100%); aspect-ratio: 5 / 3; perspective: 1000px; cursor: pointer; }
.flashcard .inner { position: relative; width: 100%; height: 100%; transition: transform .45s; transform-style: preserve-3d; }
.flashcard.flipped .inner { transform: rotateY(180deg); }
.flashcard .face { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 1.5rem; border-radius: 16px; border: 1px solid var(--border); background: var(--panel); box-shadow: var(--shadow); backface-visibility: hidden; font-size: 1.1rem; overflow: auto; }
.flashcard .back { transform: rotateY(180deg); background: var(--accent-2); }

.chat { display: flex; flex-direction: column; gap: .6rem; }
.msg { padding: .7rem 1rem; border-radius: 12px; max-width: 85%; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-text); }
.msg.ai { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: var(--text); width: min(440px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.busy { position: fixed; inset: 0; background: rgba(10,10,20,.45); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; color: #fff; z-index: 20; }
.busy[hidden] { display: none; }
.spinner { width: 42px; height: 42px; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .65rem 1.1rem; border-radius: 10px; z-index: 30; max-width: 90vw; }
.empty { color: var(--muted); padding: 1rem 0; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; position: fixed; inset: 53px 0 0 0; z-index: 4; }
  .sidebar.open { display: block; }
  .only-mobile { display: inline-block; }
  .main { padding: 1rem; }
}
