:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --text: #1e2724;
  --muted: #64706c;
  --line: #dce2df;
  --primary: #147d64;
  --primary-dark: #0d5f4b;
  --accent: #c87929;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
}

a {
  color: var(--primary-dark);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 32px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

.nav {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
}

.nav form {
  margin: 0;
}

button,
.link-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}

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

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

.secondary {
  border-color: var(--accent);
  background: #fff7ed;
  color: #7c3f12;
}

.danger {
  border-color: #f2b8b5;
  background: #fff1f0;
  color: var(--danger);
}

.container {
  width: min(1080px, calc(100% - 32px));
  margin: 32px auto;
}

.page-heading {
  margin-bottom: 24px;
}

.page-heading h1,
.auth-panel h1 {
  margin: 0 0 8px;
  line-height: 1.25;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary-dark);
  font-weight: 700;
}

.metric-grid,
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.metric,
.category-card,
.auth-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 20px;
}

.metric span,
.category-card span {
  display: block;
  color: var(--muted);
  font-size: 0.92rem;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
  line-height: 1.1;
}

.category-meta {
  min-height: 1.5em;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

.category-choice-card {
  padding: 0;
  overflow: hidden;
}

.category-pick-button {
  display: grid;
  gap: 6px;
  width: 100%;
  min-height: 116px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 18px;
  text-align: left;
}

.category-pick-button span,
.category-pick-button small {
  color: var(--muted);
}

.category-pick-button strong {
  font-size: 1.25rem;
}

.category-pick-button[aria-expanded="true"] {
  background: #eef8f4;
}

.category-difficulty-panel {
  border-top: 1px solid var(--line);
  padding: 14px;
}

.js-enabled .category-difficulty-panel {
  display: none;
}

.category-difficulty-panel.is-open {
  display: block;
}

.category-difficulty-panel p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.difficulty-button-grid form {
  margin: 0;
}

.difficulty-button-grid button {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 24px;
}

.actions form {
  margin: 0;
}

.inline-start-form,
.category-start-form {
  display: contents;
}

.quiz-start-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.quiz-start-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
}

.quiz-start-card h2 {
  margin: 0;
}

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

.quiz-start-card > span {
  color: var(--primary-dark);
  font-size: 0.85rem;
  font-weight: 800;
}

.detail-filters {
  display: grid;
  gap: 12px;
}

.detail-filters summary {
  cursor: pointer;
  color: var(--primary-dark);
  font-weight: 700;
}

.dashboard-section,
.quiz-panel {
  margin-top: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 20px;
}

.dashboard-section h2,
.quiz-panel h2 {
  margin: 0 0 12px;
}

.question-body {
  margin-top: 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.choice-list {
  display: grid;
  gap: 12px;
}

.choice-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcfb;
  font-weight: 500;
}

.choice-option input {
  width: auto;
}

.choice-skip {
  border-style: dashed;
  color: var(--muted);
}

.quiz-cancel-form {
  margin-top: 12px;
}

.quiz-cancel-form button {
  width: 100%;
}

.answer-correct,
.answer-wrong {
  border-radius: 8px;
  padding: 12px 14px;
}

.answer-correct {
  background: #e8f5ef;
  color: #0d5f4b;
}

.answer-wrong {
  background: #fff1f0;
  color: var(--danger);
}

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

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.9rem;
}

.muted {
  color: var(--muted);
}

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

.badge {
  border: 1px solid #f0d4b5;
  border-radius: 999px;
  background: #fff7ed;
  color: #7c3f12;
  padding: 6px 10px;
  font-weight: 700;
}

