:root {
  --ink: #171716;
  --paper: #f2eee7;
  --paper-deep: #e7dfd4;
  --white: #fffdf9;
  --rose: #c56f69;
  --rose-deep: #924d4a;
  --blue: #4f8498;
  --blue-deep: #315d6d;
  --sage: #687866;
  --line: rgba(23, 23, 22, 0.16);
  --surface: rgba(255, 253, 249, 0.94);
  --muted: #5e5952;
  --muted-soft: #777168;
  --field: #fffdf9;
  --button-text: #fffdf9;
  --error: #a12b2b;
  --success: #426344;
  --warning: #855d1d;
  --shadow: 0 18px 50px rgba(45, 35, 28, 0.12);
  --serif: "Nanum Myeongjo", Georgia, serif;
  --sans: "DM Sans", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  scroll-behavior: smooth;
}

html[data-theme="gothic"] {
  color-scheme: dark;
  --ink: #f2e9df;
  --paper: #100e12;
  --paper-deep: #1a161d;
  --white: #1d1920;
  --rose: #c66c7c;
  --rose-deep: #e5a0ad;
  --blue: #a38aaa;
  --blue-deep: #503a55;
  --sage: #8f9c8c;
  --line: rgba(242, 233, 223, 0.18);
  --surface: rgba(27, 23, 30, 0.96);
  --muted: #c5bab0;
  --muted-soft: #a99e95;
  --field: #171319;
  --button-text: #100e12;
  --error: #ff9b9b;
  --success: #a8d1a4;
  --warning: #e8c681;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 12%, rgba(197, 111, 105, 0.12), transparent 28rem),
    linear-gradient(135deg, var(--paper), #ece7df);
  font-family: var(--sans);
  min-height: 100vh;
}

html[data-theme="gothic"] body {
  background:
    radial-gradient(circle at 14% 9%, rgba(126, 47, 68, 0.23), transparent 28rem),
    linear-gradient(135deg, #100e12, #19141b);
}

button,
input,
select {
  font: inherit;
}

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

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: 1rem;
  z-index: 100;
  padding: 0.75rem 1rem;
  background: var(--ink);
  color: var(--paper);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: inherit;
  text-decoration: none;
}

.brand img {
  width: 56px;
  height: 70px;
  object-fit: contain;
}

.brand span {
  display: flex;
  flex-direction: column;
}

.brand strong {
  font-family: var(--serif);
  font-size: 1.05rem;
}

.brand small {
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 0.75rem;
}

.quiet-link,
.theme-toggle {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  border: 0;
  padding: 0.4rem;
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
  text-decoration: underline;
  text-underline-offset: 0.3rem;
  white-space: nowrap;
  cursor: pointer;
}

.quiet-link:hover,
.theme-toggle:hover {
  color: var(--rose-deep);
}

.text-button {
  color: var(--ink);
  font-weight: 700;
  font-size: 0.9rem;
  text-underline-offset: 0.3rem;
  background: none;
  border: 0;
  padding: 0.4rem;
  cursor: pointer;
  text-decoration: underline;
}

.student-shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 3rem auto;
  display: grid;
  grid-template-columns: minmax(0, 0.82fr) minmax(420px, 1.18fr);
  gap: clamp(2rem, 6vw, 6rem);
  align-items: start;
}

.intro-panel {
  position: sticky;
  top: 2rem;
  padding-top: 2rem;
}

.eyebrow,
.section-kicker {
  margin: 0 0 0.75rem;
  color: var(--rose-deep);
  font-size: 0.77rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  font-family: var(--serif);
  margin-top: 0;
}

h1 {
  margin-bottom: 1.4rem;
  font-size: clamp(2.6rem, 6vw, 5.4rem);
  line-height: 0.98;
  font-weight: 400;
}

h2 {
  margin-bottom: 0.65rem;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
}

h3 {
  margin-bottom: 0.5rem;
  font-size: 1.6rem;
}

p {
  line-height: 1.65;
}

