:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #62717f;
  --line: #d6dde4;
  --paper: #f7f8f5;
  --panel: #ffffff;
  --teal: #176b67;
  --teal-dark: #0f4f4d;
  --coral: #c5563f;
  --amber: #b9842f;
  --sky: #dcecf4;
  --mint: #e4f1ed;
  --shadow: 0 18px 40px rgba(23, 32, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(220, 236, 244, 0.7), rgba(247, 248, 245, 0) 420px),
    var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.student-view .teacher-only {
  display: none !important;
}

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

button,
.file-action {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.file-action:focus-within {
  outline: 3px solid rgba(23, 107, 103, 0.24);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 28px clamp(18px, 4vw, 44px) 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal-dark);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1;
}

h2 {
  font-size: 1.2rem;
}

h3 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.class-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
}

.class-stats span {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  min-height: 36px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.class-stats strong {
  color: var(--ink);
  font-size: 1.12rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(720px, 1fr) minmax(320px, 420px);
  gap: 18px;
  align-items: start;
  padding: 0 clamp(18px, 4vw, 44px) 34px;
}

.portal-shell {
  display: grid;
  grid-template-columns: minmax(620px, 1fr) minmax(320px, 420px);
  gap: 18px;
  align-items: start;
  padding: 0 clamp(18px, 4vw, 44px) 34px;
}

.portal {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 14px;
  padding: 0 clamp(18px, 4vw, 44px) 34px;
}

.portal-shell .portal {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  padding: 0;
}

.portal-card {
  display: grid;
  gap: 10px;
  min-height: 220px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  text-decoration: none;
  box-shadow: var(--shadow);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.portal-card:hover {
  border-color: rgba(23, 107, 103, 0.55);
  box-shadow: 0 12px 26px rgba(23, 32, 42, 0.14);
  transform: translateY(-2px);
}

.portal-card strong {
  font-size: clamp(2.1rem, 5vw, 4rem);
  line-height: 1;
}

.portal-card span {
  color: var(--muted);
  font-weight: 800;
}

.portal-card .portal-level {
  color: var(--teal-dark);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.class-card {
  min-height: 244px;
}

.portal-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-self: end;
}

.portal-card-actions .primary-button,
.portal-card-actions .ghost-button {
  flex: 1;
}

.seat-section,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.seat-section {
  overflow: auto;
  padding: 18px;
}

.detail-panel {
  position: sticky;
  top: 16px;
  padding: 18px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-heading.compact {
  align-items: flex-start;
}

.toolbar,
.photo-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.primary-button,
.ghost-button,
.danger-button,
.file-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 13px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.primary-button {
  background: var(--teal);
  color: #fff;
}

.primary-button:hover {
  background: var(--teal-dark);
}

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

.ghost-button:hover {
  border-color: #b8c4cc;
  background: #f9fbfb;
}

.danger-button {
  border: 1px solid rgba(197, 86, 63, 0.38);
  background: #fff;
  color: var(--coral);
}

.danger-button:hover {
  background: #fff5f2;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button:disabled:hover {
  background: #fff;
}

.file-action input {
  position: fixed;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.column-labels {
  display: grid;
  grid-template-columns: 38px repeat(8, minmax(74px, 1fr));
  gap: 8px;
  min-width: 698px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
}

.seat-grid {
  display: grid;
  grid-template-columns: 38px repeat(8, minmax(74px, 1fr));
  gap: 8px;
  min-width: 698px;
}

.row-label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 112px;
  border-radius: 8px;
  background: #eef3f2;
  color: var(--teal-dark);
  font-weight: 900;
}

.seat-card {
  display: grid;
  grid-template-rows: 50px auto auto;
  gap: 6px;
  min-height: 112px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  text-align: left;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.seat-card:hover {
  border-color: rgba(23, 107, 103, 0.55);
  box-shadow: 0 8px 20px rgba(23, 32, 42, 0.1);
  transform: translateY(-1px);
}

.seat-card.selected {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(23, 107, 103, 0.15);
}

.seat-card.filled {
  background: linear-gradient(180deg, #fff, var(--mint));
}

.seat-photo {
  width: 50px;
  height: 50px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--sky);
}

.seat-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.seat-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 900;
}

.seat-main {
  min-width: 0;
}

.seat-name {
  overflow: hidden;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 900;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-print-name {
  display: none;
}

.seat-subname,
.seat-code {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-code {
  align-self: end;
  color: var(--amber);
  font-weight: 900;
}

.save-state {
  color: var(--muted);
  font-size: 0.78rem;
  text-align: right;
}

.save-state.error {
  color: var(--coral);
}

.student-form {
  display: grid;
  gap: 16px;
}

.control-panel,
.outside-panel {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.compact-form,
.settings-grid {
  display: grid;
  gap: 10px;
}

.student-points-form {
  grid-template-columns: minmax(92px, 0.72fr) minmax(150px, 1fr);
  align-items: end;
}

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

.settings-grid button {
  grid-column: 1 / -1;
}

.group-list,
.outside-list,
.personal-total-list {
  display: grid;
  gap: 10px;
}

.group-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.group-card-head,
.group-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.group-card-head {
  justify-content: space-between;
}

.group-card-head input {
  min-height: 36px;
}

.group-card strong {
  white-space: nowrap;
}

.group-card p,
.empty-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.points-input {
  max-width: 84px;
}

.outside-item {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  text-align: left;
}

.outside-item:hover {
  border-color: rgba(23, 107, 103, 0.55);
  background: #f9fbfb;
}

.outside-item span {
  color: var(--muted);
  font-size: 0.78rem;
}

.personal-total-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  text-align: left;
}

.personal-total-item:hover {
  border-color: rgba(23, 107, 103, 0.55);
  background: #f9fbfb;
}

.personal-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--mint);
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 900;
}

.personal-total-main {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.personal-total-main strong,
.personal-total-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.personal-total-main span {
  color: var(--muted);
  font-size: 0.76rem;
}

.personal-total-score {
  color: var(--teal-dark);
  font-size: 0.86rem;
  font-weight: 900;
  white-space: nowrap;
}

.photo-zone {
  display: grid;
  grid-template-columns: 126px 1fr;
  gap: 14px;
  align-items: center;
}

.photo-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 126px;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sky);
  color: var(--teal-dark);
  font-size: 1.7rem;
  font-weight: 900;
}

.photo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

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

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

input[readonly] {
  background: #f3f5f6;
  color: var(--muted);
}

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

.form-actions {
  justify-content: space-between;
  padding-top: 2px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 5;
  max-width: min(380px, calc(100vw - 44px));
  padding: 11px 13px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.redirect-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

@media (max-width: 1120px) {
  .workspace,
  .portal-shell {
    grid-template-columns: 1fr;
  }

  .portal,
  .portal-shell .portal {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .detail-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .class-stats {
    justify-content: flex-start;
  }

  .portal,
  .portal-shell .portal {
    grid-template-columns: 1fr;
  }

  .seat-section,
  .detail-panel {
    padding: 14px;
  }

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

  .photo-zone,
  .field-grid,
  .student-points-form {
    grid-template-columns: 1fr;
  }

  .photo-frame {
    width: min(180px, 100%);
  }

  .form-actions {
    flex-direction: column-reverse;
  }

  .form-actions button {
    width: 100%;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .detail-panel,
  .toast {
    display: none;
  }

  .toolbar {
    display: none;
  }

  .workspace {
    display: block;
    padding: 0;
  }

  .seat-section {
    border: 0;
    box-shadow: none;
  }

  .seat-card {
    min-height: 82px;
    grid-template-rows: auto auto;
    page-break-inside: avoid;
  }

  .seat-photo,
  .seat-name {
    display: none;
  }

  .seat-print-name {
    display: block;
    overflow: hidden;
    color: #000;
    font-size: 1rem;
    font-weight: 900;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
