:root {
  --bg-primary: #f0f7ff;
  --bg-card: #ffffff;
  --bg-card-border: #e2e8f0;
  --text-main: #1e293b;
  --text-muted: #64748b;
  
  --accent-blue: #0284c7;
  --accent-orange: #ea580c;
  --accent-amber: #d97706;
  --accent-green: #16a34a;
  --accent-purple: #7c3aed;
  
  --clock-size: 380px;
  --clock-scale: 1;
  --hour-hand-color: #0284c7;
  --min-hand-color: #f97316;
  --sec-hand-color: #ef4444;
}

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

body {
  font-family: 'Mitr', 'Chakra Petch', sans-serif;
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(#bae6fd 1.5px, transparent 1.5px), 
    radial-gradient(#fed7aa 1.5px, #f0f7ff 1.5px);
  background-size: 40px 40px;
  background-position: 0 0, 20px 20px;
  color: var(--text-main);
  min-height: 100vh;
  padding: 16px 12px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
}

.font-mono {
  font-family: 'JetBrains Mono', monospace;
}

.app-container {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* Header */
.app-header {
  text-align: center;
  margin-bottom: 20px;
}

.teacher-tag {
  display: inline-block;
  background: #e0f2fe;
  color: #0369a1;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 4px 14px;
  border-radius: 9999px;
  border: 1.5px solid #bae6fd;
  margin-bottom: 8px;
}

.app-header h1 {
  font-size: 2rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 6px;
  line-height: 1.25;
}

.app-header .subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.5;
  padding: 0 8px;
}

/* Layout */
.main-layout {
  display: grid;
  grid-template-columns: minmax(360px, 460px) 1fr;
  gap: 24px;
  align-items: start;
}

/* Card Styling */
.card {
  background: var(--bg-card);
  border: 2px solid #e2e8f0;
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.06);
  margin-bottom: 20px;
}

.card-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px dashed #f1f5f9;
  padding-bottom: 10px;
}

/* Clock Card */
.clock-display-card {
  background: #ffffff;
  border: 3px solid #cbd5e1;
  border-radius: 24px;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
  width: 100%;
}

/* Day Night Indicator */
.day-night-indicator {
  margin-bottom: 14px;
  padding: 6px 20px;
  border-radius: 9999px;
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fef3c7;
  color: #b45309;
  border: 2px solid #fde68a;
  box-shadow: 0 4px 12px rgba(251, 191, 36, 0.25);
  transition: all 0.3s ease;
}

.day-night-indicator.night {
  background: #e0e7ff;
  color: #3730a3;
  border-color: #c7d2fe;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.clock-stage {
  position: relative;
  width: var(--clock-size);
  height: var(--clock-size);
  max-width: 100%;
  margin: 6px 0;
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
  touch-action: none; /* ป้องกันการเลื่อนหน้าจอบนมือถือขณะลากเข็ม */
}

/* Clock Dial */
.clock {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #ffffff;
  border: 14px solid #38bdf8;
  box-shadow: 
    0 0 0 6px #bae6fd,
    inset 0 0 15px rgba(0, 0, 0, 0.05),
    0 16px 32px rgba(14, 165, 233, 0.18);
  overflow: visible;
}

.clock-face {
  width: 100%;
  height: 100%;
  position: relative;
}

/* Ticks */
.tick {
  position: absolute;
  width: 2px;
  height: 8px;
  background: #cbd5e1;
  left: 50%;
  top: 8px;
  transform-origin: 50% 168px;
  margin-left: -1px;
}

.tick.major {
  width: 4px;
  height: 14px;
  background: #0284c7;
  margin-left: -2px;
  border-radius: 2px;
}

/* Outer numbers (1-12) */
.num-outer {
  position: absolute;
  width: 28px;
  height: 28px;
  left: 50%;
  top: 50%;
  margin-left: -14px;
  margin-top: -14px;
  text-align: center;
  line-height: 28px;
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f172a;
  font-family: 'Kodchasan', 'Mitr', sans-serif;
  pointer-events: none;
}

/* Inner numbers (13-24 / 00) */
.num-inner {
  position: absolute;
  width: 24px;
  height: 24px;
  left: 50%;
  top: 50%;
  margin-left: -12px;
  margin-top: -12px;
  text-align: center;
  line-height: 24px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #ea580c;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 50%;
  font-family: 'JetBrains Mono', monospace;
  pointer-events: none;
}

/* Minute Labels: รอบนอกทุก 5 นาที (:00, :05, :10, ..., :55) */
.num-minute {
  position: absolute;
  width: 20px;
  height: 15px;
  left: 50%;
  top: 50%;
  margin-left: -10px;
  margin-top: -7.5px;
  text-align: center;
  line-height: 15px;
  font-size: 0.68rem;
  font-weight: 700;
  color: #0284c7;
  background: #e0f2fe;
  border-radius: 3px;
  font-family: 'JetBrains Mono', monospace;
  pointer-events: none;
}

