:root {
  --bg: #f7f3fb;
  --bg-green: #f1faf5;
  --surface: #ffffff;
  --surface-soft: #fbfafc;
  --text: #221b2e;
  --muted: #6f657a;
  --line: #ded6e8;
  --line-strong: #cbbfd9;
  --green: #149a78;
  --green-strong: #08755c;
  --green-soft: #e4f6ef;
  --purple: #6d4bd9;
  --purple-strong: #4d319e;
  --purple-soft: #eee8fb;
  --plum: #342144;
  --amber: #9b6815;
  --danger: #b33a54;
  --danger-soft: #fde9ef;
  --blue: #365f99;
  --shadow: 0 18px 46px rgba(52, 33, 68, 0.10);
  --shadow-soft: 0 10px 28px rgba(52, 33, 68, 0.07);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(238, 232, 251, 0.92) 0%, rgba(241, 250, 245, 0.92) 42%, rgba(250, 248, 252, 0.96) 100%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: var(--purple-strong);
  text-decoration: none;
  font-weight: 700;
}

a:hover {
  color: var(--green-strong);
  text-decoration: none;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(109, 75, 217, 0.28);
  outline-offset: 2px;
}

.topbar {
  min-height: 68px;
  padding: 12px clamp(16px, 4vw, 40px);
  display: flex;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid rgba(109, 75, 217, 0.16);
  background: rgba(255, 255, 255, 0.86);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(16px);
  box-shadow: 0 1px 0 rgba(20, 154, 120, 0.08);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--plum);
  font-weight: 900;
}

.brand:hover {
  color: var(--plum);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--green), var(--purple));
  color: white;
  box-shadow: 0 12px 24px rgba(109, 75, 217, 0.22);
}

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

.nav a {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 800;
}

.nav a:hover {
  background: var(--purple-soft);
  color: var(--purple-strong);
}

.account {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-weight: 700;
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 30px auto 68px;
}

.auth-layout {
  min-height: calc(100vh - 160px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  gap: clamp(28px, 7vw, 92px);
  align-items: center;
}

.auth-copy {
  padding-left: clamp(0px, 2vw, 28px);
  border-left: 5px solid var(--green);
}

.auth-copy h1,
.page-header h1 {
  margin: 0;
  color: var(--plum);
  font-size: clamp(32px, 5vw, 54px);
  line-height: 1.02;
  letter-spacing: 0;
}

.auth-copy p {
  max-width: 560px;
  color: var(--muted);
  font-size: 18px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--green-strong);
  font-weight: 900;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0;
}

.auth-panel,
.panel,
.stat,
.referral-box {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(109, 75, 217, 0.14);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.auth-panel,
.panel {
  padding: 22px;
}

.auth-panel {
  display: grid;
  gap: 16px;
  border-top: 4px solid var(--purple);
  box-shadow: var(--shadow);
}

.panel {
  position: relative;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(90deg, var(--green), var(--purple));
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 22px;
}

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

.wide-panel,
.stats-grid {
  margin-bottom: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat {
  padding: 18px;
  border-color: rgba(20, 154, 120, 0.16);
}

.stat span,
.referral-box span,
.meta-list dt,
.hint,
.muted,
.empty,
small {
  color: var(--muted);
}

.stat strong {
  display: block;
  margin-top: 4px;
  color: var(--purple-strong);
  font-size: 26px;
}

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

.panel-heading h2 {
  margin: 0;
  color: var(--plum);
  font-size: 20px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--plum);
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--line-strong);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--purple);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(109, 75, 217, 0.10);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--green);
}

input[type="file"]::file-selector-button {
  margin-right: 12px;
  border: 0;
  border-radius: 8px;
  padding: 8px 11px;
  background: var(--purple-soft);
  color: var(--purple-strong);
  font: inherit;
  font-weight: 800;
}

textarea {
  resize: vertical;
}

form {
  margin: 0;
}

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

.compact-form {
  margin-top: 2px;
}

.code-input {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 4px;
  text-align: center;
}

.primary-button,
.ghost-button,
.danger-button,
.ghost-link-button {
  border: 0;
  border-radius: 8px;
  padding: 11px 14px;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--green), var(--green-strong));
  color: white;
  box-shadow: 0 12px 22px rgba(20, 154, 120, 0.20);
}

