/* Language Lab — ภาษาภาพ
 *
 * หลัก 4 ข้อ
 *   1. ตัวอักษรที่กำลังเรียนคือพระเอก ทุกอย่างอื่นถอยให้
 *   2. สีเน้นมีสีเดียว ใช้กับ "คำอ่าน" และสถานะที่กำลังทำงานเท่านั้น
 *   3. ไม่มีกล่องถ้าไม่จำเป็น — ใช้ที่ว่างกับเส้นบางแทนการ์ด
 *   4. ไม่ใช้อีโมจิเป็นไอคอน ใช้ตัวอักษรจริงหรือเส้นวาด
 */

:root {
  --paper:     #fbfaf7;
  --paper-2:   #f3f0e8;
  --ink:       #16140f;
  --ink-2:     #5c564a;
  --ink-3:     #948d7e;
  --rule:      #e4dfd2;
  --rule-2:    #cfc8b6;
  --accent:    #b0350f;
  --accent-bg: #f7ebe4;

  --cjk: "Songti SC", "STSong", "Hiragino Mincho ProN", "Noto Serif SC", serif;
  --cjk-2: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  --ui: "IBM Plex Sans Thai", "Sarabun", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --w: 640px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121110; --paper-2: #1b1917;
    --ink: #f2eee6; --ink-2: #a9a294; --ink-3: #736c60;
    --rule: #2c2926; --rule-2: #423d37;
    --accent: #e2764f; --accent-bg: #2c1c15;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--paper); color: var(--ink);
  font-family: var(--ui); font-size: 16px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  padding: 0 20px 96px;
}
.zh  { font-family: var(--cjk); }
.zhs { font-family: var(--cjk-2); }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; }
::selection { background: var(--accent-bg); }

/* ── หัวเรื่อง: ไม่ใช่แถบเมนู เป็นลายเซ็นบางๆ ─────────────── */
.top {
  max-width: var(--w); margin: 0 auto; padding: 22px 0 0;
  display: flex; align-items: baseline; gap: 10px;
}
.mark { font-size: 12.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3); cursor: pointer; }
.mark b { font-weight: 600; color: var(--ink-2); }
.who {
  margin-left: auto; font-size: 13px; color: var(--ink-3);
  border-bottom: 1px solid transparent;
}
.who:hover { color: var(--ink); border-bottom-color: var(--rule-2); }

main { max-width: var(--w); margin: 0 auto; }

/* ── พื้นผิวรับ: ไม่มีปุ่มโหมด — เขียนก็ได้ พิมพ์ก็ได้ ───────── */
.surface { margin-top: 50px; }
.slate {
  position: relative; width: 100%; aspect-ratio: 1 / 1; max-height: 58vh;
  border: 1px solid var(--rule); border-radius: 3px; background: var(--paper-2);
  touch-action: none; cursor: crosshair;
}
.slate canvas { display: block; width: 100%; height: 100%; }
.slate-hint {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 8px;
  text-align: center; color: var(--ink-3); pointer-events: none; transition: opacity .3s;
}
.slate-hint .big { font-family: var(--cjk); font-size: 15px; letter-spacing: .35em; }
.slate-hint .sm { font-size: 13px; }
.slate.inked .slate-hint { opacity: 0; }

/* กล้อง: สัญลักษณ์เล็กมุมล่างขวา */
.lens {
  position: absolute; right: 8px; bottom: 8px; width: 36px; height: 36px;
  display: grid; place-items: center; color: var(--ink-3); border-radius: 50%;
}
.lens:hover { color: var(--accent); background: var(--accent-bg); }

/* ช่องพิมพ์โผล่เองเมื่อเริ่มพิมพ์ */
.typed {
  width: 100%; margin-top: 16px; border: 0; border-bottom: 1px solid var(--rule-2);
  background: none; color: var(--ink); font-family: var(--cjk-2); font-size: 22px;
  padding: 6px 2px; outline: none;
}
.typed::placeholder { font-family: var(--ui); font-size: 15.5px; color: var(--ink-3); }
.typed:focus { border-bottom-color: var(--accent); }

