/* ============================================================
   Naruto World — สไตล์หลัก
   ธีมมืดโทนน้ำเงินเข้ม + ส้มนินจา
   ============================================================ */
:root{
  --bg:#0b1020; --bg2:#121a2e; --panel:#182138; --panel2:#1f2b48;
  --line:#2c3a5c; --text:#e8edf7; --dim:#96a4c2;
  --orange:#ff8c1a; --orange2:#ffb347; --red:#e5383b; --green:#57cc99;
  --blue:#4cc9f0; --purple:#9d4edd; --gold:#ffd166;
  --radius:12px;
  --hud-h:88px;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; background:var(--bg); color:var(--text);
  font-family:"Noto Sans Thai","Sarabun",system-ui,-apple-system,"Segoe UI",sans-serif;
  overflow:hidden; -webkit-tap-highlight-color:transparent;
}
button{font-family:inherit}
kbd{
  background:var(--panel2); border:1px solid var(--line); border-bottom-width:2px;
  border-radius:5px; padding:1px 6px; font-size:.82em; font-family:ui-monospace,monospace;
}

.screen{display:none; position:fixed; inset:0}
.screen.active{display:block}

/* ---------- ปุ่ม ---------- */
.btn{
  border:none; border-radius:10px; padding:11px 20px; font-size:15px; font-weight:600;
  cursor:pointer; transition:transform .08s, filter .15s; color:#fff; background:var(--panel2);
}
.btn:hover{filter:brightness(1.15)}
.btn:active{transform:translateY(1px)}
.btn.primary{background:linear-gradient(180deg,var(--orange2),var(--orange)); color:#2a1500}
.btn.ghost{background:transparent; border:1px solid var(--line); color:var(--dim)}
.btn.small{padding:7px 13px; font-size:13px}
.btn:disabled{opacity:.5; cursor:not-allowed}

/* ============ หน้าเข้าสู่ระบบ / เลือกตัวละคร ============ */
.auth-bg{
  position:absolute; inset:0; z-index:0;
  background:
    radial-gradient(ellipse 70% 50% at 50% 0%, #26344f 0%, transparent 70%),
    linear-gradient(180deg,#121a2a,#0b0f18);
}
.auth-bg::after{
  content:""; position:absolute; inset:0; opacity:.5;
  background-image:
    radial-gradient(circle at 12% 22%, rgba(255,140,26,.10) 0 2px, transparent 3px),
    radial-gradient(circle at 78% 15%, rgba(76,201,240,.10) 0 2px, transparent 3px),
    radial-gradient(circle at 42% 70%, rgba(157,78,221,.10) 0 2px, transparent 3px);
}
.auth-card{
  position:relative; z-index:1; width:min(94vw,420px);
  margin:max(4vh,24px) auto 0; padding:28px 26px 22px;
  background:rgba(27,36,55,.9); border:1px solid var(--line);
  border-radius:18px; backdrop-filter:blur(8px);
  box-shadow:0 24px 60px rgba(0,0,0,.5);
  max-height:92vh; overflow-y:auto;
}
.logo{
  margin:0 0 4px; text-align:center; font-size:30px; letter-spacing:3px; font-weight:800;
  background:linear-gradient(180deg,#fff,var(--orange)); -webkit-background-clip:text;
  background-clip:text; color:transparent;
}
.logo span{display:block; font-size:16px; letter-spacing:9px; color:var(--dim);
  background:none; -webkit-text-fill-color:var(--dim)}
.tag{margin:0 0 20px; text-align:center; color:var(--dim); font-size:13px; line-height:1.5}

.tabs{display:flex; gap:6px; background:var(--bg2); padding:5px; border-radius:11px; margin-bottom:18px}
.tab{
  flex:1; padding:9px; border:none; background:transparent; color:var(--dim);
  border-radius:8px; cursor:pointer; font-size:14px; font-weight:600;
}
.tab.active{background:var(--panel2); color:var(--text)}

form label{display:block; margin-bottom:13px; font-size:13px; color:var(--dim)}
input[type=text],input[type=password]{
  width:100%; margin-top:6px; padding:11px 13px; font-size:15px;
  background:var(--bg2); border:1px solid var(--line); border-radius:9px; color:var(--text);
}
input:focus{outline:2px solid var(--orange); outline-offset:-1px}
#btn-auth{width:100%; margin-top:6px}
.msg{min-height:19px; margin:8px 0 2px; font-size:13px; color:var(--red)}
.msg.ok{color:var(--green)}

.server-line{
  display:flex; align-items:center; gap:8px; justify-content:center;
  margin-top:18px; padding-top:14px; border-top:1px solid var(--line);
  font-size:12px; color:var(--dim);
}
.dot{width:8px; height:8px; border-radius:50%; background:var(--dim)}
.dot.on{background:var(--green); box-shadow:0 0 8px var(--green)}
.dot.off{background:var(--red)}

/* ---------- เลือกตัวละคร ---------- */
.select-wrap{
  position:relative; z-index:1; width:min(96vw,880px); margin:0 auto;
  height:100%; overflow-y:auto; padding:22px 16px 40px;
}
.select-head{display:flex; align-items:center; justify-content:space-between; margin-bottom:18px}
.select-head h2{margin:0; font-size:22px}

.char-list{display:grid; grid-template-columns:repeat(auto-fill,minmax(230px,1fr)); gap:12px; margin-bottom:22px}
.char-card{
  background:var(--panel); border:1px solid var(--line); border-radius:var(--radius);
  padding:14px; display:flex; gap:12px; align-items:center; cursor:pointer;
  transition:border-color .15s, transform .1s;
}
.char-card:hover{border-color:var(--orange); transform:translateY(-2px)}
.char-card .face{
  width:52px; height:52px; border-radius:50%; flex:none;
  display:grid; place-items:center; font-size:23px; font-weight:800; color:#10131c;
}
.char-card .nm{font-weight:700; font-size:15px}
.char-card .mt{font-size:12px; color:var(--dim); margin-top:3px}
.char-card .del{
  margin-left:auto; background:transparent; border:none; color:var(--dim);
  cursor:pointer; font-size:15px; padding:4px 6px; border-radius:6px;
}
.char-card .del:hover{background:rgba(229,56,59,.18); color:var(--red)}
.empty{color:var(--dim); font-size:14px; padding:14px 0}

.create-panel,.board{
  background:var(--panel); border:1px solid var(--line);
  border-radius:var(--radius); padding:16px; margin-bottom:18px;
}
.create-panel h3,.board h3{margin:0 0 12px; font-size:16px}
.class-grid{display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:10px; margin-bottom:14px}
.class-card{
  border:2px solid var(--line); border-radius:10px; padding:12px; cursor:pointer;
  background:var(--bg2); transition:border-color .15s;
}
.class-card.sel{border-color:var(--orange); background:#2a2010}
.class-card .cn{font-weight:700; margin-bottom:4px}
.class-card .cd{font-size:11.5px; color:var(--dim); line-height:1.45}
.class-card .cs{font-size:11px; color:var(--dim); margin-top:6px; font-family:ui-monospace,monospace}
.create-row{display:flex; gap:9px}
.create-row input{flex:1; margin:0}

.leaderboard{margin:0; padding-left:26px; font-size:13.5px; line-height:1.9}
.leaderboard li::marker{color:var(--gold); font-weight:700}
.leaderboard .lv{color:var(--orange); font-weight:700}
.leaderboard .dim{color:var(--dim)}

/* ============ หน้าเกม ============ */
#scr-game{background:#05070c}
#stage{display:block; width:100%; height:100%; image-rendering:auto; touch-action:none}

.map-name{
  position:absolute; top:84px; left:50%; transform:translateX(-50%);
  font-size:24px; font-weight:800; letter-spacing:2px; pointer-events:none;
  text-shadow:0 3px 14px #000; opacity:0; transition:opacity .5s; z-index:5;
}
.map-name.show{opacity:1}

/* ---------- HUD บน ---------- */
.hud-top{
  position:absolute; top:0; left:0; right:0; height:var(--hud-h);
  padding:8px 14px calc(8px); display:flex; align-items:center; gap:16px;
  background:linear-gradient(180deg,rgba(9,13,21,.94),rgba(9,13,21,0));
  z-index:6; pointer-events:none; font-size:13px;
  padding-top:calc(8px + env(safe-area-inset-top,0px));
}
.hud-id{display:flex; align-items:center; gap:10px; min-width:150px}
.avatar{
  width:40px; height:40px; border-radius:50%; flex:none;
  display:grid; place-items:center; font-weight:800; font-size:17px; color:#10131c;
  border:2px solid rgba(255,255,255,.25);
}
.hud-name{font-weight:700; font-size:14px; display:flex; align-items:center; gap:6px;
  text-shadow:0 1px 4px #000}
.rank{font-size:10.5px; padding:1px 7px; border-radius:20px; background:var(--panel2); color:var(--gold)}
.hud-sub{font-size:11.5px; color:#c3cde0; margin-top:2px; text-shadow:0 1px 4px #000}

.hud-bars{flex:1; max-width:400px; display:flex; flex-direction:column; gap:4px}
.bar{
  position:relative; height:15px; background:#1a2334; border:1px solid #2c3a56;
  border-radius:9px; overflow:hidden;
}
.bar i{display:block; height:100%; width:0%; transition:width .25s; border-radius:9px}
.bar.hp i{background:linear-gradient(90deg,#e5383b,#ff6b6b)}
.bar.mp i{background:linear-gradient(90deg,#3a86ff,#4cc9f0)}
.bar.xp{height:13px}
.bar.xp i{background:linear-gradient(90deg,#ff8c1a,#ffd166)}
.bar span{
  position:absolute; inset:0; display:grid; place-items:center;
  font-size:10px; font-weight:700; text-shadow:0 1px 3px #000; letter-spacing:.3px;
}
.bar.xp span{font-size:9.5px}

.hud-right{text-align:right; font-size:11.5px; color:#c3cde0; line-height:1.7; min-width:96px;
  text-shadow:0 1px 4px #000}
.hud-right b{color:var(--text)}
.coin b{color:var(--gold)}

/* ---------- HUD ล่าง ---------- */
.hud-bottom{
  position:absolute; left:0; right:0; bottom:0; z-index:6;
  display:flex; justify-content:center; align-items:flex-end; gap:12px;
  padding:0 14px calc(10px + env(safe-area-inset-bottom,0px)); pointer-events:none;
}
.skillbar{display:flex; gap:8px; pointer-events:auto}
.slot{
  position:relative; width:56px; height:56px; border-radius:11px;
  background:var(--panel); border:2px solid var(--line); cursor:pointer;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:1px;
  overflow:hidden; transition:border-color .15s;
}
.slot:hover{border-color:var(--orange)}
.slot .ic{font-size:21px; line-height:1}
.slot .kk{font-size:9px; color:var(--dim); font-weight:700}
.slot .nm{
  position:absolute; bottom:-1px; left:0; right:0; font-size:8.5px; text-align:center;
  background:rgba(0,0,0,.6); padding:1px 0; color:#cfd8ea;
}
.slot .cd{
  position:absolute; inset:0; background:rgba(5,8,14,.78); color:#fff;
  display:none; place-items:center; font-size:15px; font-weight:800;
}
.slot.cooling .cd{display:grid}
.slot.locked{opacity:.35; cursor:not-allowed}
.slot.nomp{border-color:var(--red)}

.sys-btns{display:flex; gap:7px; pointer-events:auto}
.sysbtn{
  width:38px; height:38px; border-radius:9px; background:var(--panel);
  border:1px solid var(--line); color:var(--text); font-size:16px; cursor:pointer;
}
.sysbtn:hover{border-color:var(--orange)}

/* ---------- แชท ---------- */
.chat{
  position:absolute; left:14px; bottom:76px; width:min(42vw,330px); z-index:6;
  display:flex; flex-direction:column; gap:5px;
  padding-bottom:env(safe-area-inset-bottom,0px);
}
.chat-log{
  max-height:132px; overflow-y:auto; font-size:12.5px; line-height:1.55;
  display:flex; flex-direction:column; gap:2px; scrollbar-width:thin;
}
.chat-log::-webkit-scrollbar{width:5px}
.chat-log::-webkit-scrollbar-thumb{background:var(--line); border-radius:3px}
.chat-log .line{
  background:rgba(9,13,21,.72); padding:3px 9px; border-radius:7px;
  width:fit-content; max-width:100%; word-break:break-word; text-shadow:0 1px 2px #000;
}
.chat-log .who{font-weight:700; margin-right:4px}
.chat-log .sys{color:var(--dim); font-style:italic; font-size:11.5px}
.chat-input{
  padding:7px 11px; font-size:13px; border-radius:8px; border:1px solid var(--line);
  background:rgba(9,13,21,.85); color:var(--text); display:none;
}
.chat-input.on{display:block}

/* ---------- ปุ่มสัมผัส ---------- */
.touch{display:none; position:absolute; inset:auto 0 0 0; z-index:7;
  padding:0 16px calc(74px + env(safe-area-inset-bottom,0px)); pointer-events:none;
  justify-content:space-between; align-items:flex-end}
.touch.on{display:flex}
.pad,.acts{display:grid; gap:7px; pointer-events:auto}
.pad{grid-template-columns:repeat(3,52px); grid-template-rows:repeat(2,52px)}
.pad .tbtn:nth-child(1){grid-area:2/1} .pad .tbtn:nth-child(2){grid-area:1/2}
.pad .tbtn:nth-child(3){grid-area:2/2} .pad .tbtn:nth-child(4){grid-area:2/3}
.acts{grid-template-columns:repeat(2,52px)}
.tbtn{
  width:52px; height:52px; border-radius:50%; border:2px solid var(--line);
  background:rgba(27,36,55,.85); color:var(--text); font-size:15px; font-weight:700;
  user-select:none; touch-action:none;
}
.tbtn:active{background:var(--orange); color:#2a1500}
.tbtn.jump{background:rgba(87,204,153,.28); font-size:11px}
.tbtn.atk{background:rgba(229,56,59,.28)}

/* ---------- หน้าต่าง ---------- */
.window{
  position:absolute; top:50%; left:50%; transform:translate(-50%,-50%);
  width:min(92vw,400px); max-height:78vh; overflow:hidden; z-index:20;
  background:var(--panel); border:1px solid var(--line); border-radius:14px;
  box-shadow:0 20px 60px rgba(0,0,0,.6); display:flex; flex-direction:column;
}
.window.hidden{display:none}
.window header{
  padding:12px 15px; border-bottom:1px solid var(--line); font-weight:700; font-size:15px;
  display:flex; justify-content:space-between; align-items:center; background:var(--panel2);
}
.window .x{background:none; border:none; color:var(--dim); font-size:17px; cursor:pointer}
.window .x:hover{color:var(--red)}
.win-body{padding:15px; overflow-y:auto; font-size:13.5px; line-height:1.7}

.statrow{display:flex; align-items:center; gap:10px; padding:6px 0; border-bottom:1px solid #26314a}
.statrow:last-child{border:none}
.statrow .k{color:var(--dim); width:96px; flex:none}
.statrow .v{font-weight:700; flex:1}
.statrow .plus{
  width:26px; height:26px; border-radius:7px; border:none; cursor:pointer;
  background:var(--orange); color:#2a1500; font-weight:800; font-size:15px;
}
.statrow .plus:disabled{opacity:.25; cursor:not-allowed}
.points{color:var(--gold); font-weight:700; margin-bottom:10px}

.keys{width:100%; border-collapse:collapse; font-size:13px}
.keys td{padding:5px 0; vertical-align:top}
.keys td:first-child{width:130px; white-space:nowrap}
.hint{color:var(--dim); font-size:12px; line-height:1.6; margin:12px 0 0;
  padding-top:11px; border-top:1px solid var(--line)}

/* ---------- ข้อความลอย ---------- */
.toast-wrap{position:absolute; top:100px; left:50%; transform:translateX(-50%);
  z-index:9; display:flex; flex-direction:column; gap:6px; align-items:center; pointer-events:none}
.toast{
  background:rgba(9,13,21,.9); border:1px solid var(--line); border-radius:9px;
  padding:7px 16px; font-size:13.5px; font-weight:600; animation:pop .3s ease-out;
}
.toast.gold{border-color:var(--gold); color:var(--gold)}
.toast.bad{border-color:var(--red); color:#ff8f92}
@keyframes pop{from{opacity:0; transform:translateY(-10px) scale(.94)}to{opacity:1}}

/* ---------- จอตาย / เชื่อมต่อ ---------- */
.death,.conn{
  position:absolute; inset:0; z-index:30; display:grid; place-content:center;
  justify-items:center; gap:14px; background:rgba(5,7,12,.86); text-align:center; padding:20px;
}
.death.hidden,.conn.hidden{display:none}
.death h2{margin:0; font-size:26px; color:var(--red)}
.death p{margin:0; color:var(--dim); font-size:14px}
.spin{
  width:38px; height:38px; border:3px solid var(--line); border-top-color:var(--orange);
  border-radius:50%; animation:spin .8s linear infinite;
}
@keyframes spin{to{transform:rotate(360deg)}}

/* ---------- จอเล็ก ---------- */
@media (max-width:760px){
  :root{--hud-h:78px}
  .hud-id{min-width:0}
  .hud-id > div:last-child{display:none}
  .hud-right{font-size:10.5px; min-width:80px}
  .hud-right .ping{display:none}
  .chat{width:min(58vw,260px); bottom:auto; top:calc(var(--hud-h) + 6px)}
  .chat-log{max-height:88px}
  .slot{width:46px; height:46px}
  .slot .ic{font-size:18px}
  .sys-btns{flex-direction:column}
  .sysbtn{width:32px; height:32px; font-size:13px}
  .map-name{font-size:18px; top:70px}
}
@media (max-height:520px){
  .chat-log{max-height:60px}
}


/* ============================================================
   ส่วนที่เพิ่มสำหรับ Valor Saga
   ============================================================ */

/* ---------- หน้าโหลดอาร์ต ---------- */
.boot{
  position:fixed; inset:0; z-index:100; display:grid; place-content:center;
  justify-items:center; gap:18px; background:linear-gradient(180deg,#0e1526,#070b14);
  transition:opacity .4s;
}
.boot-logo{
  font-size:34px; font-weight:800; letter-spacing:6px;
  background:linear-gradient(180deg,#fff,var(--orange)); -webkit-background-clip:text;
  background-clip:text; color:transparent;
}
.boot-logo span{-webkit-text-fill-color:var(--dim); color:var(--dim); letter-spacing:12px; font-size:22px}
.boot-track{width:min(72vw,300px); height:6px; background:#1b2540; border-radius:4px; overflow:hidden}
.boot-track i{display:block; height:100%; width:0%; border-radius:4px;
  background:linear-gradient(90deg,var(--orange),var(--gold)); transition:width .25s}
.boot p{margin:0; color:var(--dim); font-size:13px}

/* ---------- พื้นหลังหน้าเลือกตัวละคร = แผนที่โลก ---------- */
.map-bg::before{
  content:""; position:absolute; inset:0;
  background:url('../assets/bg/worldmap.jpg') center/cover no-repeat;
  opacity:.34; filter:saturate(.85);
}
.map-bg::after{
  content:""; position:absolute; inset:0;
  background:linear-gradient(180deg,rgba(9,13,24,.82),rgba(9,13,24,.94));
}

/* ---------- สร้างตัวละคร: ภาพตัวอย่าง + เลือกเพศ ---------- */
.create-grid{display:flex; gap:18px; align-items:flex-start; flex-wrap:wrap}
.preview-col{flex:none; width:158px; display:flex; flex-direction:column; gap:10px; align-items:center}
.pick-col{flex:1; min-width:280px}
#char-preview{
  width:150px; height:200px; border-radius:12px; background:
    radial-gradient(ellipse 60% 40% at 50% 92%, rgba(255,179,71,.22), transparent 70%),
    linear-gradient(180deg,#1d2942,#141d31);
  border:1px solid var(--line);
}
.gender-grid{display:flex; gap:8px; width:100%}
.gender-card{
  flex:1; padding:9px 4px; border-radius:9px; cursor:pointer; font-size:13px; font-weight:600;
  background:var(--bg2); border:2px solid var(--line); color:var(--dim);
  display:flex; align-items:center; justify-content:center; gap:5px;
}
.gender-card.sel{border-color:var(--orange); color:var(--text); background:#2a2010}
.gender-card .gi{font-size:16px}

/* ---------- ตัวติดตามเควสบนจอ ---------- */
.quest-track{
  position:absolute; right:14px; top:calc(var(--hud-h) + 8px); z-index:6;
  width:min(40vw,236px); padding:9px 12px; border-radius:11px;
  background:rgba(10,15,28,.86); border:1px solid var(--line);
  border-left:3px solid var(--gold); font-size:12.5px; pointer-events:none;
  backdrop-filter:blur(6px);
}
.quest-track.hidden{display:none}
.qt-name{font-weight:700; color:var(--gold); margin-bottom:6px}
.qt-bar{height:7px; background:#1a2338; border-radius:4px; overflow:hidden; margin-bottom:5px}
.qt-bar i{display:block; height:100%; background:linear-gradient(90deg,var(--orange),var(--gold));
  border-radius:4px; transition:width .3s}
.qt-num{color:var(--dim); font-size:11.5px}

/* ---------- หน้าต่างเควส ---------- */
.q-card{
  background:var(--bg2); border:1px solid var(--line); border-radius:11px;
  padding:14px; margin-bottom:12px;
}
.q-card.active{border-color:var(--gold)}
.q-head{font-weight:700; font-size:15px; display:flex; align-items:center; gap:8px; margin-bottom:8px}
.q-tag{font-size:10.5px; padding:2px 8px; border-radius:20px; background:var(--gold); color:#2a1d00}
.q-desc{margin:0 0 10px; color:var(--dim); font-size:12.5px; line-height:1.65}
.q-goal{font-size:13.5px; margin-bottom:8px}
.q-goal span{float:right; font-weight:700; color:var(--orange2); font-family:ui-monospace,monospace}
.q-goal span.done{color:var(--green)}
.q-reward{font-size:12px; color:var(--gold); margin-bottom:12px}
.q-card .btn{width:100%}
.q-lock{margin:0; font-size:12.5px; color:var(--dim); text-align:center;
  padding:9px; background:#161f33; border-radius:8px}
.q-empty{color:var(--green); text-align:center; padding:18px 0; font-weight:600}
.q-progress{font-size:12px; color:var(--dim); text-align:center; margin-top:4px}
.q-done{margin:10px 0 0; padding-left:20px; font-size:12px; color:var(--green); line-height:1.8}

/* ---------- ปรับหน้าเกมให้ภาพเด่นขึ้น ---------- */
#scr-game{background:#05070c}
.hud-top{background:linear-gradient(180deg,rgba(6,10,20,.92),rgba(6,10,20,0))}
.slot{background:rgba(24,33,56,.92); backdrop-filter:blur(4px)}
.sysbtn{background:rgba(24,33,56,.92); backdrop-filter:blur(4px)}
.chat-log .line{backdrop-filter:blur(3px)}

@media (max-width:760px){
  .quest-track{width:min(52vw,200px); top:calc(var(--hud-h) + 4px); font-size:11.5px; padding:7px 10px}
  .create-grid{flex-direction:column; align-items:center}
  .pick-col{width:100%}
  .chat{top:auto; bottom:78px; width:min(56vw,250px)}
}
