:root {
  --bg: #14122a;
  --bg2: #1e1b3d;
  --card: #262250;
  --card2: #302b62;
  --line: #3f3a7a;
  --text: #f2f0ff;
  --muted: #a9a4d6;
  --primary: #ffcc33;
  --primary-ink: #2a1e00;
  --good: #4cd964;
  --bad: #ff5b5b;
  --hp: #4cd964;
  --mp: #3d8bff;
  --st: #ffb020;
  --exp: #c58bff;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 20% -10%, #2c2470, transparent), var(--bg);
  color: var(--text);
  font-family: Kanit, Tahoma, sans-serif;
  min-height: 100vh;
}
button, input { font: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.5; }
.error { color: var(--bad); min-height: 1.2em; }

.top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: #0e0c22cc; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(6px);
}
.logo { font-weight: 700; font-size: 26px; letter-spacing: 0.5px; }
.logo span { color: var(--primary); }
.logo.big { font-size: 44px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.tabs button {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  padding: 6px 12px; border-radius: 999px; cursor: pointer;
}
.tabs button:hover { color: var(--text); border-color: var(--line); }
.tabs button.active { background: var(--card2); color: var(--text); border-color: var(--line); }
.user { color: var(--muted); font-size: 14px; }

.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px;
  padding: 16px; max-width: 1440px; margin: 0 auto;
}
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; padding: 12px 16px; } }

.stage { min-width: 0; }
#game { width: 100%; aspect-ratio: 16 / 9; border-radius: 16px; overflow: hidden; background: #000; box-shadow: 0 10px 40px #0008; }
#game canvas { display: block; }

