:root {
  color-scheme: light;
  --ink: #241f32;
  --muted: #665d74;
  --paper: #fffafb;
  --panel: #ffffff;
  --line: #ded5ea;
  --violet: #7a55b3;
  --violet-dark: #4f337d;
  --teal: #0d8c91;
  --coral: #d94f70;
  --gold: #e5a900;
  --green: #257e55;
  --danger: #9f273b;
  --shadow: 0 18px 42px rgba(48, 35, 72, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(140deg, rgba(122, 85, 179, 0.10), transparent 34%),
    linear-gradient(180deg, #fffafd 0%, #f4fbfb 54%, #fff8ed 100%);
  color: var(--ink);
  font-family: "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

code {
  padding: 2px 6px;
  border-radius: 6px;
  background: #f5eefb;
  color: var(--violet-dark);
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 48px);
  background: rgba(255, 250, 251, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

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

.brand-mark {
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 0 2px var(--line), 0 8px 22px rgba(122, 85, 179, 0.18);
  object-fit: cover;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1.05rem;
  line-height: 1.2;
}

.brand small {
  color: var(--muted);
  line-height: 1.35;
}

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

.top-actions {
  justify-content: flex-end;
}

.primary-button,
.ghost-button,
.danger-button,
.text-button,
.choice-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
}

.primary-button {
  background: var(--violet);
  color: #ffffff;
  box-shadow: 0 10px 22px rgba(122, 85, 179, 0.22);
}

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

.danger-button {
  background: #fff0f3;
  border-color: #f2bac5;
  color: var(--danger);
}

.text-button {
  background: #f8f5fc;
  border-color: var(--line);
  color: var(--violet-dark);
}

.small-button {
  min-height: 36px;
  padding: 7px 10px;
  font-size: 0.9rem;
}

#app {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: clamp(20px, 4vw, 46px) 0 56px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(280px, 0.95fr);
  align-items: center;
  gap: clamp(24px, 5vw, 56px);
}

.portal-hero {
  min-height: calc(100vh - 112px);
}

.hero h1,
.panel h1,
.result-panel h1 {
  margin: 0 0 14px;
  letter-spacing: 0;
  line-height: 1.08;
}

.hero h1 {
  max-width: 9ch;
  font-size: clamp(2.6rem, 6vw, 5.2rem);
}

.panel h1,
.result-panel h1 {
  font-size: clamp(1.8rem, 3.6vw, 3rem);
}

.hero p,
.panel p,
.stage-card p,
.result-panel p,
.scenario,
.note {
  color: var(--muted);
  line-height: 1.7;
}

.hero p {
  max-width: 700px;
  font-size: clamp(1.08rem, 2vw, 1.3rem);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--violet-dark);
  font-size: 0.92rem;
  font-weight: 900;
  letter-spacing: 0;
}

.logo-stage {
  display: grid;
  place-items: center;
  min-height: 390px;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(150deg, rgba(122, 85, 179, 0.12), rgba(13, 140, 145, 0.10)),
    #ffffff;
  box-shadow: var(--shadow);
}

.logo-stage img {
  width: min(74%, 360px);
  aspect-ratio: 1;
  border: 8px solid #ffffff;
  border-radius: 50%;
  background: #ffffff;
  object-fit: cover;
  box-shadow: 0 18px 40px rgba(48, 35, 72, 0.18);
}

.panel,
.mode-option,
.stage-card,
.result-panel,
.question-card,
.stat-card {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(48, 35, 72, 0.08);
}

.panel,
.stage-card,
.result-panel,
.question-card {
  padding: clamp(18px, 3vw, 30px);
}

.notice-panel {
  max-width: 820px;
  margin: 0 auto;
}

.danger-note {
  border-color: #efb1bd;
}

.setup-code {
  overflow-x: auto;
  padding: 14px;
  border-radius: 8px;
  background: #f8f5fc;
}

.team-form {
  display: grid;
  gap: 18px;
  max-width: 760px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-weight: 900;
}

input {
  width: 100%;
  min-height: 52px;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  background: #ffffff;
  color: var(--ink);
  font-size: 1.05rem;
}

input:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 4px solid rgba(122, 85, 179, 0.22);
  outline-offset: 2px;
}

.mode-grid,
.stage-grid,
.summary-grid,
.kahoot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(245px, 1fr));
  gap: 14px;
}

.compact-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.mode-option {
  position: relative;
  min-height: 116px;
  padding: 18px;
}

.mode-option input {
  position: absolute;
  inset: 16px 16px auto auto;
  width: 22px;
  min-height: 22px;
  accent-color: var(--violet);
}

.mode-option span {
  display: grid;
  gap: 8px;
  padding-right: 36px;
}