.primary-button:hover {
  background: linear-gradient(135deg, #18a983, var(--green-strong));
  transform: translateY(-1px);
  box-shadow: 0 16px 26px rgba(20, 154, 120, 0.24);
}

.ghost-button {
  background: var(--purple-soft);
  color: var(--purple-strong);
}

.ghost-link-button {
  display: inline-flex;
  justify-content: center;
  background: var(--purple-soft);
  color: var(--purple-strong);
}

.ghost-button:hover,
.ghost-link-button:hover {
  background: #e4daf8;
  color: var(--purple-strong);
}

button:disabled,
select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.danger-button {
  background: var(--danger);
  color: white;
}

.danger-button:hover {
  background: #982d45;
}

.compact {
  padding: 8px 11px;
  white-space: nowrap;
}

.badge,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.badge {
  background: var(--green-soft);
  color: var(--green-strong);
}

.muted-badge {
  background: var(--purple-soft);
  color: var(--purple-strong);
}

.status.pending,
.status.open,
.status.started {
  background: #fff4dc;
  color: var(--amber);
}

.status.assigned,
.status.replied,
.status.answered {
  background: var(--purple-soft);
  color: var(--purple-strong);
}

.status.closed,
.status.submitted {
  background: var(--green-soft);
  color: var(--green-strong);
}

.status.big {
  font-size: 15px;
  padding: 8px 12px;
}

.referral-box {
  padding: 12px 14px;
  display: grid;
  gap: 2px;
  min-width: 190px;
  border-color: rgba(20, 154, 120, 0.18);
}

.referral-box strong {
  color: var(--purple-strong);
  font-size: 18px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid rgba(109, 75, 217, 0.12);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

th,
td {
  padding: 13px 11px;
  text-align: left;
  border-bottom: 1px solid rgba(109, 75, 217, 0.10);
  vertical-align: middle;
}

tbody tr:hover {
  background: rgba(238, 232, 251, 0.32);
}

th {
  background: rgba(238, 232, 251, 0.44);
  color: var(--purple-strong);
  font-size: 13px;
  font-weight: 900;
}

.stack-list,
.message-list {
  display: grid;
  gap: 10px;
}

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

.lecture-card {
  min-height: 150px;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 16px;
  border: 1px solid rgba(109, 75, 217, 0.14);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #fbf9fe);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.lecture-card:hover {
  border-color: rgba(20, 154, 120, 0.35);
  color: var(--text);
  transform: translateY(-1px);
}

.lecture-card strong {
  color: var(--plum);
  font-size: 18px;
}

.lecture-course,
.lecture-meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.lecture-course {
  color: var(--green-strong);
}

.lecture-description {
  margin: 0 0 16px;
  color: var(--muted);
}

.lesson-materials {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.lesson-materials span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-strong);
  font-size: 12px;
  font-weight: 900;
}

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

.material-card {
  min-height: 108px;
  display: grid;
  align-content: start;
  gap: 7px;
  padding: 14px;
  border: 1px solid rgba(109, 75, 217, 0.14);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f6fff9);
  color: var(--text);
}

.material-card:hover {
  border-color: rgba(20, 154, 120, 0.38);
  color: var(--text);
  box-shadow: 0 8px 18px rgba(52, 33, 68, 0.06);
}

.material-card span {
  color: var(--green-strong);
  font-size: 12px;
  font-weight: 900;
}

.material-card strong {
  color: var(--plum);
}

.video-shell {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(109, 75, 217, 0.18);
  border-radius: 8px;
  background: #100b18;
  box-shadow: var(--shadow);
}

.lecture-video {
  display: block;
  width: 100%;
  max-height: min(70vh, 720px);
  background: #100b18;
}

.video-watermark {
  position: absolute;
  pointer-events: none;
  user-select: none;
  color: rgba(255, 255, 255, 0.30);
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

.video-watermark.corner {
  right: 16px;
  bottom: 14px;
  font-size: 13px;
  opacity: 0.55;
}

.video-watermark.ghost {
  left: 50%;
  top: 50%;
  width: 90%;
  transform: translate(-50%, -50%) rotate(-18deg);
  text-align: center;
  font-size: clamp(22px, 4vw, 52px);
  opacity: 0.08;
  letter-spacing: 0;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid rgba(109, 75, 217, 0.14);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #fbf9fe);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.list-row:hover {
  border-color: rgba(20, 154, 120, 0.35);
  box-shadow: 0 8px 18px rgba(52, 33, 68, 0.06);
}

.list-row span {
  min-width: 0;
}

.list-row strong,
.list-row small {
  display: block;
  overflow-wrap: anywhere;
}

.role-list .list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 130px auto;
}

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

.access-card {
  border: 1px solid rgba(109, 75, 217, 0.14);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
}

.access-head,
.role-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
}

.access-head {
  align-items: start;
  margin-bottom: 12px;
}

.access-head strong,
.access-head small {
  display: block;
  overflow-wrap: anywhere;
}

.course-checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid rgba(109, 75, 217, 0.14);
  border-radius: 8px;
  background: var(--surface-soft);
  font-weight: 800;
}

.check-row:hover {
  border-color: rgba(20, 154, 120, 0.38);
  background: #ffffff;
}

.admin-check-row {
  background: var(--purple-soft);
}

.form-caption {
  margin: 14px 0 0;
  color: var(--purple-strong);
  font-weight: 900;
}

