:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #69778c;
  --line: #dfe7ef;
  --paper: #ffffff;
  --soft: #f4f7fa;
  --brand: #16647c;
  --brand-2: #158a86;
  --accent: #d97706;
  --good: #1f8a5b;
  --danger: #c2410c;
  --shadow: 0 8px 24px rgba(23, 32, 51, 0.07);
  --shadow-strong: 0 18px 48px rgba(23, 32, 51, 0.14);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(22, 100, 124, 0.07), transparent 280px),
    var(--soft);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

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

button {
  border: 0;
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  padding: 10px 24px;
  background: #102331;
  color: #eef7fb;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 24px rgba(16, 35, 49, 0.14);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  font-size: 20px;
  min-width: max-content;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #35c2a5, #f2b84b);
  display: grid;
  place-items: center;
  color: #102331;
}

.nav {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
  overflow-x: auto;
}

.nav button {
  height: 36px;
  border-radius: 8px;
  color: #d8e8ef;
  background: transparent;
  text-align: center;
  padding: 0 13px;
  white-space: nowrap;
  font-weight: 800;
  letter-spacing: 0;
}

.nav button.active,
.nav button:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.header-userbar {
  margin-left: auto;
  min-width: max-content;
}

.header-userbar .btn.ghost {
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.10);
}

.main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px 26px 34px;
  overflow: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 16px;
  padding: 4px 2px;
}

.title h1 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: 0;
}

.title p,
.muted {
  margin: 0;
  color: var(--muted);
}

.userbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  background: #e8f4f3;
  color: #0b6466;
  font-weight: 700;
  font-size: 13px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(320px, 440px) 1fr;
  gap: 18px;
  align-items: start;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(620px, 1fr) minmax(330px, 420px);
  gap: 16px;
  align-items: start;
}

.generator-controls {
  padding: 0;
  position: sticky;
  top: 88px;
  overflow: hidden;
}

.generator-controls .form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}

.generator-controls .field.full {
  grid-column: 1 / -1;
}

.setting-row {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 11px;
}

.form-section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.form-section:last-child {
  border-bottom: 0;
}

.section-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}

.section-head > span {
  width: 26px;
  height: 26px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 8px 16px rgba(22, 100, 124, 0.18);
}

.section-head h2 {
  margin: 0;
  color: #223148;
  font-size: 16px;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.hint-strip {
  border: 1px solid #d7ebe8;
  border-radius: var(--radius);
  background: #f1fbf9;
  color: #28615f;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.6;
}

.form-footer {
  justify-content: space-between;
  border-top: 1px dashed var(--line);
  padding-top: 14px;
  margin-top: 2px;
}

.setting-row > span {
  color: #344255;
  font-size: 13px;
  font-weight: 800;
}

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

.segmented button {
  min-height: 33px;
  border-radius: var(--radius);
  padding: 0 12px;
  background: #f4f7fa;
  border: 1px solid #e2eaf1;
  color: var(--ink);
  font-weight: 800;
}

.segmented button.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  box-shadow: 0 6px 16px rgba(22, 100, 124, 0.18);
}

.compact-input {
  height: 38px;
}

.compact-notice {
  margin-bottom: 8px;
}

.panel,
.auth-card,
.comment-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
  border-color: rgba(223, 231, 239, 0.95);
}

.generator-controls.panel {
  padding: 0;
}

.preview-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  margin: -16px -16px 14px;
  border-radius: var(--radius) var(--radius) 0 0;
}

.preview-head strong {
  display: block;
  color: #172033;
  font-size: 15px;
}

.preview-head span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

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

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.field.full {
  grid-column: 1 / -1;
}

label {
  color: #344255;
  font-size: 13px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 11px;
  background: #fbfdff;
  color: var(--ink);
  outline: none;
}

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

input:focus,
textarea:focus,
select:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.12);
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  min-height: 40px;
  border-radius: var(--radius);
  padding: 0 14px;
  background: #e8eef4;
  color: var(--ink);
  font-weight: 800;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}

.btn:hover,
.segmented button:hover,
.select-field:hover,
.tag-btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 8px 18px rgba(22, 100, 124, 0.18);
}

.btn.accent {
  background: var(--accent);
  color: #fff;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
}

.btn:disabled {
  cursor: wait;
  opacity: 0.74;
  transform: none;
}

.generate-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 128px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-top-color: #fff;
  border-radius: 999px;
  display: inline-block;
  animation: spin .75s linear infinite;
}

