:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #657382;
  --line: #d9e0e7;
  --soft: #f4f7f9;
  --paper: #ffffff;
  --blue: #2563eb;
  --blue-dark: #1e4fc0;
  --green: #1f9d55;
  --red: #d93636;
  --amber: #f2a900;
  --shadow: 0 18px 48px rgba(23, 33, 43, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #eef3f6;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
  transform: translateY(0) scale(1);
}

button:hover {
  transform: translateY(-1px) scale(1.01);
}

button.is-pressed,
button:active {
  transform: translateY(1px) scale(0.98);
}

button:disabled {
  transform: none;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}

.topbar-side {
  display: flex;
  align-items: center;
}

.topbar-left {
  justify-content: flex-start;
}

.topbar-center {
  position: absolute;
  left: 50%;
  display: flex;
  justify-content: center;
  transform: translateX(-50%);
}

.topbar-right {
  justify-content: flex-end;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  text-align: left;
}

.topbar-build {
  min-width: 120px;
}

.topbar-home {
  min-width: 106px;
}

.topbar-play {
  min-width: 180px;
  min-height: 48px;
  padding: 0 28px;
  font-size: 18px;
}

.topbar-profile {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid #cdd8ea;
  border-radius: 999px;
  background: #f5f8ff;
  color: #244db5;
  font-size: 16px;
  font-weight: 800;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

.brand small,
.helper-text,
.workspace-toolbar span,
.activity-card p,
.field span,
.field small {
  color: var(--muted);
}

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

.button-row.compact {
  gap: 8px;
}

.button-row.center {
  justify-content: center;
}

.button-column {
  display: grid;
  gap: 10px;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 42px;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 700;
}

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

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

.secondary-button {
  background: #e9f0ff;
  border-color: #c7d7ff;
  color: #143f93;
}

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

.full {
  width: 100%;
}

main {
  padding: 24px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.menu-grid,
.builder-layout,
.game-layout {
  display: grid;
  gap: 24px;
  max-width: 1280px;
  margin: 0 auto;
}

.builder-layout,
.game-layout {
  grid-template-columns: 360px minmax(0, 1fr);
}

.landing-shell,
.teacher-gate-layout,
.student-library-layout {
  display: grid;
  gap: 24px;
  max-width: 1180px;
  margin: 0 auto;
}

.landing-card,
.student-library-hero,
.student-library-panel {
  background: var(--paper);
  border: 1px solid #d2dbe8;
  border-radius: 96px;
  box-shadow: var(--shadow);
}

.teacher-access-panel {
  background: var(--paper);
  border: 1px solid #d2dbe8;
  border-radius: 36px;
  box-shadow: var(--shadow);
}

.student-library-hero,
.student-library-panel {
  border-radius: 24px;
}

.landing-shell {
  min-height: calc(100vh - 190px);
  place-items: center;
}

.landing-card {
  display: grid;
  justify-items: center;
  gap: 14px;
  width: min(100%, 760px);
  padding: clamp(40px, 6vw, 72px);
  text-align: center;
}

.landing-brand {
  margin: 0;
  color: var(--blue);
  font-size: clamp(20px, 2vw, 28px);
  font-weight: 800;
}

.landing-card h1 {
  margin: 0;
  max-width: 680px;
  font-size: clamp(42px, 7vw, 72px);
  line-height: 0.98;
}

.landing-subtitle,
.support-copy {
  margin: 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.5;
}

.landing-actions {
  display: grid;
  justify-items: center;
  gap: 14px;
  margin-top: 12px;
}

.landing-primary,
.landing-secondary {
  min-width: 240px;
  min-height: 54px;
  padding: 0 24px;
  font-size: 18px;
}

.landing-divider {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.teacher-gate-layout {
  min-height: calc(100vh - 170px);
  place-items: center;
}

.student-library-layout {
  max-width: 1280px;
}

.teacher-access-panel,
.student-library-panel {
  padding: 24px;
}

.teacher-access-panel {
  width: min(100%, 460px);
  padding: 28px;
}

.teacher-access-panel h1 {
  margin: 8px 0 12px;
}

.student-library-hero {
  padding: 18px 24px 16px;
}

.student-library-hero h1 {
  margin: 4px 0 6px;
  font-size: clamp(22px, 3vw, 32px);
  line-height: 1.05;
}

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

.student-filter-row {
  display: flex;
  align-items: end;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.filter-field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.filter-field:first-child {
  width: min(280px, 100%);
}

.filter-field:last-child {
  flex: 1;
}

.filter-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.filter-pill {
  width: 100%;
  min-height: 50px;
  border: 1px solid #d8e3f5;
  border-radius: 999px;
  padding: 0 18px;
  background: #f9fbff;
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.filter-pill:focus {
  outline: none;
  border-color: #9fbdfc;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.filter-field select.filter-pill {
  appearance: none;
  padding-right: 48px;
  background-image:
    linear-gradient(45deg, transparent 50%, #6d7a8b 50%),
    linear-gradient(135deg, #6d7a8b 50%, transparent 50%);
  background-position:
    calc(100% - 22px) calc(50% - 2px),
    calc(100% - 16px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.student-library-summary {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.student-count-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 12px;
  border: 1px solid #d8e3f5;
  border-radius: 999px;
  background: #f7faff;
  color: #546173;
  font-size: 12px;
  font-weight: 700;
}

.student-count-pill strong {
  color: var(--ink);
  font-size: 13px;
}

.library-status {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-align: right;
}

.student-activity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 280px));
  gap: 12px;
  justify-content: center;
}

.library-empty {
  margin: 0;
  padding: 32px 20px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: #fbfcfd;
}

.notice-card {
  display: grid;
  gap: 8px;
  margin: 18px 0 22px;
  padding: 16px;
  border: 1px solid #d8e3f5;
  border-radius: 8px;
  background: #f6f9ff;
}

.notice-card p {
  margin: 0;
  color: var(--muted);
}

.auth-status {
  margin: 10px 0 0;
  min-height: 24px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.auth-status.good {
  color: var(--green);
}

.auth-status.bad {
  color: var(--red);
}

.intro-panel,
.activity-panel,
.builder-sidebar,
.workspace-panel,
.choose-panel,
.game-sidebar,
.result-panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.intro-panel,
.choose-panel,
.result-panel {
  padding: clamp(24px, 5vw, 56px);
}

.intro-panel h1,
.choose-panel h1,
.result-panel h1 {
  margin: 8px 0 14px;
  max-width: 760px;
  font-size: clamp(36px, 6vw, 68px);
  line-height: 1;
  letter-spacing: 0;
}

.intro-panel p {
  max-width: 680px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.6;
}

.eyebrow {
  margin: 0;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.activity-panel,
.builder-sidebar,
.game-sidebar {
  padding: 20px;
}

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

.panel-heading h2,
.builder-sidebar h1,
.game-sidebar h1 {
  margin: 0;
}

.panel-heading span {
  color: var(--muted);
  font-weight: 700;
}

.word-panel-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.activity-list,
.word-list {
  display: grid;
  gap: 10px;
}

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

.activity-card,
.word-item {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.activity-card strong,
.word-item strong {
  overflow-wrap: anywhere;
}

.activity-card p {
  margin: 0;
}

.activity-card.play-card {
  overflow: hidden;
  padding: 0;
  gap: 0;
  min-height: 100%;
  max-width: 280px;
}

.activity-card-media {
  aspect-ratio: 16 / 10;
  background: #dfe8ee;
  overflow: hidden;
}

.activity-card-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.activity-card-body {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.play-card .activity-card-body {
  gap: 7px;
  padding: 12px;
}

.play-card-meta {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eff4ff;
  color: #3157b7;
  font-size: 10px;
  font-weight: 800;
}

.play-card-description {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.play-card .activity-card-body strong {
  font-size: 15px;
  line-height: 1.15;
}

.play-card .activity-card-actions {
  margin-top: 4px;
}

.card-play-button {
  min-height: 38px;
  padding: 0 18px;
}

.activity-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mini-button {
  min-height: 32px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--soft);
  padding: 0 9px;
  font-weight: 700;
}

.mini-button.danger {
  color: var(--red);
  background: #fff2f2;
  border-color: #ffd0d0;
}

.field {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.category-field-stack {
  display: grid;
  gap: 8px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  color: var(--ink);
}

.word-box {
  margin: 18px 0;
}

.workspace-panel .word-box {
  margin: 0;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}

.word-box.collapsed .word-list {
  display: none;
}

.word-box.collapsed .panel-heading {
  margin-bottom: 0;
}

.word-list {
  max-height: 260px;
  overflow: auto;
  padding-right: 2px;
  scroll-padding: 8px;
}

.workspace-panel .word-list {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  max-height: 142px;
}

.word-item {
  cursor: pointer;
}

.word-item.active {
  border-color: var(--blue);
  box-shadow: inset 4px 0 0 var(--blue);
}

.word-item.mapped {
  background: #eefaf3;
  border-color: #bae7ca;
}

.builder-message {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid #d8e3f5;
  border-radius: 8px;
  background: #f7faff;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
}

.builder-message.good {
  border-color: #bde8cc;
  background: #effaf3;
  color: var(--green);
}

.builder-message.bad {
  border-color: #ffd0d0;
  background: #fff4f4;
  color: var(--red);
}

.workspace-panel {
  min-width: 0;
  overflow: hidden;
}

.workspace-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.image-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 560px;
  background: #dfe8ee;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.finish-shape-button {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 3;
  min-height: 46px;
  border: 1px solid #1748b3;
  border-radius: 999px;
  padding: 0 20px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 12px 30px rgba(37, 99, 235, 0.28);
}

.image-stage.empty {
  background: repeating-linear-gradient(45deg, #edf2f5, #edf2f5 16px, #e4ebef 16px, #e4ebef 32px);
}

.image-stage img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 160px);
  object-fit: contain;
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: none;
}

.overlay-layer {
  position: absolute;
  pointer-events: none;
}

.shape-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.shape-polygon {
  fill: rgba(37, 99, 235, 0.16);
  stroke: var(--blue);
  stroke-width: 0.45;
  vector-effect: non-scaling-stroke;
}

.shape-polygon.correct {
  fill: rgba(31, 157, 85, 0.18);
  stroke: var(--green);
}

.shape-polygon.show {
  fill: rgba(242, 169, 0, 0.2);
  stroke: var(--amber);
}

.shape-polyline {
  fill: rgba(37, 99, 235, 0.08);
  stroke: var(--blue);
  stroke-width: 0.35;
  stroke-dasharray: 1.2 0.8;
  vector-effect: non-scaling-stroke;
}

.shape-draft-polygon {
  fill: rgba(37, 99, 235, 0.1);
  stroke: var(--blue);
  stroke-width: 0.35;
  stroke-dasharray: 1.2 0.8;
  vector-effect: non-scaling-stroke;
}

.shape-vertex {
  fill: #fff;
  stroke: var(--blue);
  stroke-width: 0.35;
  vector-effect: non-scaling-stroke;
}

.shape-closing-vertex {
  fill: var(--blue);
  stroke: #fff;
  stroke-width: 0.55;
}

.hidden,
.image-stage img[src=""] {
  display: none;
}

#new-category-input::placeholder {
  color: #98a4b3;
}

#empty-builder {
  color: var(--muted);
  font-weight: 800;
}

.score-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 18px 0;
}

.score-grid div {
  padding: 14px;
  border-radius: 8px;
  background: var(--soft);
  border: 1px solid var(--line);
}

.score-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.score-grid strong {
  font-size: 28px;
}

.feedback {
  min-height: 56px;
  padding: 12px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-weight: 700;
}

.feedback.good {
  background: #eefaf3;
  color: var(--green);
}

.feedback.bad {
  background: #fff2f2;
  color: var(--red);
}

.result-panel {
  max-width: 760px;
  margin: 0 auto;
  text-align: center;
}

.result-score {
  font-size: clamp(64px, 14vw, 128px);
  font-weight: 900;
  line-height: 1;
  color: var(--blue);
}

@keyframes flash {
  50% {
    transform: scale(1.03);
    background: rgba(242, 169, 0, 0.38);
  }
}

@keyframes pulse {
  50% {
    transform: translate(-50%, -50%) scale(1.08);
  }
}

@media (max-width: 980px) {
  .builder-layout,
  .game-layout,
  .teacher-gate-layout {
    grid-template-columns: 1fr;
  }

  .student-library-hero,
  .student-library-toolbar {
    align-items: start;
    flex-direction: column;
  }

  .student-filter-row {
    width: 100%;
  }

  .builder-sidebar,
  .game-sidebar {
    order: -1;
  }

  .image-stage {
    min-height: 460px;
  }
}

@media (max-width: 640px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
    padding: 14px;
  }

  main {
    padding: 14px;
  }

  .topbar-side,
  .topbar-center,
  .topbar-right {
    position: static;
    justify-content: center;
    transform: none;
  }

  .topbar-left {
    flex-wrap: wrap;
  }

  .top-actions,
  .button-row,
  .primary-button,
  .secondary-button,
  .ghost-button {
    width: 100%;
  }

  .top-actions button,
  .button-row button {
    flex: 1;
  }

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

  .student-library-panel,
  .student-library-hero {
    padding: 18px;
  }

  .student-filter-row {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-field:first-child,
  .filter-field:last-child {
    width: 100%;
  }

  .image-stage {
    min-height: 340px;
  }
}
