/* ============================================================
   PHAMO — บทเรียน CAI / บัญชีผู้เรียน
   ต่อยอดจาก css/style.css (ใช้ตัวแปรสีชุดเดียวกัน)
   ============================================================ */

.cai {
  max-width: 980px;
  margin: 18px auto 90px;
  padding: 0 14px;
  position: relative;
}

/* Author-level display rules (เช่น .lightbox { display: grid }) มีลำดับสูงกว่า
   hidden ของเบราว์เซอร์ จึงต้องยืนยันการซ่อนภายในบทเรียนไว้อีกชั้น */
.cai [hidden] {
  display: none !important;
}

/* ---------- แถบความก้าวหน้า 5 ขั้น ---------- */
.cai-rail {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--c-white);
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  box-shadow: var(--shadow-soft);
  position: sticky;
  top: 78px;
  z-index: 60;
  margin-bottom: 18px;
}

.cai-back {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--c-bg-cloud);
  color: var(--c-primary-dark);
  font-size: 18px; font-weight: 700;
  text-decoration: none;
}
.cai-back:hover { background: var(--c-yellow); }

.cai-rail-steps {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  list-style: none;
  margin: 0; padding: 0;
  position: relative;
}
.cai-rail-steps::before {
  content: '';
  position: absolute;
  left: 6%; right: 6%; top: 17px;
  height: 3px;
  background: var(--c-bg-cloud);
  border-radius: 3px;
  z-index: 0;
}

.cai-rail-step {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1 1 0;
  min-width: 0;
}

.cai-rail-dot {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid var(--c-bg-cloud);
  background: var(--c-white);
  display: grid; place-items: center;
  font-size: 15px;
  cursor: pointer;
  transition: transform .18s, background .18s, border-color .18s;
  padding: 0;
}
.cai-rail-dot:disabled { cursor: not-allowed; opacity: .45; }
.cai-rail-step.is-done .cai-rail-dot {
  background: var(--c-green);
  border-color: var(--c-green);
}
.cai-rail-step.is-current .cai-rail-dot {
  background: var(--c-yellow);
  border-color: var(--c-orange);
  transform: scale(1.18);
  box-shadow: 0 0 0 5px rgba(255, 212, 59, .28);
}

.cai-rail-label {
  font-size: 10.5px;
  color: var(--c-text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.cai-rail-step.is-current .cai-rail-label {
  color: var(--c-primary-dark);
  font-weight: 700;
}

.cai-rail-count {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--c-text-soft);
  background: var(--c-bg-cloud);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
}

@media (max-width: 620px) {
  .cai-rail { top: 70px; padding: 8px 10px; }
  .cai-rail-label { display: none; }
  .cai-rail-steps::before { top: 15px; }
}

/* ---------- เวทีของแต่ละขั้น ---------- */
.cai-stage { display: none; animation: stage-in .32s ease both; }
.cai-stage.is-active { display: block; }

@keyframes stage-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

.stage-head { margin-bottom: 16px; text-align: center; }
.stage-head h2 {
  font-size: 24px;
  color: var(--c-primary-dark);
  margin-bottom: 4px;
}
.stage-head p { color: var(--c-text-soft); font-size: 14.5px; }
.stage-mission {
  background: var(--c-bg-soft);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  display: inline-block;
  color: var(--c-text);
  margin-top: 6px;
}

.stage-foot {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  margin-top: 22px;
  flex-wrap: wrap;
}
.stage-foot .btn { flex: 1 1 auto; min-width: 150px; }

.btn.is-ready {
  animation: nudge 1.4s ease-in-out infinite;
}
@keyframes nudge {
  0%, 100% { transform: none; }
  50% { transform: translateY(-3px); }
}

.cai-empty {
  background: var(--c-bg-cloud);
  border: 2px dashed var(--c-primary);
  border-radius: var(--radius-sm);
  padding: 20px;
  text-align: center;
  color: var(--c-text-soft);
}

/* ---------- ขั้น 1: ชวนสงสัย ---------- */
.hook {
  background: var(--c-white);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-cute);
  display: grid;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 780px) { .hook { grid-template-columns: 1fr; } }

