:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1f2540;
  --muted: #6b7394;
  --line: #e7eaf3;
  --primary: #4f7cff;
  --primary-d: #3a63e0;
  --shadow: 0 6px 22px rgba(40, 60, 120, 0.10);
  --radius: 16px;
  /* 科目主題色 */
  --c-中文: #ff6b6b;
  --c-英文: #4f7cff;
  --c-數學: #16b981;
  --c-常識: #f59e0b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang HK", "PingFang TC",
    "Noto Sans HK", "Microsoft JhengHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  padding-bottom: 40px;
}

/* 頂部 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 18px;
  background: linear-gradient(120deg, #fff, #f7f9ff);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 30px; }
.topbar h1 { font-size: 19px; margin: 0; letter-spacing: .5px; }
.sub { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }

.btn-primary {
  background: var(--primary); color: #fff; border: none;
  padding: 11px 16px; border-radius: 12px; font-size: 15px; font-weight: 600;
  cursor: pointer; box-shadow: 0 4px 12px rgba(79, 124, 255, .35);
  transition: transform .08s, background .2s; white-space: nowrap;
}
.btn-primary:active { transform: scale(.96); }
.btn-primary:hover { background: var(--primary-d); }
.btn-ghost {
  background: #eef1f8; color: var(--ink); border: none;
  padding: 11px 16px; border-radius: 12px; font-size: 15px; cursor: pointer;
}
.icon-btn { background: none; border: none; font-size: 20px; color: var(--muted); cursor: pointer; padding: 4px 8px; }

/* 科目分頁 */
.subject-tabs {
  display: flex; gap: 8px; padding: 12px 18px 4px; overflow-x: auto;
  scrollbar-width: none;
}
.subject-tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 1.5px solid var(--line); background: #fff; color: var(--muted);
  padding: 8px 15px; border-radius: 999px; font-size: 14px; font-weight: 600;
  cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 6px;
  transition: all .15s;
}
.tab .count { font-size: 12px; opacity: .8; background: #f0f2f8; border-radius: 999px; padding: 0 7px; }
.tab.active { color: #fff; border-color: transparent; }
.tab.active.s-全部 { background: #2b3358; }
.tab.active.s-中文 { background: var(--c-中文); }
.tab.active.s-英文 { background: var(--c-英文); }
.tab.active.s-數學 { background: var(--c-數學); }
.tab.active.s-常識 { background: var(--c-常識); }
.tab.active .count { background: rgba(255,255,255,.28); color: #fff; }

/* 工具列 */
.toolbar { display: flex; gap: 10px; align-items: center; padding: 10px 18px; flex-wrap: wrap; }
#search {
  flex: 1; min-width: 180px; border: 1.5px solid var(--line); border-radius: 12px;
  padding: 11px 14px; font-size: 15px; background: #fff; outline: none;
}
#search:focus { border-color: var(--primary); }
.filter-chips { display: flex; gap: 6px; }
.chip {
  border: 1.5px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 8px 13px; font-size: 13px; cursor: pointer; font-weight: 600;
}
.chip.active { background: var(--ink); color: #fff; border-color: transparent; }

/* 卡片列表 */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px; padding: 6px 18px 30px;
}
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); overflow: hidden; display: flex; flex-direction: column;
  border-top: 4px solid var(--line);
}
.card.s-中文 { border-top-color: var(--c-中文); }
.card.s-英文 { border-top-color: var(--c-英文); }
.card.s-數學 { border-top-color: var(--c-數學); }
.card.s-常識 { border-top-color: var(--c-常識); }
.card.done { opacity: .62; }

.card-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 0; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; color: #fff; }
.badge.s-中文 { background: var(--c-中文); }
.badge.s-英文 { background: var(--c-英文); }
.badge.s-數學 { background: var(--c-數學); }
.badge.s-常識 { background: var(--c-常識); }
.card-date { font-size: 11px; color: var(--muted); }

.card-body { padding: 10px 14px 4px; }
.q { font-size: 15.5px; font-weight: 600; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.ans-row { margin-top: 10px; font-size: 13.5px; line-height: 1.5; }
.ans-row .lbl { font-weight: 700; margin-right: 4px; }
.ans-wrong { color: #d24b4b; }
.ans-wrong .val { text-decoration: line-through; opacity: .85; white-space: pre-wrap; }
.ans-right { color: #12996a; }
.ans-right .val { white-space: pre-wrap; }
.notes { margin-top: 8px; background: #fafbff; border: 1px dashed var(--line); border-radius: 10px; padding: 8px 10px; font-size: 13px; color: #4a5170; white-space: pre-wrap; }

.card-imgs { display: flex; gap: 6px; padding: 8px 14px 0; flex-wrap: wrap; }
.card-imgs img { width: 66px; height: 66px; object-fit: cover; border-radius: 10px; cursor: zoom-in; border: 1px solid var(--line); }

.tags { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 14px 0; }
.tag { font-size: 11.5px; background: #eef1fb; color: #5566a8; border-radius: 999px; padding: 3px 9px; }

.card-foot { display: flex; gap: 8px; padding: 12px 14px; margin-top: auto; }
.card-foot button { flex: 1; border: none; border-radius: 10px; padding: 9px; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.act-master { background: #e8f8f0; color: #12996a; }
.act-master.on { background: #12996a; color: #fff; }
.act-edit { background: #eef1f8; color: #46507a; }
.act-del { background: #fdeaea; color: #d24b4b; }

/* 空狀態 */
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty-emoji { font-size: 52px; margin-bottom: 12px; }
.empty p { font-size: 15px; line-height: 1.7; }

/* 彈窗 */
.modal { position: fixed; inset: 0; background: rgba(24,30,60,.5); z-index: 40; display: flex; align-items: flex-end; justify-content: center; backdrop-filter: blur(2px); }
.modal-card { background: #fff; width: 100%; max-width: 560px; max-height: 92vh; border-radius: 22px 22px 0 0; display: flex; flex-direction: column; animation: slideup .22s ease; }
@media (min-width: 620px) { .modal { align-items: center; } .modal-card { border-radius: 22px; } }
@keyframes slideup { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.field { display: block; margin-bottom: 15px; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 7px; }
.field small { color: var(--muted); font-weight: 400; }
.field textarea, .field input[type=text] {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 12px;
  font-size: 15px; font-family: inherit; resize: vertical; outline: none; background: #fbfcff;
}
.field textarea:focus, .field input:focus { border-color: var(--primary); background: #fff; }

.subject-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.sp-btn { border: 1.5px solid var(--line); background: #fff; color: var(--muted); border-radius: 12px; padding: 9px 16px; font-size: 15px; font-weight: 600; cursor: pointer; }
.sp-btn.active { color: #fff; border-color: transparent; }
.sp-btn.active.s-中文 { background: var(--c-中文); }
.sp-btn.active.s-英文 { background: var(--c-英文); }
.sp-btn.active.s-數學 { background: var(--c-數學); }
.sp-btn.active.s-常識 { background: var(--c-常識); }

.uploader { border: 2px dashed var(--line); border-radius: 14px; padding: 16px; text-align: center; cursor: pointer; background: #fbfcff; }
.uploader-hint { color: var(--muted); font-size: 14px; line-height: 1.6; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.thumb { position: relative; width: 72px; height: 72px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.thumb .rm { position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%; background: #d24b4b; color: #fff; border: none; font-size: 13px; cursor: pointer; line-height: 22px; padding: 0; }

.form-error { background: #fdeaea; color: #c0392b; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; }
.modal-foot { display: flex; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); }
.modal-foot button { flex: 1; }

/* 圖片放大 */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* Toast */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); background: #1f2540; color: #fff; padding: 12px 20px; border-radius: 12px; font-size: 14px; z-index: 80; box-shadow: 0 8px 24px rgba(0,0,0,.25); }

.hidden { display: none !important; }
