/* =====================================================================
   这是我的教室 (ห้องเรียนของฉัน) - UDL Special Education Stylesheet
   Warm Storybook Notebook Theme + Mobile/Tablet Responsive + Print CSS
   ===================================================================== */

:root {
  --paper: #FBF7F0;
  --skycream: #FFFDF9;
  --sage: #5E8B7E;
  --sage-dark: #446A5F;
  --sage-light: #E7F1EE;
  --mustard: #E9965B;
  --mustard-dark: #C9753A;
  --mustard-light: #FDF1E6;
  --wood: #8D6E63;
  --wood-dark: #6D4C41;
  --wood-light: #F3ECE7;
  --ink: #2D3142;

  /* Tone Color-Coding */
  --tone1: #D9534F;
  --tone2: #E67E22;
  --tone3: #2E8B57;
  --tone4: #2B6CB0;
  --tone0: #64748B;
}

/* =====================================================================
   1. พื้นหลังสมุดห้องเรียนไม้แสนอบอุ่น & ค่าเริ่มต้นที่เหมาะกับมือถือ/แท็บเล็ต
   ===================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(to bottom, transparent 31px, rgba(141, 110, 99, 0.08) 32px),
    linear-gradient(to right, rgba(233, 150, 91, 0.08) 1px, transparent 1px);
  background-size: 100% 32px, 32px 100%;
  color: var(--ink);
  font-family: 'Mali', 'Leelawadee UI', 'Thonburi', 'Sarabun', sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  touch-action: manipulation;
}

.hanzi-font {
  font-family: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', 'Kaiti SC', 'STKaiti', sans-serif;
}

/* Focus ring ที่มองเห็นชัดเจนสำหรับผู้ใช้คีย์บอร์ด / Switch Access */
button:focus-visible,
[role="button"]:focus-visible,
input:focus-visible {
  outline: 3px solid var(--mustard);
  outline-offset: 2px;
}

/* ซ่อน scrollbar แนวนอนในแถบหมวดหมู่บนมือถือแต่ยังเลื่อนได้ */
.no-scrollbar::-webkit-scrollbar {
  display: none;
}
.no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* =====================================================================
   2. สไตล์ปุ่มและการ์ด Tactile 3D แบบนูนนุ่ม (Duolingo-inspired Soft 3D)
   ===================================================================== */
.storybook-card {
  background-color: var(--skycream);
  border-radius: 22px;
  border: 2.5px solid #E8DFD3;
  border-bottom: 6px solid #D9CBB9;
  box-shadow: 0 6px 20px -6px rgba(109, 76, 65, 0.12);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.2s ease;
}

.tactile-btn {
  min-height: 52px;
  border-radius: 18px;
  border-width: 2.5px;
  border-style: solid;
  border-bottom-width: 6px;
  transition: transform 0.12s ease, border-bottom-width 0.12s ease, background-color 0.18s ease, box-shadow 0.18s ease;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}

@media (min-width: 640px) {
  .tactile-btn {
    min-height: 56px;
  }
}

.tactile-btn:active:not(:disabled) {
  transform: translateY(3px);
  border-bottom-width: 3px;
}

.tactile-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.tactile-pill {
  min-height: 44px;
  border-radius: 16px;
  border-width: 2px;
  border-style: solid;
  border-bottom-width: 4px;
  transition: transform 0.12s ease, border-bottom-width 0.12s ease, background-color 0.18s ease;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}

.tactile-pill:active:not(:disabled) {
  transform: translateY(2px);
  border-bottom-width: 2px;
}