.hook-visual {
  position: relative;
  min-height: 260px;
  background: linear-gradient(135deg, var(--c-primary), var(--c-purple));
  display: grid; place-items: center;
}
.hook-visual img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.hook-emoji { font-size: 96px; }

.hook-chips {
  position: absolute;
  left: 12px; bottom: 12px;
  display: flex; gap: 6px; flex-wrap: wrap;
  z-index: 1;
}
.hook-chips span {
  background: rgba(255, 255, 255, .92);
  color: var(--c-primary-dark);
  font-size: 11.5px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  backdrop-filter: blur(4px);
}

.hook-copy { padding: 26px 24px 28px; }
.hook-eyebrow {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--c-orange);
  text-transform: none;
  margin-bottom: 6px;
}
.hook-copy h1 {
  font-size: 30px;
  line-height: 1.18;
  color: var(--c-primary-dark);
  margin-bottom: 6px;
}
.hook-title { color: var(--c-text-soft); font-size: 15px; margin-bottom: 16px; }

.hook-question {
  position: relative;
  background: var(--c-bg-soft);
  border-left: 6px solid var(--c-orange);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 16px 18px 16px 52px;
  font-size: 16.5px;
  line-height: 1.65;
  color: var(--c-text);
  margin-bottom: 12px;
}
.hook-question span {
  position: absolute;
  left: 14px; top: 12px;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--c-orange);
  color: #fff;
  font-weight: 800;
  font-size: 17px;
  display: grid; place-items: center;
}

.hook-note { color: var(--c-text-soft); font-size: 14px; margin-bottom: 18px; }
.hook-copy .btn { width: 100%; }

.cai-guest-note {
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--c-text-soft);
  text-align: center;
}
.cai-guest-note a { font-weight: 700; text-decoration: underline; }

/* ---------- ขั้น 2: บัตรความรู้ ---------- */
.deck { position: relative; min-height: 300px; }

.deck-card {
  display: none;
  background: var(--c-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-cute);
  padding: 30px 26px 26px;
  text-align: center;
  position: relative;
  animation: card-in .3s ease both;
}
.deck-card.is-active { display: block; }

@keyframes card-in {
  from { opacity: 0; transform: scale(.96) translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.deck-card-num {
  position: absolute;
  top: 14px; right: 18px;
  font-size: 12px;
  font-weight: 700;
  color: var(--c-text-soft);
  background: var(--c-bg-cloud);
  border-radius: var(--radius-pill);
  padding: 3px 10px;
}
.deck-card-icon { font-size: 52px; display: block; margin-bottom: 8px; }
.deck-card h3 {
  font-size: 22px;
  color: var(--c-primary-dark);
  margin-bottom: 12px;
}
.deck-card-body {
  font-size: 16px;
  line-height: 1.85;
  color: var(--c-text);
  max-width: 62ch;
  margin: 0 auto;
}
.deck-fact {
  margin: 18px auto 0;
  max-width: 62ch;
  background: var(--c-bg-soft);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--c-text);
  text-align: left;
}
.deck-fact b { color: var(--c-orange); margin-right: 6px; }

.deck-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
}
.deck-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--c-white);
  box-shadow: var(--shadow-soft);
  color: var(--c-primary-dark);
  font-size: 20px;
  cursor: pointer;
  transition: transform .15s;
}
.deck-btn:hover { transform: scale(1.1); background: var(--c-yellow); }

.deck-dots { display: flex; gap: 8px; }
.deck-dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  border: none;
  background: var(--c-bg-cloud);
  cursor: pointer;
  padding: 0;
  transition: all .18s;
}
.deck-dot.is-active {
  background: var(--c-orange);
  width: 26px;
  border-radius: var(--radius-pill);
}

/* ---------- ขั้น 3: คำถามทบทวน ---------- */
.checks { display: grid; gap: 16px; }

.check {
  background: var(--c-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-cute);
  padding: 22px 22px 18px;
}

.check-q {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  font-size: 17px;
  line-height: 1.6;
  color: var(--c-text);
  margin-bottom: 16px;
  font-weight: 600;
}
.check-n {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  display: grid; place-items: center;
  font-size: 14px;
  font-weight: 700;
}

