:root {
  --bg: #f6f4ef;
  --panel: #fffdf8;
  --ink: #1d2328;
  --muted: #66727d;
  --line: #d8d1c3;
  --teal: #0f766e;
  --red: #b42318;
  --orange: #b54708;
  --blue: #1570ef;
  --gray: #667085;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.58 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

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

button {
  min-height: 42px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

button.ghost {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

button.compact {
  min-height: 34px;
  padding: 5px 10px;
  font-size: 13px;
}

.hidden { display: none !important; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 24px clamp(16px, 4vw, 42px);
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--red);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: clamp(26px, 4vw, 40px); }
h2 { font-size: 20px; }

main {
  width: min(1320px, calc(100% - 28px));
  margin: 0 auto;
}

.session-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.login-panel {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 92px);
}

.login-form {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

.message {
  margin: 0;
  color: var(--red);
}

.app-panel {
  padding: 20px 0 36px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) minmax(160px, 220px) minmax(130px, 180px) minmax(140px, 190px) 92px;
  gap: 12px;
  align-items: end;
}

.grade-boxes {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.grade-box {
  min-height: 86px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: left;
  color: var(--ink);
}

.grade-box.active {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}

.grade-box strong {
  display: block;
  font-size: 28px;
}

.grade-box span { color: var(--muted); }

.content-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 16px;
}

.result-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

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

.paper-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.paper-card {
  min-height: 250px;
  display: flex;
  flex-direction: column;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
}

.paper-card.selected {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.grade-badge {
  min-width: 36px;
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: #fff;
  font-weight: 900;
}

.grade-S { background: var(--red); }
.grade-A { background: var(--orange); }
.grade-B { background: var(--blue); }
.grade-C, .grade-D, .grade-未分级 { background: var(--gray); }

.paper-id {
  color: var(--muted);
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 12px;
}

.paper-card h3 {
  margin-top: 10px;
  font-size: 17px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
}

.theme-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 2px 0 10px;
}

.theme-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7f5ef;
  color: #40505a;
  padding: 2px 8px;
  font-size: 12px;
}

.takeaway {
  margin: auto 0 0;
  border-left: 3px solid var(--blue);
  padding-left: 10px;
}

.detail-panel {
  position: sticky;
  top: 12px;
  align-self: start;
  min-height: 420px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.detail-close {
  display: none;
  margin: 0 0 12px auto;
}

.detail-panel h2 {
  margin-bottom: 8px;
}

.detail-meta {
  color: var(--muted);
  margin: 0 0 12px;
}

.detail-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.report-content {
  margin-top: 10px;
}

.report-placeholder {
  margin: 0;
  color: var(--muted);
}

.markdown-body {
  max-height: min(62vh, 680px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf6;
  padding: 12px;
  color: #26323a;
}

.markdown-body > *:first-child { margin-top: 0; }
.markdown-body > *:last-child { margin-bottom: 0; }

.markdown-body h3,
.markdown-body h4,
.markdown-body h5 {
  margin: 18px 0 8px;
  line-height: 1.25;
}

.markdown-body h3 { font-size: 18px; }
.markdown-body h4 { font-size: 16px; }
.markdown-body h5 { font-size: 15px; }

.markdown-body p,
.markdown-body ul,
.markdown-body blockquote,
.markdown-body pre {
  margin: 0 0 12px;
}

.markdown-body ul {
  padding-left: 22px;
}

.markdown-body li + li {
  margin-top: 5px;
}

.markdown-body blockquote {
  border-left: 3px solid var(--teal);
  padding: 8px 10px;
  background: #f2f7f5;
  color: #34454c;
}

.markdown-body code {
  border-radius: 4px;
  background: #ece7da;
  padding: 1px 4px;
  font: 0.94em/1.45 Consolas, "Cascadia Mono", monospace;
}

.markdown-body pre {
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-radius: 6px;
  background: #20272d;
  padding: 10px;
  color: #f7f3e8;
  font: 13px/1.65 Consolas, "Cascadia Mono", "Microsoft YaHei", monospace;
}

.markdown-body pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 16px 0;
}

.state-form {
  display: grid;
  gap: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.checkbox-line {
  display: flex;
  gap: 8px;
  align-items: center;
}

.checkbox-line input {
  width: auto;
  min-height: 0;
}

@media (max-width: 1040px) {
  .toolbar, .content-layout, .paper-grid {
    grid-template-columns: 1fr;
  }
  .grade-boxes {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .detail-panel {
    position: static;
  }
}

@media (max-width: 760px) {
  .detail-panel {
    display: none;
  }
  body.mobile-detail-open {
    overflow: hidden;
  }
  body.mobile-detail-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(29, 35, 40, 0.38);
  }
  body.mobile-detail-open .detail-panel {
    display: block;
    position: fixed;
    inset: 10px;
    z-index: 21;
    min-height: 0;
    max-height: calc(100vh - 20px);
    overflow-y: auto;
    padding: 14px;
    box-shadow: 0 18px 50px rgba(29, 35, 40, 0.28);
  }
  .detail-close {
    display: block;
    position: sticky;
    top: 0;
    z-index: 1;
  }
}

@media (max-width: 560px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }
  main {
    width: calc(100% - 20px);
  }
  .grade-boxes, .form-grid {
    grid-template-columns: 1fr;
  }
}
