:root {
  color-scheme: light;
  --page: #eef6f4;
  --page-2: #e5eff4;
  --panel: #ffffff;
  --panel-soft: #f7fbfb;
  --ink: #13212b;
  --muted: #617181;
  --quiet: #8a98a6;
  --line: #d7e3e5;
  --line-strong: #b9c9ce;
  --teal: #0f766e;
  --teal-dark: #0a5d57;
  --teal-soft: #dff5f1;
  --blue: #2563eb;
  --blue-soft: #e4edff;
  --amber: #f59e0b;
  --amber-soft: #fff4d6;
  --coral: #f9735b;
  --coral-soft: #ffe8e2;
  --danger: #b42318;
  --shadow-sm: 0 10px 24px rgba(19, 33, 43, 0.08);
  --shadow: 0 22px 58px rgba(19, 33, 43, 0.14);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
}

html {
  background: var(--page);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 10%, rgba(15, 118, 110, 0.16), transparent 28%),
    radial-gradient(circle at 88% 6%, rgba(37, 99, 235, 0.13), transparent 24%),
    linear-gradient(135deg, #f8fbfb 0%, var(--page) 48%, var(--page-2) 100%);
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.pin-gate {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 26px;
}

.pin-layout {
  display: grid;
  grid-template-columns: minmax(0, 460px) minmax(320px, 400px);
  width: min(100%, 940px);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(185, 201, 206, 0.84);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.pin-intro {
  position: relative;
  display: grid;
  min-height: 540px;
  place-items: center;
  overflow: hidden;
  padding: 44px;
  background:
    linear-gradient(145deg, rgba(15, 118, 110, 0.98), rgba(19, 33, 43, 0.94)),
    #0f766e;
}

.pin-intro::before,
.pin-intro::after {
  position: absolute;
  content: "";
  border-radius: 999px;
}

.pin-intro::before {
  right: -120px;
  bottom: -130px;
  width: 310px;
  height: 310px;
  background: rgba(245, 158, 11, 0.36);
}

.pin-intro::after {
  top: 64px;
  left: -84px;
  width: 220px;
  height: 220px;
  background: rgba(37, 99, 235, 0.2);
}

.pin-hero-logo {
  position: relative;
  z-index: 1;
  width: min(82%, 340px);
  height: 160px;
  object-fit: contain;
  filter: drop-shadow(0 24px 34px rgba(0, 0, 0, 0.28));
}

.pin-preview-stack {
  position: absolute;
  right: 48px;
  bottom: 46px;
  display: grid;
  gap: 12px;
}

.mini-page {
  width: 132px;
  background:
    linear-gradient(90deg, var(--teal) 0 46%, transparent 46%),
    linear-gradient(90deg, var(--amber) 0 34%, transparent 34%),
    #ffffff;
  background-size: 74% 10px, 56% 10px, auto;
  background-position: 18px 28px, 18px 52px, center;
  background-repeat: no-repeat;
  border-radius: 6px;
  box-shadow: 0 24px 45px rgba(0, 0, 0, 0.26);
}

.mini-page.tall {
  aspect-ratio: 1 / 1.414;
  transform: rotate(5deg);
}

.mini-page.wide {
  aspect-ratio: 1.414 / 1;
  transform: rotate(-4deg);
}

.pin-card {
  display: grid;
  align-content: center;
  gap: 21px;
  min-height: 540px;
  padding: 40px;
  background: rgba(255, 255, 255, 0.9);
}

.pin-logo {
  width: 148px;
  height: 64px;
  object-fit: contain;
  filter: drop-shadow(0 12px 18px rgba(19, 33, 43, 0.14));
}

.pin-card h1 {
  max-width: 330px;
  font-size: 34px;
  line-height: 1.05;
  letter-spacing: 0;
}

.pin-card p:not(.small-label):not(.status-message) {
  margin-top: 9px;
  color: var(--muted);
  font-weight: 620;
  line-height: 1.45;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 440px) minmax(0, 1fr) minmax(220px, 270px);
  min-height: 100vh;
}

.app-shell.admin-mode {
  grid-template-columns: 1fr;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 100vh;
  padding: 26px;
  overflow: auto;
  background: rgba(255, 255, 255, 0.94);
  border-right: 1px solid var(--line);
  box-shadow: 12px 0 40px rgba(19, 33, 43, 0.06);
}

.brand-row,
.admin-header > div {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  flex: 0 0 112px;
  width: 112px;
  height: 50px;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 10px 16px rgba(19, 33, 43, 0.14));
}