.check-opts { display: grid; gap: 9px; }
.check-opt {
  text-align: left;
  background: var(--c-bg-cloud);
  border: 3px solid transparent;
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  font: inherit;
  font-size: 15.5px;
  color: var(--c-text);
  cursor: pointer;
  transition: all .16s;
}
.check-opt:hover:not(:disabled) {
  border-color: var(--c-primary);
  transform: translateX(4px);
}
.check-opt:disabled { cursor: default; opacity: .75; }
.check-opt.is-correct {
  background: #d3f9d8;
  border-color: var(--c-green);
  opacity: 1;
  font-weight: 700;
}
.check-opt.is-wrong {
  background: #ffe3e3;
  border-color: var(--c-coral);
  opacity: 1;
}
.check-opt.is-answer {
  border-color: var(--c-green);
  border-style: dashed;
  opacity: 1;
}

.check-feedback {
  margin-top: 14px;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14.5px;
  line-height: 1.7;
  animation: card-in .25s ease both;
}
.check-feedback.is-ok { background: #d3f9d8; color: #1b6b30; }
.check-feedback.is-no { background: var(--c-bg-soft); color: #8a5a00; }

.check-tools {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.check-hint-btn, .check-retry {
  background: none;
  border: 2px solid var(--c-bg-cloud);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font: inherit;
  font-size: 13px;
  color: var(--c-text-soft);
  cursor: pointer;
  transition: all .15s;
}
.check-hint-btn:hover, .check-retry:hover {
  border-color: var(--c-orange);
  color: var(--c-orange);
}

/* ---------- ขั้น 4: ออกสำรวจ ---------- */
.explore-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 16px;
}
@media (max-width: 780px) { .explore-grid { grid-template-columns: 1fr; } }

.mini-map {
  height: 280px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--c-bg-cloud);
  border: 3px solid var(--c-yellow);
  display: grid;
  place-items: center;
  position: relative;
}
.mini-map-load {
  border: none;
  background: var(--c-white);
  border-radius: var(--radius-pill);
  padding: 12px 22px;
  font: inherit;
  font-weight: 700;
  color: var(--c-primary-dark);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
}
.mini-map-load:hover { background: var(--c-yellow); }
.mini-map-loading { color: var(--c-text-soft); font-size: 14px; }

.map-pin {
  width: 42px; height: 42px;
  background: var(--c-orange);
  border: 3px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
  display: grid; place-items: center;
}
.map-pin span { transform: rotate(45deg); font-size: 17px; }

.explore-coord {
  text-align: center;
  font-size: 12.5px;
  color: var(--c-text-soft);
  margin-top: 8px;
}

.explore-links { display: grid; gap: 10px; align-content: start; }
.explore-link {
  display: block;
  text-align: left;
  width: 100%;
  background: var(--c-white);
  border: 3px solid transparent;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-soft);
  padding: 14px 18px;
  font: inherit;
  color: var(--c-text);
  text-decoration: none;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
}
.explore-link:hover { transform: translateY(-3px); border-color: var(--c-primary); }
.explore-link b { display: block; color: var(--c-primary-dark); font-size: 16px; margin-bottom: 2px; }
.explore-link span { font-size: 13px; color: var(--c-text-soft); }
.explore-link--ar { border-color: var(--c-pink); }
.explore-link--ai { border-color: var(--c-purple); }

.reflect {
  background: var(--c-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-cute);
  padding: 20px 22px;
  margin-top: 18px;
}
.reflect label { display: block; margin-bottom: 10px; font-size: 15px; line-height: 1.6; }
.reflect label b { color: var(--c-primary-dark); }
.reflect textarea {
  width: 100%;
  border: 3px solid var(--c-bg-cloud);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font: inherit;
  font-size: 15px;
  resize: vertical;
  margin-bottom: 10px;
}
.reflect textarea:focus { outline: none; border-color: var(--c-primary); }
.reflect-answer {
  margin-top: 12px;
  background: var(--c-bg-cloud);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 14.5px;
  line-height: 1.75;
  white-space: pre-wrap;
}

/* ---------- ขั้น 5: สรุป ---------- */
.summary {
  background: var(--c-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-cute);
  padding: 30px 26px;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 26px;
  align-items: start;
}
@media (max-width: 780px) { .summary { grid-template-columns: 1fr; text-align: center; } }

