:root {
  --ink: #1e1530;
  --muted: #625a73;
  --panel: rgba(255, 255, 255, 0.8);
  --panel-strong: rgba(255, 255, 255, 0.95);
  --ruby: #e53873;
  --sapphire: #266ee8;
  --emerald: #05a777;
  --gold: #f4b832;
  --amethyst: #864be3;
  --diamond: #4ed8ff;
  --shadow: 0 22px 60px rgba(42, 25, 80, 0.2);
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 18%, rgba(244, 184, 50, 0.34), transparent 25%),
    radial-gradient(circle at 86% 12%, rgba(78, 216, 255, 0.34), transparent 24%),
    radial-gradient(circle at 78% 84%, rgba(229, 56, 115, 0.26), transparent 28%),
    linear-gradient(135deg, #fff7fb 0%, #eefaff 43%, #f7fff4 100%);
  overflow-x: hidden;
}

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

.app-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel,
.topbar,
.progress-wrap,
.column-panel,
.controls,
.login-card,
.dashboard-card {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.topbar {
  min-height: 112px;
  padding: 20px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-gem {
  width: 58px;
  height: 50px;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--ruby);
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
h3 {
  margin: 0;
}

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

h2 {
  font-size: clamp(1.45rem, 3vw, 2.2rem);
}

h3 {
  font-size: 1.1rem;
}

.page-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.link-button,
.ghost-button,
.primary-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  color: white;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(40, 105, 230, 0.22);
}

.primary-button {
  background: linear-gradient(135deg, var(--ruby), var(--amethyst), var(--sapphire));
}

.ghost-button {
  background: linear-gradient(135deg, var(--emerald), var(--sapphire));
}

.link-button {
  background: linear-gradient(135deg, var(--gold), var(--ruby));
}

.secondary-button {
  min-height: 40px;
  border: 1px solid rgba(33, 19, 61, 0.14);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  font-weight: 900;
  cursor: pointer;
}

.score-card {
  min-width: 154px;
  min-height: 64px;
  padding: 12px 16px;
  border-radius: 8px;
  color: white;
  background: linear-gradient(135deg, #e53873, #864be3 55%, #266ee8);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 1.1rem;
  box-shadow: 0 12px 30px rgba(101, 50, 185, 0.32);
}

.gem-shape,
.gem-drop {
  width: 30px;
  height: 26px;
  display: inline-block;
  clip-path: polygon(18% 0, 82% 0, 100% 38%, 50% 100%, 0 38%);
  box-shadow: inset 0 5px 9px rgba(255, 255, 255, 0.72);
}

.gem-diamond {
  background: linear-gradient(135deg, #ffffff 0 18%, #4ed8ff 19% 57%, #266ee8 58% 100%);
}

.gem-ruby {
  background: linear-gradient(135deg, #ffd8e5 0 18%, #e53873 19% 58%, #9a1747 59% 100%);
}

.gem-emerald {
  background: linear-gradient(135deg, #dfffe9 0 18%, #05a777 19% 58%, #04714f 59% 100%);
}

.gem-aqeeq {
  background: linear-gradient(135deg, #ffe6be 0 18%, #c95b2f 19% 58%, #7d2c21 59% 100%);
}

.gem-manik {
  background: linear-gradient(135deg, #fff0a6 0 18%, #f04b60 19% 58%, #7c35d8 59% 100%);
}

.gem-sapphire {
  background: linear-gradient(135deg, #d9f2ff 0 18%, #266ee8 19% 58%, #163b9c 59% 100%);
}

.login-grid {
  flex: 1;
  display: grid;
  place-items: center;
}

.login-card {
  width: min(480px, 100%);
  padding: 22px;
  display: grid;
  gap: 16px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
  font-weight: 900;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(33, 19, 61, 0.16);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  outline: 0;
}

.field textarea {
  min-height: 86px;
  resize: vertical;
}

.hint,
.message {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.error {
  color: #bf1d50;
}

.progress-wrap {
  min-height: 54px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.progress-track {
  height: 14px;
  flex: 1;
  border-radius: 999px;
  background: rgba(33, 19, 61, 0.12);
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--emerald), var(--gold), var(--ruby), var(--diamond));
  transition: width 240ms ease;
}

#progressText {
  min-width: 52px;
  font-weight: 900;
}

#timerText {
  min-width: 52px;
  color: var(--muted);
  font-weight: 900;
}

.match-board {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.column-panel {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.column-title {
  font-size: 1.1rem;
  font-weight: 900;
}

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

.jewel-button {
  position: relative;
  min-height: 96px;
  border: 0;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  box-shadow: 0 14px 28px rgba(55, 26, 100, 0.2);
  transform: translateY(0);
  transition: transform 150ms ease, filter 150ms ease, box-shadow 150ms ease, opacity 180ms ease;
  overflow: hidden;
}

.jewel-button::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.74), transparent 34%),
    linear-gradient(315deg, rgba(255, 255, 255, 0.3), transparent 36%);
  pointer-events: none;
}

.jewel-button::after {
  content: "";
  position: absolute;
  inset: 9px 12px auto;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.45);
}

.jewel-button:hover,
.jewel-button:focus-visible {
  transform: translateY(-2px);
  filter: brightness(1.06);
}

.jewel-button.selected {
  box-shadow:
    0 0 0 5px rgba(255, 255, 255, 0.95),
    0 0 0 10px rgba(255, 199, 56, 0.5),
    0 20px 38px rgba(55, 26, 100, 0.3);
  transform: translateY(-3px) scale(1.02);
}

.jewel-button.matched {
  opacity: 0.34;
  cursor: default;
  transform: scale(0.96);
}

.jewel-button.soft-hidden {
  opacity: 0.14;
  filter: grayscale(0.6);
  pointer-events: none;
}

.jewel-button.wrong {
  animation: shake 260ms ease;
}

.pair-text,
.answer-text {
  position: relative;
  z-index: 1;
  display: block;
  direction: rtl;
  font-size: clamp(2.6rem, 6vw, 4.25rem);
  line-height: 1;
  text-shadow: 0 3px 10px rgba(35, 16, 72, 0.26);
}

.plus {
  margin: 0 8px;
  font-size: 0.74em;
  opacity: 0.86;
}

.controls {
  min-height: 64px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.buff-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.buff-button {
  min-width: 78px;
}

.buff-button.buff-disabled,
.buff-button:disabled {
  opacity: 0.34;
  cursor: not-allowed;
  filter: grayscale(0.75);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 16px;
}

.student-home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr);
  gap: 16px;
}

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

.stat-card {
  min-height: 76px;
  border-radius: 8px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  display: grid;
  align-content: center;
  gap: 2px;
}

.stat-card strong {
  font-size: 1.35rem;
}

.stat-card span {
  color: var(--muted);
  font-weight: 900;
}

.teacher-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.teacher-sidebar {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.class-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 4px;
}

.side-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.74);
  font-weight: 900;
  text-align: left;
  cursor: pointer;
}

.side-button.active {
  color: white;
  background: linear-gradient(135deg, var(--ruby), var(--amethyst), var(--sapphire));
  box-shadow: 0 10px 22px rgba(101, 50, 185, 0.24);
}

.teacher-main {
  display: grid;
  gap: 16px;
}

.teacher-layout {
  display: grid;
  grid-template-columns: minmax(280px, 370px) minmax(320px, 1fr);
  gap: 16px;
  align-items: start;
}

.dashboard-card {
  padding: 16px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.wide-card {
  grid-column: span 2;
}

.card-head,
.student-row,
.row-actions,
.inline-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-head,
.student-row {
  justify-content: space-between;
}

.pill {
  min-height: 30px;
  border-radius: 999px;
  padding: 6px 10px;
  color: white;
  background: linear-gradient(135deg, var(--amethyst), var(--sapphire));
  font-size: 0.82rem;
  font-weight: 900;
}

.inline-form {
  align-items: stretch;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 150px;
  gap: 12px;
}

.inline-form input {
  min-width: 0;
  flex: 1;
  min-height: 42px;
  border: 1px solid rgba(33, 19, 61, 0.16);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
}

.inline-form select {
  min-height: 42px;
  border: 1px solid rgba(33, 19, 61, 0.16);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  font-weight: 900;
}

.student-table {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
  padding-right: 2px;
}

.student-row {
  border: 1px solid rgba(33, 19, 61, 0.12);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.66);
}

.danger-button {
  color: #bf1d50;
}

.leaderboard-row:first-child {
  border-color: rgba(244, 184, 50, 0.68);
  background: rgba(255, 248, 216, 0.82);
}

.student-list,
.assignment-list,
.results-list {
  display: grid;
  gap: 8px;
}

.student-choice,
.assignment-item,
.result-row {
  border: 1px solid rgba(33, 19, 61, 0.12);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.66);
}

