* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Noto Serif TC", "Microsoft JhengHei", "PingFang TC", "STKaiti", serif;
  background: linear-gradient(135deg, #FAF5EB 0%, #F0E2C0 100%);
  color: #1F2937;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px;
  min-height: 100vh;
  position: relative;
}

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

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}

/* === 首頁 === */
.title {
  font-size: 72px;
  text-align: center;
  color: #B91C1C;
  margin-top: 56px;
  letter-spacing: 10px;
  font-weight: 700;
  text-shadow: 3px 3px 0 rgba(201, 162, 39, 0.25);
}
.subtitle {
  text-align: center;
  font-size: 18px;
  color: #6B7280;
  margin: 12px 0 56px;
  letter-spacing: 6px;
}
.menu {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 32px auto;
  max-width: 320px;
}
.footnote {
  text-align: center;
  color: #9CA3AF;
  font-size: 12px;
  margin-top: 48px;
  letter-spacing: 1px;
}

/* === 分享按鈕 === */
.btn-share {
  display: block;
  margin: 24px auto 0;
  background: transparent;
  border: 1px dashed #C9A227;
  color: #92580B;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 20px;
  border-radius: 24px;
  cursor: pointer;
  letter-spacing: 2px;
  transition: all 0.2s;
}
.btn-share:hover {
  background: #FEF3C7;
  border-style: solid;
}