.summary-badge {
  background: linear-gradient(150deg, var(--c-yellow), var(--c-orange));
  border-radius: var(--radius);
  padding: 24px 18px;
  text-align: center;
  color: #6b3d00;
  box-shadow: var(--shadow-pop);
}
.summary-badge-emoji {
  font-size: 62px;
  display: block;
  animation: badge-pop .6s cubic-bezier(.34, 1.56, .64, 1) both;
}
@keyframes badge-pop {
  0% { transform: scale(0) rotate(-30deg); }
  100% { transform: none; }
}
.summary-badge p { font-size: 12.5px; margin: 6px 0 2px; opacity: .85; }
.summary-badge strong { font-size: 18px; line-height: 1.35; display: block; }

.summary-copy h2 { color: var(--c-primary-dark); font-size: 24px; margin-bottom: 12px; }
.summary-idea { font-size: 16px; line-height: 1.8; margin-bottom: 14px; }
.summary-take {
  background: var(--c-bg-cloud);
  border-left: 5px solid var(--c-primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 14px 18px;
  font-size: 15.5px;
  line-height: 1.75;
  color: var(--c-primary-dark);
  font-weight: 600;
}
.summary-score {
  margin-top: 14px;
  font-size: 14px;
  color: var(--c-text-soft);
}

.summary-cta-guest {
  margin-top: 18px;
  background: var(--c-bg-soft);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
}
.summary-cta-guest p { font-size: 14.5px; line-height: 1.7; margin-bottom: 12px; }

.summary-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 20px;
}

/* ---------- ครูผามอ (AI) ---------- */
.tutor-fab {
  position: fixed;
  right: 18px; bottom: 18px;
  z-index: 1100; /* ต้องสูงกว่า .site-header ที่ใช้ z-index 1000 */
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--c-purple), var(--c-primary));
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  padding: 12px 20px 12px 14px;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  box-shadow: var(--shadow-deep);
  transition: transform .18s;
}
.tutor-fab:hover { transform: translateY(-3px) scale(1.03); }
.tutor-fab-face { font-size: 24px; animation: bounce-soft 2.4s ease-in-out infinite; }

@media (max-width: 520px) {
  .tutor-fab { padding: 12px 16px; right: 12px; bottom: 12px; }
  .tutor-fab-text { display: none; }
}

.tutor {
  position: fixed;
  right: 18px; bottom: 82px;
  width: min(370px, calc(100vw - 24px));
  max-height: min(580px, calc(100vh - 150px));
  background: var(--c-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-deep);
  border: 3px solid var(--c-purple);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1110; /* สูงกว่าแถบเมนู ไม่งั้นหัวกล่องจะถูกเมนูบัง */
  opacity: 0;
  transform: translateY(16px) scale(.97);
  transition: opacity .22s ease, transform .22s ease;
}
.tutor.is-open { opacity: 1; transform: none; }

@media (max-width: 520px) {
  .tutor { right: 8px; left: 8px; width: auto; bottom: 74px; }
}

.tutor-head {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--c-purple), var(--c-primary));
  color: #fff;
  padding: 12px 14px;
}
.tutor-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .25);
  display: grid; place-items: center;
  font-size: 20px;
}
.tutor-head div { flex: 1; min-width: 0; }
.tutor-head strong { display: block; font-size: 15px; }
.tutor-head small { font-size: 11.5px; opacity: .85; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tutor-close {
  background: rgba(255, 255, 255, .2);
  border: none;
  color: #fff;
  width: 30px; height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
}

.tutor-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--c-bg-cloud);
  min-height: 180px;
}

.tutor-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  animation: card-in .22s ease both;
}
.tutor-msg--bot {
  background: var(--c-white);
  border-bottom-left-radius: 5px;
  align-self: flex-start;
  box-shadow: var(--shadow-soft);
}
.tutor-msg--user {
  background: var(--c-primary);
  color: #fff;
  border-bottom-right-radius: 5px;
  align-self: flex-end;
}
.tutor-msg--error {
  background: #ffe3e3;
  color: #a12b2b;
  align-self: flex-start;
}