.guest {
  background: linear-gradient(180deg, #eef5f1, #f7f4ee);
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(460px, 100%);
}

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

.form.narrow {
  max-width: 520px;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font: inherit;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}

.check input {
  width: auto;
}

.error,
.error-box {
  color: var(--danger);
}

.error-box,
.flash {
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.error-box {
  background: #fff1f0;
}

.flash {
  background: #e8f5ef;
  color: #0d5f4b;
}

.switch-link {
  margin-bottom: 0;
}

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

.celebration-label {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  border: 1px solid #f0d4b5;
  border-radius: 999px;
  background: #fff7ed;
  color: #7c3f12;
  padding: 10px 18px;
  font-weight: 800;
  box-shadow: 0 12px 28px rgb(30 39 36 / 14%);
  animation: celebration-label-pop 2.2s ease-out forwards;
}

.cracker-burst {
  position: absolute;
  top: 30vh;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: radial-gradient(circle, #f2c94c 0 18%, #d94f45 19% 32%, transparent 33%);
  opacity: 0;
  animation: cracker-burst 0.8s ease-out forwards;
}

.cracker-burst-left {
  left: 8vw;
}

.cracker-burst-right {
  right: 8vw;
}

.celebration-layer span {
  position: absolute;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 5%);
  animation: cracker-pop 1.3s ease-out forwards;
}

.celebration-layer span:nth-child(3n) {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.celebration-layer span:nth-child(4n) {
  width: 6px;
  height: 18px;
}

@keyframes cracker-pop {
  0% {
    opacity: 0;
    transform: translate3d(0, 0, 0) scale(0.4) rotate(0deg);
  }
  10% {
    opacity: 1;
  }
  55% {
    transform: translate3d(calc(var(--drift) * 0.55), var(--rise), 0) scale(1) rotate(var(--rotate));
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--drift), 72vh, 0) scale(0.85) rotate(var(--rotate-end));
  }
}

@keyframes celebration-label-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, 12px) scale(0.85);
  }
  18%,
  72% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -10px) scale(0.96);
  }
}

@keyframes cracker-burst {
  0% {
    opacity: 0;
    transform: scale(0.2);
  }
  25% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(2.6);
  }
}

@media (prefers-reduced-motion: reduce) {
  .celebration-layer {
    display: none;
  }
}

@media (max-width: 720px) {
  .site-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 10px 16px;
  }

  .container {
    width: min(100% - 24px, 1080px);
    margin: 14px auto 24px;
  }

  .page-heading {
    margin-bottom: 12px;
  }

  .page-heading h1 {
    font-size: 1.35rem;
    line-height: 1.25;
  }

  .eyebrow {
    font-size: 0.86rem;
  }

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

  .dashboard-metrics .metric,
  .quiz-result-metrics .metric {
    min-height: 72px;
    padding: 10px 12px;
  }

  .dashboard-metrics .metric-secondary {
    display: none;
  }

  .metric span {
    font-size: 0.78rem;
  }

  .metric strong {
    margin-top: 4px;
    font-size: 1.35rem;
  }

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

  .dashboard-actions .link-button,
  .quiz-result-actions .link-button {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 10px;
    text-align: center;
    font-size: 0.92rem;
  }

  .dashboard-actions .link-button:first-child {
    grid-column: 1 / -1;
  }

  .inline-start-form {
    display: block;
    grid-column: 1 / -1;
  }

  .inline-start-form .link-button {
    width: 100%;
  }

  .quiz-result-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .quiz-result-actions .link-button:first-child {
    grid-column: 1 / -1;
  }

  .dashboard-section,
  .quiz-panel {
    margin-top: 18px;
    padding: 14px;
  }

  .question-body {
    margin-bottom: 10px;
    font-size: 1.04rem;
  }

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

  .choice-option {
    min-height: 40px;
    gap: 8px;
    padding: 7px 9px;
    font-size: 0.9rem;
    line-height: 1.35;
  }

  .choice-option span {
    overflow-wrap: anywhere;
  }

  .choice-list .primary {
    grid-column: 1 / -1;
    min-height: 40px;
    padding: 8px 10px;
  }

  .quiz-cancel-form {
    margin-top: 8px;
  }

  .quiz-cancel-form button {
    min-height: 38px;
    padding: 7px 10px;
    font-size: 0.9rem;
  }

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

  .compact-category-grid .category-card {
    padding: 0;
  }

  .category-pick-button {
    min-height: 92px;
    padding: 12px;
  }

  .category-pick-button strong {
    font-size: 1.05rem;
  }

  .category-pick-button span,
  .category-pick-button small {
    font-size: 0.76rem;
  }

  .quiz-start-options {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .quiz-start-card {
    gap: 8px;
    padding: 12px;
  }

  .quiz-start-card h2 {
    font-size: 1.1rem;
  }
}