/* === QR 分享 modal === */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
  padding: 16px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: white;
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  position: relative;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  animation: slideUp 0.25s ease;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  font-size: 24px;
  color: #9CA3AF;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  font-family: inherit;
  line-height: 1;
}
.modal-close:hover { background: #F3F4F6; color: #1F2937; }
.modal-title {
  font-size: 22px;
  color: #B91C1C;
  letter-spacing: 4px;
  margin-bottom: 8px;
}
.modal-hint {
  color: #6B7280;
  font-size: 14px;
  margin-bottom: 16px;
}
.qr-box {
  width: 200px;
  height: 200px;
  margin: 0 auto 16px;
  padding: 8px;
  background: white;
  border: 1px solid #E5E7EB;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-box img, .qr-box canvas { display: block; }
.share-url {
  background: #F9FAFB;
  border-radius: 8px;
  padding: 10px;
  color: #4B5563;
  font-size: 13px;
  word-break: break-all;
  margin-bottom: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

/* === 按鈕 === */
.btn-primary, .btn-secondary {
  font-family: inherit;
  font-size: 20px;
  padding: 16px 32px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.1s, box-shadow 0.2s;
  letter-spacing: 4px;
}
.btn-primary {
  background: #B91C1C;
  color: white;
  box-shadow: 0 4px 12px rgba(185, 28, 28, 0.3);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(185, 28, 28, 0.4);
}
.btn-primary:active { transform: translateY(0); }
.btn-secondary {
  background: white;
  color: #B91C1C;
  border: 2px solid #B91C1C;
}
.btn-secondary:hover {
  background: #FEE2E2;
  transform: translateY(-2px);
}
.btn-back {
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 16px;
  color: #6B7280;
  cursor: pointer;
  margin: 32px auto 0;
  padding: 8px 16px;
  display: block;
}
.btn-back:hover { color: #1F2937; }
.btn-quit {
  background: transparent;
  border: 1px solid #D1D5DB;
  font-family: inherit;
  font-size: 14px;
  color: #6B7280;
  cursor: pointer;
  padding: 6px 16px;
  border-radius: 8px;
  position: absolute;
  top: 24px;
  right: 24px;
}
.btn-quit:hover { border-color: #B91C1C; color: #B91C1C; }

/* === 最高分 === */
.best-scores {
  margin: 32px auto 0;
  background: white;
  border-radius: 12px;
  padding: 16px 24px;
  max-width: 320px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.best-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 16px;
}
.best-type { color: #6B7280; letter-spacing: 2px; }
.best-score { color: #B91C1C; font-weight: 600; }
.best-empty {
  text-align: center;
  color: #9CA3AF;
  font-size: 14px;
}

/* === 題型選擇 === */
.screen-title {
  font-size: 32px;
  text-align: center;
  color: #B91C1C;
  margin-top: 40px;
  letter-spacing: 6px;
}
.screen-subtitle {
  text-align: center;
  color: #6B7280;
  margin: 12px 0 32px;
  letter-spacing: 2px;
}
.type-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 32px;
}
.type-card {
  background: white;
  border: 2px solid transparent;
  border-radius: 16px;
  padding: 32px 20px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  box-shadow: 0 2px 12px rgba(0,0,0,0.05);
  text-align: center;
}
.type-card:hover {
  border-color: #B91C1C;
  transform: translateY(-4px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}
.type-icon {
  font-size: 56px;
  color: #C9A227;
  margin-bottom: 12px;
  font-weight: 700;
}
.type-name {
  font-size: 22px;
  font-weight: 600;
  color: #1F2937;
  margin-bottom: 8px;
  letter-spacing: 4px;
}
.type-desc {
  font-size: 14px;
  color: #6B7280;
  line-height: 1.6;
}

/* === HUD === */
.game-header {
  display: flex;
  gap: 8px;
  background: white;
  border-radius: 12px;
  padding: 16px;
  margin: 16px 0 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.hud-cell {
  text-align: center;
  flex: 1;
}
.hud-cell.hidden { visibility: hidden; }
.hud-label {
  font-size: 12px;
  color: #9CA3AF;
  margin-bottom: 4px;
  letter-spacing: 1px;
}
.hud-value {
  font-size: 22px;
  font-weight: 600;
  color: #1F2937;
}
.timer-warning {
  color: #DC2626 !important;
  animation: pulse 1s ease-in-out infinite;
}

/* === 遊戲區 === */
.game-body {
  background: white;
  border-radius: 16px;
  padding: 32px 24px;
  min-height: 280px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}
.prompt {
  text-align: center;
  font-size: 18px;
  color: #4B5563;
  margin-bottom: 32px;
  letter-spacing: 2px;
}

/* 將錯糾錯 */
.choice-row {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}
.choice {
  flex: 1;
  min-width: 140px;
  max-width: 260px;
  font-family: inherit;
  font-size: 32px;
  padding: 28px 16px;
  background: white;
  border: 2px solid #E5E7EB;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 6px;
  color: #1F2937;
  font-weight: 500;
}
.choice:not(:disabled):hover {
  border-color: #B91C1C;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(185, 28, 28, 0.15);
}
.choice-correct {
  background: #D1FAE5 !important;
  border-color: #10B981 !important;
  color: #065F46 !important;
}
.choice-wrong {
  background: #FEE2E2 !important;
  border-color: #DC2626 !important;
  color: #991B1B !important;
}

/* 字字珠璣 */
.hint-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 24px 0 12px;
}
.hint-pair {
  display: inline-flex;
  align-items: center;
  background: #F9FAFB;
  border: 1px solid #E5E7EB;
  padding: 16px 12px;
  border-radius: 12px;
  font-size: 34px;
  min-width: 96px;
  justify-content: center;
}
.blank {
  display: inline-block;
  min-width: 44px;
  text-align: center;
  border-bottom: 3px solid #B91C1C;
  margin: 0 2px;
  color: #B91C1C;
  font-weight: 600;
}
.blank-correct {
  background: #D1FAE5;
  color: #065F46 !important;
  border-radius: 4px;
  border-bottom: none;
  padding: 0 4px;
}
.blank-revealed {
  background: #FEE2E2;
  color: #991B1B !important;
  border-radius: 4px;
  border-bottom: none;
  padding: 0 4px;
}
.position-hint {
  text-align: center;
  color: #9CA3AF;
  font-size: 14px;
  margin-bottom: 24px;
  letter-spacing: 1px;
}
.input-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  max-width: 360px;
  margin: 0 auto;
}
#answer-input {
  font-family: inherit;
  font-size: 28px;
  padding: 12px 16px;
  border: 2px solid #E5E7EB;
  border-radius: 12px;
  text-align: center;
  width: 120px;
  transition: border-color 0.2s;
}
#answer-input:focus {
  outline: none;
  border-color: #B91C1C;
}
#answer-input:disabled {
  background: #F3F4F6;
  color: #9CA3AF;
}
#btn-submit {
  font-family: inherit;
  font-size: 18px;
  padding: 14px 28px;
  background: #B91C1C;
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  letter-spacing: 2px;
}
#btn-submit:hover { background: #991B1B; }
#btn-submit:disabled { background: #9CA3AF; cursor: default; }

/* === 回饋 === */
.game-feedback { margin-top: 16px; }
.feedback {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  text-align: center;
  animation: slideUp 0.3s ease;
}
.feedback-correct { border-top: 4px solid #10B981; }
.feedback-wrong { border-top: 4px solid #DC2626; }
.feedback-icon {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: 4px;
}
.feedback-correct .feedback-icon { color: #065F46; }
.feedback-wrong .feedback-icon { color: #991B1B; }
.feedback-text {
  color: #4B5563;
  margin-bottom: 16px;
  line-height: 1.8;
  font-size: 16px;
  letter-spacing: 1px;
}
.btn-next {
  background: #1F2937;
  color: white;
  border: none;
  font-family: inherit;
  font-size: 16px;
  padding: 12px 32px;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 4px;
}
.btn-next:hover { background: #B91C1C; }

/* === 結算 === */
.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin: 32px 0;
}
.result-stat {
  background: white;
  border-radius: 12px;
  padding: 24px 12px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.stat-label {
  font-size: 13px;
  color: #6B7280;
  margin-bottom: 8px;
  letter-spacing: 1px;
}
.stat-value {
  font-size: 30px;
  font-weight: 700;
  color: #B91C1C;
}
.result-message {
  text-align: center;
  font-size: 18px;
  color: #4B5563;
  margin-bottom: 32px;
  letter-spacing: 2px;
  min-height: 28px;
}
.result-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

/* === 手機適配 === */
@media (max-width: 600px) {
  .app { padding: 16px; }
  .title { font-size: 56px; margin-top: 32px; letter-spacing: 8px; }
  .subtitle { letter-spacing: 4px; margin-bottom: 40px; }
  .type-cards { grid-template-columns: 1fr; }
  .choice { font-size: 26px; padding: 24px 12px; }
  .hint-pair { font-size: 26px; min-width: 80px; padding: 12px 8px; }
  .blank { min-width: 36px; }
  .result-stats { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .result-stat { padding: 16px 8px; }
  .stat-value { font-size: 24px; }
  .game-header { padding: 12px 8px; }
  .hud-value { font-size: 18px; }
  .btn-quit { top: 16px; right: 16px; }
}