.intro-copy {
  max-width: 34rem;
  color: var(--muted);
  font-size: 1.08rem;
}

.mini-steps {
  list-style: none;
  margin-top: 2rem;
  padding: 0;
  border-top: 1px solid var(--line);
}

.mini-steps li {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
  font-family: var(--serif);
  font-size: 1.05rem;
}

.work-panel,
.login-card,
.creator-card,
.activity-list-card,
.detail-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.work-panel {
  padding: clamp(1.5rem, 5vw, 3.5rem);
  border-radius: 0.5rem;
}

.status {
  min-height: 1.5rem;
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.status[data-tone="error"] {
  color: var(--error);
}

.status[data-tone="success"] {
  color: var(--success);
}

.status[data-tone="warning"] {
  color: var(--warning);
}

.stacked-form {
  display: grid;
  gap: 0.7rem;
  margin-top: 1.5rem;
}

.stacked-form label {
  margin-top: 0.5rem;
  font-size: 0.83rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  background: var(--field);
  color: var(--ink);
  padding: 0.95rem 1rem;
}

input::placeholder {
  color: var(--muted-soft);
}

.code-input {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 46px;
  border-radius: 0.25rem;
  padding: 0.85rem 1.1rem;
  border: 1px solid transparent;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}

.primary-button {
  background: var(--ink);
  color: var(--button-text);
}

.secondary-button {
  background: transparent;
  border-color: var(--ink);
  color: var(--ink);
}

.danger-button {
  background: transparent;
  border-color: var(--error);
  color: var(--error);
}

.primary-button:hover,
.secondary-button:hover,
.danger-button:hover {
  transform: translateY(-2px);
}

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

.activity-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
}

.activity-heading p {
  margin: 0.25rem 0;
}

#change-class-button {
  flex-shrink: 0;
  white-space: nowrap;
}

.stage {
  padding: 2rem 0;
  border-top: 1px solid var(--line);
}

.stage-content > p {
  color: var(--muted);
  margin-top: 0;
}

.prompt-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

.saved-card,
.final-card {
  border-radius: 0.35rem;
  padding: 1.25rem;
}

.saved-card {
  background: var(--paper);
  border: 1px solid var(--line);
}

.saved-card span {
  display: block;
  color: var(--muted-soft);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.saved-card strong {
  display: block;
  margin-top: 0.5rem;
  font-family: var(--serif);
  font-size: 1.25rem;
}

.prompt-grid {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.prompt-card {
  width: 100%;
  height: 100%;
  min-height: 84px;
  border: 1px solid rgba(79, 132, 152, 0.35);
  border-radius: 0.3rem;
  padding: 1rem;
  background: rgba(79, 132, 152, 0.11);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.08rem;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease;
}

.prompt-card:hover {
  background: rgba(197, 111, 105, 0.18);
  transform: translateY(-2px);
}

.empty-state {
  color: var(--muted-soft);
  font-style: italic;
}

.final-card {
  margin-top: 1rem;
  color: white;
  background: var(--blue-deep);
}

.final-card .section-kicker {
  color: #d6dfe2;
}

.final-card blockquote {
  margin: 1.5rem 0;
  font-family: var(--serif);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
}

.confirm-dialog {
  width: min(480px, calc(100% - 2rem));
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  padding: 2rem;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.28);
}

.confirm-dialog::backdrop {
  background: rgba(20, 18, 16, 0.65);
  backdrop-filter: blur(3px);
}

.confirm-dialog blockquote {
  margin: 1.5rem 0;
  border-left: 3px solid var(--rose);
  padding-left: 1rem;
  font-family: var(--serif);
  font-size: 1.35rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
  margin-top: 1.5rem;
}

footer {
  width: min(1180px, calc(100% - 2rem));
  margin: 2rem auto;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8rem;
}

footer span {
  color: var(--ink);
  font-weight: 700;
}

/* Teacher dashboard */
#teacher-status {
  text-align: center;
}