/* ผลลัพธ์ — ตัวอักษรล้วน ไม่ใช่ปุ่มกล่อง */
.cands { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 18px; min-height: 46px; align-items: center; }
.cand { font-family: var(--cjk); font-size: 31px; line-height: 1; padding: 6px 10px; border-radius: 2px; }
.cand:hover { background: var(--accent-bg); color: var(--accent); }

/* แถวคำอ่าน — หนึ่งแถวต่อหนึ่งภาษาที่ใช้อักษรตัวนี้ */
.readings { display: flex; flex-direction: column; gap: 16px; }
.rdg { display: flex; gap: 14px; align-items: baseline; }
.rdg-lang {
  flex: none; min-width: 3.6em; font-size: 12.5px; color: var(--ink-3);
  letter-spacing: .04em; padding-top: 6px;
}
.rdg-col { min-width: 0; }
.rdg + .rdg { padding-top: 15px; border-top: 1px solid var(--rule); }

/* ── หน้าอักษร ────────────────────────────────────────── */
.entry { padding-top: 38px; }
.entry-head { display: flex; align-items: flex-start; gap: 26px; }
.glyph { font-family: var(--cjk); font-size: 126px; line-height: .92; letter-spacing: -.02em; user-select: all; flex: none; }
.entry-meta { padding-top: 12px; min-width: 0; }
.reading { font-size: 30px; color: var(--accent); letter-spacing: -.01em; border-bottom: 1px dashed transparent; display: inline-block; }
.reading:hover { border-bottom-color: var(--accent); }
.reading.on { opacity: .45; }
.sense { font-size: 18px; margin-top: 8px; }
.sense-2 { font-size: 14.5px; color: var(--ink-3); margin-top: 4px; }
.facts { font-size: 13px; color: var(--ink-3); margin-top: 15px; }
.facts i { font-style: normal; color: var(--ink-2); }

.rule { height: 1px; background: var(--rule); margin-top: 34px; }
.block { padding-top: 26px; }
.block h3 { font-size: 11.5px; font-weight: 600; letter-spacing: .13em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 14px; }
.block p { font-size: 15px; color: var(--ink-2); }
.block p + p { margin-top: 8px; }
.k { color: var(--accent); }
.k:hover { text-decoration: underline; }