.roster { display: flex; gap: 10px; overflow-x: auto; padding: 12px 2px; }
.mini {
  flex: 0 0 118px; background: var(--card); border: 2px solid var(--line); border-radius: 14px;
  padding: 6px; cursor: pointer; text-align: center; position: relative;
}
.mini.active { border-color: var(--primary); background: var(--card2); }
.mini canvas { width: 100%; height: 86px; display: block; }
.mini .n { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini .l { font-size: 12px; color: var(--muted); }
.mini .dot { position: absolute; top: 6px; right: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 8px var(--primary); }
.mini.add { display: grid; place-items: center; color: var(--muted); font-size: 14px; border-style: dashed; min-height: 130px; }

.panel {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; padding: 16px;
  max-height: calc(100vh - 90px); overflow-y: auto; position: sticky; top: 76px;
}
@media (max-width: 1000px) { .panel { max-height: none; position: static; } }
.panel h2 { margin: 0 0 8px; font-size: 22px; }
.panel h3 { margin: 18px 0 8px; font-size: 16px; color: var(--muted); font-weight: 600; }

.row { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 0; }
input {
  background: #0f0d26; border: 1px solid var(--line); color: var(--text);
  padding: 10px 12px; border-radius: 10px; outline: none;
}
input:focus { border-color: var(--primary); }
.btn {
  background: var(--card2); color: var(--text); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; transition: transform .08s, background .15s;
}
.btn:hover:not(:disabled) { background: #3b357a; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #ffd95c; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 9px; font-size: 13px; border-radius: 8px; }

.hero { display: flex; gap: 12px; align-items: center; }
.hero canvas { width: 130px; height: 130px; flex: none; background: radial-gradient(circle at 50% 70%, #ffffff14, transparent 70%); border-radius: 14px; }
.hero .name { font-size: 22px; font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.hero .title { color: var(--muted); font-size: 14px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #0004; border: 1px solid currentColor; }

.bar { height: 10px; background: #0007; border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 6px; transition: width .4s; }
.barline { display: grid; grid-template-columns: 70px 1fr 90px; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; }
.barline .v { text-align: right; color: var(--muted); }

.stats { width: 100%; border-collapse: collapse; font-size: 14px; }
.stats td { padding: 5px 4px; border-bottom: 1px solid #ffffff10; }
.stats td:first-child { font-weight: 600; width: 52px; }
.stats .stars { color: var(--primary); letter-spacing: 1px; font-size: 12px; }
.stats .val { text-align: right; width: 44px; font-variant-numeric: tabular-nums; }
.stats .plus { text-align: right; width: 76px; }

.derived { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 14px; font-size: 14px; }
.derived div { display: flex; justify-content: space-between; border-bottom: 1px dashed #ffffff12; padding: 3px 0; }
.derived b { font-variant-numeric: tabular-nums; }

.grid-btn { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.grid-btn .btn { padding: 8px 4px; font-size: 13px; line-height: 1.3; }
.grid-btn .btn small { display: block; color: var(--muted); font-size: 11px; }

.tiers { display: flex; gap: 4px; margin: 6px 0 10px; }
.tiers i { flex: 1; height: 8px; border-radius: 4px; background: #ffffff18; }
.tiers i.on { background: var(--primary); box-shadow: 0 0 6px var(--primary); }

.lines { display: grid; gap: 8px; }
.line-opt { text-align: left; display: flex; gap: 10px; align-items: center; padding: 10px; }
.line-opt .sw { width: 14px; height: 40px; border-radius: 6px; flex: none; }
.line-opt small { color: var(--muted); display: block; }

.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 8px; text-align: center; font-size: 13px; }
.card canvas { width: 100%; height: 110px; display: block; }
.card .n { font-weight: 600; font-size: 15px; }
.card .s { color: var(--muted); font-size: 12px; }
.card .btn { margin-top: 6px; width: 100%; }

.reveal { margin-top: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; text-align: center; animation: pop .5s cubic-bezier(.2,1.6,.4,1); }
.reveal canvas { width: 100%; height: 200px; }
.reveal .first { color: var(--primary); font-weight: 600; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }

.camera { margin: 10px 0; }
.camera video { width: 100%; border-radius: 12px; background: #000; }

.rank { width: 100%; border-collapse: collapse; font-size: 14px; }
.rank td { padding: 6px 4px; border-bottom: 1px solid #ffffff10; }
.rank canvas { width: 54px; height: 46px; display: block; }

.modal { position: fixed; inset: 0; background: #05041099; display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--bg2); border: 1px solid var(--line); border-radius: 20px; padding: 24px; width: min(440px, 100%); text-align: center; max-height: 90vh; overflow-y: auto; }
.modal-card form { display: flex; gap: 8px; margin-top: 14px; }
.modal-card form input { flex: 1; min-width: 0; }

#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 60; width: min(420px, calc(100% - 32px)); }
.toast { background: #000d; border: 1px solid var(--line); padding: 10px 14px; border-radius: 12px; animation: pop .3s; font-size: 14px; }
.toast.err { border-color: var(--bad); }
.toast.good { border-color: var(--good); }

.ver { font-size: 12px; font-weight: 400; color: var(--muted); letter-spacing: 0; vertical-align: middle; }

.pid { font-variant-numeric: tabular-nums; }
.plist { display: grid; gap: 8px; }
.pcard { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.phead { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.invite { background: var(--card); border: 1px dashed var(--line); border-radius: 14px; padding: 10px 12px; font-size: 14px; }
.invite code { color: var(--primary); user-select: all; }

.seg { display: inline-flex; background: #0f0d26; border: 1px solid var(--line); border-radius: 999px; padding: 3px; margin: 4px 0 8px; }
.seg button { background: transparent; color: var(--muted); border: 0; padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.seg button.on { background: var(--primary); color: var(--primary-ink); font-weight: 600; }
.ult { background: var(--card); border: 1px solid var(--line); border-left-width: 4px; border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.ult.locked { opacity: .55; }

.spells { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
@media (max-width: 420px) { .spells { grid-template-columns: repeat(3, 1fr); } }
.spell { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px 4px; text-align: center; font-size: 12px; opacity: .5; display: grid; gap: 2px; }
.spell.on { opacity: 1; background: var(--card2); }
.spell.capped { opacity: .3; border-style: dashed; }
.spell b { font-size: 13px; line-height: 1.2; }
.spell small { color: var(--muted); font-size: 10.5px; line-height: 1.25; }
.spell .stars { font-size: 10px; letter-spacing: 1px; }

.mini .bot { position: absolute; top: 4px; left: 6px; font-size: 13px; }
.auto { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-top: 14px; }
.auto.on { border-color: #22d3a6; box-shadow: 0 0 0 1px #22d3a633 inset; }
.auto-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.auto-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.auto-f { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.auto-f.check { display: flex; align-items: center; gap: 6px; grid-column: 1 / -1; color: var(--text); font-size: 13px; }
.auto-f select { background: #0f0d26; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font: inherit; font-size: 13px; }
.switch { width: 46px; height: 26px; border-radius: 999px; border: 1px solid var(--line); background: #0f0d26; position: relative; cursor: pointer; flex: none; padding: 0; }
.switch i { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: left .15s, background .15s; }
.switch.on { background: #22d3a6; border-color: #22d3a6; }
.switch.on i { left: 23px; background: #fff; }

/* ---------- tabs: ไอคอน + ข้อความ ---------- */
.tabs button { display: inline-flex; align-items: center; gap: 6px; }
.tabs button i { font-style: normal; }
#style-btn { white-space: nowrap; }
.user { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }
img, canvas, video { max-width: 100%; }
.panel, .modal-card { overscroll-behavior: contain; }

/* ---------- แท็บเล็ต ---------- */
@media (max-width: 1000px) {
  .top { gap: 10px; }
  .tabs { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: none; }
  .user { margin-left: auto; }
}

/* ---------- มือถือ ---------- */
@media (max-width: 760px) {
  body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }

  /* หัวเว็บแถวเดียว (ต้องไม่มี backdrop-filter ไม่งั้นแถบแท็บแบบ fixed จะติดอยู่กับหัวเว็บ) */
  .top {
    -webkit-backdrop-filter: none; backdrop-filter: none; background: #0e0c22;
    flex-wrap: nowrap; gap: 8px;
    padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right));
  }
  .logo { font-size: 21px; flex: none; }
  .ver, .user .uname, #style-btn .pre, #style-btn .nm { display: none; }
  #sound-btn { margin-left: auto; padding: 6px 10px; }
  #style-btn { padding: 6px 10px; }
  .user { margin-left: 0; }
  .user .pid { padding: 6px 10px; }

  /* แท็บย้ายลงล่างแบบแอปมือถือ */
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; overflow: visible;
    padding: 6px max(6px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-right));
    background: #0e0c22f2; border-top: 1px solid var(--line);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  }
  .tabs button {
    flex-direction: column; justify-content: center; gap: 3px;
    min-height: 54px; padding: 4px 2px; border-radius: 12px; border: 0;
    font-size: 11px; line-height: 1.1; white-space: nowrap; overflow: hidden;
    color: var(--muted);
  }
  .tabs button i { font-size: 21px; line-height: 1; }
  .tabs button.active { background: var(--card2); color: var(--primary); border: 0; }
  .tabs button:hover { border: 0; }

  /* เนื้อหา */
  .layout { padding: 10px 12px; gap: 12px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  #game { border-radius: 12px; box-shadow: 0 6px 20px #0008; }
  .roster { gap: 8px; padding: 10px 0 4px; scroll-snap-type: x proximity; }
  .mini { flex-basis: 92px; scroll-snap-align: start; padding: 4px; border-radius: 12px; }
  .mini canvas { height: 70px; }
  .mini.add { min-height: 112px; }
  .panel { padding: 14px; border-radius: 14px; scroll-margin-top: 64px; min-height: calc(100vh - 150px); min-height: calc(100dvh - 150px); }
  .invite code, .muted code { word-break: break-all; }
  .panel h2 { font-size: 20px; }

  /* กดง่าย + กัน iOS ซูมตอนพิมพ์ (ต้อง 16px ขึ้นไป) */
  input, select, .auto-f select { font-size: 16px; }
  .btn { min-height: 42px; }
  .btn.small { min-height: 34px; padding: 4px 10px; }
  .grid-btn .btn { min-height: 52px; }
  .row { gap: 8px; }
  .row > .btn { flex: 1 1 auto; }
  form.row > input { flex: 1 1 auto; }
  form.row > .btn { flex: 0 0 auto; padding: 8px 18px; }

  .hero { gap: 10px; }
  .hero canvas { width: 104px; height: 104px; }
  .hero .name { font-size: 19px; }
  .barline { grid-template-columns: 62px 1fr 78px; }
  .stats td:nth-child(2) .muted { display: none; }   /* คำอธิบาย stat ยาวเกินจอ */
  .stats td { padding: 7px 4px; }
  .stats .plus .btn { min-width: 44px; }
  .derived { gap: 2px 12px; font-size: 13px; }
  .spells { grid-template-columns: repeat(3, 1fr); }
  .auto-grid { grid-template-columns: 1fr; }
  .cards { gap: 8px; }
  .card { padding: 6px; }
  .card canvas { height: 96px; }
  .card .n { font-size: 14px; }
  .phead { flex-wrap: wrap; }
  .phead .btn { flex: 1 1 100%; }
  .seg { display: flex; }
  .seg button { flex: 1; min-height: 38px; }
  .rank td { padding: 6px 2px; }
  .reveal canvas { height: 170px; }

  /* ป๊อปอัปเป็นแผ่นเลื่อนขึ้นจากด้านล่าง */
  .modal { align-items: end; padding: 0; }
  .modal-card {
    width: 100%; max-height: 90vh; max-height: 90dvh; border-radius: 22px 22px 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
    animation: sheet .25s ease-out;
  }
  .modal-card form { flex-direction: column; }
  .logo.big { font-size: 38px; }

  #toasts { bottom: calc(76px + env(safe-area-inset-bottom)); }
}
@keyframes sheet { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* จอเล็กมาก (iPhone SE รุ่นแรก / Android เล็ก) */
@media (max-width: 340px) {
  .logo { font-size: 19px; }
  .tabs button { font-size: 10px; }
  .cards { grid-template-columns: 1fr 1fr; }
  .grid-btn { grid-template-columns: repeat(2, 1fr); }
  .hero canvas { width: 88px; height: 88px; }
}

/* มือถือแนวนอน: ให้ฉากเกมไม่สูงเกินจอ */
@media (max-height: 500px) and (orientation: landscape) {
  #game { max-height: 78vh; aspect-ratio: auto; height: 78vh; }
  .tabs { padding-top: 2px; }
  .tabs button { min-height: 42px; }
  .tabs button i { font-size: 17px; }
}

.camera video { max-height: 60vh; object-fit: cover; }
.camera { display: grid; gap: 8px; }

.qr-box { background: #fff; border-radius: 16px; padding: 10px; width: min(300px, 80vw); margin: 10px auto; }
.qr-box canvas.qr { width: 100%; height: auto; display: block; image-rendering: pixelated; }
.qr-id { font-size: 18px; margin: 4px 0; }
.qr-id b { color: var(--primary); letter-spacing: 1px; font-variant-numeric: tabular-nums; }

/* ---------- อุปกรณ์ ---------- */
.equip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.eslot { background: var(--card); border: 1px dashed var(--line); border-radius: 12px; padding: 6px 4px; color: var(--muted); cursor: pointer; display: grid; justify-items: center; gap: 2px; min-height: 68px; position: relative; font: inherit; }
.eslot.has { border-style: solid; border-width: 2px; background: var(--card2); color: var(--text); }
.eslot .ei { font-size: 24px; line-height: 1.1; }
.eslot:not(.has) .ei { opacity: .35; filter: grayscale(1); }
.eslot .en { font-size: 11px; line-height: 1.2; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eslot .eg { position: absolute; top: 3px; right: 5px; font-size: 10px; color: var(--muted); }
.fxlist { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }

.items { display: grid; gap: 8px; }
.item { display: flex; gap: 10px; align-items: center; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 12px; padding: 8px 10px; text-align: left; }
.item.box { border-left-color: #ffb020; background: linear-gradient(90deg, #ffb02018, var(--card)); }
.item .ii { font-size: 30px; width: 40px; text-align: center; flex: none; }
.item .ib { flex: 1; min-width: 0; font-size: 13px; }
.item .ib b { font-size: 15px; }
.item .ia { display: grid; gap: 4px; flex: none; }
.imods { color: var(--text); margin-top: 2px; }
.ifx { color: #ff9be0; font-size: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 10px; }
.chip { background: var(--card); color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; cursor: pointer; font: inherit; font-size: 13px; }
.chip.on { background: var(--primary); color: var(--primary-ink); border-color: transparent; font-weight: 600; }
.mini.locked { opacity: .45; }
.mini .pick { position: absolute; top: 4px; right: 6px; background: var(--primary); color: var(--primary-ink); border-radius: 50%; width: 20px; height: 20px; display: grid; place-items: center; font-size: 12px; font-weight: 700; }

/* ---------- หอคอย ---------- */
.tower { display: flex; gap: 14px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.tower-bar { width: 22px; height: 90px; background: #0007; border-radius: 8px; position: relative; overflow: hidden; flex: none; }
.tower-bar i { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(0deg, #ffb020, #ff6ad5); border-radius: 8px; }
.floor-card { background: linear-gradient(135deg, var(--th), var(--card) 70%); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.floor-card .fl { font-size: 24px; }
.pmember { display: flex; gap: 10px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; margin-bottom: 6px; }
.pmember canvas { width: 64px; height: 60px; flex: none; }
.pmember.down { opacity: .5; }
.pmember .barline { grid-template-columns: 30px 1fr 80px; margin: 3px 0; }

@media (max-width: 760px) {
  .equip { gap: 5px; }
  .eslot { min-height: 64px; }
  .item .ii { font-size: 26px; width: 32px; }
  .item { flex-wrap: wrap; }
  .item .ia { grid-auto-flow: column; width: 100%; justify-content: end; }
}

/* ---------- ไอคอน game-icons.net (ย้อมสีด้วย mask) ---------- */
.gi { display: inline-block; width: 1em; height: 1em; vertical-align: -0.15em; background: var(--c, #fff);
  -webkit-mask-size: contain; mask-size: contain; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; -webkit-mask-position: center; mask-position: center; }
.gi.glow { filter: drop-shadow(0 0 4px var(--c)) drop-shadow(0 0 8px var(--c)); }
.item .ii .gi { width: 34px; height: 34px; }
.eslot .ei .gi { width: 28px; height: 28px; }
.eslot:not(.has) .ei { opacity: .6; filter: none; }
.chip .gi { width: 15px; height: 15px; }
.ih { display: flex; align-items: center; justify-content: center; gap: 6px; }
.ih .gi { width: 30px; height: 30px; flex: none; }
.credit { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.credit-icons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.credit-icons .ci { display: grid; justify-items: center; gap: 2px; width: 70px; text-decoration: none; color: var(--muted); }
.credit-icons .ci .gi { width: 30px; height: 30px; }
.credit-icons .ci small { font-size: 10px; text-align: center; word-break: break-all; }
.panel a { color: var(--primary); }

/* ---------- หน้าเริ่มเกม / บัญชี ---------- */
.play-now { width: 100%; min-height: 52px; font-size: 18px; margin-top: 12px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 16px 0 10px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.gbox { display: flex; justify-content: center; min-height: 44px; }
.acct { display: grid; gap: 6px; justify-items: center; margin: 8px 0 4px; }
.uchip { display: inline-flex; align-items: center; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 760px) { .user .uname { display: none; } .uchip { padding: 6px 10px; } }

/* ---------- การดูแล ---------- */
.care { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin: 10px 0; }
.care-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.hearts { display: flex; gap: 1px; font-size: 17px; line-height: 1; }
.hearts span:not(.on) { opacity: .45; }
.care-btns { margin-top: 8px; }
.mini .grave { font-size: 48px; height: 86px; display: grid; place-items: center; }
@media (max-width: 760px) { .hearts { font-size: 15px; } .mini .grave { height: 70px; font-size: 40px; } }
.mini .healer { position: absolute; top: 4px; left: 26px; font-size: 12px; }

/* ---------- เต็มจอ ---------- */
#game { position: relative; }
.fs-btn {
  position: absolute; top: 10px; right: 10px; z-index: 5; width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid #ffffff55; background: #0009; color: #fff; font-size: 20px; line-height: 1; cursor: pointer;
  display: grid; place-items: center; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.fs-btn:hover { background: #000c; }
body.fs { overflow: hidden; }
body.fs .stage {
  position: fixed; inset: 0; z-index: 70; background: #000; display: grid; place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.fs #game { width: 100vw; height: 100vh; height: 100dvh; aspect-ratio: auto; border-radius: 0; box-shadow: none; max-height: none; }
body.fs .roster, body.fs .tabs { display: none; }
body.fs .fs-btn { top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); }
.stage:fullscreen { background: #000; }
@media (max-width: 760px) { .fs-btn { width: 36px; height: 36px; font-size: 18px; top: 8px; right: 8px; } }

/* ---------- หน้าตั้งค่า ---------- */
.themes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.theme { background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 8px 4px; color: var(--text); cursor: pointer; display: grid; gap: 6px; justify-items: center; font: inherit; font-size: 13px; }
.theme .sw { width: 100%; aspect-ratio: 16 / 10; border-radius: 10px; display: grid; place-items: center; font-size: 22px; box-shadow: inset 0 0 0 1px #0002; }
.theme.on { border-color: var(--primary); background: var(--card2); }
.vol { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; flex: 1; }
.vol input { flex: 1; accent-color: var(--primary); }
@media (max-width: 520px) { .themes { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 760px) { #settings-btn .pre { display: none; } #settings-btn { padding: 6px 10px; } }
.mini.add.full { cursor: default; color: var(--primary); border-color: var(--primary); }

/* ---------- 📻 วิทยุฟาร์ม ---------- */
.radio { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; margin-top: 10px; }
.radio-screen { width: 200px; height: 200px; flex: none; border-radius: 10px; overflow: hidden; background: #000; }
.radio-screen iframe, .radio-screen > div { width: 200px; height: 200px; display: block; border: 0; }
.radio-side { flex: 1; min-width: 0; display: grid; gap: 6px; }
.radio-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.radio-sub { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1em; }
.radio-ctrl { display: flex; gap: 6px; flex-wrap: wrap; }
.rbtn { min-width: 42px; font-size: 18px; padding: 4px 8px; }
.rbtn.on { background: var(--primary); color: var(--primary-ink); }
.radio-vol { accent-color: var(--primary); }
/* เต็มจอ: วิทยุลอยมุมซ้ายล่าง (วิดีโอยังเห็นอยู่ตามข้อกำหนด YouTube) */
body.fs #radio-slot .radio { position: fixed; left: 12px; bottom: 12px; z-index: 75; margin: 0; background: #000c; max-width: calc(100vw - 24px); }
body.fs #radio-slot .radio.hidden { display: none; }
@media (max-width: 520px) { .radio { flex-wrap: wrap; justify-content: center; } .radio-side { flex-basis: 100%; } }

/* 🟢 ผู้เล่นออนไลน์ */
.online-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; font-size: 13px;
  background: rgba(60, 200, 120, .12); border: 1px solid rgba(60, 200, 120, .35); color: var(--text, #fff); white-space: nowrap; }
.online-pill.hidden { display: none; }
.online-pill b { font-weight: 700; }
.online-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #3fdc86; box-shadow: 0 0 0 0 rgba(63, 220, 134, .6); animation: online-pulse 2s infinite; }
@keyframes online-pulse { 0% { box-shadow: 0 0 0 0 rgba(63, 220, 134, .6); } 70% { box-shadow: 0 0 0 7px rgba(63, 220, 134, 0); } 100% { box-shadow: 0 0 0 0 rgba(63, 220, 134, 0); } }
@media (prefers-reduced-motion: reduce) { .online-pill .dot { animation: none; } }
@media (max-width: 760px) {
  .online-pill { margin-left: auto; padding: 4px 8px; font-size: 12px; }
  .online-pill .pre { display: none; }
  .online-pill:not(.hidden) + #sound-btn { margin-left: 4px; }
}

/* 🎵 บัฟเพลง */
.radio-music { margin-top: 6px; font-size: 12px; color: var(--muted, #aab); }
.radio-music .music-bar { height: 5px; border-radius: 99px; background: rgba(255, 255, 255, .1); overflow: hidden; margin-top: 4px; }
.radio-music .music-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #a78bfa, #f472b6); transition: width .6s; }
.radio-music.full .music-fill { background: linear-gradient(90deg, #fbbf24, #f472b6); }

/* 🏡 ของตกแต่งฟาร์ม */
.bag-views { margin-bottom: 8px; }
.decor-card { border-left: 3px solid var(--rc, #888); }
.decor-card.placed { background: linear-gradient(90deg, rgba(110, 224, 138, .10), transparent 70%); }
.decor-ic { display: block; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; margin-bottom: 10px; }
.book-cell { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border-radius: 12px; text-align: center;
  background: rgba(255, 255, 255, .05); border: 1px solid color-mix(in srgb, var(--rc, #888) 55%, transparent); }
.book-cell small { font-size: 11px; line-height: 1.2; }
.book-cell.unknown { opacity: .55; border-style: dashed; }
.book-cell .q { font-size: 30px; line-height: 40px; filter: grayscale(1); }

/* 🚦 ป้ายต่อคิวเมื่อเซิร์ฟเวอร์ยุ่ง */
.queue-badge { position: fixed; left: 50%; bottom: 18px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none; z-index: 9999;
  padding: 8px 16px; border-radius: 999px; background: #2b2244ee; color: #ffe9a8; font-size: 14px; box-shadow: 0 6px 20px #0006; transition: .25s; }
.queue-badge.show { opacity: 1; transform: translate(-50%, 0); }

/* ❤️ สนับสนุน */
#donate-btn { color: #ff8fab; }
.donate-pp { display: grid; gap: 10px; justify-items: center; }
.pp-card { background: #fff; color: #0b2447; border-radius: 16px; padding: 0 0 12px; width: min(300px, 100%); text-align: center; overflow: hidden; box-shadow: 0 8px 24px #0005; }
.pp-head { background: #0b2447; color: #fff; font-weight: 700; letter-spacing: .5px; padding: 8px; margin-bottom: 6px; }
.pp-card .qr-box { background: #fff; padding: 0; }
.pp-card canvas.qr { width: min(240px, 72vw); height: auto; image-rendering: pixelated; }
.donate-amt { font-size: 22px; font-weight: 700; }
.pp-name { font-weight: 600; }
.pp-card .muted { color: #5a6b85; }
.paypal-btn { display: inline-block; text-decoration: none; padding: 10px 22px; }
@media (max-width: 760px) { #donate-btn .pre { display: none; } #donate-btn { padding: 6px 10px; } }
/* QR พร้อมเพย์อยู่กลางการ์ด */
.pp-card .qr-box { display: flex; justify-content: center; align-items: center; width: 100%; margin: 0; }
.pp-card canvas.qr { display: block; margin: 0 auto; }
.donate-amt.free { font-size: 14px; font-weight: 600; color: #5a6b85; padding: 0 12px; }

/* 🎉 กิจกรรม */
.event-banner { margin: 8px 0; padding: 8px 14px; border-radius: 12px; font-size: 13px; background: linear-gradient(90deg, #ffc94a22, #b46bff22); border: 1px solid #ffc94a55; }
.event-banner b { color: #ffd77a; }
/* 🎁 รายวัน */
#daily-btn { position: relative; }
#daily-btn .red-dot { display: none; position: absolute; top: 2px; right: 2px; width: 9px; height: 9px; border-radius: 50%; background: #ff4d6d; box-shadow: 0 0 0 2px #1a1530; }
#daily-btn.ready .red-dot { display: block; }
#daily-btn.ready { animation: daily-wiggle 2.4s infinite; }
@keyframes daily-wiggle { 0%, 88%, 100% { transform: rotate(0); } 92% { transform: rotate(-10deg); } 96% { transform: rotate(10deg); } }
@media (prefers-reduced-motion: reduce) { #daily-btn.ready { animation: none; } }
.day-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0 14px; }
.day-card { background: #ffffff0d; border: 1px solid #ffffff1f; border-radius: 12px; padding: 8px 4px; text-align: center; }
.day-card .di { font-size: 28px; line-height: 1.3; } .day-card .dt { font-size: 11px; line-height: 1.25; } .day-card small { font-size: 11px; color: var(--muted, #aab); }
.day-card.done { opacity: .55; } .day-card.now { border-color: #ffc94a; background: #ffc94a1f; box-shadow: 0 0 0 2px #ffc94a55; }
.day-card.big { grid-column: span 2; }
@media (max-width: 420px) { .day-grid { grid-template-columns: repeat(3, 1fr); } .day-card.big { grid-column: span 3; } }
/* 👥 ชวนเพื่อน */
.invite-stats { display: flex; justify-content: center; gap: 28px; margin: 10px 0; text-align: center; }
.invite-stats b { display: block; font-size: 24px; } .invite-stats small { color: var(--muted, #aab); }
/* 📤 การ์ดแชร์ */
.share-preview { width: min(360px, 100%); display: block; margin: 0 auto 8px; border-radius: 14px; box-shadow: 0 10px 30px #0007; }
.btn.gold { background: linear-gradient(90deg, #ffc94a, #ff9f43); color: #2a1d05; border-color: #ffc94a; font-weight: 700; }
/* 📘 สอนเล่น */
.tut-card { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 9000; width: min(440px, calc(100vw - 24px));
  background: #241d44; border: 1px solid #ffc94a88; border-radius: 16px; padding: 14px 16px; box-shadow: 0 12px 40px #000a; }
.tut-card h3 { margin: 2px 0 6px; } .tut-card p { margin: 0 0 12px; font-size: 14px; line-height: 1.5; }
.tut-step { font-size: 11px; color: #ffc94a; }
.tut-hl { position: relative; z-index: 8999; outline: 3px solid #ffc94a; outline-offset: 3px; border-radius: 10px; animation: tut-pulse 1.4s infinite; }
@keyframes tut-pulse { 0%, 100% { outline-color: #ffc94a; } 50% { outline-color: #ffc94a44; } }
@media (prefers-reduced-motion: reduce) { .tut-hl { animation: none; } }

.ios-steps { text-align: left; line-height: 1.8; margin: 8px 0 12px; padding-left: 22px; }

/* 💬 แชทแจ้งปัญหา (สไตล์ LINE) */
.support-fab { position: fixed; right: 16px; bottom: 16px; z-index: 8500; width: 54px; height: 54px; border-radius: 50%; border: 0; cursor: pointer;
  background: #06c755; color: #fff; font-size: 24px; box-shadow: 0 6px 18px #0007; }
.support-fab .badge { position: absolute; top: -2px; right: -2px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: #ff3b30; color: #fff; font-size: 12px; line-height: 20px; }
.support-fab .badge.hidden { display: none; }
.support-panel { position: fixed; right: 16px; bottom: 80px; z-index: 8600; width: min(380px, calc(100vw - 24px)); height: min(560px, calc(100vh - 110px));
  display: flex; flex-direction: column; border-radius: 16px; overflow: hidden; background: #8cabd8; box-shadow: 0 16px 48px #000a; color: #111; }
.sup-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #2a3a55; color: #fff; }
.sup-head small { display: block; font-size: 11px; opacity: .75; }
.sup-head .x { margin-left: auto; background: none; border: 0; color: #fff; font-size: 18px; cursor: pointer; }
.av { width: 34px; height: 34px; flex: none; border-radius: 50%; background: #fff; display: grid; place-items: center; font-size: 18px; }
.sup-list { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 8px; }
.msg { display: flex; gap: 8px; align-items: flex-start; }
.msg.me { justify-content: flex-end; }
.msg .bwrap { max-width: 78%; }
.msg .who { font-size: 11px; color: #33415c; margin: 0 0 2px 4px; }
.msg .row-b { display: flex; align-items: flex-end; gap: 5px; }
.msg .b { padding: 8px 12px; border-radius: 18px; background: #fff; white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.45; }
.msg.me .b { background: #06c755; color: #fff; }
.msg .t { font-size: 10px; color: #33415c; white-space: nowrap; }
.msg.sys, .msg.day { justify-content: center; }
.msg.sys span, .msg.day span { background: #0000002a; color: #fff; font-size: 12px; padding: 4px 12px; border-radius: 12px; text-align: center; max-width: 90%; }
.sup-list .topics { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.sup-list .topics .chip { background: #ffffffcc; color: #223; }
.sup-list .topics .chip.on { background: #06c755; color: #fff; }
.sup-input { display: flex; gap: 6px; align-items: flex-end; padding: 8px; background: #fff; }
.sup-input textarea { flex: 1; resize: none; border: 1px solid #d5d9e0; border-radius: 18px; padding: 8px 12px; font: inherit; font-size: 14px; color: #111; background: #f5f6f8; max-height: 110px; }
.sup-input .send { width: 38px; height: 38px; border-radius: 50%; border: 0; background: #06c755; color: #fff; font-size: 16px; cursor: pointer; }
@media (max-width: 760px) {
  .support-fab { bottom: 76px; right: 12px; width: 48px; height: 48px; font-size: 21px; }
  .support-panel { right: 8px; left: 8px; width: auto; bottom: 132px; height: calc(100vh - 190px); }
}

/* 🔴 โหมดสตรีมเมอร์ */
body.streamer .support-fab, body.streamer .support-panel { display: none !important; }
body.streamer .acct .muted, body.streamer [data-private] { filter: blur(6px); }
.stream-link { background: #0006; border-radius: 8px; padding: 6px 10px; margin: 6px 0; overflow-x: auto; white-space: nowrap; font-size: 12px; }
.stream-steps { font-size: 13px; line-height: 1.7; margin: 6px 0; padding-left: 20px; }