/* Hands */
.hand {
  position: absolute;
  bottom: 50%;
  left: 50%;
  transform-origin: 50% 100%;
  pointer-events: none;
  transition: transform 0.05s cubic-bezier(0.4, 2.08, 0.55, 0.44);
}

.hand.dragging {
  transition: none !important;
}

/* Hour Hand (เข็มสั้น สีฟ้า - ยาวพอดีชี้ตัวเลขชั้นใน ไม่ทับบังตัวเลข) */
.hour-hand {
  width: 12px;
  height: 76px;
  margin-left: -6px;
  z-index: 4;
}

.hour-hand .hand-line {
  width: 100%;
  height: 100%;
  background: #0284c7;
  border-radius: 10px 10px 4px 4px;
  box-shadow: 0 4px 8px rgba(2, 132, 199, 0.35);
  border: 2px solid #0369a1;
}

/* Minute Hand (เข็มยาว สีส้มสดใส - ชี้ขีดนาทีวงนอก ไม่ทับบังตัวเลข) */
.minute-hand {
  width: 9px;
  height: 118px;
  margin-left: -4.5px;
  z-index: 5;
}

.minute-hand .hand-line {
  width: 100%;
  height: 100%;
  background: #f97316;
  border-radius: 8px 8px 4px 4px;
  box-shadow: 0 4px 8px rgba(249, 115, 22, 0.35);
  border: 2px solid #c2410c;
}

/* Second Hand */
.second-hand {
  width: 2px;
  height: 138px;
  margin-left: -1px;
  z-index: 6;
}

.second-hand .hand-line {
  width: 100%;
  height: 100%;
  background: #ef4444;
}

.second-hand::after {
  content: '';
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 20px;
  background: #ef4444;
  border-radius: 2px;
}

.center-nut {
  position: absolute;
  width: 22px;
  height: 22px;
  background: #0f172a;
  border: 4px solid #ffffff;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Draggers - จุดจับสำหรับหมุนเข็ม (โปร่งใส 100% ไม่บังตัวเลขด้านล่าง) */
.hand-dragger {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  pointer-events: auto;
  cursor: grab;
  background: transparent; /* โปร่งใสสนิท มองเห็นตัวเลขทะลุได้ชัดเจน */
  border: 2px dashed #0284c7;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.8);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.hand-dragger::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: #0284c7;
  border-radius: 50%;
}

.hand-dragger:hover {
  transform: translateX(-50%) scale(1.3);
  border-style: solid;
}

.hand-dragger:active {
  cursor: grabbing;
}

.minute-hand .hand-dragger {
  border-color: #f97316;
}

.minute-hand .hand-dragger::after {
  background: #f97316;
}

/* Hand Guide Bar */
.hand-guide-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 14px;
  margin-top: 14px;
  background: #f8fafc;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  width: 100%;
  max-width: 440px;
}

.guide-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  white-space: nowrap;
}

.color-dot {
  width: 14px;
  height: 14px;
  border-radius: 4px;
}