.teacher-shell {
  width: min(1280px, calc(100% - 2rem));
  margin: 2.5rem auto;
}

.login-card {
  width: min(520px, 100%);
  margin: 3rem auto;
  padding: clamp(1.5rem, 5vw, 3rem);
  border-radius: 0.5rem;
}

.login-card h1,
.dashboard-header h1 {
  font-size: clamp(2.4rem, 5vw, 4.2rem);
}

.dashboard-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 1.4rem;
  align-items: start;
}

.dashboard-sidebar {
  display: grid;
  gap: 1rem;
}

.creator-card,
.activity-list-card,
.detail-panel {
  border-radius: 0.5rem;
  padding: 1.2rem;
}

.creator-card summary {
  cursor: pointer;
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 700;
}

.compact-form {
  margin-top: 1rem;
}

.simple-list {
  margin: 1rem 0 0;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.activity-list-card h2 {
  font-size: 1.3rem;
}

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.activity-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  padding: 0.8rem;
  text-align: left;
  background: var(--field);
  color: var(--ink);
  cursor: pointer;
}

.activity-row span:first-child {
  display: grid;
  gap: 0.25rem;
}

.activity-row small {
  color: var(--muted-soft);
}

.activity-row.is-selected {
  border-color: var(--blue);
  background: rgba(79, 132, 152, 0.1);
}

.activity-row.is-archived {
  opacity: 0.68;
}

.code-chip {
  padding: 0.3rem 0.4rem;
  border-radius: 0.2rem;
  color: var(--ink);
  background: rgba(79, 132, 152, 0.13);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.detail-panel {
  padding: clamp(1.4rem, 4vw, 2.4rem);
}

.detail-heading,
.roster-heading,
.danger-zone {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.class-code-card {
  min-width: 165px;
  padding: 0.9rem;
  border-radius: 0.3rem;
  background: var(--ink);
  color: var(--paper);
  text-align: center;
}

.class-code-card span {
  display: block;
  color: #bbb7af;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.class-code-card strong {
  display: block;
  margin: 0.25rem 0;
  font-size: 1.45rem;
  letter-spacing: 0.15em;
}

.class-code-card .text-button {
  color: var(--paper);
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin: 2rem 0;
}

.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  padding: 1rem;
}

.switch-row span {
  display: grid;
  gap: 0.25rem;
}

.switch-row small {
  color: var(--muted);
}

.switch-row input {
  width: 1.35rem;
  height: 1.35rem;
  accent-color: var(--blue-deep);
}

.roster-heading {
  margin-top: 2.5rem;
}

.roster-heading h3 {
  margin-bottom: 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  padding: 0.85rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.danger-zone {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.danger-zone p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

@media (max-width: 850px) {
  .student-shell,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .intro-panel {
    position: static;
    padding-top: 0;
  }

  .intro-panel h1 {
    max-width: 12ch;
  }

  .mini-steps {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .mini-steps li {
    padding-right: 0.75rem;
    font-size: 0.9rem;
  }
}

@media (max-width: 620px) {
  .site-header {
    align-items: center;
  }

  .brand img {
    width: 44px;
    height: 56px;
  }

  .header-actions {
    flex-direction: row;
    gap: 0.5rem;
  }

  .quiet-link,
  .theme-toggle {
    font-size: 0.8rem;
  }

  .student-shell {
    margin-top: 1.5rem;
  }

  .work-panel {
    padding: 1.25rem;
    border-radius: 0.35rem;
  }

  .prompt-form,
  .prompt-grid,
  .control-row {
    grid-template-columns: 1fr;
  }

  .activity-heading,
  .dashboard-header,
  .detail-heading,
  .roster-heading,
  .danger-zone {
    align-items: stretch;
    flex-direction: column;
  }

  .class-code-card {
    width: 100%;
  }

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

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

@media (max-width: 420px) {
  .site-header {
    flex-wrap: wrap;
    row-gap: 0.5rem;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