.mode-option small {
  color: var(--muted);
  font-weight: 700;
  line-height: 1.55;
}

.map-panel,
.dashboard-head {
  margin-bottom: 16px;
}

.dashboard-head {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
  gap: 18px;
  align-items: center;
}

.stat-card {
  padding: 18px;
}

.stat-card strong {
  display: block;
  color: var(--violet-dark);
  font-size: 2rem;
  line-height: 1;
}

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

.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 12px;
}

.filter-button {
  min-height: 38px;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  background: #ffffff;
  color: var(--violet-dark);
  font-weight: 900;
}

.filter-button.active {
  border-color: var(--violet);
  background: var(--violet);
  color: #ffffff;
}

.stage-card {
  min-height: 255px;
  text-align: left;
}

.stage-card.locked {
  cursor: not-allowed;
  opacity: 0.58;
}

.stage-card.locked:hover {
  border-color: var(--line);
}

.stage-card h2,
.panel h2,
.result-panel h2 {
  margin: 12px 0 8px;
}

.stage-card:hover,
.stage-card:focus-visible,
.choice-button:hover,
.choice-button:focus-visible,
.mode-option:has(input:checked) {
  border-color: var(--violet);
}

.stage-number {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--violet);
  color: #ffffff;
  font-weight: 900;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 6px 10px;
  border: 2px solid #d9cde8;
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 800;
}

.badge.earned {
  border-color: #e9cf70;
  background: #fff6d6;
  color: #6d5200;
}

.question-shell {
  display: grid;
  gap: 18px;
}

.question-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
}

.meter {
  width: min(380px, 100%);
  height: 16px;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
}

.meter > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--violet), var(--teal), var(--gold));
}

.question-card {
  border-color: var(--ink);
}

.question-card h1 {
  margin: 0 0 16px;
  font-size: clamp(1.55rem, 3.8vw, 2.45rem);
  line-height: 1.25;
  letter-spacing: 0;
}

.scenario {
  margin: 0 0 18px;
  font-size: clamp(1.05rem, 2vw, 1.22rem);
}

.choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.choice-button {
  justify-content: flex-start;
  min-height: 82px;
  background: #fbf9fd;
  border-color: #d8cde8;
  color: var(--ink);
  text-align: left;
}

.choice-button.correct {
  background: #eaf8f1;
  border-color: var(--green);
}

.choice-button.wrong {
  background: #fff0f3;
  border-color: var(--coral);
}

.feedback {
  display: none;
  margin-top: 18px;
  padding: 16px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  line-height: 1.7;
}

.feedback.show {
  display: block;
}