.brand-row h1,
.admin-header h1 {
  font-size: 23px;
  line-height: 1.08;
  letter-spacing: 0;
}

.brand-row p,
.admin-header p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 620;
  line-height: 1.35;
}

.account-name {
  display: inline-flex;
  width: fit-content;
  margin-top: 9px;
  padding: 6px 9px;
  color: var(--teal-dark);
  background: var(--teal-soft);
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 780;
}

.teacher-stats,
.admin-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.teacher-stats div,
.admin-stats div {
  min-width: 0;
  padding: 12px;
  background: linear-gradient(180deg, #ffffff, #f6fbfa);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.teacher-stats span,
.admin-stats span {
  display: block;
  color: var(--quiet);
  font-size: 10px;
  font-weight: 820;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.teacher-stats strong,
.admin-stats strong {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: var(--ink);
  font-size: 18px;
  font-weight: 880;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.form-stack {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 19px;
}

.control-section {
  display: grid;
  gap: 13px;
  padding-top: 17px;
  border-top: 1px solid var(--line);
}

.control-section:first-child {
  padding-top: 0;
  border-top: 0;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.section-heading.compact {
  align-items: center;
}

.step-mark {
  display: grid;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  place-items: center;
  color: #ffffff;
  background: var(--teal);
  border-radius: 50%;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.22);
  font-size: 13px;
  font-weight: 860;
}

.section-heading h2 {
  font-size: 15px;
  font-weight: 840;
  line-height: 1.25;
}

.section-heading p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 560;
  line-height: 1.35;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend,
.input-block span,
.small-label,
.search-box span {
  display: block;
  margin-bottom: 8px;
  color: #526271;
  font-size: 11px;
  font-weight: 820;
  letter-spacing: 0.08em;
  line-height: 1.2;
  text-transform: uppercase;
}

.choice-card-grid,
.subject-grid,
.template-grid,
.select-grid,
.filter-grid {
  display: grid;
  gap: 9px;
}

.choice-card-grid,
.subject-grid,
.select-grid,
.filter-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.grade-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

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

.compact-controls {
  display: grid;
  grid-template-columns: 0.82fr 1.18fr;
  gap: 12px;
}

.choice-card,
.choice-button,
.template-card,
.revision-chips button,
.history-actions button,
.history-actions a,
.admin-actions button,
.admin-fields button,
.bulk-actions button {
  color: var(--ink);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition:
    background 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    color 0.16s ease,
    transform 0.16s ease;
}

.choice-card {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  min-height: 88px;
  padding: 13px;
  text-align: left;
}

.choice-card strong,
.choice-card small {
  display: block;
}

.choice-card strong {
  font-size: 14px;
  font-weight: 830;
  line-height: 1.2;
}

.choice-card small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 560;
  line-height: 1.25;
}

.choice-icon {
  position: relative;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: var(--teal);
  background: var(--teal-soft);
  border-radius: var(--radius);
}

.choice-icon::before,
.choice-icon::after {
  position: absolute;
  content: "";
}

.doc-icon::before,
.handout-icon::before {
  width: 18px;
  height: 22px;
  border: 2px solid currentColor;
  border-radius: 3px;
}

.doc-icon::after {
  width: 12px;
  height: 2px;
  background: currentColor;
  box-shadow: 0 6px 0 currentColor;
}

.handout-icon::after {
  width: 16px;
  height: 2px;
  background: currentColor;
  box-shadow: 0 6px 0 currentColor, 0 12px 0 currentColor;
}

.choice-button {
  min-height: 43px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.choice-card:hover,
.choice-button:hover,
.template-card:hover,
.revision-chips button:hover,
.history-actions button:hover,
.history-actions a:hover,
.admin-actions button:hover,
.admin-fields button:hover,
.bulk-actions button:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.choice-card.is-selected,
.choice-button.is-selected,
.template-card.is-active {
  color: #ffffff;
  background: var(--teal);
  border-color: var(--teal);
  box-shadow: 0 12px 24px rgba(15, 118, 110, 0.22);
}

.choice-card.is-selected small,
.choice-card.is-selected .choice-icon {
  color: #e9fffb;
}

.choice-card.is-selected .choice-icon {
  background: rgba(255, 255, 255, 0.16);
}

.template-card {
  min-height: 72px;
  padding: 12px;
  text-align: left;
}

.template-card strong,
.template-card span {
  display: block;
}

.template-card strong {
  font-size: 13px;
  font-weight: 830;
  line-height: 1.2;
}

.template-card span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.template-card.is-active span {
  color: rgba(255, 255, 255, 0.82);
}

.input-block,
.search-box {
  display: block;
}

input,
select,
textarea {
  width: 100%;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: 0;
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    background 0.16s ease;
}

input,
select {
  height: 46px;
  padding: 0 13px;
  font-size: 14px;
  font-weight: 650;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 20px,
    calc(100% - 12px) 20px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

textarea {
  min-height: 132px;
  padding: 13px 14px;
  resize: vertical;
  font-size: 14px;
  line-height: 1.46;
}

input:focus,
select:focus,
textarea:focus {
  background: #ffffff;
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.14);
}

::placeholder {
  color: #9aa8b4;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.summary-strip div {
  min-width: 0;
  padding: 11px 10px;
  background: #ffffff;
}

.summary-strip span,
.summary-strip strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-strip span {
  color: var(--quiet);
  font-size: 10px;
  font-weight: 820;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.summary-strip strong {
  margin-top: 3px;
  font-size: 13px;
  font-weight: 830;
}

.primary-button,
.secondary-button,
.download-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 50px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 830;
  line-height: 1;
  text-decoration: none;
}

.button-plus,
.download-icon {
  position: relative;
  width: 20px;
  height: 20px;
}

.button-plus::before,
.button-plus::after,
.download-icon::before,
.download-icon::after {
  position: absolute;
  content: "";
  background: currentColor;
}

.button-plus::before {
  top: 9px;
  left: 2px;
  width: 16px;
  height: 2px;
}

.button-plus::after {
  top: 2px;
  left: 9px;
  width: 2px;
  height: 16px;
}

.download-icon::before {
  top: 2px;
  left: 9px;
  width: 2px;
  height: 12px;
}

.download-icon::after {
  left: 4px;
  bottom: 2px;
  width: 12px;
  height: 2px;
  box-shadow: 5px -6px 0 -4px currentColor, -5px -6px 0 -4px currentColor;
}

.primary-button {
  width: 100%;
  color: #ffffff;
  background: linear-gradient(135deg, var(--teal), #0e5f99);
  border: 1px solid rgba(15, 118, 110, 0.92);
  box-shadow: 0 16px 32px rgba(15, 118, 110, 0.25);
  cursor: pointer;
}

.primary-button:hover,
.download-button:not(.is-disabled):hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled,
.bulk-actions button:disabled {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

.secondary-button {
  width: 100%;
  color: var(--teal-dark);
  background: var(--teal-soft);
  border: 1px solid rgba(15, 118, 110, 0.3);
  cursor: pointer;
}

.ghost-button {
  width: 100%;
  min-height: 42px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: 13px;
}

.ghost-button.compact {
  width: auto;
  min-width: 120px;
  padding: 0 16px;
}

.status-message {
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 590;
  line-height: 1.4;
}

.status-message.is-error {
  color: var(--danger);
}

.revision-panel {
  display: grid;
  gap: 13px;
  padding: 18px;
  background: linear-gradient(135deg, rgba(223, 245, 241, 0.8), rgba(255, 255, 255, 0.92));
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: var(--radius);
}

.revision-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.revision-chips button {
  min-height: 32px;
  padding: 0 10px;
  color: var(--teal-dark);
  background: #edf8f6;
  font-size: 12px;
  font-weight: 780;
}

.output-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 100vh;
  padding: 26px;
  gap: 18px;
}

.output-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 18px 20px;
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid rgba(215, 227, 229, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(16px);
}

.output-toolbar .small-label {
  margin-bottom: 7px;
}

.output-toolbar h2 {
  max-width: min(720px, 48vw);
  overflow: hidden;
  font-size: 22px;
  font-weight: 820;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.download-button {
  flex: 0 0 auto;
  min-width: 146px;
  padding: 0 18px;
  color: #ffffff;
  background: var(--teal);
  border: 1px solid var(--teal);
  box-shadow: 0 16px 34px rgba(15, 118, 110, 0.22);
}

.download-button.is-disabled {
  pointer-events: none;
  color: #83909d;
  background: #e2e9e7;
  border-color: #e2e9e7;
  box-shadow: none;
}

.preview-stage {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  padding: 30px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.42) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.42) 1px, transparent 1px),
    radial-gradient(circle at 28% 18%, rgba(249, 115, 91, 0.15), transparent 22%),
    radial-gradient(circle at 78% 30%, rgba(37, 99, 235, 0.13), transparent 24%),
    linear-gradient(135deg, #dfecea, #edf5f3 62%, #dce8ef);
  background-size: 34px 34px, 34px 34px, auto, auto, auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.78),
    var(--shadow-sm);
}

#generatedImage {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 210px);
  object-fit: contain;
  background: #ffffff;
  border-radius: 2px;
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.9),
    0 28px 62px rgba(19, 33, 43, 0.24);
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 18px;
  color: var(--muted);
  text-align: center;
}

.empty-state h3 {
  color: var(--ink);
  font-size: 22px;
  font-weight: 830;
  line-height: 1.2;
}

.empty-state p {
  max-width: 340px;
  margin-top: 7px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
}

.paper-icon {
  display: grid;
  width: min(38vw, 285px);
  max-width: 285px;
  aspect-ratio: 1 / 1.414;
  align-content: start;
  gap: 16px;
  padding: 34px 30px;
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.paper-icon span {
  display: block;
  height: 14px;
  background: linear-gradient(90deg, var(--teal), #79d0c5);
  border-radius: 999px;
}

.paper-icon span:nth-child(2) {
  width: 78%;
  background: linear-gradient(90deg, var(--amber), #fbd38d);
}

.paper-icon span:nth-child(3) {
  width: 90%;
  background: linear-gradient(90deg, var(--blue), #93c5fd);
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--teal-dark);
  background: rgba(238, 246, 244, 0.84);
  backdrop-filter: blur(10px);
  font-size: 15px;
  font-weight: 800;
  text-align: center;
}

.loading-overlay small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(15, 118, 110, 0.18);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

.image-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: #526271;
  font-size: 13px;
  font-weight: 760;
}

.image-meta span {
  padding: 9px 11px;
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.history-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  min-height: 100vh;
  padding: 22px 16px;
  overflow: auto;
  background: rgba(255, 255, 255, 0.86);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 34px rgba(19, 33, 43, 0.05);
}

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.history-heading .small-label {
  margin-bottom: 5px;
}

.history-heading h2 {
  font-size: 18px;
  font-weight: 850;
  line-height: 1.15;
}

.history-heading span {
  display: grid;
  min-width: 32px;
  height: 32px;
  place-items: center;
  color: var(--teal-dark);
  background: var(--teal-soft);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 850;
}

.library-tools {
  display: grid;
  gap: 10px;
  padding: 14px 0;
}

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

.bulk-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.bulk-actions button,
.admin-actions button,
.admin-fields button,
.history-actions button,
.history-actions a {
  min-height: 34px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
}

.selected-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.history-empty {
  padding: 16px 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 620;
  line-height: 1.45;
}

.history-list {
  display: grid;
  align-content: start;
  gap: 12px;
  padding-top: 4px;
}

.history-item {
  position: relative;
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 8px;
  color: var(--ink);
  background: rgba(247, 251, 251, 0.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 18px rgba(19, 33, 43, 0.06);
}

.history-item.is-active {
  border-color: rgba(15, 118, 110, 0.5);
  box-shadow: 0 12px 24px rgba(15, 118, 110, 0.14);
}

.history-check {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(19, 33, 43, 0.12);
}

.history-check input {
  width: 14px;
  height: 14px;
}

.history-open {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.history-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1.414;
  object-fit: cover;
  object-position: top center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.history-info {
  display: grid;
  gap: 4px;
}

.history-info strong,
.history-info small {
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-info strong {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 13px;
  font-weight: 830;
  line-height: 1.2;
}

.history-info small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}

.history-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

.history-actions button,
.history-actions a {
  color: var(--teal-dark);
  background: #ffffff;
  text-align: center;
}

.history-actions [data-delete-id],
.danger-button {
  color: var(--danger) !important;
}

.admin-panel {
  min-height: 100vh;
  padding: 28px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.admin-stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 18px;
}

.admin-create-panel,
.admin-account-card {
  margin-top: 16px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.admin-create-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(140px, 190px) 150px 150px;
  gap: 12px;
  align-items: end;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.admin-account-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.admin-account-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-account-title strong {
  display: block;
  font-size: 17px;
  font-weight: 850;
}

.admin-account-title span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

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

.toggle-row input {
  width: 18px;
  height: 18px;
}

.admin-fields {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(120px, 160px) 100px 90px 90px;
  gap: 10px;
  align-items: end;
  margin-top: 14px;
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1280px) {
  .app-shell {
    grid-template-columns: minmax(330px, 400px) minmax(0, 1fr);
  }

  .history-panel {
    grid-column: 1 / -1;
    min-height: auto;
    border-top: 1px solid var(--line);
    border-left: 0;
    box-shadow: none;
  }

  .history-list {
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  }

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

@media (max-width: 980px) {
  .app-shell,
  .pin-layout {
    grid-template-columns: 1fr;
  }

  .pin-intro {
    display: none;
  }

  .pin-card {
    min-height: auto;
  }

  .control-panel {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: none;
  }

  .output-panel {
    min-height: 720px;
  }

  .admin-create-form,
  .admin-fields,
  .admin-stats {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 640px) {
  .pin-gate,
  .control-panel,
  .output-panel,
  .admin-panel {
    padding: 18px;
  }

  .pin-card {
    padding: 26px;
  }

  .brand-row,
  .admin-header > div {
    align-items: flex-start;
  }

  .brand-logo {
    flex-basis: 96px;
    width: 96px;
    height: 44px;
  }

  .choice-card-grid,
  .subject-grid,
  .template-grid,
  .select-grid,
  .summary-strip,
  .compact-controls,
  .filter-grid,
  .admin-create-form,
  .admin-fields,
  .admin-stats,
  .teacher-stats {
    grid-template-columns: 1fr;
  }

  .grade-grid {
    grid-template-columns: repeat(5, minmax(42px, 1fr));
  }

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

  .output-toolbar h2 {
    max-width: calc(100vw - 76px);
  }

  .download-button {
    width: 100%;
  }

  .preview-stage {
    padding: 18px;
  }

  #generatedImage {
    max-height: 720px;
  }
}