.short-dot { background: #0284c7; }
.long-dot { background: #f97316; }

.min-tag-example {
  background: #e0f2fe;
  color: #0284c7;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.drag-hint {
  margin-top: 10px;
  font-size: 0.9rem;
  color: #475569;
  text-align: center;
  background: #e0f2fe;
  border: 1px solid #bae6fd;
  padding: 8px 14px;
  border-radius: 10px;
}

/* Right Controls */
.live-pill {
  font-size: 0.8rem;
  background: #e2e8f0;
  color: #475569;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 600;
}

.live-pill.active {
  background: #dcfce7;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

/* Kid Speech Bubble */
.kid-reading-box {
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 16px;
  padding: 18px 16px;
  text-align: center;
  margin-bottom: 16px;
}

.kid-speech-bubble {
  font-size: 2.2rem;
  font-weight: 700;
  color: #0369a1;
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}

.kid-time-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.detail-badge {
  background: #f1f5f9;
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #334155;
}

.detail-badge.clock-24h {
  background: #ffedd5;
  color: #9a3412;
}

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

.teach-box {
  background: #f1f5f9;
  padding: 10px 12px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.teach-box .lbl {
  font-size: 0.82rem;
  color: #64748b;
}

.teach-box .val {
  font-size: 1.2rem;
  font-weight: 700;
  color: #0f172a;
}

/* Routine Presets (ป.1 - ป.2) */
.routine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.btn-routine {
  background: #ffffff;
  border: 2px solid #e2e8f0;
  padding: 10px 8px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  transition: all 0.2s ease;
  font-family: 'Mitr', sans-serif;
}

.btn-routine .icon {
  font-size: 1.5rem;
}

.btn-routine .text {
  font-size: 0.92rem;
  font-weight: 600;
  color: #1e293b;
  line-height: 1.3;
}

.btn-routine small {
  color: #64748b;
  font-size: 0.78rem;
  font-weight: 400;
}

.btn-routine:hover {
  border-color: #38bdf8;
  background: #f0f9ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(14, 165, 233, 0.15);
}

/* Sliders */
.teacher-slider-area {
  background: #f8fafc;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  margin-bottom: 16px;
}

.slider-group {
  margin-bottom: 12px;
}

.slider-group:last-child {
  margin-bottom: 0;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 0.95rem;
  font-weight: 500;
}

.slider-val {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: #0284c7;
}

input[type="range"] {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: #cbd5e1;
  outline: none;
  cursor: pointer;
  accent-color: #0284c7;
}

/* Action Buttons */
.mode-actions {
  display: flex;
  gap: 12px;
}

.btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: 'Mitr', sans-serif;
  font-weight: 600;
  font-size: 1.05rem;
  padding: 12px 16px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: #0284c7;
  color: #ffffff;
}

.btn-primary:hover {
  background: #0369a1;
  transform: translateY(-1px);
}

.btn-secondary {
  background: #ea580c;
  color: #ffffff;
}

.btn-secondary:hover {
  background: #c2410c;
  transform: translateY(-1px);
}

/* Quiz */
.quiz-card {
  border-left: 6px solid #ea580c;
  background: #fff7ed;
}

.btn-close-quiz {
  background: transparent;
  border: none;
  color: #9a3412;
  cursor: pointer;
  font-weight: 600;
}

.quiz-prompt {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: #9a3412;
}

.quiz-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.quiz-choice-btn {
  font-family: 'Mitr', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 12px;
  background: #ffffff;
  border: 2px solid #fed7aa;
  color: #1e293b;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.quiz-choice-btn:hover {
  border-color: #f97316;
  background: #fff;
  transform: translateY(-2px);
}

.quiz-feedback {
  margin-top: 12px;
  font-size: 1.05rem;
  font-weight: 600;
}

.quiz-feedback.correct { color: #16a34a; }
.quiz-feedback.incorrect { color: #dc2626; }

/* Guide Card */
.guide-card summary {
  font-size: 1.05rem;
  font-weight: 600;
  color: #0369a1;
  cursor: pointer;
  outline: none;
}

.guide-content {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tip-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 12px 14px;
  border-radius: 10px;
}

.tip-box h4 {
  color: #0284c7;
  font-size: 1rem;
  margin-bottom: 6px;
}

.tip-box p {
  font-size: 0.92rem;
  line-height: 1.6;
  color: #334155;
  margin-bottom: 4px;
}

/* Ad & Footer */
.ad-card {
  padding: 14px;
  text-align: center;
  border: 1px dashed #cbd5e1;
  background: #f8fafc;
}

.ad-placeholder-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: #94a3b8;
  margin-bottom: 6px;
}

.ad-box {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-mock-text {
  font-size: 0.85rem;
  color: #94a3b8;
}

.app-footer {
  margin-top: 40px;
  padding: 24px 16px;
  border-top: 1px solid #e2e8f0;
  text-align: center;
  font-size: 0.92rem;
  color: #64748b;
}

.app-footer a {
  color: #0284c7;
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

.footer-links {
  margin-top: 6px;
}

/* =========================================================
   Mobile & Tablet Responsive Optimizations (รองรับมือถือ)
   ========================================================= */

@media (max-width: 920px) {
  .main-layout {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

@media (max-width: 480px) {
  :root {
    --clock-size: 320px;
  }

  body {
    padding: 12px 8px;
  }

  .app-header h1 {
    font-size: 1.65rem;
  }

  .app-header .subtitle {
    font-size: 0.92rem;
  }

  .teacher-tag {
    font-size: 0.8rem;
    padding: 3px 12px;
  }

  .clock-display-card {
    padding: 16px 8px;
  }

  .day-night-indicator {
    font-size: 0.95rem;
    padding: 5px 16px;
  }

  /* ย่อขอบนาฬิกาให้พอดีหน้าจอมือถือขนาดเล็ก */
  .clock {
    border-width: 10px;
    box-shadow: 
      0 0 0 4px #bae6fd,
      inset 0 0 10px rgba(0, 0, 0, 0.04),
      0 10px 20px rgba(14, 165, 233, 0.15);
  }

  /* ปรับขยายหัวจับสำหรับนิ้วแตะบนจอมือถือ (Touch Target โปร่งใส ไม่บังตัวเลข) */
  .hand-dragger {
    width: 38px;
    height: 38px;
    top: -19px;
    background: transparent;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.9);
  }

  .kid-reading-box {
    padding: 14px 10px;
  }

  .kid-speech-bubble {
    font-size: 1.75rem;
  }

  .detail-badge {
    font-size: 0.85rem;
    padding: 3px 10px;
  }

  .routine-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .btn-routine {
    padding: 8px 6px;
  }

  .btn-routine .text {
    font-size: 0.85rem;
  }

  .mode-actions {
    flex-direction: column;
    gap: 10px;
  }

  .btn {
    padding: 12px 14px;
    font-size: 1rem;
  }

  .quiz-choices {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .quiz-choice-btn {
    font-size: 1rem;
    padding: 10px;
  }
}

@media (max-width: 360px) {
  :root {
    --clock-size: 290px;
  }

  .kid-speech-bubble {
    font-size: 1.5rem;
  }

  .routine-grid {
    grid-template-columns: 1fr;
  }
}