.tutor-speak {
  display: block;
  margin-top: 8px;
  background: var(--c-bg-cloud);
  border: none;
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font: inherit;
  font-size: 12px;
  color: var(--c-primary-dark);
  cursor: pointer;
}

.tutor-typing { display: flex; gap: 5px; align-items: center; padding: 14px; }
.tutor-typing i {
  width: 8px; height: 8px;
  background: var(--c-primary);
  border-radius: 50%;
  animation: typing 1.2s infinite;
}
.tutor-typing i:nth-child(2) { animation-delay: .2s; }
.tutor-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes typing {
  0%, 60%, 100% { transform: none; opacity: .4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

.tutor-chips {
  display: flex;
  gap: 6px;
  padding: 10px 12px 0;
  flex-wrap: wrap;
}
.tutor-chips button {
  background: var(--c-bg-soft);
  border: none;
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font: inherit;
  font-size: 12.5px;
  color: var(--c-text);
  cursor: pointer;
  text-align: left;
}
.tutor-chips button:hover { background: var(--c-yellow); }

.tutor-form {
  display: flex;
  gap: 6px;
  padding: 10px 12px 12px;
  align-items: center;
}
.tutor-form input {
  flex: 1;
  border: 3px solid var(--c-bg-cloud);
  border-radius: var(--radius-pill);
  padding: 9px 14px;
  font: inherit;
  font-size: 14.5px;
  min-width: 0;
}
.tutor-form input:focus { outline: none; border-color: var(--c-primary); }
.tutor-form button {
  width: 40px; height: 40px;
  flex: 0 0 auto;
  border: none;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
.tutor-form button#tutorMic { background: var(--c-bg-cloud); color: var(--c-primary-dark); }
.tutor-form button#tutorMic.is-listening { background: var(--c-coral); color: #fff; animation: nudge .8s infinite; }

/* ============================================================
   หน้าสมัคร / เข้าสู่ระบบ
   ============================================================ */
.auth-wrap {
  max-width: 620px;
  margin: 30px auto 70px;
  padding: 0 14px;
}
.auth-card {
  background: var(--c-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-cute);
  padding: 32px 28px;
}
.auth-card--slim { max-width: 440px; margin: 0 auto; }

.auth-head { text-align: center; margin-bottom: 22px; }
.auth-badge {
  display: inline-block;
  background: var(--c-bg-soft);
  color: var(--c-orange);
  font-size: 12px;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 5px 14px;
  margin-bottom: 10px;
}
.auth-head h1 { font-size: 27px; color: var(--c-primary-dark); margin-bottom: 8px; }
.auth-head p { color: var(--c-text-soft); font-size: 14.5px; line-height: 1.7; }

.auth-error {
  background: #ffe3e3;
  color: #a12b2b;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  margin-bottom: 16px;
}

.auth-form { display: grid; gap: 16px; }

.field { display: block; }
.field-label { display: block; font-size: 14px; font-weight: 700; color: var(--c-text); margin-bottom: 6px; }
.field-label em { font-style: normal; font-weight: 400; color: var(--c-text-soft); font-size: 12.5px; }
.field input {
  width: 100%;
  border: 3px solid var(--c-bg-cloud);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font: inherit;
  font-size: 15.5px;
}
.field input:focus { outline: none; border-color: var(--c-primary); }
.field small { display: block; margin-top: 5px; font-size: 12px; color: var(--c-text-soft); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 520px) { .field-row { grid-template-columns: 1fr; } }

.avatar-picker { border: none; padding: 0; }
.avatar-picker legend { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.avatar-row { display: flex; gap: 8px; flex-wrap: wrap; }
.avatar-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.avatar-opt span {
  display: grid; place-items: center;
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--c-bg-cloud);
  font-size: 24px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: all .15s;
}
.avatar-opt input:checked + span {
  border-color: var(--c-orange);
  background: var(--c-bg-soft);
  transform: scale(1.1);
}

.auth-submit { width: 100%; margin-top: 4px; }
.auth-alt {
  text-align: center;
  margin-top: 18px;
  font-size: 14px;
  color: var(--c-text-soft);
}
.auth-alt a { font-weight: 700; }

/* ============================================================
   ห้องเรียนของฉัน (โปรไฟล์)
   ============================================================ */
.profile-wrap {
  max-width: 900px;
  margin: 24px auto 70px;
  padding: 0 14px;
}

.profile-flash {
  background: #d3f9d8;
  color: #1b6b30;
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin-bottom: 18px;
  font-size: 15px;
}

.profile-hero {
  background: var(--c-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-cute);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.profile-avatar {
  width: 84px; height: 84px;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--c-yellow), var(--c-orange));
  display: grid; place-items: center;
  font-size: 42px;
  box-shadow: var(--shadow-pop);
}
.profile-id { flex: 1; min-width: 190px; }
.profile-id h1 { font-size: 26px; color: var(--c-primary-dark); }
.profile-rank { color: var(--c-orange); font-weight: 700; font-size: 15px; }
.profile-meta { color: var(--c-text-soft); font-size: 13.5px; }

.profile-ring {
  width: 96px; height: 96px;
  border-radius: 50%;
  display: grid; place-items: center;
  text-align: center;
  background: conic-gradient(var(--c-green) calc(var(--pct) * 1%), var(--c-bg-cloud) 0);
  position: relative;
}
.profile-ring::before {
  content: '';
  position: absolute;
  inset: 9px;
  background: var(--c-white);
  border-radius: 50%;
}
.profile-ring span, .profile-ring small { position: relative; z-index: 1; display: block; }
.profile-ring span { font-size: 22px; font-weight: 800; color: var(--c-primary-dark); }
.profile-ring small { font-size: 10.5px; color: var(--c-text-soft); }

.profile-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.stat {
  background: var(--c-white);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-soft);
  padding: 16px;
  text-align: center;
}
.stat b { display: block; font-size: 24px; color: var(--c-primary-dark); }
.stat span { font-size: 12.5px; color: var(--c-text-soft); }

.profile-next {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: linear-gradient(135deg, var(--c-primary), var(--c-purple));
  color: #fff;
  border-radius: var(--radius);
  padding: 18px 22px;
  text-decoration: none;
  box-shadow: var(--shadow-deep);
  transition: transform .16s;
}
.profile-next:hover { transform: translateY(-3px); }
.profile-next-label { font-size: 12.5px; opacity: .85; width: 100%; }
.profile-next strong { font-size: 21px; flex: 1; }
.profile-next-go { font-weight: 700; }
.profile-next--done { background: var(--c-bg-soft); color: var(--c-text); display: block; }

.profile-section { margin-top: 26px; }
.profile-section h2 { font-size: 20px; color: var(--c-primary-dark); margin-bottom: 12px; }

.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.badge-chip {
  background: var(--c-white);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-soft);
  padding: 16px 12px;
  text-align: center;
  border: 3px solid var(--c-yellow);
}
.badge-chip-emoji { font-size: 36px; display: block; margin-bottom: 6px; }
.badge-chip strong { display: block; font-size: 14px; color: var(--c-primary-dark); line-height: 1.4; }
.badge-chip small { font-size: 11.5px; color: var(--c-text-soft); }