.student-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}

.student-choice input {
  width: 18px;
  height: 18px;
}

.assignment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.assignment-meta,
.result-meta {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.result-row {
  display: grid;
  gap: 4px;
}

.rain-layer {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden;
}

.gem-drop {
  position: absolute;
  top: -34px;
  animation: fall 1100ms ease-in forwards;
}

.spark {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: white;
  box-shadow: 0 0 18px rgba(255, 255, 255, 0.95);
  animation: sparkle 760ms ease-out forwards;
}

.finish-card {
  position: fixed;
  inset: 50% auto auto 50%;
  z-index: 20;
  width: min(430px, calc(100vw - 32px));
  min-height: 190px;
  transform: translate(-50%, -50%);
  border-radius: 8px;
  padding: 24px;
  color: var(--ink);
  background: var(--panel-strong);
  box-shadow: 0 28px 90px rgba(33, 19, 61, 0.32);
  text-align: center;
}

.finish-card p {
  margin: 8px 0 18px;
}

.hint-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(30, 21, 48, 0.24);
}

.hint-card p {
  font-size: 1.35rem;
  font-weight: 900;
}

@keyframes fall {
  to {
    transform: translateY(calc(100vh + 80px)) rotate(540deg);
    opacity: 0;
  }
}

@keyframes sparkle {
  to {
    transform: translate(var(--tx), var(--ty)) scale(0.1);
    opacity: 0;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-7px);
  }
  75% {
    transform: translateX(7px);
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 540px);
    padding-top: 12px;
    gap: 12px;
  }

  .topbar {
    min-height: auto;
    padding: 16px;
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 2.1rem;
  }

  .match-board,
  .dashboard-grid,
  .teacher-layout,
  .teacher-shell,
  .student-home-grid,
  .two-col {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .teacher-sidebar {
    position: static;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .class-switch {
    grid-column: 1 / -1;
  }

  .stats-strip {
    grid-template-columns: 1fr;
  }

  .side-button {
    text-align: center;
    padding: 0 8px;
  }

  .wide-card {
    grid-column: auto;
  }

  .inline-form,
  .student-row,
  .row-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .column-panel,
  .dashboard-card {
    padding: 12px;
  }

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

  .jewel-button {
    min-height: 82px;
  }

  .pair-text,
  .answer-text {
    font-size: 2.75rem;
  }

  .controls,
  .assignment-item {
    align-items: stretch;
    flex-direction: column;
  }

  .message {
    min-height: 22px;
    text-align: center;
  }
}