.meta-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.meta-list div {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 14px;
}

.meta-list dt,
.meta-list dd {
  margin: 0;
}

.message {
  padding: 14px;
  border: 1px solid rgba(109, 75, 217, 0.14);
  border-radius: 8px;
  background: #ffffff;
}

.message header {
  margin-bottom: 8px;
  color: var(--purple-strong);
  font-size: 13px;
  font-weight: 900;
}

.message p {
  margin: 0 0 10px;
  white-space: pre-wrap;
}

blockquote {
  margin: 10px 0 0;
  padding: 11px 0 11px 14px;
  border-left: 4px solid var(--green);
  color: var(--text);
  background: rgba(228, 246, 239, 0.46);
}

.inline-form,
.rating-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
}

.rating-form {
  grid-template-columns: 150px minmax(0, 1fr) auto;
}

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

.top-gap {
  margin-top: 14px;
}

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 18px;
  border: 1px solid rgba(179, 58, 84, 0.22);
}

.alert.error {
  background: var(--danger-soft);
  color: #83263a;
}

.alert.success {
  border-color: rgba(20, 154, 120, 0.24);
  background: var(--green-soft);
  color: var(--green-strong);
}

.game-titlebar {
  align-items: center;
}

.game-personal {
  min-width: 170px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
  align-items: start;
}

.game-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(109, 75, 217, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.game-hud {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 14px;
  z-index: 3;
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) 88px;
  gap: 12px;
  align-items: center;
  pointer-events: none;
}

.game-hud > div:not(.game-timer) {
  min-height: 56px;
  padding: 8px 10px;
  border: 1px solid rgba(109, 75, 217, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 8px 18px rgba(52, 33, 68, 0.08);
}

.game-hud span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.game-hud strong {
  display: block;
  color: var(--plum);
  font-size: 24px;
  line-height: 1;
}

.game-timer {
  height: 16px;
  overflow: hidden;
  border: 1px solid rgba(20, 154, 120, 0.24);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
}

.game-timer span {
  width: 100%;
  height: 100%;
  display: block;
  transform-origin: left center;
  background: linear-gradient(90deg, var(--green), var(--purple));
}

.game-canvas-shell {
  position: relative;
}

.lumberjack-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 6 / 7;
  min-height: 480px;
  touch-action: manipulation;
}

.game-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: none;
  place-items: center;
  gap: 14px;
  align-content: center;
  background: rgba(247, 243, 251, 0.52);
  backdrop-filter: blur(6px);
}

.game-overlay.is-visible {
  display: grid;
}

.game-overlay strong {
  color: var(--plum);
  font-size: clamp(34px, 6vw, 64px);
  line-height: 1;
}

.game-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 12px;
  border-top: 1px solid rgba(109, 75, 217, 0.12);
  background: rgba(255, 255, 255, 0.92);
}

.lumber-button {
  min-height: 58px;
  font-size: 30px;
  line-height: 1;
}

.leaderboard-panel {
  max-height: calc(100vh - 126px);
  overflow: auto;
}

.leaderboard-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid rgba(109, 75, 217, 0.12);
  border-radius: 8px;
  background: #ffffff;
}

.leaderboard-list li.is-current {
  border-color: rgba(20, 154, 120, 0.36);
  background: var(--green-soft);
}

.leaderboard-list li.empty {
  display: block;
  color: var(--muted);
}

.leader-rank {
  color: var(--purple-strong);
  font-weight: 900;
}

.leader-name {
  overflow: hidden;
  color: var(--plum);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-list strong {
  color: var(--green-strong);
  font-size: 18px;
}

@media (max-width: 860px) {
  .topbar,
  .account,
  .page-header {
    align-items: flex-start;
  }

  .topbar,
  .account {
    flex-direction: column;
  }

  .account {
    margin-left: 0;
  }

  .auth-layout,
  .split-grid,
  .stats-grid,
  .lecture-grid,
  .material-grid,
  .file-grid,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .leaderboard-panel {
    max-height: none;
  }

  .inline-form,
  .rating-form,
  .role-list .list-row,
  .admin-user-list,
  .role-form {
    grid-template-columns: 1fr;
  }

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

  .course-checkbox-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .page {
    width: min(100% - 20px, 1180px);
    margin-top: 18px;
  }

  .auth-panel,
  .panel {
    padding: 16px;
  }

  .game-hud {
    left: 10px;
    right: 10px;
    top: 10px;
    grid-template-columns: 70px minmax(0, 1fr) 70px;
    gap: 8px;
  }

  .game-hud > div:not(.game-timer) {
    min-height: 48px;
    padding: 7px 8px;
  }

  .game-hud strong {
    font-size: 20px;
  }

  .lumberjack-canvas {
    min-height: 390px;
  }

  .meta-list div {
    grid-template-columns: 1fr;
    gap: 2px;
  }

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