:root {
  --paper: #f6f3ec;
  --card: #fffdf8;
  --ink: #26231d;
  --muted: #7a7365;
  --line: #e3ddd0;
  --accent: #8c2b23;
  --accent-light: #f7e9e5;
  --green: #2f6b4f;
  --amber: #9a6b16;
  --shadow: 0 2px 10px rgba(60, 45, 25, .06);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.6 "Segoe UI", "Microsoft YaHei", sans-serif; }
a { color: var(--accent); }
.hidden { display: none !important; }
.small { font-size: 12px; }
.muted { color: var(--muted); }

.site-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 28px; background: var(--card); border-bottom: 2px solid var(--accent); }
.brand { display: flex; align-items: center; gap: 14px; }
.seal { width: 44px; height: 44px; background: var(--accent); color: #fff; font-family: "KaiTi", serif; font-size: 14px; line-height: 21px; text-align: center; border-radius: 4px; }
.site-header h1 { margin: 0; font-size: 21px; font-family: "KaiTi", "STKaiti", serif; letter-spacing: 2px; }
.site-header p { margin: 0; color: var(--muted); font-size: 12px; }
.header-user { display: flex; align-items: center; gap: 12px; }
.user-chip { background: var(--accent-light); color: var(--accent); padding: 4px 12px; border-radius: 20px; font-size: 13px; }
.container { max-width: 1500px; margin: 0 auto; padding: 22px 28px 60px; }
.site-footer { text-align: center; color: var(--muted); font-size: 12px; padding: 18px; border-top: 1px solid var(--line); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card h2 { margin: 0 0 10px; font-size: 18px; font-family: "KaiTi", "STKaiti", serif; }
.card h3 { margin: 18px 0 8px; font-size: 15px; }
.card-title { font-weight: 600; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }

.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 5px; padding: 7px 15px; cursor: pointer; font-size: 14px; transition: .15s; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #74221c; color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-ai { background: #f3f7fb; border-color: #cfddea; }
.btn-ai:hover { border-color: #4a7fa8; color: #2b5878; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; text-decoration: underline; font-size: inherit; padding: 0; }

label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
input, select, textarea { display: block; width: 100%; margin-top: 5px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: var(--ink); font: inherit; font-size: 14px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-light); border-color: var(--accent); }
textarea { resize: vertical; }
textarea#content { min-height: 420px; font-family: "KaiTi", "STKaiti", "Microsoft YaHei", serif; font-size: 18px; line-height: 2; }

.choose-wrap { max-width: 780px; margin: 70px auto; text-align: center; }
.choose-title { font-size: 24px; font-family: "KaiTi", "STKaiti", serif; margin-bottom: 8px; }
.choose-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 22px; margin-top: 32px; }
.choose-card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 36px 24px; cursor: pointer; text-align: center; box-shadow: var(--shadow); transition: .18s; font: inherit; color: inherit; }
.choose-card:hover { border-color: var(--accent); transform: translateY(-3px); box-shadow: 0 8px 22px rgba(60,45,25,.12); }
.choose-icon { width: 60px; height: 60px; margin: 0 auto 14px; background: var(--accent-light); color: var(--accent); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-family: "KaiTi", serif; font-size: 26px; }
.choose-card h3 { margin: 0 0 10px; font-size: 18px; }
.choose-card p { margin: 0; color: var(--muted); font-size: 13px; }
.preview-banner { display: flex; justify-content: space-between; align-items: center; background: var(--accent-light); border: 1px solid #e8c9c3; border-radius: 6px; padding: 10px 16px; margin-bottom: 16px; font-size: 13px; color: var(--accent); }

.auth-wrap { max-width: 460px; margin: 40px auto; }
.auth-card h2 { font-size: 22px; }
.auth-switch { margin: 14px 0 0; text-align: center; font-size: 13px; color: var(--muted); }

.student-layout { display: grid; grid-template-columns: 280px 1fr; gap: 18px; align-items: start; }
.task-list-panel { position: sticky; top: 18px; max-height: calc(100vh - 40px); overflow-y: auto; }
.task-list { display: flex; flex-direction: column; gap: 8px; }
.task-item { border: 1px solid var(--line); border-left: 3px solid var(--line); border-radius: 5px; padding: 10px 12px; cursor: pointer; background: #fff; }
.task-item:hover { background: var(--accent-light); }
.task-item.active { border-left-color: var(--accent); background: var(--accent-light); }
.task-item .t-title { font-weight: 600; font-size: 14px; }
.task-item .t-meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.task-item.draft .t-badge { color: var(--amber); }
.task-item.submitted .t-badge { color: var(--green); }
.task-item.final .t-badge { color: var(--muted); }
.work-header { display: flex; justify-content: space-between; align-items: center; }
.work-header h2 { margin: 0; }
.status-box { text-align: right; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; background: var(--accent-light); color: var(--accent); font-size: 12px; }
.editor-grid { display: grid; grid-template-columns: minmax(340px, 46%) 1fr; gap: 18px; align-items: start; }
.image-toolbar, .action-row, .ai-buttons { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.image-scroll { overflow: auto; max-height: 74vh; background: #eae5da; border-radius: 5px; padding: 8px; text-align: center; }
.image-scroll img { max-width: none; transform-origin: top center; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.ai-panel { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.ai-result { background: #f3f7fb; border: 1px solid #cfddea; border-radius: 5px; padding: 12px; white-space: pre-wrap; font-size: 14px; max-height: 300px; overflow-y: auto; }
.empty-state { text-align: center; padding: 60px 20px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab { padding: 9px 18px; border: none; background: transparent; cursor: pointer; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 14px; text-align: center; }
.stat .n { font-size: 26px; font-weight: 600; color: var(--accent); }
.stat .l { font-size: 12px; color: var(--muted); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; background: #faf8f3; }
th[data-sort] { user-select: none; white-space: nowrap; }
th[data-sort]:hover { color: var(--ink); background: #f2efe6; }
th.sorted { color: var(--accent, #8c2b23); }
th.sorted[data-dir="asc"]::after { content: " \25B2"; font-size: 10px; }
th.sorted[data-dir="desc"]::after { content: " \25BC"; font-size: 10px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
#upload-results, #student-results, #settings-status { margin-top: 12px; font-size: 13px; }

.toast { position: fixed; right: 24px; bottom: 24px; max-width: 420px; background: #2f6b4f; color: #fff; padding: 12px 18px; border-radius: 6px; box-shadow: 0 4px 18px rgba(0,0,0,.2); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 99; }
.toast.show { opacity: 1; }
.toast.error { background: var(--accent); }

@media (max-width: 1000px) {
  .student-layout, .editor-grid { grid-template-columns: 1fr; }
  .task-list-panel { position: static; max-height: none; }
}
