/* PROJECTMOONLIGHT — ระบบดีไซน์ UI (Design System)
 * ใช้ร่วมกันทุกหน้าจอ: นอกเกม, HUD ในเกม, หน้าต่าง, GM/Server Dashboard
 * กฎ: ห้ามใส่สีตรง ๆ ในไฟล์หน้าจอ ให้ใช้ตัวแปรในไฟล์นี้เท่านั้น
 */
:root {
  /* พื้นหลัง/พื้นผิว */
  --bg: #0d1020;
  --bg-2: #141a33;
  --surface: #1b2140;
  --surface-2: #232b52;
  --surface-3: #2d376a;
  --panel: linear-gradient(#262f58f5, #171c36f5);
  --panel-head: linear-gradient(#46558f, #313d70);
  --scrim: rgba(4, 6, 16, 0.72);

  /* เส้น */
  --line: rgba(190, 205, 255, 0.14);
  --line-2: rgba(190, 205, 255, 0.28);
  --frame: #6c7bb0;
  --frame-hi: #a9b8ef;

  /* ตัวอักษร */
  --text: #f1ede4;
  --text-2: #cfd6ee;
  --muted: #9aa0bc;
  --faint: #6b7294;

  /* สีแบรนด์ (ดวงจันทร์) */
  --moon: #fff6d6;
  --moon-glow: #9fd8ff;
  --gold: #f3c969;
  --gold-2: #b88a1c;
  --gold-ink: #2a1e00;

  /* สถานะ */
  --ok: #7ee39a;
  --warn: #ffc857;
  --danger: #ff7a7a;
  --info: #8fc8ff;

  /* แถบค่า */
  --hp: #e0524a;
  --hp-hi: #f27a70;
  --sp: #4a8fe0;
  --sp-hi: #7ab3f2;
  --exp: #e8c14a;
  --exp-hi: #f5d97a;
  --jexp: #6fb33a;
  --jexp-hi: #b4e87a;

  /* ความหายากของไอเทม (rarity) */
  --r-common: #d8d8d8;
  --r-uncommon: #7ee39a;
  --r-rare: #6fb6ff;
  --r-epic: #c58bff;
  --r-legend: #ffb347;

  /* ช่องแชท */
  --ch-local: #ffffff;
  --ch-party: #7ee3d0;
  --ch-guild: #9dff8a;
  --ch-whisper: #ff9ee0;
  --ch-world: #ffd36e;
  --ch-system: #9fd8ff;
  --ch-gm: #ff8a5c;

  /* ขนาด */
  --r-sm: 5px;
  --r: 8px;
  --r-lg: 14px;
  --gap: 8px;
  --slot: 42px;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 14px 48px rgba(0, 0, 0, 0.6);
  --font: "Sarabun", "Thonburi", "Noto Sans Thai", system-ui, sans-serif;
  --font-display: "Cinzel", "Trajan Pro", Georgia, serif;
  --z-hud: 10;
  --z-win: 100;
  --z-modal: 1000;
  --z-toast: 1100;
  --z-tip: 1200;

  color-scheme: dark;
  font-family: var(--font);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
a { color: var(--gold); }
img { max-width: 100%; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }
:focus-visible { outline: 2px solid var(--moon-glow); outline-offset: 2px; }

/* ---------- ตัวอักษร ---------- */
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.gold { color: var(--gold); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.danger { color: var(--danger); }
.info { color: var(--info); }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.display { font-family: var(--font-display); letter-spacing: 0.08em; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
.h-sec { font-size: 12px; font-weight: 700; color: #9fb4ff; margin: 10px 0 6px; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- เลย์เอาต์ ---------- */
.row { display: flex; align-items: center; gap: var(--gap); }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: var(--gap); }
.grow { flex: 1; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
.sep { height: 1px; background: var(--line); margin: 10px 0; border: 0; }
.scroll { overflow: auto; min-height: 0; }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 6px 14px; border-radius: var(--r-sm);
  background: linear-gradient(#323b66, #262d52); color: var(--text);
  border: 1px solid var(--line-2); font: inherit; font-size: 14px; cursor: pointer;
  transition: filter .12s, transform .06s, background .12s; white-space: nowrap;
}
.btn:hover { filter: brightness(1.18); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .42; cursor: not-allowed; filter: none; }
.btn.primary { background: linear-gradient(#f0cc5c, var(--gold-2)); color: var(--gold-ink); border-color: #ffe08a; font-weight: 700; }
.btn.moon { background: linear-gradient(#bfe6ff, #5d8fd6); color: #0c1a33; border-color: #dff2ff; font-weight: 700; }
.btn.danger { background: linear-gradient(#7a2c3a, #52202b); border-color: #b0505f; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(255, 255, 255, .06); }
.btn.sm { min-height: 26px; padding: 2px 10px; font-size: 12.5px; }
.btn.lg { min-height: 46px; padding: 10px 22px; font-size: 16px; border-radius: var(--r); }
.btn.block { width: 100%; }
.btn.icon { width: 34px; padding: 0; }
.btn.icon.sm { width: 26px; }
.btn .badge { margin-left: 2px; }

/* ---------- ฟอร์ม ---------- */
.input, .select, .textarea {
  width: 100%; min-height: 36px; padding: 7px 10px; border-radius: var(--r-sm);
  background: #0e1226; color: var(--text); border: 1px solid var(--line-2); font: inherit; font-size: 14px;
}
.textarea { min-height: 80px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--moon-glow); outline: none; box-shadow: 0 0 0 3px rgba(159, 216, 255, .15); }
.input.invalid { border-color: var(--danger); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > label { font-size: 12.5px; color: var(--text-2); }
.field .hint { font-size: 11.5px; color: var(--muted); }
.field .err { font-size: 11.5px; color: var(--danger); }
.check { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 13.5px; line-height: 1.5; }
.check input { margin-top: 3px; accent-color: var(--gold); width: 16px; height: 16px; }
input[type="range"] { accent-color: var(--gold); width: 100%; }

/* สวิตช์เปิด/ปิด */
.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: var(--surface-3); border-radius: 22px; transition: .15s; cursor: pointer; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + i { background: var(--gold-2); }
.switch input:checked + i::after { transform: translateX(18px); }

/* segmented control */
.seg { display: inline-flex; background: #0e1226; border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 2px; gap: 2px; }
.seg button { background: transparent; border: 0; color: var(--muted); padding: 4px 12px; border-radius: 4px; font: inherit; font-size: 13px; cursor: pointer; }
.seg button.on { background: var(--surface-3); color: var(--text); }

/* ---------- แผง/การ์ด ---------- */
.panel { background: var(--panel); border: 1px solid var(--frame); border-radius: var(--r); box-shadow: var(--shadow); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.card.hover:hover { border-color: var(--frame-hi); cursor: pointer; }
.card.selected { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 18px rgba(243, 201, 105, .25); }
.inset { background: rgba(0, 0, 0, .25); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px; }

/* ---------- ป้าย ---------- */
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; font-weight: 700; background: var(--danger); color: #fff; line-height: 1; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 10px; font-size: 11.5px; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--line); }
.tag.ok { background: #1f4a31; color: var(--ok); border-color: #2f6e48; }
.tag.warn { background: #4d3b12; color: var(--warn); border-color: #7a5d1a; }
.tag.danger { background: #4d1c24; color: var(--danger); border-color: #7a2c38; }
.tag.info { background: #173656; color: var(--info); border-color: #265485; }
.tag.gold { background: #4a3a10; color: var(--gold); border-color: #7a6020; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot.warn { background: var(--warn); }
.dot.danger { background: var(--danger); }
kbd { display: inline-block; min-width: 18px; padding: 0 4px; border-radius: 3px; background: #0e1226; border: 1px solid var(--line-2); font: 700 10.5px/16px var(--font); text-align: center; color: var(--text-2); }

/* ---------- แถบค่า (HP/SP/EXP/ความคืบหน้า) ---------- */
.bar { position: relative; height: 14px; background: rgba(0, 0, 0, .5); border-radius: 7px; overflow: hidden; border: 1px solid rgba(0, 0, 0, .4); }
.bar > i { position: absolute; inset: 0 auto 0 0; border-radius: 7px; background: var(--info); transition: width .2s; }
.bar > span { position: relative; display: block; text-align: center; font-size: 10px; line-height: 12px; font-weight: 700; text-shadow: 0 1px 2px #000; }
.bar.hp > i { background: linear-gradient(var(--hp-hi), var(--hp)); }
.bar.sp > i { background: linear-gradient(var(--sp-hi), var(--sp)); }
.bar.exp > i { background: linear-gradient(var(--exp-hi), var(--exp)); }
.bar.jexp > i { background: linear-gradient(var(--jexp-hi), var(--jexp)); }
.bar.gold > i { background: linear-gradient(#ffe08a, var(--gold-2)); }
.bar.thin { height: 6px; }
.bar.thin > span { display: none; }

/* ---------- แท็บ ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 8px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 6px 10px; font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--gold); border-bottom-color: var(--gold); }

/* ---------- ช่องไอเทม/สกิล ---------- */
.slot {
  position: relative; width: var(--slot); height: var(--slot); flex: none; padding: 0;
  border-radius: var(--r-sm); background: linear-gradient(#10152b, #0b0f20); border: 1px solid #3b4468;
  display: grid; place-items: center; overflow: hidden; cursor: pointer; color: var(--muted);
}
.slot:hover { border-color: var(--frame-hi); }
.slot.empty { cursor: default; opacity: .7; }
.slot.selected { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.slot.locked::after { content: "🔒"; position: absolute; font-size: 12px; right: 2px; top: 1px; }
.slot img, .slot canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.slot .qty { position: absolute; right: 3px; bottom: 1px; font: 700 11px var(--font); color: #fff; text-shadow: 0 1px 2px #000, 0 0 2px #000; }
.slot .key { position: absolute; left: 3px; top: 1px; font: 700 10.5px var(--font); color: #fff; text-shadow: 0 1px 2px #000; }
.slot .cd { position: absolute; inset: auto 0 0 0; background: rgba(0, 0, 0, .68); }
.slot .cdt { position: absolute; inset: 0; display: grid; place-items: center; font: 800 13px var(--font); color: #fff; text-shadow: 0 1px 3px #000; }
.slot[data-rarity="uncommon"] { border-color: var(--r-uncommon); }
.slot[data-rarity="rare"] { border-color: var(--r-rare); }
.slot[data-rarity="epic"] { border-color: var(--r-epic); }
.slot[data-rarity="legend"] { border-color: var(--r-legend); box-shadow: inset 0 0 10px rgba(255, 179, 71, .35); }
/* ภาพชั่วคราว (รอ Artwork จริง) */
.ph { display: grid; place-items: center; width: 100%; height: 100%; font-size: 20px; line-height: 1; background: repeating-linear-gradient(45deg, transparent 0 6px, rgba(255, 255, 255, .03) 6px 12px); }
.ph-art { display: grid; place-items: center; border: 1px dashed var(--line-2); border-radius: var(--r); color: var(--faint); font-size: 12px; background: repeating-linear-gradient(45deg, transparent 0 10px, rgba(255, 255, 255, .025) 10px 20px); }
.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, var(--slot)); gap: 4px; }

/* ---------- รายการ/ตาราง ---------- */
.list { display: flex; flex-direction: column; }
.list > .item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.list > .item:last-child { border-bottom: 0; }
.list > .item.hover:hover { background: rgba(255, 255, 255, .04); cursor: pointer; }
.list > .item.on { background: rgba(243, 201, 105, .08); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.table td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:hover td { background: rgba(255, 255, 255, .025); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; }
.kv dt { color: #9fb4ff; }
.kv dd { margin: 0; }
.empty-state { padding: 26px 12px; text-align: center; color: var(--muted); font-size: 13px; }
.empty-state .ico { font-size: 28px; opacity: .6; margin-bottom: 6px; }

/* ---------- หน้าต่างในเกม (ลากได้) ---------- */
.win {
  position: absolute; z-index: var(--z-win); display: flex; flex-direction: column;
  min-width: 240px; max-width: calc(100vw - 16px); max-height: calc(100vh - 16px);
  background: var(--panel); border: 1px solid var(--frame); border-radius: var(--r); box-shadow: var(--shadow);
}
.win > .win-head {
  display: flex; align-items: center; gap: 8px; padding: 5px 6px 5px 12px; flex: none;
  background: var(--panel-head); border-radius: calc(var(--r) - 1px) calc(var(--r) - 1px) 0 0;
  font-weight: 700; cursor: move; touch-action: none; user-select: none;
}
.win > .win-head .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.win > .win-head kbd { opacity: .7; }
.win > .win-head .x { background: transparent; border: 0; color: var(--text); width: 26px; height: 26px; border-radius: 4px; cursor: pointer; font-size: 15px; }
.win > .win-head .x:hover { background: rgba(255, 255, 255, .12); }
.win > .win-body { padding: 10px 12px; overflow: auto; min-height: 0; flex: 1; }
.win > .win-foot { padding: 8px 12px; border-top: 1px solid var(--line); display: flex; gap: 6px; justify-content: flex-end; align-items: center; flex: none; }
.win.focused { border-color: var(--frame-hi); }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; z-index: var(--z-modal); background: var(--scrim); display: flex; padding: 16px; overflow-y: auto; animation: fade .15s; }
.modal { margin: auto; width: min(460px, 100%); background: var(--panel); border: 1px solid var(--frame); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); animation: pop .18s; }
.modal.wide { width: min(720px, 100%); }
.modal > header { padding: 14px 18px 4px; font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.modal > .body { padding: 8px 18px 14px; line-height: 1.6; color: var(--text-2); }
.modal > footer { padding: 10px 18px 16px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Toast / แจ้งเตือน ---------- */
.toasts { position: fixed; z-index: var(--z-toast); top: 64px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: min(420px, 92vw); }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-radius: var(--r); background: #121731f2; border: 1px solid var(--frame); box-shadow: var(--shadow); font-size: 13.5px; animation: drop .2s; }
.toast.ok { border-color: #2f6e48; } .toast.warn { border-color: #7a5d1a; } .toast.danger { border-color: #7a2c38; }

/* ---------- Tooltip ---------- */
.tip { position: fixed; z-index: var(--z-tip); max-width: 260px; padding: 8px 10px; background: #0c1022f5; border: 1px solid var(--frame); border-radius: var(--r-sm); font-size: 12.5px; line-height: 1.5; pointer-events: none; box-shadow: var(--shadow); }
.tip .tt-name { font-weight: 700; font-size: 13.5px; }
.tip .tt-type { color: var(--muted); font-size: 11.5px; margin-bottom: 4px; }

/* ---------- โลโก้/ดวงจันทร์ ---------- */
.moon-orb { width: 84px; height: 84px; border-radius: 50%; background: radial-gradient(circle at 38% 36%, #fffbe8, #e6dcb4 45%, #9d9474 100%); box-shadow: 0 0 40px #fff6c880, 0 0 90px #9fd8ff40; flex: none; }
.moon-orb.sm { width: 36px; height: 36px; box-shadow: 0 0 16px #fff6c860; }
.logo { text-align: center; }
.logo .l1 { font-family: var(--font-display); font-size: 34px; letter-spacing: .18em; color: #eaf2ff; text-shadow: 0 0 24px rgba(159, 216, 255, .45); }
.logo .l2 { color: var(--gold); font-size: 16px; font-weight: 600; letter-spacing: .06em; }

/* พื้นหลังฉากนอกเกม (ท้องฟ้ากลางคืน) */
.sky { position: fixed; inset: 0; background: radial-gradient(ellipse at 50% 18%, #2b3a6e 0%, #141a33 45%, #070914 100%); overflow: hidden; }
.sky::before { content: ""; position: absolute; inset: 0; background-image: radial-gradient(1px 1px at 12% 20%, #fff8, transparent), radial-gradient(1px 1px at 32% 8%, #fff9, transparent), radial-gradient(1.5px 1.5px at 72% 16%, #fffa, transparent), radial-gradient(1px 1px at 88% 34%, #fff7, transparent), radial-gradient(1px 1px at 54% 28%, #fff6, transparent), radial-gradient(1.5px 1.5px at 22% 44%, #fff5, transparent), radial-gradient(1px 1px at 64% 52%, #fff5, transparent), radial-gradient(1px 1px at 8% 64%, #fff4, transparent), radial-gradient(1px 1px at 94% 70%, #fff4, transparent); animation: twinkle 6s ease-in-out infinite alternate; }
.sky::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 32%; background: linear-gradient(transparent, #0a0e1c 70%), radial-gradient(ellipse at 30% 100%, #1b2a3a 0 40%, transparent 41%), radial-gradient(ellipse at 75% 100%, #16222f 0 45%, transparent 46%); }

/* ---------- แอนิเมชัน ---------- */
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(6px); } }
@keyframes drop { from { opacity: 0; transform: translateY(-8px); } }
@keyframes twinkle { to { opacity: .55; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .5; } }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line-2); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- มือถือ ---------- */
@media (max-width: 760px), (max-height: 480px) {
  html, body { font-size: 13px; }
  :root { --slot: 38px; }
  /* หน้าต่างบนมือถือ: ลาก/ยืด/ขยาย/ปิด ได้เหมือนคอม (D-061 · กรอบใน windows.css) */
  .modal > header { padding: 12px 14px 2px; }
  .modal > .body { padding: 6px 14px 10px; }
  .modal > footer { padding: 8px 14px 12px; }
  .logo .l1 { font-size: 24px; }
}

/* ---------- ไอคอน (วาดด้วยโค้ด/ภาพ Artwork) ---------- */
.ico { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; image-rendering: auto; }
.slot > .ico { position: absolute; inset: 8%; width: 84%; height: 84%; }
.slot > .ico.art { inset: 10%; width: 80%; height: 80%; filter: drop-shadow(0 2px 2px rgba(0,0,0,.5)); }
:is(p, span, b, td, dd, div, li, label) > .ico { display: inline-block; width: 1.5em; height: 1.5em; vertical-align: -0.4em; }
.toast .ico { width: 26px; height: 26px; }
.job-ava { display: inline-block; width: 1.6em; height: 1.6em; border-radius: 50%; object-fit: cover; object-position: 50% 8%; vertical-align: -0.45em; background: color-mix(in srgb, var(--moon) 14%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--gold) 45%, transparent); }
