/**
 * 台語精熟闖關 - 完整樣式表 (style.css)
 * 適配 iPad 橫/直向與教室大屏，支援積分連擊特效、寶物交換中心與雲端版排行榜
 */

:root {
  --bg-start: #f0fdf4;
  --bg-end: #e0f2fe;
  --card-bg: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --success-hover: #15803d;
  --warning: #d97706;
  --warning-hover: #b45309;
  --danger: #dc2626;
  --secondary: #475569;
  --border-color: #e2e8f0;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow-card: 0 20px 40px -15px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 20px 16px 60px;
  min-height: 100vh;
  font-family: "Iansui", "Huninn", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 100%);
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.wrap {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  position: relative;
  z-index: 2;
}

.title {
  text-align: center;
  margin-bottom: 20px;
}

.title h1 {
  margin: 0;
  font-size: 2rem;
  font-family: "Huninn", "Iansui", sans-serif;
  color: #0f172a;
  letter-spacing: 1px;
}

.title p {
  margin: 6px 0 0;
  font-size: 0.98rem;
  color: var(--text-muted);
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 28px 24px;
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.screen {
  width: 100%;
}

.center {
  text-align: center;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 6px 0;
}

/* 彈性排版與資訊網格 */
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin: 16px 0;
}

.meta-box {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  text-align: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.meta-box:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.06);
}

.meta-box .label {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.meta-box .value {
  font-size: 1.65rem;
  font-weight: 700;
  color: #0f172a;
}

/* 標籤、徽章與寶物列 */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 6px 14px;
  border-radius: 999px;
}

.student-badge {
  display: inline-block;
  background: #f1f5f9;
  color: #334155;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 6px 14px;
  border-radius: 10px;
  margin: 8px 0;
}

.inventory-bar {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.98rem;
}

/* 表單元件 */
label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  color: #334155;
  font-size: 0.95rem;
}

select,
input[type="text"],
input[type="password"],
input[type="number"],
textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 1.05rem;
  font-family: inherit;
  border: 1.5px solid #cbd5e1;
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

textarea {
  min-height: 90px;
  resize: vertical;
}

/* 按鈕樣式 */
button {
  font-family: inherit;
  font-size: 1.02rem;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.15s ease, opacity 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

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

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #e2e8f0;
  color: #1e293b;
}
.btn-secondary:hover:not(:disabled) {
  background: #cbd5e1;
}

.btn-success {
  background: var(--success);
  color: #ffffff;
}
.btn-success:hover:not(:disabled) {
  background: var(--success-hover);
}

.btn-warning {
  background: var(--warning);
  color: #ffffff;
}
.btn-warning:hover:not(:disabled) {
  background: var(--warning-hover);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

/* 題目與選項區塊 */
.question-box {
  margin-top: 16px;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 22px 20px;
}

.question-title {
  margin: 0 0 18px;
  font-size: 1.35rem;
  line-height: 1.5;
  font-weight: 700;
  color: #0f172a;
}

.options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 600px) {
  .options {
    grid-template-columns: 1fr 1fr;
  }
}

.option-btn {
  width: 100%;
  text-align: left;
  justify-content: flex-start;
  padding: 16px 18px;
  font-size: 1.12rem;
  background: #ffffff;
  color: #1e293b;
  border: 2px solid #cbd5e1;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 4px rgba(15, 23, 42, 0.04);
}

.option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: #eff6ff;
}

/* 答題回饋訊息 */
.feedback {
  display: none;
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 1.05rem;
  text-align: center;
}

.feedback.success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
}

.feedback.error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

/* 過關結算與完美加成 */
.perfect-badge {
  display: inline-block;
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  color: #ffffff;
  font-size: 1.35rem;
  font-weight: 800;
  padding: 10px 24px;
  border-radius: 999px;
  box-shadow: 0 10px 20px rgba(234, 88, 12, 0.25);
  margin-bottom: 10px;
}

.bonus-info {
  background: #fffbeb;
  border: 1.5px dashed #f59e0b;
  color: #b45309;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  margin: 14px auto;
  max-width: 320px;
  font-weight: 700;
}

.treasure-drop-anim {
  margin: 18px auto;
  padding: 16px;
  max-width: 320px;
  background: #fffbeb;
  border: 2px solid #fcd34d;
  border-radius: var(--radius-md);
  color: #b45309;
  font-weight: 700;
  animation: popIn 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

/* 結果碼與 QR Code */
.result-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #0f172a;
  padding: 12px;
  border-radius: var(--radius-sm);
  word-break: break-all;
  margin: 12px 0;
  font-size: 0.95rem;
}

#qrcode,
#giftQr,
#statsQrcode {
  display: flex;
  justify-content: center;
  margin: 16px auto;
}

#qrcode canvas,
#giftQr canvas,
#statsQrcode canvas {
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  max-width: 100%;
  height: auto;
}

/* 彈窗 Modal 與掃描器 */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  z-index: 1000;
}

.modal-card {
  background: #ffffff;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
}

.parse-panel {
  text-align: left;
}

.scanner-video-wrap {
  display: none;
  width: 100%;
  max-width: 380px;
  margin: 12px auto;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000000;
  border: 2px solid #cbd5e1;
}

.scanner-video-wrap video {
  width: 100%;
  display: block;
}

/* 右下角碎形樹畫布 */
.fractal-box {
  position: fixed;
  right: 16px;
  bottom: 12px;
  width: 160px;
  height: 160px;
  pointer-events: none;
  z-index: 1;
  opacity: 0.9;
}

.fractal-box canvas {
  width: 100%;
  height: 100%;
}

/* 連擊浮動數字與星星特效 */
.combo-popup {
  position: fixed;
  transform: translate(-50%, -50%);
  font-weight: 900;
  font-size: 2.2rem;
  pointer-events: none;
  z-index: 2000;
  text-shadow: 0 4px 10px rgba(0, 0, 0, 0.18);
  animation: floatUpFade 1.4s ease-out forwards;
}

.combo-popup.good {
  color: #16a34a;
}
.combo-popup.great {
  color: #2563eb;
  font-size: 2.6rem;
}
.combo-popup.amazing {
  color: #ea580c;
  font-size: 3rem;
}

.emoji-burst {
  position: fixed;
  font-size: 1.8rem;
  pointer-events: none;
  z-index: 1999;
  animation: burstOut 1.4s ease-out forwards;
}

.star-twinkle {
  position: fixed;
  font-size: 2.2rem;
  pointer-events: none;
  z-index: 1999;
  animation: twinkleFade 2.8s ease-in-out forwards;
}

@keyframes floatUpFade {
  0% {
    opacity: 1;
    transform: translate(-50%, -20%) scale(0.8);
  }
  30% {
    transform: translate(-50%, -60%) scale(1.15);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -140%) scale(1);
  }
}

@keyframes burstOut {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.5);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--tx, 60px)), calc(-50% + var(--ty, -60px))) scale(1.3);
  }
}

@keyframes twinkleFade {
  0% {
    opacity: 0;
    transform: scale(0.4) rotate(0deg);
  }
  30% {
    opacity: 1;
    transform: scale(1.2) rotate(20deg);
  }
  100% {
    opacity: 0;
    transform: scale(0.8) translateY(-40px) rotate(-20deg);
  }
}

@keyframes popIn {
  0% {
    opacity: 0;
    transform: scale(0.85);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}
