/* ============================================================
   tools.css — 5 หมวดเครื่องมือคอหวย
   #history ดูผลย้อนหลัง · #guide แนวทางเลข · #news ข่าวหวย
   #dream ทำนายฝัน · #wheel วงล้อสุ่มเลข
   ใช้โทนเดิมของช่วงล่างหน้า (maroon-gold tokens ใน index.html)
   ============================================================ */

/* ---------- ธงชาติ SVG (แทน emoji ที่ Windows แสดงไม่ได้) ---------- */
.flag-ico{
  width:27px;height:20px;border-radius:4px;object-fit:cover;flex-shrink:0;
  box-shadow:0 0 0 1px rgba(255,255,255,.18),0 2px 6px rgba(0,0,0,.45);
  display:inline-block;vertical-align:-3px;
}

/* ---------- ควบคุมร่วม ---------- */
.tool-controls{
  display:flex;flex-wrap:wrap;gap:.8rem;justify-content:center;align-items:center;
  margin-bottom:1.6rem;
}
.tool-select,.tool-input{
  height:46px;border-radius:12px;border:1px solid var(--line);
  background:var(--surface);color:var(--ink);
  padding-inline:14px;font-family:var(--font-body);font-size:.95rem;
  min-width:220px;
}
.tool-select:focus-visible,.tool-input:focus-visible{
  outline:2px solid var(--gold-2);outline-offset:0;
  box-shadow:0 0 0 4px rgba(212,175,55,.15);
}
.tool-note{text-align:center;font-size:.76rem;color:var(--ink-faint);margin-top:1rem}

/* ---------- history modal (เปิดจากการ์ดผลหวย / เมนูผลย้อนหลัง) ---------- */
.hist-modal{position:fixed;inset:0;z-index:150;display:none;align-items:center;justify-content:center;padding:16px}
.hist-modal.is-open{display:flex}
.hist-modal__backdrop{
  position:absolute;inset:0;width:100%;border:0;cursor:pointer;
  background:rgba(10,3,3,.72);
  -webkit-backdrop-filter:blur(6px);backdrop-filter:blur(6px);
}
.hist-modal__dialog{
  position:relative;width:min(680px,100%);max-height:86vh;overflow-y:auto;
  background:linear-gradient(170deg,var(--bg-3),var(--bg-2));
  border:1px solid var(--line);border-radius:20px;box-shadow:var(--shadow);
  padding:1.6rem;
}
.hist-modal__head{display:flex;justify-content:space-between;align-items:center;gap:1rem;margin-bottom:1rem}
.hist-modal__head h2{font-family:var(--font-display);font-weight:400;font-size:1.4rem}
.hist-modal__close{
  width:38px;height:38px;border-radius:10px;flex-shrink:0;
  border:1px solid var(--line-soft);color:var(--ink-dim);font-size:1rem;
  transition:color .15s,border-color .15s;
}
.hist-modal__close:hover{color:var(--gold-2);border-color:var(--gold)}
.result-card[data-code]{cursor:pointer}
body.hist-lock{overflow:hidden}

