/* =========================================================
   น้องฟันยิ้ม • สไตล์ร่วม (โทนสีฟ้า)
   ========================================================= */
:root{
  --blue:#3B8FE3;
  --blue-dark:#1E5FA8;
  --blue-deep:#163C6E;
  --sky:#9FCBF5;
  --sky-bg:#E7F2FE;
  --cyan:#46C7E8;
  --navy:#232C73;     /* จากโลโก้ */
  --pink:#E5238C;     /* จากโลโก้ */
  --ink:#1B2A4A;
  --ink-soft:#5E76A0;
  --white:#FFFFFF;
  --good:#27AE8B;
  --warn:#F2A33C;
  --bad:#EE5A6F;
  --shadow:0 12px 32px rgba(30,95,168,.18);
  --shadow-sm:0 5px 16px rgba(30,95,168,.14);
}

*{box-sizing:border-box; -webkit-tap-highlight-color:transparent;}
html,body{margin:0; padding:0;}
body{
  font-family:'Mali', sans-serif;
  color:var(--ink);
  background:
    radial-gradient(circle at 15% 50%, rgba(70, 199, 232, 0.4), transparent 50%),
    radial-gradient(circle at 85% 30%, rgba(59, 143, 227, 0.4), transparent 50%),
    linear-gradient(135deg, #E7F2FE 0%, #DCEBFF 100%);
  min-height:100vh; display:flex; justify-content:center;
}
.display{font-family:'Baloo Thai 2', sans-serif;}

/* ---- โครงแอปมือถือ ---- */
.app{
  width:100%; max-width:430px; min-height:100vh;
  background:rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  box-shadow:0 0 70px rgba(30,95,168,.2);
  display:flex; flex-direction:column; position:relative; overflow:hidden;
}

/* ---- หัวแอป + โลโก้โรงเรียนมุมบนขวา ---- */
header{
  position:relative; z-index:5;
  padding:18px 18px 16px;
  background:linear-gradient(125deg, rgba(59,143,227,0.7) 0%, rgba(70,199,232,0.7) 100%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color:#fff;
  border-bottom-left-radius:28px; border-bottom-right-radius:28px;
  box-shadow:var(--shadow-sm);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-top: none;
  display:flex; align-items:center; gap:12px;
}
header .brand-icon{
  width:46px; height:46px; background:#fff; border-radius:15px;
  display:grid; place-items:center; flex-shrink:0; box-shadow:0 4px 10px rgba(0,0,0,.14);
}
header .brand-icon svg{width:30px; height:34px;}
header .brand h1{font-family:'Baloo Thai 2'; font-size:22px; margin:0; line-height:1; font-weight:800;}
header .brand p{margin:3px 0 0; font-size:12px; opacity:.93; max-width:210px; line-height:1.35;}
header .school-logo{
  position:absolute; top:12px; right:14px;
  width:54px; height:54px; border-radius:50%;
  background:rgba(255,255,255,.95);
  display:grid; place-items:center;
  box-shadow:0 4px 12px rgba(0,0,0,.18);
  border:2px solid rgba(255,255,255,.7);
}
header .school-logo img{width:42px; height:42px; object-fit:contain;}

/* ---- เนื้อหา ---- */
main{flex:1; overflow-y:auto; padding:18px 18px 100px; -webkit-overflow-scrolling:touch;}
.fade{animation:fade .35s ease;}
@keyframes fade{from{opacity:0; transform:translateY(8px);} to{opacity:1; transform:none;}}

/* ---- ตัวละครมาสคอต ---- */
.buddy-wrap{display:flex; justify-content:center; margin:2px 0 8px;}
.buddy{
  width:auto; height:200px; object-fit:contain;
  filter:
    drop-shadow(1px 0 0 #15294d) drop-shadow(-1px 0 0 #15294d)
    drop-shadow(0 1px 0 #15294d) drop-shadow(0 -1px 0 #15294d)
    drop-shadow(0 8px 10px rgba(22,60,110,.18));
  transition:transform .3s;
}
.buddy.bob{animation:bob 2s ease-in-out infinite;}
@keyframes bob{0%,100%{transform:translateY(0) rotate(-1.5deg);}50%{transform:translateY(-9px) rotate(1.5deg);}}

/* ---- การ์ด ---- */
.card{
  background:rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius:24px; padding:20px; margin-bottom:16px;
  box-shadow:var(--shadow-sm); border:1px solid rgba(255, 255, 255, 0.7);
}
.card h2{font-family:'Baloo Thai 2'; font-size:19px; margin:0 0 6px; font-weight:700; color:var(--blue-deep);}
.lead{font-size:14px; color:var(--ink-soft); line-height:1.55; margin:0;}

/* ---- เวทีกล้อง/รูป ---- */
.stage{
  position:relative; width:100%; aspect-ratio:1/1;
  background:rgba(231, 242, 254, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius:22px; overflow:hidden;
  display:grid; place-items:center; margin-bottom:14px;
  border:2px dashed rgba(159, 203, 245, 0.8);
}
.stage video,.stage canvas,.stage img{width:100%; height:100%; object-fit:cover; display:none;}
.stage.has-media{border-style:solid; border-color:var(--blue);}
.stage-hint{position:absolute; text-align:center; color:var(--ink-soft); padding:20px; pointer-events:none;}
.stage-hint .big{font-family:'Baloo Thai 2'; font-size:54px; line-height:1;}
.stage-hint p{margin:8px 0 0; font-size:13px;}

/* ---- ปุ่ม ---- */
.btn{
  font-family:'Baloo Thai 2'; font-weight:700; font-size:16px;
  border:none; border-radius:18px; padding:14px 16px; cursor:pointer;
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  width:100%; transition:transform .12s, box-shadow .2s;
}
.btn:active{transform:scale(.97);}
.btn-primary{background:var(--blue); color:#fff; box-shadow:0 6px 0 var(--blue-dark);}
.btn-primary:active{box-shadow:0 2px 0 var(--blue-dark); transform:translateY(3px);}
.btn-cyan{background:var(--cyan); color:#0A3A4A; box-shadow:0 6px 0 #2BA9C9;}
.btn-cyan:active{box-shadow:0 2px 0 #2BA9C9; transform:translateY(3px);}
.btn-pink{background:var(--pink); color:#fff; box-shadow:0 6px 0 #B01069;}
.btn-pink:active{box-shadow:0 2px 0 #B01069; transform:translateY(3px);}
.btn-ghost{background:#fff; color:var(--blue-dark); border:2px solid var(--blue);}
.btn-row{display:flex; gap:10px;} .btn-row .btn{flex:1;}
.btn[disabled]{opacity:.5; pointer-events:none;}
.hidden{display:none !important;}

/* ---- แถบระดับฟันผุ ---- */
.levels{display:flex; gap:8px; margin:4px 0 12px;}
.level-pip{
  flex:1; text-align:center; padding:8px 4px; border-radius:14px;
  font-family:'Baloo Thai 2'; font-weight:700; font-size:12.5px;
  background:#EEF4FD; color:var(--ink-soft); border:2px solid transparent; transition:.25s;
}
.level-pip .lv{display:block; font-size:18px; line-height:1;}
.level-pip.on-good{background:#E4F7F0; color:#0C7A5C; border-color:var(--good);}
.level-pip.on-warn{background:#FEF4E5; color:#9A5C00; border-color:var(--warn);}
.level-pip.on-bad{background:#FDE9EC; color:#C03048; border-color:var(--bad);}

/* ---- กล่องสรุปผล ---- */
#result{display:none;}
.verdict{text-align:center; border-radius:22px; padding:16px; margin-bottom:14px; border:3px solid;}
.verdict .lvtag{font-family:'Baloo Thai 2'; font-weight:800; font-size:13px; letter-spacing:.5px; opacity:.9;}
.verdict .title{font-family:'Baloo Thai 2'; font-size:23px; font-weight:800; margin:2px 0 4px;}
.verdict .msg{font-size:14px; line-height:1.5; margin:0;}
.v-good{background:#E4F7F0; border-color:var(--good); color:#0B6F52;}
.v-warn{background:#FEF4E5; border-color:var(--warn); color:#9A5C00;}
.v-bad{background:#FDE9EC; border-color:var(--bad); color:#C03048;}
.v-unknown{background:#EEF4FD; border-color:var(--sky); color:#3F5680;}

.tips{list-style:none; padding:0; margin:8px 0 0;}
.tips li{display:flex; gap:10px; align-items:flex-start; font-size:14px; padding:9px 0; border-bottom:1px dashed #E3ECF8; line-height:1.45;}
.tips li:last-child{border-bottom:none;}
.tips li .dot{flex-shrink:0; font-size:18px;}

.bars{margin-top:6px;}
.bar-item{margin-bottom:9px;}
.bar-top{display:flex; justify-content:space-between; font-size:13px; margin-bottom:3px;}
.bar-track{height:14px; background:var(--sky-bg); border-radius:10px; overflow:hidden;}
.bar-fill{height:100%; width:0%; border-radius:10px; background:linear-gradient(90deg,var(--blue),var(--cyan)); transition:width .6s ease;}
.note{font-size:12px; color:var(--ink-soft); text-align:center; margin-top:10px; line-height:1.5;}

/* ---- หน้า 2: ขั้นตอน ---- */
.step{display:flex; gap:14px; align-items:flex-start; background:rgba(255,255,255,0.6); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-radius:20px; padding:14px 16px; margin-bottom:12px; box-shadow:var(--shadow-sm); border:1px solid rgba(255,255,255,0.7);}
.step .num{flex-shrink:0; width:40px; height:40px; border-radius:14px; background:#E2EEFC; color:var(--blue); font-family:'Baloo Thai 2'; font-weight:800; font-size:20px; display:grid; place-items:center;}
.step h3{font-family:'Baloo Thai 2'; font-size:16px; margin:0 0 2px; font-weight:700; color:var(--blue-deep);}
.step p{margin:0; font-size:13.5px; color:var(--ink-soft); line-height:1.5;}

/* ---- นาฬิกาแปรงฟัน ---- */
.timer-card{text-align:center;}
.ring-wrap{position:relative; width:200px; height:200px; margin:6px auto 4px;}
.ring-wrap svg{transform:rotate(-90deg);}
.ring-bg{fill:none; stroke:var(--sky-bg); stroke-width:14;}
.ring-fg{fill:none; stroke:var(--blue); stroke-width:14; stroke-linecap:round; transition:stroke-dashoffset 1s linear;}
.ring-center{position:absolute; inset:0; display:grid; place-items:center;}
.ring-time{font-family:'Baloo Thai 2'; font-size:40px; font-weight:800; line-height:1; color:var(--blue-deep);}
.ring-step{font-size:13px; color:var(--pink); font-weight:600; margin-top:4px; min-height:18px;}

/* ---- เมนูล่าง ---- */
nav{
  position:fixed; bottom:0; left:50%; transform:translateX(-50%);
  width:100%; max-width:430px; 
  background:rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border-top:1px solid rgba(255, 255, 255, 0.6);
  display:flex; padding:8px 10px calc(8px + env(safe-area-inset-bottom));
  box-shadow:0 -6px 20px rgba(30,95,168,.10); z-index:20;
}
.tab{
  flex:1; text-decoration:none; background:none; border:none; cursor:pointer;
  display:flex; flex-direction:column; align-items:center; gap:3px;
  color:var(--ink-soft); font-family:'Baloo Thai 2'; font-size:12px; font-weight:600;
  padding:6px 0; border-radius:14px; transition:.2s;
}
.tab svg{width:26px; height:26px;}
.tab.active{color:var(--blue-dark); background:var(--sky-bg);}

/* ---- โหลด ---- */
#loader{position:absolute; inset:0; background:rgba(255,255,255,.93); z-index:30; display:none; flex-direction:column; align-items:center; justify-content:center; gap:16px; text-align:center; padding:30px;}
#loader.show{display:flex;}
.spin{width:54px; height:54px; border:6px solid #D6E8FB; border-top-color:var(--blue); border-radius:50%; animation:sp 1s linear infinite;}
@keyframes sp{to{transform:rotate(360deg);}}
#loader p{font-family:'Baloo Thai 2'; font-size:16px; margin:0; color:var(--blue-dark);}
#loader small{color:var(--ink-soft); font-size:12px; max-width:250px;}