/* ส่วนประกอบ */
.parts { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.part { text-align: center; }
.part .c { font-family: var(--cjk); font-size: 46px; line-height: 1.05; display: block; }
.part .l { font-size: 12px; color: var(--ink-3); margin-top: 3px; display: block; max-width: 11em; }
.part:hover .c { color: var(--accent); }
.part.lead .c { box-shadow: 0 2px 0 var(--accent); }
.op { font-size: 20px; color: var(--rule-2); padding-top: 14px; }

/* ตระกูล */
.fam { display: flex; flex-wrap: wrap; gap: 1px; }
.fam-i { min-width: 62px; padding: 9px 6px 8px; text-align: center; border-radius: 2px; }
.fam-i .c { font-family: var(--cjk); font-size: 30px; line-height: 1.12; display: block; }
.fam-i .p { font-size: 12px; color: var(--ink-3); display: block; margin-top: 1px; }
.fam-i:hover { background: var(--paper-2); }
.fam-i.off .c { color: var(--ink-3); }
.fam-i.off .p { text-decoration: line-through; }
.fam-i.here { background: var(--accent-bg); }
.fam-i.here .c, .fam-i.here .p { color: var(--accent); }
.legend { font-size: 12.5px; color: var(--ink-3); margin-top: 13px; }

/* คำ */
.words { columns: 2; column-gap: 30px; }
@media (max-width: 560px) { .words { columns: 1; } }
.word { break-inside: avoid; padding: 5px 0; display: flex; gap: 10px; align-items: baseline; width: 100%; }
.word:hover .w { color: var(--accent); }
.word .w { font-family: var(--cjk); font-size: 19px; flex: none; }
.word .g { font-size: 13.5px; color: var(--ink-3); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }

/* ── ทบทวน: แทรกบนพื้นผิวเดิม ─────────────────────────── */
.recall { padding-top: 44px; text-align: center; }
.recall .q { font-family: var(--cjk); font-size: 108px; line-height: 1; }
.recall .ask { font-size: 13.5px; color: var(--ink-3); margin-top: 18px; }
.recall .ans { margin-top: 16px; }
.recall .ans .r { font-size: 26px; color: var(--accent); }
.recall .ans .m { font-size: 16px; color: var(--ink-2); margin-top: 4px; }
.recall .ans .w2 { font-size: 13.5px; color: var(--ink-3); margin-top: 10px; }
.grade { display: flex; justify-content: center; gap: 26px; margin-top: 28px; }
.grade button { font-size: 14.5px; color: var(--ink-3); border-bottom: 1px solid transparent; padding-bottom: 2px; }
.grade button:hover { color: var(--ink); border-bottom-color: var(--rule-2); }
.skip { margin-top: 34px; font-size: 13px; color: var(--ink-3); }
.skip button { border-bottom: 1px solid var(--rule-2); padding-bottom: 1px; }
.skip button:hover { color: var(--ink); }

/* ── เปิดครั้งแรก: เลือกภาษาที่อ่านออก ─────────────────── */
.intro { padding-top: 96px; }
.choose {
  font-size: 40px; font-weight: 500; letter-spacing: -.02em; line-height: 1.2;
  max-width: 12em;
}
.greets { margin-top: 56px; border-top: 1px solid var(--rule); }
.greet {
  width: 100%; display: flex; align-items: baseline; gap: 16px; text-align: left;
  padding: 20px 2px; border-bottom: 1px solid var(--rule);
}
.greet .g { font-size: 30px; letter-spacing: -.01em; flex: none; }
.greet .g.rtl { direction: rtl; }
.greet .l { font-size: 13.5px; color: var(--ink-3); }
button.greet:hover .g { color: var(--accent); }
button.greet:hover .l { color: var(--ink-2); }
.greet.soon { cursor: default; }
.greet.soon .g { color: var(--ink-3); opacity: .5; }
.greet.soon .l { opacity: .6; }
.nat { margin-top: 40px; font-size: 13px; color: var(--ink-3); }
.nat button { border-bottom: 1px solid var(--rule-2); padding-bottom: 1px; }
.nat button:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* ── กล้อง ────────────────────────────────────────────── */
.cam { position: relative; margin-top: 16px; background: #000; border-radius: 3px; overflow: hidden; touch-action: none; }
.cam video, .cam canvas { display: block; width: 100%; max-height: 58vh; object-fit: contain; }
.cam .box { position: absolute; border: 1px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.5); }
.cam-bar { display: flex; gap: 24px; margin-top: 14px; font-size: 14.5px; color: var(--ink-2); flex-wrap: wrap; }
.cam-bar button { border-bottom: 1px solid var(--rule-2); padding-bottom: 2px; }
.cam-bar button:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* ── ระบบเสนอ: หนึ่งบรรทัด ไม่ใช่การ์ด ──────────────────── */
.offer { margin-top: 42px; padding-top: 22px; border-top: 1px solid var(--rule); }
.offer button { text-align: left; }
.offer .t { font-size: 15.5px; border-bottom: 1px solid var(--rule-2); padding-bottom: 2px; display: inline-block; }
.offer button:hover .t { color: var(--accent); border-bottom-color: var(--accent); }
.offer .y { font-size: 13px; color: var(--ink-3); margin-top: 6px; }

.hidden { display: none !important; }
.muted { color: var(--ink-3); font-size: 13.5px; }
.warn { color: var(--ink-3); font-size: 12.5px; margin-top: 12px; line-height: 1.6; }
.spinner { padding: 64px 0; text-align: center; color: var(--ink-3); font-size: 14px; }

@media (max-width: 560px) {
  body { padding: 0 18px 80px; }
  .glyph { font-size: 92px; }
  .entry-head { gap: 18px; }
  .reading { font-size: 25px; }
  .surface { margin-top: 32px; }
  .intro { padding-top: 62px; }
  .choose { font-size: 30px; }
  .greets { margin-top: 40px; }
  .greet { padding: 17px 2px; }
  .greet .g { font-size: 26px; }
  .recall .q { font-size: 88px; }
}