/* ---------- reader modal — อ่านข่าวเต็มในเว็บ (iframe จากต้นทาง) ---------- */
.reader-modal{position:fixed;inset:0;z-index:170;display:none;align-items:center;justify-content:center;padding:14px}
.reader-modal.is-open{display:flex}
.reader-modal__backdrop{
  position:absolute;inset:0;width:100%;border:0;cursor:pointer;
  background:rgba(10,3,3,.75);
  -webkit-backdrop-filter:blur(6px);backdrop-filter:blur(6px);
}
.reader-modal__dialog{
  position:relative;width:min(1100px,97vw);height:90vh;
  display:flex;flex-direction:column;
  border:1px solid var(--line);border-radius:18px;overflow:hidden;
  background:var(--bg-2);box-shadow:var(--shadow);
}
.reader-modal__head{
  position:relative;z-index:2;                       /* ทับขอบบน iframe ที่ถูกดันขึ้นมาซ่อน */
  display:flex;align-items:center;gap:1rem;padding:.7rem 1rem;
  border-bottom:1px solid var(--line-soft);background:#1a0908;
}
.reader-modal__head h2{flex:1;font-size:.95rem;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.reader-modal__head a{font-size:.8rem;color:var(--gold-2);white-space:nowrap}
.reader-modal__head a:hover{color:var(--gold-3)}
/* margin-top ติดลบ = crop แถบหัวเว็บต้นทาง (ข่าวด่วน+โลโก้+เมนู) ให้เปิดมาเจอเนื้อข่าวเลย */
.reader-modal iframe{flex:1;width:100%;border:0;background:#fff;margin-top:-150px}
/* reader body — render เนื้อบทความเองบนพื้นแดงเข้มธีมฮ่องเต้ (รูปสีถูกต้อง) */
.reader-modal__body{
  flex:1;overflow-y:auto;
  background:linear-gradient(180deg,#420806,#260403 60%,#1d0302);
}
.reader-modal__body .rb-inner{
  max-width:780px;margin-inline:auto;
  padding:1.8rem clamp(1rem,4vw,2.4rem) 3rem;
}
.reader-modal__body h1{
  font-size:clamp(1.3rem,2.6vw,1.8rem);font-weight:600;line-height:1.5;
  color:var(--gold-3);margin:0 0 1.2rem;
}
.reader-modal__body h2,.reader-modal__body h3{color:var(--gold-2);line-height:1.55;margin:1.6rem 0 .7rem}
.reader-modal__body p{color:#f2e3cf;font-size:1.02rem;line-height:1.95;margin:0 0 1rem}
.reader-modal__body strong,.reader-modal__body b{color:#ffe9b0}
.reader-modal__body ul,.reader-modal__body ol{color:#f2e3cf;line-height:1.95;padding-left:1.5rem;margin:0 0 1rem}
.reader-modal__body a{color:var(--gold-2);text-decoration:underline dotted}
.reader-modal__body img{max-width:100%;height:auto;display:block;border-radius:12px;margin:1.2rem auto}
.reader-modal__body figure{margin:1.2rem 0}
.reader-modal__body figcaption{font-size:.78rem;color:#c9a17f;text-align:center;margin-top:.4rem}
.reader-modal__body table{width:100%;border-collapse:collapse;margin:1rem 0;color:#f2e3cf}
.reader-modal__body td,.reader-modal__body th{border:1px solid rgba(212,175,55,.25);padding:.5rem .7rem}
.reader-modal__body .rb-linebtn{max-width:420px;margin:2.2rem auto 0;display:flex}
.reader-modal__body .rb-credit{
  margin-top:1.6rem;text-align:center;
  font-size:.62rem;color:rgba(154,127,99,.45);   /* เล็กและจางมาก */
}
@media (max-width:767.98px){
  .reader-modal iframe{margin-top:-105px}
}

/* ---------- #guide แนวทางเลข ---------- */
.guide-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:1.4rem}
.guide-card{
  border-radius:var(--radius);border:1px solid var(--line-soft);
  background:linear-gradient(170deg,var(--surface-2),var(--surface));
  padding:1.6rem;transition:transform .25s,border-color .25s;
}
.guide-card:hover{transform:translateY(-4px);border-color:var(--line)}
.guide-card h3{font-size:1.05rem;font-weight:600;display:flex;align-items:center;gap:.5rem;margin-bottom:.2rem}
.guide-card .guide-date{font-size:.78rem;color:var(--ink-faint);margin-bottom:1.1rem}
.guide-row{display:flex;align-items:center;gap:.7rem;margin-bottom:.8rem}
.guide-row small{font-size:.8rem;color:var(--ink-dim);min-width:64px}
.guide-nums{display:flex;flex-wrap:wrap;gap:.45rem}
.guide-num{
  min-width:40px;height:40px;padding-inline:.55rem;border-radius:10px;
  display:inline-grid;place-items:center;
  font-family:var(--font-display);font-size:1.15rem;color:var(--gold-3);
  background:rgba(20,7,7,.55);border:1px solid var(--line-soft);
  font-variant-numeric:tabular-nums;
}
.guide-num--hot{border-color:rgba(200,35,47,.55);color:#ff9d9d;background:rgba(163,22,33,.2)}

/* ---------- #news ข่าวหวย ---------- */
.news-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:1.4rem}
.news-card{
  border-radius:var(--radius);border:1px solid var(--line-soft);background:var(--bg-2);
  padding:1.5rem 1.5rem 1.3rem;display:flex;flex-direction:column;gap:.6rem;
  transition:transform .25s,border-color .25s;
}
.news-card:hover{transform:translateY(-4px);border-color:var(--line)}
.news-tag{
  align-self:flex-start;font-size:.7rem;padding:.24rem .7rem;border-radius:999px;
  border:1px solid var(--line-soft);color:var(--gold-2);background:rgba(212,175,55,.07);
}
.news-card h3{font-size:1rem;font-weight:600;line-height:1.5}
.news-card h3 a:hover{color:var(--gold-2)}
.news-card p{font-size:.85rem;color:var(--ink-dim);font-weight:300;flex:1}
.news-card time{font-size:.75rem;color:var(--ink-faint)}
/* การ์ดข่าวแบบมีรูป (จาก DB ที่ scrape มา — รูป hotlink จาก CDN ต้นทาง) */
.news-card--img{padding:0}
.news-card__img{width:100%;aspect-ratio:390/220;object-fit:cover;display:block;background:#1a0d0a}
.news-card__body{padding:1.15rem 1.35rem 1.25rem;display:flex;flex-direction:column;gap:.55rem;flex:1}
.news-src{font-size:.72rem;color:var(--ink-faint)}
.news-toolbar{display:flex;flex-wrap:wrap;gap:.8rem;justify-content:center;align-items:center;margin-bottom:2rem}
/* กล่อง embed หน้าเว็บต้นฉบับ */
.embed-box{border:1px solid var(--line-soft);border-radius:16px;overflow:hidden;margin-top:3rem;background:var(--bg-2)}
.embed-box summary{
  list-style:none;cursor:pointer;padding:1.1rem 1.4rem;font-weight:600;font-size:.95rem;
  display:flex;justify-content:space-between;align-items:center;gap:1rem;
}
.embed-box summary::-webkit-details-marker{display:none}
.embed-box summary::after{content:"+";font-size:1.4rem;color:var(--gold);transition:transform .25s}
.embed-box[open] summary::after{transform:rotate(45deg)}
.embed-box iframe{width:100%;height:78vh;border:0;background:#fff;display:block}

/* ---------- #dream ทำนายฝัน ---------- */
.dream-box{
  max-width:680px;margin-inline:auto;border-radius:20px;
  border:1px solid var(--line);background:linear-gradient(170deg,var(--surface-2),var(--surface));
  box-shadow:var(--shadow);padding:1.8rem;
}
.dream-form{display:flex;gap:.7rem}
.dream-form .tool-input{flex:1;min-width:0}
.dream-chips{display:flex;flex-wrap:wrap;gap:.5rem;margin-top:1rem;justify-content:center}
.dream-chip{
  font-size:.8rem;padding:.35rem .85rem;border-radius:999px;cursor:pointer;
  border:1px solid var(--line-soft);color:var(--ink-dim);background:rgba(212,175,55,.05);
  transition:color .15s,border-color .15s;
}
.dream-chip:hover{color:var(--gold-2);border-color:var(--gold)}
.dream-chip.is-on{color:var(--gold-2);border-color:var(--gold);background:rgba(212,175,55,.16)}
.dream-az{display:flex;flex-wrap:wrap;gap:.4rem;justify-content:center;max-width:920px;margin-inline:auto}
.dream-result{margin-top:1.4rem;display:grid;gap:.9rem}
.dream-item{
  border:1px solid var(--line-soft);border-radius:14px;padding:1rem 1.2rem;
  background:rgba(20,7,7,.45);
  display:grid;grid-template-columns:1fr auto;gap:.8rem;align-items:center;
}
.dream-item h4{font-size:.98rem;font-weight:600;color:var(--gold-2);margin-bottom:.15rem}
.dream-item p{font-size:.84rem;color:var(--ink-dim);font-weight:300}
.dream-item .guide-nums{justify-content:flex-end}
.dream-none{text-align:center;color:var(--ink-dim);font-weight:300;padding:.6rem}

/* ---------- #wheel วงล้อสุ่มเลข ---------- */
.wheel-box{
  max-width:720px;margin-inline:auto;border-radius:20px;
  border:1px solid var(--line);background:linear-gradient(170deg,var(--surface-2),var(--surface));
  box-shadow:var(--shadow);padding:2rem;
  display:grid;grid-template-columns:auto 1fr;gap:2rem;align-items:center;
}
.wheel-stage{position:relative;width:min(280px,70vw);margin-inline:auto}
.wheel-stage svg{width:100%;height:auto;display:block}
#wheelRotor{transform-origin:50% 50%;transition:transform 2.6s cubic-bezier(.15,.85,.25,1)}
.wheel-pointer{
  position:absolute;top:-6px;left:50%;transform:translateX(-50%);
  width:0;height:0;border:14px solid transparent;border-top:22px solid var(--gold-2);
  filter:drop-shadow(0 2px 4px rgba(0,0,0,.5));z-index:2;
}
.wheel-hub{
  position:absolute;inset:0;margin:auto;width:64px;height:64px;border-radius:50%;
  background:linear-gradient(160deg,var(--gold-3),var(--gold) 55%,#8a671f);
  border:3px solid rgba(255,255,255,.25);
  display:grid;place-items:center;font-family:var(--font-display);
  color:#2a1200;font-size:1.3rem;z-index:2;
}
.wheel-panel h3{font-size:1.05rem;font-weight:600;margin-bottom:.3rem}
.wheel-panel > p{font-size:.85rem;color:var(--ink-dim);font-weight:300;margin-bottom:1.2rem}
.wheel-slots{display:flex;gap:.7rem;margin-bottom:1.4rem}
.wheel-slot{
  width:64px;height:72px;border-radius:14px;
  display:grid;place-items:center;
  background:rgba(20,7,7,.6);border:1px solid var(--line-soft);
  font-family:var(--font-display);font-size:2.1rem;color:var(--gold-3);
  font-variant-numeric:tabular-nums;
}
.wheel-slot.is-hit{border-color:var(--gold);box-shadow:0 0 18px rgba(212,175,55,.35)}
.wheel-actions{display:flex;flex-wrap:wrap;gap:.7rem;align-items:center}
.wheel-mode{display:inline-flex;border:1px solid var(--line-soft);border-radius:999px;overflow:hidden}
.wheel-mode button{
  padding:.55rem 1.1rem;font-size:.85rem;font-weight:600;color:var(--ink-dim);
  background:transparent;transition:background .15s,color .15s;
}
.wheel-mode button.is-on{background:rgba(212,175,55,.16);color:var(--gold-2)}
.wheel-note{margin-top:1rem;font-size:.75rem;color:var(--ink-faint)}

/* ---------- responsive ---------- */
@media (max-width:1020px){
  .guide-grid,.news-grid{grid-template-columns:repeat(2,1fr)}
}
@media (max-width:700px){
  .wheel-box{grid-template-columns:1fr;text-align:center;padding:1.5rem}
  .wheel-slots,.wheel-actions{justify-content:center}
  .dream-form{flex-direction:column}
}
@media (max-width:560px){
  .guide-grid,.news-grid{grid-template-columns:1fr}
  .dream-item{grid-template-columns:1fr}
  .dream-item .guide-nums{justify-content:flex-start}
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion:reduce){
  #wheelRotor{transition:none}
  .guide-card,.news-card{transition:none}
}
