/* 國小三年級生字部件拆解系統專屬樣式 - 教室教學操作與自適應拓樸 */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;600;700;900&family=Noto+Serif+TC:wght@700;900&family=Edu+TW+Guides&display=swap');

:root {
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --bg-main: #f8fafc;
  --tian-red: #ef4444;
  --tian-dash: #fca5a5;
  --card-bg: #ffffff;
  --text-main: #1e293b;
  --tian-size: 290px; /* 動態田字格尺寸變數，預設調校為 290px */
}

body {
  font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overflow-x: hidden;
}

/* 楷書大字風格 */
.font-kaishu {
  font-family: 'Noto Serif TC', "BiauKai", "DFKai-SB", "標楷體", serif;
}

/* 桌面/電子白板高度鎖定免上下滾動 */
@media (min-width: 1024px) and (min-height: 620px) {
  .viewport-height-lock {
    height: calc(100dvh - 7.5rem);
    max-height: calc(100dvh - 7.5rem);
    overflow: hidden;
  }
}

/* 觸控按鈕大熱區微互動 */
button {
  touch-action: manipulation;
  transition: transform 0.1s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}
button:active:not(:disabled) {
  transform: scale(0.96);
}

/* 標準田字格容器 (支援 CSS 變數動態縮放與垂直防溢出約束) */
.tian-grid {
  position: relative;
  width: var(--tian-size, 290px);
  height: var(--tian-size, 290px);
  max-width: min(90vw, calc(100% - 1.5rem));
  max-height: calc(100% - 3.75rem);
  aspect-ratio: 1 / 1;
  margin: auto;
  background-color: #ffffff;
  box-shadow: inset 0 0 0 4px #dc2626, 0 10px 25px -5px rgba(0, 0, 0, 0.08);
  border-radius: 1.5rem;
  overflow: hidden;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), height 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
}

/* 田字格紅虛線十字 (垂直與水平) */
.tian-grid::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  width: 2px;
  background: repeating-linear-gradient(to bottom, #f87171 0, #f87171 8px, transparent 8px, transparent 16px);
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 1;
}

.tian-grid::after {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 2px;
  background: repeating-linear-gradient(to right, #f87171 0, #f87171 8px, transparent 8px, transparent 16px);
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 1;
}

/* 田字格整字淡灰色底印 (描紅臨摹) */
#grey-trace-char {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Noto Serif TC', "BiauKai", "DFKai-SB", "標楷體", serif;
  font-size: min(13rem, calc(var(--tian-size, 290px) * 0.76));
  line-height: 1;
  color: #94a3b8;
  opacity: 0.38;
  pointer-events: none;
  user-select: none;
  z-index: 5;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#grey-trace-char.hidden-trace {
  opacity: 0 !important;
  visibility: hidden;
}

/* 田字格手寫書寫畫布 (HTML5 Canvas) */
#handwriting-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 20;
  touch-action: none;
  cursor: crosshair;
  pointer-events: none;
  border-radius: 1.5rem;
}

/* 書寫模式激活用樣式 */
.practice-writing-mode #handwriting-canvas {
  pointer-events: auto;
}

.practice-writing-mode .char-slot {
  opacity: 0.18;
  pointer-events: none;
}

.practice-writing-mode #component-tray-container {
  display: none !important;
}

.practice-writing-mode #handwriting-toolbar {
  display: flex !important;
}

/* 幾何槽位樣式 */
.char-slot {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
  box-sizing: border-box;
}

.char-slot.drop-hover {
  background-color: rgba(59, 130, 246, 0.18) !important;
  border-color: #2563eb !important;
  box-shadow: inset 0 0 0 3px #3b82f6;
  transform: scale(0.98);
}

.char-slot.slot-correct {
  background-color: rgba(16, 185, 129, 0.12) !important;
  border-color: #10b981 !important;
}

/* 拖曳部件卡片 (大尺寸觸控) */
.component-card {
  touch-action: none;
  cursor: grab;
  min-width: 48px;
  min-height: 48px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.component-card:active, .component-card.is-dragging {
  cursor: grabbing;
  transform: scale(1.12) !important;
  box-shadow: 0 20px 30px -8px rgba(0, 0, 0, 0.25), 0 10px 15px -3px rgba(0, 0, 0, 0.15) !important;
  z-index: 999 !important;
}

/* 點選選中狀態 (供點選放置模式) */
.component-card.is-selected {
  outline: 4px solid #f59e0b;
  outline-offset: 3px;
  animation: pulseSelect 1.5s infinite;
}

@keyframes pulseSelect {
  0%, 100% { transform: scale(1.06); }
  50% { transform: scale(1.12); }
}

/* 合成成功激勵效果 */
@keyframes characterMerge {
  0% { transform: scale(0.85); opacity: 0.7; }
  50% { transform: scale(1.18); filter: drop-shadow(0 0 25px rgba(245, 158, 11, 0.85)); }
  100% { transform: scale(1); opacity: 1; }
}

.character-merge-anim {
  animation: characterMerge 0.75s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ================= 教室大螢幕電子白板全螢幕授課模式 ================= */
body.whiteboard-mode {
  background-color: #0f172a !important; /* 護眼深藍黑 */
  color: #f8fafc !important;
}

body.whiteboard-mode header {
  background-color: #1e293b !important;
  border-color: #334155 !important;
}

body.whiteboard-mode .filter-bar-container {
  display: none !important;
}

body.whiteboard-mode .encyclopedia-column {
  display: none !important;
}

body.whiteboard-mode .workshop-column {
  grid-column: span 12 / span 12 !important;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

body.whiteboard-mode .tian-grid {
  --tian-size: min(450px, 52vh) !important;
  background-color: #1e293b !important;
  box-shadow: inset 0 0 0 6px #ef4444, 0 25px 50px -12px rgba(0, 0, 0, 0.6) !important;
}

body.whiteboard-mode .component-card {
  background-color: #334155 !important;
  border-color: #64748b !important;
  color: #ffffff !important;
  width: 6rem !important;
  height: 7.2rem !important;
}

body.whiteboard-mode .component-card div:first-child {
  color: #ffffff !important;
  font-size: 3.2rem !important;
}

/* ================= UDL 高對比無障礙模式 ================= */
body.high-contrast {
  background-color: #000000 !important;
  color: #fef08a !important;
}

body.high-contrast .bg-white,
body.high-contrast .bg-slate-50,
body.high-contrast .bg-slate-100 {
  background-color: #18181b !important;
  color: #fef08a !important;
  border-color: #fef08a !important;
}

body.high-contrast .tian-grid {
  background-color: #121212 !important;
  box-shadow: inset 0 0 0 5px #facc15 !important;
}

body.high-contrast .tian-grid::before,
body.high-contrast .tian-grid::after {
  background: #facc15 !important;
}

body.high-contrast .component-card {
  background-color: #27272a !important;
  border: 3px solid #facc15 !important;
  color: #ffffff !important;
}

/* 乾淨捲動條樣式 */
.custom-scrollbar::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.03);
  border-radius: 9999px;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
  background-color: #cbd5e1;
  border-radius: 9999px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background-color: #94a3b8;
}

.no-scrollbar::-webkit-scrollbar {
  display: none;
}
.no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}
