:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-soft: #fbfaf8;
  --text: #1b1b1b;
  --muted: #626262;
  --light: #8b8b8b;
  --line: #e5e2dd;
  --line-strong: #d7d2ca;
  --gold: #9a7b56;
  --green: #2f7456;
  --green-soft: #eaf4ef;
  --red: #b84e42;
  --red-soft: #f8e9e6;
  --soft: #f2f0ec;
  --radius: 8px;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(247, 247, 245, 0.96) 220px),
    var(--bg);
  line-height: 1.7;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 10px max(18px, calc((100vw - 1480px) / 2));
  border-bottom: 1px solid rgba(229, 226, 221, 0.88);
  background: rgba(247, 247, 245, 0.92);
  backdrop-filter: blur(14px);
}

.brand,
.text-button {
  color: var(--text);
  font-size: 14px;
  font-weight: 760;
  text-decoration: none;
}

.top-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.text-button {
  border: 0;
  background: transparent;
}

.shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 34px 0 56px;
}

.query-panel,
.login-card,
.result-panel,
.table-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.query-panel {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span,
.status-block > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(154, 123, 86, 0.16);
}

textarea {
  resize: vertical;
}

.primary-button,
.secondary-button,
.small-button {
  min-height: 42px;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-weight: 760;
}

.primary-button {
  color: #fff;
  background: var(--text);
  border: 1px solid var(--text);
}

.secondary-button,
.small-button {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
}

.small-button {
  min-height: 36px;
  padding: 6px 10px;
}

.hint {
  grid-column: 1 / -1;
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.result-panel {
  display: grid;
  gap: 14px;
  max-width: 760px;
  min-height: 96px;
  margin: 18px auto 0;
  padding: 16px;
}

.result-panel:empty {
  display: none;
}

.result-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.result-head span {
  color: var(--muted);
}

.result-section {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.result-section h2 {
  margin: 0 0 10px;
  font-size: 15px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 8px;
}

.result-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.result-item span {
  color: var(--muted);
}

.empty-state {
  color: var(--muted);
}

.login-card {
  width: min(380px, 100%);
  margin: 72px auto 0;
  padding: 22px;
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
}

.login-card .primary-button {
  width: 100%;
  margin-top: 14px;
}

.teacher-view {
  display: grid;
  gap: 14px;
}

.teacher-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.status-block {
  display: grid;
  gap: 6px;
}

.compact-field {
  width: 180px;
}

.status-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.status-palette button {
  min-height: 34px;
  padding: 7px 11px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.status-palette button.active {
  color: #fff;
  background: var(--text);
  border-color: var(--text);
}

.project-add {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  width: min(320px, 100%);
}

.save-hint {
  min-width: 48px;
  min-height: 18px;
  margin: 0;
  color: var(--light);
  font-size: 13px;
}

.save-hint.error-text {
  color: var(--red);
}

.table-panel {
  min-width: 0;
  overflow: hidden;
}

.table-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.table-head h2 {
  margin: 0;
  font-size: 18px;
}

.table-head span {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  max-height: calc(100vh - 170px);
  overflow: auto;
  padding: 14px;
}

.sync-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

.sync-table th,
.sync-table td {
  min-width: 74px;
  height: 39px;
  padding: 0;
  border: 1px solid var(--line);
  text-align: center;
}

.sync-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 7px 8px;
  background: var(--surface-soft);
  font-size: 13px;
  font-weight: 760;
  white-space: nowrap;
}

.sync-table thead th:not(.student-col) {
  position: sticky;
}

.sync-table thead th span {
  display: inline-block;
  max-width: 120px;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
}

.delete-project {
  width: 22px;
  height: 22px;
  margin-left: 5px;
  color: var(--light);
  background: transparent;
  border: 0;
  border-radius: 50%;
}

.delete-project:hover {
  color: var(--red);
  background: var(--red-soft);
}

.sync-table .student-col {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 58px;
  color: var(--gold);
  background: var(--surface-soft);
  font-weight: 860;
}

.sync-table tbody .student-col {
  background: var(--surface);
}

.sync-cell {
  width: 100%;
  min-height: 38px;
  color: var(--text);
  background: transparent;
  border: 0;
  font-weight: 760;
}

.sync-cell.passed,
.result-item.passed {
  color: var(--green);
  background: var(--green-soft);
}

.sync-cell.needs-work,
.result-item.needs-work {
  color: var(--red);
  background: var(--red-soft);
}

.sync-cell.muted,
.result-item.muted {
  color: var(--muted);
  background: var(--soft);
}

body.login-mode .public-view,
body.teacher-mode .public-view,
body.login-mode #teacherEntryBtn,
body.teacher-mode #teacherEntryBtn {
  display: none;
}

body.login-mode #publicBtn,
body.teacher-mode #publicBtn {
  display: inline-flex;
}

@media (max-width: 980px) {
  .shell {
    width: min(100% - 24px, 1480px);
  }

  .teacher-view,
  .query-panel {
    grid-template-columns: 1fr;
  }

  .teacher-toolbar {
    align-items: stretch;
  }

  .table-wrap {
    max-height: 68vh;
  }
}
