.grade-summary {
  grid-template-columns: repeat(6, minmax(42px, 1fr)) minmax(105px, 1.65fr);
}

.grade-login-view {
  display: grid;
  min-height: calc(100vh - 110px);
  grid-template-columns: minmax(340px, 0.9fr) minmax(480px, 1.25fr);
  align-items: stretch;
  gap: 16px;
  margin-top: 14px;
}

.grade-login-card,
.grade-login-guide {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.grade-login-card {
  display: flex;
  justify-content: center;
  flex-direction: column;
  padding: clamp(34px, 5vw, 68px);
}

.grade-login-card h1 {
  margin: 4px 0 8px;
  font-size: clamp(26px, 3vw, 38px);
}

.grade-login-card > p:not(.eyebrow) {
  max-width: 480px;
  margin: 0;
  color: var(--muted);
  line-height: 1.8;
}

.grade-login-form {
  display: grid;
  gap: 13px;
  margin-top: 28px;
}

.grade-login-form label > span {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 650;
}

.grade-login-guide {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  padding: 22px;
  background:
    radial-gradient(circle at 85% 10%, rgba(211, 160, 67, 0.13), transparent 16rem),
    linear-gradient(145deg, #214f47, #12352f);
}

.grade-login-guide > div {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-content: center;
  padding: 30px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
}

.grade-login-guide > div:last-child {
  border-bottom: 0;
}

.grade-login-guide span {
  grid-row: 1 / 3;
  color: #d6b56d;
  font-size: 20px;
  font-weight: 800;
}

.grade-login-guide strong {
  font-size: 17px;
}

.grade-login-guide p {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  line-height: 1.8;
}

.grade-filter-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grade-status-filter {
  grid-column: span 2;
}

.record-item[data-grade-status="completed"]::before {
  background: var(--success);
}

.record-item[data-grade-status="draft"]::before {
  background: var(--accent);
}

.grade-list-state {
  flex: 0 0 auto;
  padding: 2px 7px;
  border-radius: 99px;
  color: var(--muted);
  background: #edf1ee;
  font-size: 9px;
  font-weight: 700;
}

.grade-list-state.is-draft {
  color: #7c5719;
  background: var(--accent-soft);
}

.grade-list-state.is-completed {
  color: var(--success);
  background: var(--success-soft);
}

.grade-editor-panel {
  min-width: 0;
}

.grade-record-header {
  align-items: center;
}

.grade-status-badge {
  padding: 2px 8px;
  border-radius: 99px;
  color: var(--muted);
  background: #edf1ee;
  font-size: 10px;
  font-weight: 700;
}

.grade-status-badge.is-draft {
  color: #7a5416;
  background: var(--accent-soft);
}

.grade-status-badge.is-completed {
  color: var(--success);
  background: var(--success-soft);
}

.grading-layout {
  display: grid;
  grid-template-areas:
    "task"
    "score"
    "essay";
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 14px;
  padding: 14px;
}

.grade-layout-card {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.task-brief-card {
  grid-area: task;
}

.essay-viewer-section,
.rubric-grade-section {
  min-width: 0;
}

.essay-viewer-section {
  grid-area: essay;
}

.rubric-grade-section {
  grid-area: score;
}

.grade-task-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.grade-task-fact {
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f8faf7;
}

.grade-task-fact span,
.grade-task-fact strong {
  display: block;
}

.grade-task-fact span {
  color: var(--muted);
  font-size: 9px;
}

.grade-task-fact strong {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 11px;
}

.grade-task-copy {
  display: grid;
  gap: 7px;
  margin-top: 9px;
}

.grade-copy-row {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 10px;
  padding: 8px 10px;
  border-left: 3px solid #b7c9c1;
  border-radius: 0 8px 8px 0;
  background: #f7f9f6;
}

.grade-copy-row > span {
  color: var(--brand);
  font-size: 10px;
  font-weight: 700;
}

.grade-copy-row > div {
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.75;
  white-space: pre-wrap;
}

.essay-viewer {
  display: grid;
  gap: 12px;
  min-height: 380px;
}

.essay-page-card {
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fff;
}

.essay-page-card img {
  display: block;
  width: 100%;
  max-height: 1120px;
  object-fit: contain;
  background: #eceeea;
  cursor: zoom-in;
}

.essay-page-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
}

.essay-page-footer span {
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.essay-page-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 5px;
}

.essay-page-actions .button {
  min-height: 29px;
  padding: 0 9px;
  font-size: 9px;
}

.grade-loading,
.essay-empty {
  display: grid;
  min-height: 260px;
  place-items: center;
  padding: 28px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  color: var(--muted);
  background: #fbfcfa;
  text-align: center;
}

.word-grade-preview {
  max-height: 1120px;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fff;
}

.word-grade-preview .word-preview-content {
  min-height: 460px;
  background: #fff;
}

.rubric-grade-heading {
  align-items: center;
}

.grade-section-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-left: 6px;
}

.grade-section-nav .button {
  min-height: 29px;
  padding: 0 10px;
  font-size: 10px;
}

.grade-topic-stats {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.grade-topic-stats b {
  color: var(--brand-deep);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.grade-total-card {
  min-width: 150px;
  padding: 8px 12px;
  border: 1px solid #c9d9d2;
  border-radius: 10px;
  background: var(--brand-soft);
  text-align: right;
}

.grade-total-card span {
  display: block;
  color: var(--muted);
  font-size: 9px;
}

.grade-total-card strong {
  display: block;
  margin-top: 1px;
  color: var(--brand-deep);
  font-size: 13px;
}

.grade-total-card b {
  font-size: 22px;
}

.grade-total-card em {
  font-style: normal;
}

.rubric-grade-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: 8px;
}

.rubric-grade-list.is-five-items {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.rubric-grade-list.is-five-items .rubric-grade-item {
  grid-column: span 2;
}

.rubric-grade-list.is-five-items .rubric-grade-item:nth-child(4),
.rubric-grade-list.is-five-items .rubric-grade-item:nth-child(5) {
  grid-column: span 3;
}

.rubric-grade-item {
  display: flex;
  height: 100%;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fff;
}

.rubric-grade-item-header {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  background: #f7faf7;
}

.rubric-item-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rubric-item-title-row > strong {
  font-size: 12px;
}

.rubric-inline-score {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
}

.rubric-inline-score span {
  color: var(--muted);
  font-size: 10px;
}

.rubric-inline-score input {
  width: 66px;
  height: 28px;
  padding: 0 7px;
  text-align: right;
  font-size: 14px;
  font-weight: 750;
}

.rubric-level-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.rubric-level {
  min-height: 0;
  padding: 6px 10px;
  border-right: 1px solid var(--line);
  background: #fff;
}

.rubric-level:last-child {
  border-right: 0;
}

.rubric-level.is-good {
  background: #f4faf6;
}

.rubric-level.is-medium {
  background: #fffdf5;
}

.rubric-level.is-poor {
  background: #fff8f7;
}

.rubric-level-text {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.45;
}

.rubric-level-text strong {
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
}

.grade-actions {
  position: sticky;
  z-index: 8;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 -8px 20px rgba(31, 55, 48, 0.06);
  backdrop-filter: blur(10px);
}

.grade-actions > div:first-child {
  display: grid;
  gap: 2px;
}

.grade-actions > div:first-child strong {
  font-size: 11px;
}

.grade-actions > div:first-child span {
  color: var(--muted);
  font-size: 9px;
}

.grade-action-buttons {
  display: flex;
  gap: 8px;
}

.essay-image-modal .preview-body {
  padding: 12px;
  background: #111815;
}

.essay-image-modal .preview-body img {
  max-width: 100%;
  max-height: calc(100vh - 160px);
  object-fit: contain;
}

.save-state.is-dirty .save-dot {
  background: var(--accent);
}

@media (max-width: 1400px) {
  .topbar {
    grid-template-columns: max-content max-content minmax(280px, 1fr) max-content;
  }

  .brand p {
    display: none;
  }

  .grading-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .rubric-level-grid {
    grid-template-columns: 1fr;
  }

  .rubric-level {
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .rubric-level:last-child {
    border-bottom: 0;
  }
}

@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: max-content minmax(0, 1fr) max-content;
  }

  .topbar .summary-strip {
    grid-column: 1 / -1;
  }

  .grade-login-view {
    min-height: auto;
    grid-template-columns: 1fr;
  }

  .grade-login-guide {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: none;
  }

  .grade-login-guide > div {
    grid-template-columns: 1fr;
    padding: 24px;
    border-right: 1px solid rgba(255, 255, 255, 0.15);
    border-bottom: 0;
  }

  .grade-login-guide span {
    grid-row: auto;
    margin-bottom: 8px;
  }

  .workspace {
    grid-template-columns: minmax(285px, 330px) minmax(0, 1fr);
  }

  .grading-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "task"
      "score"
      "essay";
  }

  .essay-viewer {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 840px) {
  .app-shell {
    width: min(100% - 20px, 1720px);
  }

  .topbar {
    position: static;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar .module-tabs {
    grid-column: 1 / -1;
    display: grid;
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .topbar .module-tab {
    min-width: 0;
    padding: 0 5px;
    justify-content: center;
    text-align: center;
  }

  .topbar .topbar-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }

  .grade-login-view,
  .grade-login-card,
  .grade-login-guide,
  .workspace,
  .list-panel,
  .editor-panel {
    min-width: 0;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .list-panel {
    position: static;
    height: auto;
    min-height: 0;
    max-height: none;
  }

  .record-list {
    max-height: 440px;
  }

  .record-header {
    padding: 18px;
  }

  .record-header h2 {
    font-size: 18px;
  }

  .grading-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "task"
      "score"
      "essay";
  }

  .essay-viewer {
    grid-template-columns: 1fr;
  }

  .rubric-grade-list {
    grid-template-columns: 1fr;
  }

  .rubric-grade-list.is-five-items {
    grid-template-columns: 1fr;
  }

  .rubric-grade-list.is-five-items .rubric-grade-item,
  .rubric-grade-list.is-five-items .rubric-grade-item:nth-child(4),
  .rubric-grade-list.is-five-items .rubric-grade-item:nth-child(5) {
    grid-column: auto;
  }

  .grade-actions {
    position: static;
  }
}

@media (max-width: 620px) {
  .grade-page {
    overflow-x: hidden;
  }

  .app-shell {
    width: calc(100% - 16px);
  }

  .topbar {
    padding: 8px;
    gap: 8px;
  }

  .brand h1 {
    font-size: 15px;
  }

  .topbar .module-tab {
    padding: 0 3px;
    font-size: 9px;
  }

  .topbar .module-status {
    display: none;
  }

  .topbar .topbar-actions {
    justify-content: space-between;
  }

  .grade-login-guide {
    grid-template-columns: 1fr;
  }

  .grade-login-guide > div {
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  }

  .grade-summary {
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(3, 1fr);
  }

  .grade-summary .summary-metric {
    min-width: 0;
    padding-right: 5px;
    padding-left: 5px;
  }

  .grade-summary .summary-progress {
    grid-column: span 3;
  }

  .grade-filter-grid,
  .grade-task-facts {
    grid-template-columns: 1fr;
  }

  .grade-status-filter {
    grid-column: auto;
  }

  .record-header,
  .record-nav,
  .grade-actions,
  .grade-action-buttons {
    align-items: stretch;
    flex-direction: column;
  }

  .rubric-grade-heading > div:first-child,
  .essay-viewer-section .section-heading > div:first-child {
    flex-wrap: wrap;
  }

  .grade-section-nav {
    margin-left: 0;
  }

  .record-nav,
  .grade-action-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    width: 100%;
  }

  .grade-action-buttons {
    grid-template-columns: 1fr;
  }

  .grade-copy-row {
    grid-template-columns: 1fr;
  }

  .grade-login-card {
    min-width: 0;
    padding: 28px 20px;
  }

  .grade-login-card h1 {
    font-size: 28px;
  }

  .grade-login-card > p:not(.eyebrow) {
    max-width: 100%;
  }

  .grade-login-guide > div {
    padding: 20px;
  }

  .rubric-grade-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .grade-total-card {
    width: 100%;
    text-align: left;
  }

  .essay-page-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .essay-page-actions {
    width: 100%;
  }

  .essay-page-actions .button {
    flex: 1;
  }
}