.progress-list { display: grid; gap: 8px; }
.progress-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1.4fr) minmax(70px, 1fr) 78px;
  align-items: center;
  gap: 10px;
  background: var(--c-white);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-soft);
  padding: 12px 16px;
  text-decoration: none;
  color: var(--c-text);
  border-left: 5px solid var(--c-bg-cloud);
  transition: transform .14s;
}
.progress-row:hover { transform: translateX(4px); }
.progress-row.is-done  { border-left-color: var(--c-green); }
.progress-row.is-doing { border-left-color: var(--c-yellow); }
.progress-row-mark { font-size: 18px; }
.progress-row-name strong { display: block; font-size: 15px; }
.progress-row-name small { font-size: 12px; color: var(--c-text-soft); }
.progress-row-bar {
  height: 9px;
  background: var(--c-bg-cloud);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-row-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--c-primary), var(--c-green));
  border-radius: var(--radius-pill);
  transition: width .5s ease;
}
.progress-row-pct { font-size: 12.5px; color: var(--c-text-soft); text-align: right; }

@media (max-width: 620px) {
  .progress-row { grid-template-columns: 26px 1fr 64px; }
  .progress-row-bar { grid-column: 2 / 4; height: 7px; }
}

.profile-signout { text-align: center; margin-top: 28px; }
.profile-signout a { color: var(--c-text-soft); font-size: 14px; text-decoration: underline; }


