/* 民主小勇士闖關網 */
:root {
  --blue: #1971c2;
  --blue-dark: #1864ab;
  --red: #e03131;
  --green: #2f9e44;
  --yellow: #ffd43b;
  --ink: #22303c;
  --paper: #f8fafd;
  --card: #ffffff;
  --shadow: 0 10px 24px rgba(24, 64, 100, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #dff1ff 0%, #f4fbff 40%, #fff 100%);
  min-height: 100vh;
}

/* ---------- 頂部列 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 3px solid #d0ebff;
}

.logo {
  font-weight: 900;
  font-size: 20px;
  color: var(--blue);
  cursor: pointer;
  user-select: none;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.star-badge {
  background: #fff3bf;
  border: 2px solid #ffd43b;
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 800;
  font-size: 14px;
}

/* ---------- 按鈕 ---------- */
.btn {
  border: none;
  border-radius: 14px;
  background: #e9ecef;
  color: var(--ink);
  font-family: inherit;
  font-weight: 800;
  font-size: 16px;
  padding: 10px 18px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.btn:active {
  transform: translateY(0);
}

.btn.primary {
  background: linear-gradient(180deg, #4dabf7, var(--blue));
  color: #fff;
}

.btn.big {
  font-size: 18px;
  padding: 14px 26px;
  border-radius: 18px;
}

.btn.tiny {
  font-size: 14px;
  padding: 6px 12px;
}

.btn.ghost {
  background: transparent;
  border: 2px dashed #a5c9ea;
  color: var(--blue-dark);
}

/* ---------- 畫面切換 ---------- */
.screen {
  display: none;
  max-width: 1080px;
  margin: 0 auto;
  padding: 22px 16px 60px;
}

.screen.active {
  display: block;
  animation: fadein 0.3s ease;
}

@keyframes fadein {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- 首頁 ---------- */
.hero {
  text-align: center;
  background: linear-gradient(135deg, #1971c2, #4dabf7 60%, #74c0fc);
  color: #fff;
  border-radius: 26px;
  padding: 34px 22px;
  box-shadow: var(--shadow);
}

.hero-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 14px;
  font-weight: 700;
}

.hero h1 {
  margin: 14px 0 8px;
  font-size: clamp(24px, 5vw, 40px);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.15);
}

.hero-sub {
  margin: 0 auto 18px;
  max-width: 640px;
  line-height: 1.7;
  opacity: 0.96;
}

.hero-btns {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.card-grid {
  margin-top: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}

.game-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  text-align: left;
  background: var(--card);
  border: 3px solid #e7f5ff;
  border-radius: 22px;
  padding: 18px;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.15s, border-color 0.15s;
  animation: pop 0.4s ease backwards;
}

.game-card:hover {
  transform: translateY(-5px);
  border-color: #74c0fc;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
}

.game-card-icon {
  font-size: 44px;
  line-height: 1;
}

.game-card h2 {
  margin: 0 0 6px;
  font-size: 19px;
  color: var(--blue-dark);
}

.game-card p {
  margin: 0 0 10px;
  font-size: 14px;
  color: #495057;
  line-height: 1.6;
}

.game-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tag {
  background: #e7f5ff;
  color: var(--blue-dark);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  padding: 3px 10px;
}

.stars {
  color: #fab005;
  font-size: 18px;
  letter-spacing: 2px;
}

.stars.has-star {
  text-shadow: 0 0 10px rgba(255, 176, 5, 0.7);
}

.home-links {
  margin-top: 22px;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.foot {
  margin-top: 34px;
  text-align: center;
  color: #868e96;
  font-size: 13px;
}

/* ---------- 學習地圖 ---------- */
.section-head {
  text-align: center;
  margin-bottom: 18px;
}

.section-head h1 {
  margin: 0 0 6px;
  color: var(--blue-dark);
}

.section-head p {
  margin: 0;
  color: #666;
}

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

.know-card {
  background: var(--card);
  border-radius: 20px;
  padding: 18px;
  border: 3px solid #eef7ff;
  box-shadow: var(--shadow);
  animation: fadein 0.4s ease backwards;
  animation-delay: var(--d, 0s);
}

.know-icon {
  font-size: 32px;
}

.know-card h3 {
  margin: 8px 0 6px;
  font-size: 18px;
  color: var(--blue-dark);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.know-page {
  font-size: 12px;
  background: #fff3bf;
  color: #997404;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

.know-card p {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.75;
  color: #343a40;
}

.center-btns {
  margin-top: 26px;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- 遊戲畫面 ---------- */
.game-top {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.game-title {
  font-weight: 900;
  font-size: 18px;
  color: var(--blue-dark);
  flex: 1;
}

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

.hud-stats span {
  background: #fff;
  border: 2px solid #d0ebff;
  border-radius: 999px;
  padding: 5px 12px;
  font-weight: 800;
  font-size: 14px;
}

.hud-question-wrap {
  margin-bottom: 10px;
}

.hud-question {
  background: linear-gradient(135deg, #fff, #eef7ff);
  border: 3px solid #74c0fc;
  border-radius: 16px;
  padding: 12px 16px;
  font-size: clamp(16px, 2.4vw, 21px);
  font-weight: 800;
  line-height: 1.6;
}

.q-no {
  background: var(--blue);
  color: #fff;
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 14px;
  margin-right: 6px;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 4px solid #bcdfff;
  background: #d0ebff;
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
}

.toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 22px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 20px;
  color: #fff;
  z-index: 5;
  animation: toastIn 0.2s ease;
}

.toast-ok {
  background: rgba(47, 158, 68, 0.95);
}

.toast-bad {
  background: rgba(224, 49, 49, 0.95);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate(-50%, -14px);
  }
}

.feedback {
  position: absolute;
  inset: 0;
  background: rgba(18, 32, 47, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 8;
  padding: 16px;
}

.feedback-box {
  background: #fff;
  border-radius: 20px;
  padding: 22px;
  max-width: 560px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
  animation: pop 0.22s ease;
}

.feedback-title {
  font-size: 26px;
  font-weight: 900;
  margin-bottom: 10px;
}

.feedback-title.ok {
  color: var(--green);
}

.feedback-title.bad {
  color: var(--red);
}

.feedback-body {
  font-size: 16px;
  line-height: 1.8;
  text-align: left;
  background: #f8f9fa;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.fb-page {
  display: inline-block;
  margin-top: 8px;
  background: #fff3bf;
  color: #997404;
  font-size: 12px;
  border-radius: 999px;
  padding: 2px 10px;
  float: right;
}

.hidden {
  display: none !important;
}

.touch-controls {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin-top: 14px;
}

.ctrl-btn {
  min-width: 76px;
  height: 58px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(180deg, #e7f5ff, #d0ebff);
  border: 3px solid #74c0fc;
  font-family: inherit;
  font-size: 22px;
  font-weight: 900;
  color: var(--blue-dark);
  cursor: pointer;
  user-select: none;
  touch-action: none;
}

.ctrl-btn:active {
  background: #74c0fc;
  color: #fff;
}

.ctrl-btn.jump-btn {
  background: linear-gradient(180deg, #fff3bf, #ffe066);
  border-color: #ffd43b;
  color: #997404;
}

.game-hint {
  margin-top: 10px;
  text-align: center;
  color: #5b6770;
  font-size: 14px;
  line-height: 1.7;
}

/* ---------- 成績頁 ---------- */
.result-box {
  background: var(--card);
  border-radius: 26px;
  padding: 26px 20px;
  box-shadow: var(--shadow);
  text-align: center;
}

.result-emoji {
  font-size: 64px;
}

.result-box h1 {
  margin: 6px 0;
  color: var(--blue-dark);
}

.result-stars {
  font-size: 44px;
  color: #fab005;
  letter-spacing: 6px;
  text-shadow: 0 0 14px rgba(255, 176, 5, 0.55);
}

.result-box p {
  line-height: 1.8;
}

.review-list {
  margin-top: 18px;
  display: grid;
  gap: 10px;
  text-align: left;
}

.review-item {
  border-radius: 14px;
  padding: 12px 14px;
  border-left: 8px solid;
  background: #f8f9fa;
}

.review-item.ok {
  border-color: var(--green);
}

.review-item.no {
  border-color: var(--red);
}

.review-q {
  font-weight: 800;
  margin-bottom: 4px;
}

.review-a {
  font-size: 14.5px;
  color: var(--blue-dark);
}

.review-w {
  font-size: 13.5px;
  color: #666;
  margin-top: 4px;
  line-height: 1.6;
}

/* ---------- 證書 ---------- */
.cert-wrap {
  text-align: center;
}

.certificate {
  background: #fffdf5;
  max-width: 760px;
  margin: 0 auto;
  padding: 14px;
  box-shadow: var(--shadow);
  border-radius: 10px;
}

.cert-border {
  border: 6px double #c9a227;
  border-radius: 6px;
  padding: 34px 22px;
}

.cert-top {
  font-size: 34px;
  font-weight: 900;
  color: #b8860b;
}

.cert-lesson {
  margin-top: 8px;
  font-size: 17px;
  color: var(--blue-dark);
  font-weight: 800;
}

.cert-name-line {
  margin: 22px auto 6px;
}

.cert-name {
  font-family: inherit;
  font-size: 30px;
  font-weight: 900;
  text-align: center;
  border: none;
  border-bottom: 3px dashed #c9a227;
  background: transparent;
  width: min(420px, 90%);
  padding: 6px;
  color: #2b3a46;
  outline: none;
}

.cert-name::placeholder {
  color: #b8b8b8;
  font-size: 20px;
}

.cert-text {
  margin-top: 14px;
  font-size: 16px;
  line-height: 1.9;
  color: #343a40;
}

.cert-stars {
  margin-top: 16px;
  font-size: 30px;
  color: #fab005;
  letter-spacing: 4px;
}

.cert-foot {
  margin-top: 22px;
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: #868e96;
  gap: 10px;
  flex-wrap: wrap;
}

.cert-lock {
  color: #997404;
  background: #fff9db;
  display: inline-block;
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 700;
}

/* ---------- 手機 ---------- */
@media (max-width: 560px) {
  .game-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .game-card-meta {
    justify-content: center;
    gap: 12px;
  }

  .logo {
    font-size: 16px;
  }

  .ctrl-btn {
    min-width: 64px;
    height: 54px;
  }

  .feedback-body {
    font-size: 14px;
  }
}

/* ---------- 列印 ---------- */
@media print {
  body * {
    visibility: hidden;
  }
  .certificate,
  .certificate * {
    visibility: visible;
  }
  .certificate {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    box-shadow: none;
  }
  .cert-name {
    border-bottom: 3px dashed #c9a227;
  }
}