.student-list {
  display: grid;
  gap: 9px;
  margin: 12px 0 10px;
}

.student-row {
  display: grid;
  gap: 8px;
  padding: 8px;
  background: linear-gradient(180deg, #ffffff, #f8fbfd);
  border: 1px solid #e5edf4;
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(23, 32, 51, 0.04);
}

.student-main {
  display: grid;
  grid-template-columns: 1fr 1fr 38px;
  gap: 8px;
}

.student-tags {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.trait-target {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.trait-target label {
  font-weight: 900;
}

.generator-controls .student-list {
  grid-template-columns: 1fr;
  margin: 8px 0;
}

.preview-panel {
  min-height: auto;
  position: sticky;
  top: 88px;
  padding: 16px;
  background: linear-gradient(180deg, #ffffff, #f9fbfd);
}

.preview-toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 14px;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.preview-toolbar h2 {
  margin: 0 0 4px;
}

.preview-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: center;
}

.preview-controls label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 0;
  white-space: nowrap;
}

.preview-controls select {
  width: 100%;
  height: 40px;
  padding: 0 10px;
}

.preview-controls .btn {
  white-space: nowrap;
  padding: 0 10px;
}

.preview-controls .pill {
  grid-column: 1 / -1;
  max-width: 100%;
  justify-content: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #eef7f6;
}

.preview-empty {
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  line-height: 1.8;
  background: rgba(255, 255, 255, 0.62);
  border-radius: var(--radius);
  padding: 24px;
}

.preview-empty.generating {
  align-content: center;
  gap: 10px;
  color: var(--ink);
}

.preview-empty.generating .spinner {
  width: 34px;
  height: 34px;
  border-width: 3px;
  border-color: rgba(15, 139, 141, 0.22);
  border-top-color: var(--brand);
}

.preview-empty.generating strong,
.preview-empty.generating small {
  display: block;
}

.preview-empty.generating small {
  color: var(--muted);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.certificate-layout {
  grid-template-columns: minmax(420px, 560px) minmax(0, 1fr);
}

.certificate-sheet {
  width: min(100%, 760px);
  aspect-ratio: 1.414 / 1;
  margin: 0 auto 16px;
  padding: 34px;
  border-radius: 8px;
  background: #fffaf0;
  box-shadow: 0 14px 36px rgba(29, 38, 51, 0.10);
  position: relative;
  overflow: hidden;
}

.certificate-inner {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  place-items: center;
  text-align: center;
  padding: 34px 52px;
  border: 4px double rgba(159, 107, 28, 0.55);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  position: relative;
  z-index: 1;
}

.cert-ribbon {
  color: #9b6a1b;
  font-weight: 900;
  letter-spacing: 6px;
  font-size: 20px;
}

.certificate-sheet h1 {
  margin: 16px 0 8px;
  font-size: clamp(28px, 4vw, 52px);
  letter-spacing: 0;
}

.certificate-sheet h2 {
  margin: 0;
  font-size: clamp(24px, 3vw, 38px);
  color: #1d2633;
}

.certificate-sheet p {
  align-self: center;
  margin: 22px 0;
  max-width: 78%;
  line-height: 1.9;
  font-size: clamp(15px, 1.55vw, 20px);
}

.cert-footer {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  color: #344255;
  font-weight: 800;
}

.cert-template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px;
}

.cert-template {
  border: 2px solid transparent;
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  border-radius: var(--radius);
  padding: 8px;
  text-align: left;
  box-shadow: 0 4px 14px rgba(23, 32, 51, 0.05);
}

.cert-template.active {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.12);
}

.cert-template span {
  display: block;
  height: 48px;
  border-radius: 6px;
  margin-bottom: 7px;
}

.cert-template strong {
  font-size: 12px;
}

.cert-template .cert-gold,
.certificate-sheet.cert-gold {
  background: radial-gradient(circle at 50% 8%, rgba(218, 165, 61, .34), transparent 18%), linear-gradient(135deg, #fff8d9, #ffffff 45%, #f6e3b4);
}

.cert-template .cert-red,
.certificate-sheet.cert-red {
  background: radial-gradient(circle at 8% 10%, rgba(211, 55, 45, .24), transparent 20%), linear-gradient(135deg, #fff6f2, #ffffff 48%, #ffe5df);
}

.cert-template .cert-blue,
.certificate-sheet.cert-blue {
  background: linear-gradient(135deg, #e8f6ff, #ffffff 50%, #d9edf8);
}

.cert-template .cert-green,
.certificate-sheet.cert-green {
  background: linear-gradient(135deg, #edf9ec, #ffffff 48%, #d9f0df);
}

.cert-template .cert-purple,
.certificate-sheet.cert-purple {
  background: linear-gradient(135deg, #f3efff, #ffffff 48%, #e4dcff);
}

.cert-template .cert-sun,
.certificate-sheet.cert-sun {
  background: radial-gradient(circle at 85% 16%, rgba(255, 196, 72, .52), transparent 16%), linear-gradient(135deg, #fff5d2, #ffffff);
}

.cert-template .cert-star,
.certificate-sheet.cert-star {
  background: radial-gradient(circle at 15% 20%, rgba(242,184,75,.32), transparent 8%), radial-gradient(circle at 86% 72%, rgba(23,107,135,.18), transparent 14%), #fffdf4;
}

.cert-template .cert-book,
.certificate-sheet.cert-book {
  background: linear-gradient(20deg, rgba(23,107,135,.18), transparent 22%), #fbf7ef;
}

.cert-template .cert-sport,
.certificate-sheet.cert-sport {
  background: linear-gradient(135deg, #f2fff2, #ffffff), radial-gradient(circle at 12% 82%, rgba(231,144,60,.35), transparent 14%);
}

.cert-template .cert-art,
.certificate-sheet.cert-art {
  background: radial-gradient(circle at 12% 18%, rgba(239,138,164,.28), transparent 12%), radial-gradient(circle at 88% 18%, rgba(242,184,75,.26), transparent 12%), #fff8fb;
}

.cert-template .cert-science,
.certificate-sheet.cert-science {
  background: radial-gradient(circle at 12% 18%, transparent 0 7%, rgba(23,107,135,.22) 7.5% 8%, transparent 8.5%), #f3fbff;
}

.cert-template .cert-classic,
.certificate-sheet.cert-classic {
  background: linear-gradient(135deg, #fffaf0, #ffffff 46%, #f4ead8);
}

.cert-template .cert-ink,
.certificate-sheet.cert-ink {
  background: radial-gradient(ellipse at 15% 20%, rgba(48, 70, 82, .18), transparent 28%), #fbfbf8;
}

.cert-template .cert-flower,
.certificate-sheet.cert-flower {
  background: radial-gradient(circle at 10% 12%, rgba(239,138,164,.35), transparent 10%), radial-gradient(circle at 90% 84%, rgba(239,138,164,.28), transparent 12%), #fff8fb;
}

.cert-template .cert-rainbow,
.certificate-sheet.cert-rainbow {
  background: linear-gradient(135deg, rgba(239,123,123,.20), rgba(242,184,75,.16), rgba(104,185,132,.16), rgba(90,166,209,.18)), #fff;
}

.cert-template .cert-ocean,
.certificate-sheet.cert-ocean {
  background: linear-gradient(180deg, #dff9ff, #ffffff 60%, #d8f1f2);
}

.cert-template .cert-mountain,
.certificate-sheet.cert-mountain {
  background: linear-gradient(135deg, transparent 0 58%, rgba(122,165,154,.22) 59% 72%, transparent 73%), #f5fbff;
}

.cert-template .cert-tech,
.certificate-sheet.cert-tech {
  background: linear-gradient(90deg, rgba(23,107,135,.12) 1px, transparent 1px) 0 0 / 36px 36px, linear-gradient(180deg, rgba(23,107,135,.12) 1px, transparent 1px) 0 0 / 36px 36px, #f8fbff;
}

.cert-template .cert-cute,
.certificate-sheet.cert-cute {
  background: radial-gradient(circle at 12% 18%, rgba(242,184,75,.32), transparent 8%), radial-gradient(circle at 86% 16%, rgba(239,138,164,.28), transparent 9%), #fffdf7;
}

.cert-template .cert-minimal,
.certificate-sheet.cert-minimal {
  background: #ffffff;
}

.certificate-sheet.cert-red .certificate-inner,
.certificate-sheet.cert-flower .certificate-inner {
  border-color: rgba(196, 64, 57, .52);
}

.certificate-sheet.cert-blue .certificate-inner,
.certificate-sheet.cert-ocean .certificate-inner,
.certificate-sheet.cert-science .certificate-inner,
.certificate-sheet.cert-tech .certificate-inner {
  border-color: rgba(23, 107, 135, .44);
}

.certificate-sheet.cert-green .certificate-inner,
.certificate-sheet.cert-sport .certificate-inner,
.certificate-sheet.cert-mountain .certificate-inner {
  border-color: rgba(47, 142, 98, .44);
}

.certificate-sheet.cert-purple .certificate-inner {
  border-color: rgba(100, 86, 176, .42);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #f1f4f7;
}

.select-field {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 900;
}

.select-field:hover {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.10);
}

.select-field-strong {
  background: linear-gradient(180deg, #e8f7f4, #f8fffd);
  border-color: rgba(15, 139, 141, 0.42);
  color: #0b6466;
  box-shadow: inset 0 0 0 1px rgba(15, 139, 141, 0.08);
}

.select-field-warn {
  background: linear-gradient(180deg, #fff4e6, #fffdf8);
  border-color: rgba(217, 119, 6, 0.42);
  color: #92400e;
  box-shadow: inset 0 0 0 1px rgba(217, 119, 6, 0.08);
}

.select-field-strong::before {
  content: "+ ";
}

.select-field-warn::before {
  content: "! ";
}

.trait-modal {
  width: min(920px, 100%);
}

.tag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 10px;
  max-height: 46vh;
  overflow: auto;
  padding-right: 4px;
}

.tag-btn {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.tag-btn.active {
  background: #e8f4f3;
  border-color: var(--brand-2);
  color: #0b6466;
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.10);
}

.custom-add {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 14px;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 14px;
}

.result-list {
  display: grid;
  gap: 14px;
}

.record-list {
  display: grid;
  gap: 12px;
}

.records-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.record-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.record-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  padding: 14px;
  box-shadow: 0 6px 18px rgba(23, 32, 51, 0.05);
}

.record-select-card {
  display: grid;
  gap: 12px;
  transition: border-color .12s ease, box-shadow .12s ease, transform .12s ease;
}

.record-select-card.selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.12), 0 10px 24px rgba(23, 32, 51, 0.08);
}

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

.record-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 900;
}

.record-check span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-comments {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.record-comments.compact {
  margin-top: 0;
}

.record-comments div {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.record-comments p {
  margin: 6px 0 0;
  line-height: 1.7;
  color: #344255;
}

.record-comments.compact p {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.record-card-actions {
  margin-top: auto;
}

.panel-title-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.admin-record-panel {
  grid-column: 1 / -1;
}

.admin-record-list {
  max-height: 620px;
  overflow: auto;
  padding-right: 4px;
}

.admin-record-card .record-head {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.comment-card {
  padding: 16px;
}

.result-item {
  padding: 12px;
  background: linear-gradient(180deg, #ffffff, #fbfdff);
}

.result-actions {
  margin-bottom: 10px;
  justify-content: flex-start;
}

.comment-sheet {
  width: min(100%, 420px);
  min-height: auto;
  aspect-ratio: 210 / 297;
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  padding: clamp(24px, 6%, 64px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid rgba(23, 107, 135, 0.16);
  position: relative;
  box-shadow: 0 12px 30px rgba(23, 32, 51, 0.10);
}

.comment-sheet[class*="template-"] {
  background-size: auto;
}

.template-campus-fresh,
.template-blue-sky {
  background:
    radial-gradient(circle at 82% 14%, rgba(255, 214, 110, .55) 0 9%, transparent 10%),
    linear-gradient(180deg, rgba(223, 245, 242, .95), rgba(255,255,255,.98) 58%, rgba(237, 249, 230, .95));
}

.template-campus-fresh::before,
.template-blue-sky::before,
.template-green-leaves::before,
.template-flower-frame::before,
.template-golden-award::before,
.template-honor-certificate::before {
  content: "";
  position: absolute;
  inset: 4%;
  border: 2px solid rgba(23, 107, 135, .22);
  border-radius: 14px;
  pointer-events: none;
}

.template-star-growth,
.template-golden-award {
  background:
    radial-gradient(circle at 10% 16%, rgba(242, 184, 75, .36) 0 3%, transparent 4%),
    radial-gradient(circle at 88% 80%, rgba(15, 139, 141, .22) 0 8%, transparent 9%),
    linear-gradient(135deg, #f4f0ff, #fff8e6 48%, #eaf8ff);
}

.template-summer-reading,
.template-pencil-note,
.template-warm-paper {
  background:
    repeating-linear-gradient(180deg, transparent 0 8.5%, rgba(215, 226, 232, .44) 8.7% 9%),
    linear-gradient(135deg, #fff5d4, #fffdf8 50%, #e8f6ee);
}

.template-honor-certificate {
  background:
    radial-gradient(circle at 50% 8%, rgba(214, 168, 91, .44) 0 6%, transparent 7%),
    linear-gradient(135deg, #fffdf4, #fff7e8 55%, #f4e2bd);
}

.template-green-leaves {
  background:
    radial-gradient(ellipse at 0% 0%, rgba(47, 142, 98, .28) 0 18%, transparent 19%),
    radial-gradient(ellipse at 100% 100%, rgba(47, 142, 98, .22) 0 18%, transparent 19%),
    linear-gradient(135deg, #f5fbf3, #ffffff);
}

.template-chalkboard {
  background:
    linear-gradient(#276b5f, #276b5f) padding-box,
    linear-gradient(135deg, #8b6138, #c39a62) border-box;
  border: 10px solid transparent;
}

.template-rainbow-soft {
  background:
    radial-gradient(ellipse at 10% 100%, rgba(239,123,123,.22) 0 22%, transparent 23%),
    radial-gradient(ellipse at 20% 100%, rgba(242,184,75,.20) 0 26%, transparent 27%),
    radial-gradient(ellipse at 30% 100%, rgba(104,185,132,.18) 0 30%, transparent 31%),
    linear-gradient(135deg, #fbfdff, #fff);
}

.template-ocean-calm {
  background:
    radial-gradient(ellipse at 50% 100%, rgba(74,169,189,.32) 0 24%, transparent 25%),
    linear-gradient(180deg, #dff9ff, #ffffff 62%, #d8f1f2);
}

.template-book-corner {
  background:
    linear-gradient(15deg, rgba(23,107,135,.25) 0 10%, transparent 11%) left bottom / 48% 28% no-repeat,
    linear-gradient(195deg, rgba(242,184,75,.24) 0 10%, transparent 11%) right top / 42% 24% no-repeat,
    #fbf7ef;
}

.template-flower-frame {
  background:
    radial-gradient(circle at 9% 12%, rgba(239,138,164,.35) 0 5%, transparent 6%),
    radial-gradient(circle at 90% 86%, rgba(239,138,164,.32) 0 6%, transparent 7%),
    linear-gradient(135deg, #fff8fb, #ffffff);
}

.template-geometric-bright {
  background:
    linear-gradient(135deg, rgba(23,107,135,.28) 0 14%, transparent 15%) left top / 50% 45% no-repeat,
    radial-gradient(circle at 92% 84%, rgba(15,139,141,.24) 0 12%, transparent 13%),
    linear-gradient(135deg, #f7fbff, #ffffff);
}

.template-minimal-lines,
.template-soft-grid {
  background:
    linear-gradient(90deg, rgba(207,221,232,.38) 1px, transparent 1px) 0 0 / 11% 11%,
    linear-gradient(180deg, rgba(207,221,232,.38) 1px, transparent 1px) 0 0 / 11% 11%,
    #ffffff;
}

.template-pastel-dots {
  background:
    radial-gradient(circle at 8% 10%, rgba(242,184,75,.34) 0 3%, transparent 4%),
    radial-gradient(circle at 88% 16%, rgba(239,138,164,.28) 0 4%, transparent 5%),
    radial-gradient(circle at 12% 86%, rgba(104,185,132,.25) 0 4%, transparent 5%),
    #ffffff;
}

.template-mountain-path {
  background:
    linear-gradient(135deg, transparent 0 55%, rgba(122,165,154,.24) 56% 70%, transparent 71%),
    linear-gradient(225deg, transparent 0 58%, rgba(88,127,121,.18) 59% 72%, transparent 73%),
    linear-gradient(180deg, #eaf7ff, #ffffff 70%, #eef3dd);
}

.template-science-lab {
  background:
    radial-gradient(circle at 12% 18%, transparent 0 7%, rgba(23,107,135,.22) 7.5% 8%, transparent 8.5%),
    radial-gradient(circle at 88% 20%, rgba(15,139,141,.18) 0 4%, transparent 5%),
    linear-gradient(135deg, #f3fbff, #ffffff);
}

.comment-sheet.size-a4p {
  width: min(100%, 360px);
}

.comment-sheet.size-a4l {
  aspect-ratio: 297 / 210;
  width: min(100%, 430px);
}

.comment-sheet.size-sixteen-nine {
  aspect-ratio: 16 / 9;
  width: min(100%, 440px);
}

.comment-sheet.size-four-three {
  aspect-ratio: 4 / 3;
  width: min(100%, 420px);
}

.comment-sheet.size-square {
  aspect-ratio: 1 / 1;
  width: min(100%, 360px);
}

.comment-content {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: 1fr;
  gap: 12px;
  padding: clamp(18px, 4%, 46px);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.50);
  backdrop-filter: blur(0.5px);
}

.comment-content.has-signature {
  grid-template-rows: 1fr auto;
}

.comment-sheet.size-a4p .comment-content {
  padding: 12% 10%;
}

.comment-sheet.size-a4l .comment-content,
.comment-sheet.size-sixteen-nine .comment-content {
  padding: 8% 10%;
}

.comment-sheet.size-four-three .comment-content {
  padding: 9% 9%;
}

.comment-sheet.size-square .comment-content {
  padding: 10% 10%;
}

.comment-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.comment-head h2 {
  margin: 0;
}

.comment-head strong {
  font-size: 17px;
}

.comment-text {
  line-height: 1.8;
  white-space: pre-wrap;
  background: rgba(255, 255, 255, 0.72);
  min-height: 0;
  height: 100%;
  border: 0;
  border-radius: 8px;
  padding: clamp(14px, 3%, 24px);
  overflow: hidden;
  display: block;
  align-content: center;
  word-break: break-word;
  overflow-wrap: anywhere;
  outline: none;
  cursor: text;
}

.comment-text:focus {
  box-shadow: inset 0 0 0 2px rgba(15, 139, 141, 0.34);
  background: rgba(255, 255, 255, 0.86);
}

.comment-sheet .comment-text {
  --card-font-size: clamp(14px, 1.35vw, 18px);
  font-size: var(--card-font-size);
  color: #263345;
}

.comment-sheet.size-a4p .comment-text {
  --card-font-size: clamp(15px, 1.45vw, 19px);
  font-size: var(--card-font-size);
  line-height: 1.95;
}

.comment-sheet.size-a4l .comment-text {
  --card-font-size: clamp(13px, 1.15vw, 17px);
  font-size: var(--card-font-size);
  line-height: 1.75;
}

.comment-sheet.size-sixteen-nine .comment-text {
  --card-font-size: clamp(12px, 1.05vw, 16px);
  font-size: var(--card-font-size);
  line-height: 1.65;
}

.comment-sheet.size-four-three .comment-text {
  --card-font-size: clamp(13px, 1.2vw, 17px);
  font-size: var(--card-font-size);
  line-height: 1.75;
}

.comment-sheet.size-square .comment-text {
  --card-font-size: clamp(13px, 1.28vw, 17px);
  font-size: var(--card-font-size);
  line-height: 1.7;
}

.comment-sheet.text-small .comment-text {
  font-size: calc(var(--card-font-size, 1rem) * 0.88);
}

.comment-sheet.text-large .comment-text {
  font-size: calc(var(--card-font-size, 1rem) * 1.12);
}

.comment-sheet.text-xlarge .comment-text {
  font-size: calc(var(--card-font-size, 1rem) * 1.25);
}

.comment-text.text-fitted {
  padding: clamp(10px, 2.4%, 18px);
}

.comment-signature {
  justify-self: end;
  max-width: 100%;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.70);
  color: #263345;
  font-weight: 900;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comment-sheet.size-sixteen-nine .comment-head {
  margin-bottom: 4px;
}

.bg-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.bg-picker select {
  min-width: 140px;
  height: 38px;
  padding: 0 10px;
}

.bg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.bg-choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  max-height: min(66vh, 620px);
  overflow: auto;
  padding-right: 3px;
}

.bg-choice {
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 6px;
  background: #fff;
  text-align: left;
  color: var(--ink);
}

.bg-choice.active {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.12);
}

.bg-choice img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

.bg-choice span {
  display: block;
  padding: 6px 2px 0;
  font-size: 12px;
  font-weight: 800;
}

.bg-current {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: #fff;
}

.bg-current img {
  width: 72px;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.bg-current strong,
.bg-current span {
  display: block;
}

.bg-current span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(16, 35, 49, 0.46);
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-panel {
  width: min(1060px, 100%);
  max-height: 88vh;
  overflow: hidden;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(16, 35, 49, 0.24);
  padding: 18px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0 0 5px;
}

.paste-modal {
  width: min(780px, 100%);
}

.paste-class-field {
  margin-bottom: 12px;
}

.paste-class-field input {
  height: 44px;
  font-size: 15px;
  font-weight: 800;
}

.paste-textarea {
  width: 100%;
  min-height: 300px;
  resize: vertical;
  border: 1px solid #d8e4ee;
  border-radius: 8px;
  padding: 16px;
  font-size: 15px;
  line-height: 1.8;
  background: linear-gradient(180deg, #fbfdff, #ffffff);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78);
}

.paste-textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.12);
}

.paste-tips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.paste-tips span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: #f8fbfd;
}

.bg-tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.bg-tile img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  display: block;
}

.bg-tile strong,
.bg-tile span {
  display: block;
  padding: 8px 10px 0;
}

.bg-tile span {
  padding-top: 3px;
  padding-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.bg-delete {
  width: calc(100% - 20px);
  margin: 0 10px 10px;
  min-height: 34px;
}

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(960px, 100%);
  display: grid;
  grid-template-columns: 0.95fr 1.05fr;
  overflow: hidden;
  box-shadow: var(--shadow-strong);
}

.auth-visual {
  min-height: 560px;
  padding: 38px;
  color: #fff;
  background:
    linear-gradient(rgba(16, 35, 49, 0.30), rgba(16, 35, 49, 0.74)),
    url("/classroom.svg") center/cover;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.auth-visual h1 {
  margin: 0;
  font-size: 42px;
}

.auth-panel {
  padding: 38px;
  background: linear-gradient(180deg, #ffffff, #fbfdff);
}

.tabs {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 20px;
}

.tabs button {
  padding: 10px 22px;
  background: #fff;
}

.tabs button.active {
  background: var(--brand);
  color: #fff;
}

.notice {
  border-left: 4px solid var(--brand-2);
  background: #eef9f8;
  padding: 11px 12px;
  border-radius: 8px;
  color: #24525b;
  line-height: 1.6;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
}

th,
td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.code-credit-input {
  width: 82px;
  height: 34px;
  padding: 0 8px;
  border-radius: 8px;
  font-weight: 800;
}

th {
  color: var(--muted);
  font-size: 12px;
  background: #f7fafc;
  font-weight: 900;
}

.danger {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .shell,
  .grid,
  .auth-card,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .app-header {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
  }

  .header-userbar {
    margin-left: 0;
  }

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

  .student-main,
  .student-tags,
  .trait-target {
    grid-template-columns: 1fr;
  }

  .editor-layout {
    grid-template-columns: 1fr;
  }

  .preview-toolbar {
    grid-template-columns: 1fr;
  }

  .generator-controls {
    position: static;
  }

  .generator-controls .form-grid {
    grid-template-columns: 1fr;
  }

  .generator-controls .field.full {
    grid-column: 1;
  }

  .setting-row {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .bg-current {
    grid-template-columns: 72px 1fr;
  }

  .bg-current .btn {
    grid-column: 1 / -1;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .records-toolbar {
    flex-direction: column;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  .app-header,
  .topbar,
  .panel:first-child,
  .comment-head .actions,
  .bg-picker,
  .btn {
    display: none !important;
  }

  .shell,
  .grid {
    display: block;
  }

  .main,
  .panel,
  .comment-card {
    padding: 0;
    box-shadow: none;
    border: 0;
    background: #fff;
  }

  .comment-sheet {
    width: 100vw;
    height: 100vh;
    aspect-ratio: auto;
    padding: 8vh 8vw;
    page-break-after: always;
    background-size: 100% 100% !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
  }

  .comment-sheet .comment-text {
    border: 0;
    background: rgba(255, 255, 255, 0.62);
    height: 100%;
  }

  body:has(.certificate-sheet) .generator-controls,
  body:has(.certificate-sheet) .preview-toolbar,
  body:has(.certificate-sheet) .cert-template-grid,
  body:has(.certificate-sheet) .topbar {
    display: none !important;
  }

  body:has(.certificate-sheet) .preview-panel {
    display: block !important;
  }

  body:has(.certificate-sheet) .certificate-sheet {
    width: 100vw;
    height: 70.7vw;
    max-height: 100vh;
    box-shadow: none;
    border-radius: 0;
    margin: 0;
    page-break-after: always;
  }
}