/* ============================================================
   ประวัติฉบับเต็มจากวิกิพีเดีย
   ออกแบบให้ "อ่านสบาย" เป็นหลัก: บรรทัดไม่ยาวเกิน 62 ตัวอักษร
   ระยะบรรทัดกว้างสำหรับภาษาไทยที่มีสระบนล่าง และพับหัวข้อไว้ไม่ให้ท่วม
   ============================================================ */

.deepdive {
  background: var(--c-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-cute);
  padding: 22px 24px;
  margin-top: 18px;
}

.deepdive-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.deepdive-head h3 { font-size: 20px; color: var(--c-primary-dark); margin-bottom: 3px; }
.deepdive-head p  { font-size: 13.5px; color: var(--c-text-soft); line-height: 1.65; max-width: 52ch; }
.deepdive-head .btn { flex: 0 0 auto; }

.deepdive-body { margin-top: 20px; }

/* โครงร่างระหว่างโหลด — บอกผู้ใช้ว่ากำลังมา ไม่ใช่ค้าง */
.dd-skeleton { display: grid; gap: 10px; }
.dd-skeleton i {
  display: block;
  height: 14px;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--c-bg-cloud) 25%, #f1f7fd 50%, var(--c-bg-cloud) 75%);
  background-size: 200% 100%;
  animation: dd-shimmer 1.3s ease-in-out infinite;
}
.dd-skeleton i.short { width: 55%; }
@keyframes dd-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

.dd-empty {
  background: var(--c-bg-soft);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-size: 14.5px;
  color: var(--c-text);
}

/* ภาพเปิดเรื่อง */
.dd-hero { margin-bottom: 18px; }
.dd-hero img {
  width: 100%;
  max-height: 340px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 3px solid var(--c-yellow);
}
.dd-hero figcaption {
  text-align: center;
  font-size: 12.5px;
  color: var(--c-text-soft);
  margin-top: 7px;
}

/* ย่อหน้านำ — ตัวใหญ่กว่าเนื้อหาปกติ ให้เริ่มอ่านง่าย
   หมายเหตุ: ไม่ใช้อักษรตัวแรกขนาดใหญ่ (drop cap) เพราะภาษาไทยมีสระบน-ล่าง
   การตัดตัวอักษรตัวแรกออกมาจะทำให้คำแรกดูขาดและอ่านสะดุด */
.dd-lead {
  border-left: 5px solid var(--c-orange);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--c-bg-soft);
  padding: 18px 20px 8px;
  margin-bottom: 6px;
}
.dd-lead p {
  font-size: 16.5px;
  line-height: 1.95;
  color: var(--c-text);
  max-width: 62ch;
  margin-bottom: 12px;
}

/* สารบัญ */
.dd-toc {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  background: var(--c-bg-cloud);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 18px 0;
}
.dd-toc b { font-size: 13px; color: var(--c-primary-dark); margin-right: 4px; }
.dd-toc button {
  background: var(--c-white);
  border: none;
  border-radius: var(--radius-pill);
  padding: 5px 13px;
  font: inherit;
  font-size: 12.5px;
  color: var(--c-primary-dark);
  cursor: pointer;
  transition: background .15s;
}
.dd-toc button:hover { background: var(--c-yellow); }

/* หัวข้อแบบพับได้ */
.dd-section {
  border-top: 2px solid var(--c-bg-cloud);
  padding: 4px 0;
}
.dd-section.is-sub { margin-left: 18px; border-top-style: dashed; }

.dd-section summary {
  cursor: pointer;
  list-style: none;
  padding: 13px 34px 13px 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--c-primary-dark);
  position: relative;
}
.dd-section.is-sub summary { font-size: 15px; color: var(--c-text); }
.dd-section summary::-webkit-details-marker { display: none; }
.dd-section summary::after {
  content: '▾';
  position: absolute;
  right: 8px; top: 50%;
  transform: translateY(-50%);
  color: var(--c-text-soft);
  transition: transform .2s;
}
.dd-section[open] > summary::after { transform: translateY(-50%) rotate(180deg); }
.dd-section summary:hover { color: var(--c-orange); }