.certificate {
  margin: 22px 0;
  padding: clamp(20px, 4vw, 38px);
  border: 4px double var(--violet);
  border-radius: 8px;
  background: linear-gradient(180deg, #fffdf7, #fbf6ff);
  text-align: center;
}

.certificate h2 {
  margin: 0;
  color: var(--violet-dark);
  font-size: clamp(1.8rem, 4vw, 3rem);
}

body[data-page="certificate"] {
  min-height: 100vh;
  background: #f6f1fb;
  color: #000000;
  font-family: "DFKai-SB", "BiauKai", "KaiTi", serif;
}

.certificate-toolbar {
  display: grid;
  grid-template-columns: auto minmax(180px, 260px) minmax(240px, 360px) minmax(180px, 240px) auto auto auto;
  align-items: end;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: #fffafb;
  border-bottom: 1px solid var(--line);
  font-family: "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
}

.certificate-name-control,
.certificate-roster-control,
.certificate-file-control {
  color: var(--ink);
  font-weight: 800;
}

.certificate-name-control input,
.certificate-file-control input,
.certificate-roster-control textarea {
  min-height: 44px;
}

.certificate-roster-control textarea {
  width: 100%;
  resize: vertical;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  line-height: 1.45;
}

.certificate-status {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 800;
  text-align: center;
}

.certificate-page {
  display: grid;
  gap: 24px;
  place-items: center;
  min-height: calc(100vh - 174px);
  padding: 20px;
  overflow-x: auto;
}

.certificate-sheet {
  width: 210mm;
  height: 297mm;
  flex: 0 0 auto;
  padding: 6mm;
  background:
    linear-gradient(135deg, rgba(122, 85, 179, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(229, 169, 0, 0.12), transparent 30%),
    #fffefa;
  box-shadow: 0 24px 60px rgba(48, 35, 72, 0.18);
}

.certificate-border {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  overflow: hidden;
  border: 3px double #7a55b3;
  outline: 1px solid rgba(229, 169, 0, 0.55);
  outline-offset: -7mm;
  padding: 14mm 13mm 11mm;
  background:
    radial-gradient(circle at 12% 18%, rgba(122, 85, 179, 0.10), transparent 20%),
    radial-gradient(circle at 88% 82%, rgba(13, 140, 145, 0.10), transparent 22%),
    rgba(255, 255, 255, 0.82);
}

.certificate-border::before,
.certificate-border::after {
  position: absolute;
  color: rgba(122, 85, 179, 0.18);
  font-size: 42pt;
  line-height: 1;
  content: "✦";
}

.certificate-border::before {
  top: 10mm;
  right: 11mm;
}

.certificate-border::after {
  bottom: 10mm;
  left: 11mm;
}

.certificate-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 0;
  width: 135mm;
  max-height: 170mm;
  opacity: 0.12;
  object-fit: contain;
  transform: translate(-50%, -50%);
}

.certificate-head {
  position: relative;
  z-index: 1;
  text-align: center;
}

.certificate-kicker {
  margin: 6mm 0 0;
  color: #4f337d;
  font-family: "Times New Roman", serif;
  font-size: 22pt;
  letter-spacing: 0.08em;
  text-align: center;
}

.certificate-head h1 {
  margin: 0;
  color: #000000;
  font-size: 40pt;
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: 0;
  text-align: center;
}

.certificate-content {
  position: relative;
  z-index: 1;
  display: grid;
  align-content: start;
  justify-items: center;
  padding: 26mm 10mm 0;
  text-align: center;
}

.certificate-label {
  margin: 0 0 4mm;
  color: #000000;
  font-size: 19pt;
}

.certificate-name {
  display: grid;
  place-items: center;
  width: 124mm;
  min-height: 22mm;
  margin: 0 0 11mm;
  border-bottom: 1.8pt solid #000000;
  color: #000000;
  font-size: 38pt;
  font-weight: 700;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.certificate-name.is-empty {
  color: transparent;
}

.certificate-copy {
  max-width: 150mm;
  margin: 0;
  color: #000000;
  font-size: 18pt;
  line-height: 1.72;
  text-align: center;
}

.certificate-copy p {
  margin: 0 0 5mm;
}

.certificate-copy p:last-child {
  margin-bottom: 0;
  text-align: center;
}

.certificate-footer {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 5mm;
  align-items: end;
  justify-items: stretch;
  max-width: 155mm;
  width: 100%;
  margin: 0 auto;
  color: #000000;
  font-size: 16pt;
  line-height: 1.45;
}

.certificate-chief-line,
.certificate-date-line {
  margin: 0;
}

.certificate-chief-line {
  text-align: left;
}

.certificate-chief-name {
  display: inline-block;
  min-width: 4.5em;
  border-bottom: 1.4pt solid #000000;
  text-align: center;
}

.certificate-date-line {
  text-align: center;
  font-size: 20pt;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #ffffff;
}

.data-table th,
.data-table td {
  border: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: #f3eff9;
  color: var(--violet-dark);
  font-weight: 900;
}

.teacher-table {
  min-width: 1060px;
}

.muted {
  color: var(--muted);
  font-size: 0.92rem;
}

.error-text {
  margin: 0;
  color: var(--danger);
  font-weight: 900;
}

.action-stack {
  display: grid;
  gap: 8px;
  min-width: 96px;
}

@media (max-width: 860px) {
  .topbar,
  .dashboard-head {
    align-items: flex-start;
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

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

  .logo-stage {
    min-height: 300px;
  }
}

@media (max-width: 560px) {
  .brand-mark {
    width: 48px;
    height: 48px;
  }

  .hero h1 {
    font-size: 2.4rem;
  }

  .primary-button,
  .ghost-button,
  .danger-button,
  .text-button,
  .filter-button {
    width: 100%;
  }

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

@media (max-width: 760px) {
  .certificate-toolbar {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .certificate-toolbar .text-button,
  .certificate-toolbar .ghost-button,
  .certificate-toolbar .primary-button {
    width: 100%;
  }

  .certificate-page {
    justify-content: start;
    overflow-x: auto;
  }
}

@page {
  size: A4 portrait;
  margin: 0;
}

@media print {
  html,
  body[data-page="certificate"] {
    width: 210mm;
    min-width: 0;
    height: auto;
    margin: 0;
    background: #ffffff;
  }

  body[data-page="certificate"] {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .certificate-toolbar {
    display: none;
  }

  .certificate-page {
    display: block;
    min-height: 0;
    padding: 0;
  }

  .certificate-sheet {
    width: 210mm;
    height: 297mm;
    padding: 6mm;
    break-after: page;
    page-break-after: always;
    box-shadow: none;
  }

  .certificate-sheet:last-child {
    break-after: auto;
    page-break-after: auto;
  }
}