/* ชุดสีปุ่ม 3D */
.btn-sage {
  background-color: #5E8B7E;
  border-color: #4A7367;
  border-bottom-color: #3A5C52;
  color: #FFFFFF;
}
.btn-sage:hover:not(:disabled) { background-color: #527C70; }

.btn-mustard {
  background-color: #E9965B;
  border-color: #D47E42;
  border-bottom-color: #B3622B;
  color: #FFFFFF;
}
.btn-mustard:hover:not(:disabled) { background-color: #DF884B; }

.btn-cream {
  background-color: #FFFDF9;
  border-color: #E5DACB;
  border-bottom-color: #CFC0AC;
  color: #2D3142;
}
.btn-cream:hover:not(:disabled) { background-color: #FBF5EB; }

.btn-wood {
  background-color: #8D6E63;
  border-color: #74584E;
  border-bottom-color: #5A423A;
  color: #FFFFFF;
}
.btn-wood:hover:not(:disabled) { background-color: #7D5F55; }

.btn-sky {
  background-color: #4A89B8;
  border-color: #39729E;
  border-bottom-color: #2A587C;
  color: #FFFFFF;
}
.btn-sky:hover:not(:disabled) { background-color: #3F7CA9; }

/* =====================================================================
   3. แถบนำทางด้านล่างสำหรับสมาร์ทโฟน (Mobile Bottom Navigation)
   ===================================================================== */
.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 35;
  background-color: rgba(255, 253, 249, 0.97);
  backdrop-filter: blur(8px);
  border-top: 3px solid #E5DACB;
  box-shadow: 0 -4px 18px rgba(109, 76, 65, 0.10);
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px));
}

.mobile-nav-item {
  min-height: 54px;
  border-radius: 14px;
  border: 2px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-weight: 700;
  font-size: 11px;
  line-height: 1.15;
  color: var(--wood-dark);
  background: transparent;
  transition: background-color 0.16s ease, color 0.16s ease, transform 0.12s ease;
  cursor: pointer;
}

.mobile-nav-item.active {
  background-color: var(--sage-light);
  border-color: #9CC0B5;
  color: var(--sage-dark);
}

.mobile-nav-item:active {
  transform: scale(0.95);
}

/* =====================================================================
   4. แอนิเมชันอ่อนโยนเป็นมิตรต่อระบบประสาท (Gentle Animations Only)
   ===================================================================== */
@keyframes gentleBlink {
  0%, 46%, 50%, 100% { transform: scaleY(1); }
  48% { transform: scaleY(0.1); }
}
.mascot-eyes {
  transform-origin: center 54px;
  animation: gentleBlink 4.8s infinite;
}

@keyframes mascotHappyBounce {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  30% { transform: translateY(-10px) rotate(-3deg); }
  60% { transform: translateY(-6px) rotate(3deg); }
}
.mascot-happy {
  animation: mascotHappyBounce 0.7s ease-in-out 2;
}

@keyframes mascotGentleTilt {
  0%, 100% { transform: rotate(0deg); }
  35% { transform: rotate(-7deg); }
  70% { transform: rotate(5deg); }
}
.mascot-thinking {
  animation: mascotGentleTilt 0.8s ease-in-out;
}

@keyframes gentleWobble {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.animate-gentle-wobble {
  animation: gentleWobble 0.45s ease-in-out;
}

@keyframes softPop {
  0% { opacity: 0; transform: scale(0.92) translateY(6px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
.animate-soft-pop {
  animation: softPop 0.28s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes cardPulseSoft {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.025); border-color: #5E8B7E; }
}
.animate-card-pulse {
  animation: cardPulseSoft 0.42s ease;
}

@keyframes floatStarUp {
  0% { opacity: 0; transform: translateY(10px) scale(0.6); }
  25% { opacity: 1; transform: translateY(-8px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-48px) scale(0.9); }
}
.floating-star {
  animation: floatStarUp 1.3s ease-out forwards;
}

@keyframes voiceBar {
  0%, 100% { height: 12px; }
  50% { height: 38px; }
}
.voice-wave-bar {
  animation: voiceBar 0.85s ease-in-out infinite;
}

/* เคารพการตั้งค่าลดแอนิเมชันของผู้ใช้ระบบประสาทไว (Reduced Motion) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* =====================================================================
   5. ตารางคัดอักษรจีน (田字格), Pointer Drag Ghost และโซน 2.5D Drop Zone
   ===================================================================== */
.tianzige-grid {
  background-color: #FFFDF9;
  background-image:
    linear-gradient(to right, transparent 49.4%, #E2D9CC 49.4%, #E2D9CC 50.6%, transparent 50.6%),
    linear-gradient(to bottom, transparent 49.4%, #E2D9CC 49.4%, #E2D9CC 50.6%, transparent 50.6%),
    linear-gradient(45deg, transparent 49.5%, rgba(226, 217, 204, 0.45) 49.5%, rgba(226, 217, 204, 0.45) 50.5%, transparent 50.5%),
    linear-gradient(-45deg, transparent 49.5%, rgba(226, 217, 204, 0.45) 49.5%, rgba(226, 217, 204, 0.45) 50.5%, transparent 50.5%);
  border: 3px solid #C8B8A6;
  border-radius: 22px;
}

/* สิ่งของที่รองรับ Touch & Mouse Drag */
.spatial-draggable-item {
  touch-action: none;
  cursor: grab;
}
.spatial-draggable-item:active {
  cursor: grabbing;
}

/* เงาสิ่งของที่ลอยตามนิ้ว/เมาส์ขณะลากในด่าน 3 */
.drag-ghost-floating {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  width: 84px;
  height: 84px;
  transform: translate(-50%, -50%) scale(1.1);
  background: rgba(255, 253, 249, 0.94);
  border: 3px solid #E9965B;
  border-radius: 20px;
  box-shadow: 0 14px 28px rgba(45, 49, 66, 0.22);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px;
}

/* ไฮไลต์เมื่อลากสิ่งของมาเหนือจุดวางในห้อง 2.5D */
.drop-zone-active {
  background-color: rgba(233, 150, 91, 0.28) !important;
  border-color: #E9965B !important;
  border-style: solid !important;
  box-shadow: 0 0 0 3px rgba(233, 150, 91, 0.3);
}

/* จุดแตะในฉาก I-Spy ห้องเรียน */
.ispy-hotspot {
  cursor: pointer;
  transition: transform 0.22s ease, filter 0.22s ease;
  transform-box: fill-box;
  transform-origin: center;
}
.ispy-hotspot:hover,
.ispy-hotspot:focus-visible {
  filter: drop-shadow(0 0 8px rgba(233, 150, 91, 0.9));
  transform: scale(1.04);
  outline: none;
}
.ispy-discovered {
  filter: drop-shadow(0 0 10px rgba(94, 139, 126, 0.95));
}

/* โหมดโฟกัส (Focus Mode) */
body.focus-mode-active #stage-nav,
body.focus-mode-active #mobile-bottom-nav,
body.focus-mode-active #udl-controls-panel,
body.focus-mode-active #btn-mobile-udl-toggle,
body.focus-mode-active #app-subtitle {
  display: none !important;
}
body.focus-mode-active main {
  max-width: 960px;
  padding-top: 1.5rem;
}

/* =====================================================================
   6. Offline Fallback Utilities (เผื่อเปิดแบบไม่มีอินเทอร์เน็ตแล้วโหลด CDN ไม่ได้)
   ===================================================================== */
.offline-safe-container {
  max-width: 72rem;
  margin-left: auto;
  margin-right: auto;
}
.hidden {
  display: none;
}
.text-tone1 { color: var(--tone1); }
.text-tone2 { color: var(--tone2); }
.text-tone3 { color: var(--tone3); }
.text-tone4 { color: var(--tone4); }
.text-tone0 { color: var(--tone0); }

/* =====================================================================
   7. สไตล์สำหรับการสั่งพิมพ์ใบงาน & รายงาน IEP (@media print)
   ===================================================================== */
#printable-worksheet-area {
  display: none;
}

@page {
  size: A4 portrait;
  margin: 12mm;
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  body {
    background: #FFFFFF !important;
    background-image: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  #app-shell,
  #mobile-bottom-nav,
  #stroke-modal,
  #speaking-modal,
  #teacher-modal,
  #mascot-dock {
    display: none !important;
  }
  #printable-worksheet-area {
    display: block !important;
    padding: 0;
    color: #1E293B;
    font-family: 'Mali', 'Leelawadee UI', sans-serif;
  }
}