.dd-text p {
  font-size: 15.5px;
  line-height: 1.95;
  color: var(--c-text);
  max-width: 62ch;
  margin-bottom: 12px;
}

/* ปุ่มให้ AI เล่าใหม่ */
.dd-explain {
  background: none;
  border: 2px dashed var(--c-purple);
  border-radius: var(--radius-pill);
  padding: 7px 16px;
  font: inherit;
  font-size: 13px;
  color: #7048c8;
  cursor: pointer;
  margin-bottom: 14px;
  transition: all .15s;
}
.dd-explain:hover { background: #f3f0ff; border-style: solid; }
.dd-explain:disabled { opacity: .5; cursor: wait; }

.dd-simple {
  background: #f3f0ff;
  border-left: 5px solid var(--c-purple);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 16px 18px;
  margin: 0 0 16px;
  animation: card-in .3s ease both;
}
.dd-simple.is-error { background: #ffe3e3; border-left-color: var(--c-coral); color: #a12b2b; }
.dd-simple p {
  font-size: 15.5px;
  line-height: 1.95;
  margin-bottom: 10px;
  max-width: 62ch;
}
.dd-simple-tag {
  display: block;
  font-size: 13px;
  color: #7048c8;
  margin-bottom: 8px;
}
.dd-simple-note {
  display: block;
  font-size: 11.5px;
  color: var(--c-text-soft);
  margin-top: 6px;
  line-height: 1.6;
}

/* คลังภาพ */
.dd-gallery-title {
  font-size: 17px;
  color: var(--c-primary-dark);
  margin: 24px 0 12px;
}
.dd-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.dd-shot {
  position: relative;
  padding: 0;
  border: 3px solid var(--c-bg-cloud);
  border-radius: var(--radius-sm);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  cursor: zoom-in;
  background: var(--c-bg-cloud);
  transition: transform .16s, border-color .16s;
}
.dd-shot:hover { transform: scale(1.03); border-color: var(--c-yellow); }
.dd-shot img { width: 100%; height: 100%; object-fit: cover; }
.dd-shot-credit {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, .75));
  color: #fff;
  font-size: 10.5px;
  padding: 14px 8px 5px;
  text-align: left;
}

.dd-source {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 2px solid var(--c-bg-cloud);
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--c-text-soft);
}
.dd-source a { font-weight: 700; text-decoration: underline; }

/* ---------- กล่องดูภาพขนาดใหญ่ ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1200; /* คลุมทั้งหน้าจอ รวมถึงแถบเมนู */
  background: rgba(12, 24, 36, .96); /* เกือบทึบ เพื่อให้ข้อความเครดิตสีอ่อนอ่านชัดเสมอ */
  display: grid;
  place-items: center;
  padding: 24px 18px;
  opacity: 0;
  transition: opacity .2s;
}
.lightbox.is-open { opacity: 1; }

.lightbox-figure {
  max-width: min(920px, 100%);
  text-align: center;
}
.lightbox-figure img {
  max-width: 100%;
  max-height: 74vh;
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .55);
  margin: 0 auto;
}
.lightbox-figure figcaption {
  margin-top: 14px;
  color: #e8f1f9;
  font-size: 13px;
  line-height: 1.8;
}
.lightbox-figure figcaption b { display: block; font-size: 15px; margin-bottom: 4px; }
.lightbox-figure figcaption span { display: block; opacity: .8; }
.lightbox-figure figcaption a {
  display: inline-block;
  margin-top: 8px;
  color: var(--c-yellow);
  text-decoration: underline;
}

.lightbox-close {
  position: absolute;
  top: 16px; right: 18px;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--c-yellow);
  color: var(--c-text);
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
}

@media (max-width: 620px) {
  .deepdive { padding: 18px 16px; }
  .deepdive-head .btn { width: 100%; }
  .dd-lead { padding: 14px 16px 4px; }
  .dd-lead p { font-size: 16px; }
}
