/* สไตล์กลาง (มินิมอลสายเทค): แก้สีหรือฟอนต์ตรงนี้ที่เดียว ทุกหน้าเปลี่ยนตาม */
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f6f6f7;
  --hover: #f2f2f4;
  --border: #e8e8eb;
  --border-strong: #d6d6db;
  --border-hover: #b8b8c0;
  --text: #18181b;
  --muted: #62626b;
  --faint: #9a9aa3;

  /* สีเน้น: ไล่จากแอปริคอตไปราสเบอร์รี่ (เข้มขึ้นให้อ่านชัดบนพื้นขาว) */
  --apricot: #e07a2e;
  --rose: #d6456b;
  --accent: linear-gradient(90deg, var(--apricot), var(--rose));
  --good: #16a06a;
  --warn: #d0761f;
  --bad: #e0384f;

  --radius: 10px;
  --font: "IBM Plex Sans Thai", "Leelawadee UI", "Tahoma", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Consolas", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
/* แสงไล่สีด้านบน: แอปริคอตตรงกลาง ราสเบอร์รี่สองข้าง ค่อย ๆ จางลงมา (ปรับความเข้มที่ตัวเลข 0.xx) */
body::before {
  content: ""; position: fixed; inset: 0 0 auto 0; height: 600px; pointer-events: none; z-index: -1;
  background:
    radial-gradient(55% 90% at 50% 0%, rgba(240, 150, 80, 0.40), transparent 72%),
    radial-gradient(38% 75% at 12% 0%, rgba(214, 69, 107, 0.24), transparent 70%),
    radial-gradient(38% 75% at 88% 0%, rgba(214, 69, 107, 0.20), transparent 70%),
    linear-gradient(180deg, rgba(240, 163, 94, 0.18), transparent 85%);
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.grad { background: var(--accent); -webkit-background-clip: text; background-clip: text; color: transparent; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 20px; }

/* ---------- แถบบน ---------- */
.nav { position: sticky; top: 0; z-index: 20; background: rgba(250, 250, 250, 0.5); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); }
.nav-inner { height: 56px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-family: var(--mono); font-weight: 700; font-size: 15px;
}
.nav-links { display: flex; gap: 4px; }
.nav-links a { padding: 6px 10px; border-radius: 8px; color: var(--muted); font-size: 0.9rem; }
.nav-links a:hover { color: var(--text); background: var(--hover); }
.nav-links a.active { color: var(--text); }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.kbd {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  border: 1px solid var(--border-strong); border-radius: 5px; padding: 0 5px; line-height: 18px;
}
.search-btn {
  display: flex; align-items: center; gap: 10px; min-width: 220px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
  color: var(--faint); font-size: 0.88rem;
}
.search-btn:hover { border-color: var(--border-strong); }
.search-btn .kbd { margin-left: auto; }
.user-btn {
  display: flex; align-items: center; gap: 8px; cursor: pointer; background: none; border: 1px solid transparent;
  border-radius: 8px; padding: 3px 8px 3px 3px; font-size: 0.88rem; color: var(--muted);
}
.user-btn:hover { border-color: var(--border); color: var(--text); }

/* ---------- ปุ่ม ป้าย ช่องกรอก ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  border-radius: 8px; padding: 8px 14px; font-size: 0.9rem; font-weight: 500;
  background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text);
  transition: background 0.12s, border-color 0.12s;
}
.btn { background: var(--surface); }
.btn:hover { background: var(--hover); border-color: var(--border-hover); }
.btn.primary { background: var(--text); color: #fff; border-color: var(--text); }
.btn.primary:hover { background: #34343a; }
.btn.small { padding: 5px 10px; font-size: 0.82rem; }

.tag {
  display: inline-block; font-family: var(--mono); font-size: 11px; line-height: 18px; white-space: nowrap;
  padding: 0 6px; border-radius: 5px; border: 1px solid var(--border-strong); color: var(--muted);
}
.tag.good { color: var(--good); border-color: rgba(79, 209, 154, 0.35); }
.tag.warn { color: var(--warn); border-color: rgba(240, 163, 94, 0.35); }

.field {
  width: 100%; font: inherit; color: var(--text); outline: none;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 8px; padding: 10px 12px;
}
.field::placeholder { color: var(--faint); }
.field { background: var(--surface); }
.field:focus { border-color: var(--border-hover); box-shadow: 0 0 0 3px rgba(224, 122, 46, 0.15); }

.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.seg button {
  border: none; background: none; cursor: pointer; padding: 4px 10px; border-radius: 6px;
  font-size: 0.82rem; color: var(--muted);
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--hover); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-strong); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.label { font-family: var(--mono); font-size: 11px; color: var(--faint); letter-spacing: 0.04em; text-transform: uppercase; }

.avatar {
  flex: none; border-radius: 7px; display: grid; place-items: center;
  font-weight: 600; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.bar { height: 4px; border-radius: 4px; background: var(--border); overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.3s; }

.stars { font-family: var(--mono); letter-spacing: 1px; color: var(--apricot); }
.stars .off { color: var(--border-strong); }

/* ---------- หน้าต่างลอย (กรอกชื่อ / ค้นหา) ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; justify-content: center; align-items: flex-start;
  padding: 14vh 16px 16px; background: rgba(24, 24, 27, 0.28); backdrop-filter: blur(4px);
}
.dialog {
  width: min(520px, 100%); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 14px;
  box-shadow: 0 24px 60px rgba(24, 24, 27, 0.18); overflow: hidden;
}
.dialog.pad { padding: 24px; }
.dialog h2 { font-size: 1.2rem; margin: 6px 0 4px; }
.dialog p { color: var(--muted); margin: 0 0 16px; font-size: 0.9rem; }
.dialog .err { color: var(--bad); font-size: 0.82rem; min-height: 1.3em; margin: 6px 0 8px; }
.dialog .actions { display: flex; gap: 8px; justify-content: flex-end; }

.palette input { border: none; border-bottom: 1px solid var(--border); border-radius: 0; background: none; padding: 14px 16px; font-size: 1rem; box-shadow: none; }
.palette input:focus { box-shadow: none; border-color: var(--border); }
.palette ul { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow-y: auto; }
.palette li a, .palette li div {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 8px; font-size: 0.92rem;
}
.palette li .grade { margin-left: auto; }
.palette li.sel a { background: var(--hover); }
.palette li.soon div { color: var(--faint); }
.palette .empty { padding: 18px; color: var(--faint); text-align: center; font-size: 0.9rem; }
.palette .foot { border-top: 1px solid var(--border); padding: 8px 14px; display: flex; gap: 14px; font-size: 11px; color: var(--faint); }

/* ---------- มือถือ ---------- */
button, a, input { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.tabbar { display: none; }

@media (max-width: 760px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  body.focus { padding-bottom: env(safe-area-inset-bottom); }   /* หน้าเกม: ไม่มีแถบล่าง */
  .container { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }

  /* แถบบนเหลือแค่โลโก้ เมนูย้ายไปแถบล่างให้นิ้วโป้งกดถึง */
  .nav-inner { height: 52px; }
  .nav-links, .nav-right { display: none; }
  body.focus .nav-right { display: flex; }
  body.focus .search-btn { display: none; }
  body.focus .user-btn .uname { display: none; }

  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(12px);
    border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  }
  body.focus .tabbar { display: none; }
  .tabbar a, .tabbar button {
    height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    border: none; background: none; cursor: pointer; color: var(--faint); font-size: 11px; font-weight: 500;
  }
  .tabbar .active { color: var(--text); }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar .avatar { width: 22px !important; height: 22px !important; font-size: 10px !important; }

  /* ขนาดสำหรับนิ้ว */
  .field { font-size: 16px; padding: 12px 14px; }    /* 16px กัน iPhone ซูมเมื่อแตะช่องกรอก */
  .btn { min-height: 44px; padding: 10px 16px; }
  .btn.small { min-height: 36px; }
  .seg { display: flex; flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .seg::-webkit-scrollbar { display: none; }
  .seg button { flex: none; padding: 8px 14px; font-size: 0.9rem; }

  /* หน้าต่างลอย */
  .overlay { padding: max(12px, env(safe-area-inset-top)) 12px 12px; }
  .dialog.pad { padding: 20px; }
  .palette input { font-size: 16px; }
  .palette ul { max-height: 52vh; }
  .palette li a, .palette li div { padding: 13px 10px; }
  .palette .foot { display: none; }
}

/* ---------- อวาตาร์ + กรอบออร่า 7 เลเวล ---------- */
.ava {
  position: relative; isolation: isolate; flex: none; display: inline-grid; place-items: center;
  border-radius: 50%; box-sizing: border-box;
}
.ava::before { content: ""; position: absolute; inset: 0; border-radius: 50%; z-index: -1; background: var(--ring, #e4e4e7); }
.ava > img, .ava > .ini {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: grid; place-items: center;
  border: 2px solid var(--surface); box-sizing: border-box; background: var(--surface-2);
  color: #fff; font-weight: 600; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18); line-height: 1;
}
.ava.l1 { --ring: #e1e1e6; }
.ava.l2 { --ring: linear-gradient(135deg, #e7a46f, #9a5a2f 60%, #d79060); }
.ava.l3 { --ring: linear-gradient(135deg, #f8fafc, #94a3b8 50%, #e2e8f0); }
.ava.l4 { --ring: linear-gradient(135deg, #fde68a, #f59e0b 50%, #fcd34d); filter: drop-shadow(0 0 4px rgba(245, 158, 11, 0.45)); }
.ava.l5 { --ring: linear-gradient(135deg, #a7f3d0, #22d3ee 50%, #818cf8); filter: drop-shadow(0 0 5px rgba(34, 211, 238, 0.5)); }
.ava.l6::before, .ava.l7::before { animation: aura-spin 4s linear infinite; }
.ava.l6 { --ring: conic-gradient(#60a5fa, #a78bfa, #f472b6, #60a5fa); filter: drop-shadow(0 0 6px rgba(167, 139, 250, 0.55)); }
.ava.l7 { --ring: conic-gradient(#f43f5e, #f59e0b, #facc15, #22c55e, #06b6d4, #8b5cf6, #f43f5e); }
.ava.l7::after {
  content: ""; position: absolute; inset: -22%; border-radius: 50%; z-index: -2;
  background: conic-gradient(#f43f5e, #f59e0b, #facc15, #22c55e, #06b6d4, #8b5cf6, #f43f5e);
  filter: blur(8px); opacity: 0.55; animation: aura-spin 6s linear infinite reverse, aura-pulse 2.4s ease-in-out infinite;
}
@keyframes aura-spin { to { transform: rotate(360deg); } }
@keyframes aura-pulse { 50% { opacity: 0.25; transform: scale(0.92) rotate(180deg); } }
@media (prefers-reduced-motion: reduce) { .ava::before, .ava::after { animation: none !important; } }

/* ---------- ฟอร์มบัญชี ---------- */
.auth { position: relative; }
.auth .auth-tabs { margin: 10px 0 16px; width: 100%; }
.auth .auth-tabs button { flex: 1; }
.fld { display: block; margin-bottom: 12px; }
.fld > span { display: block; font-size: 0.82rem; font-weight: 500; margin-bottom: 5px; }
.fld > span em { font-style: normal; font-weight: 400; color: var(--faint); margin-left: 4px; }
.fld-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field.invalid { border-color: var(--bad); box-shadow: 0 0 0 3px rgba(224, 56, 79, 0.12); }
.field.pin { font-family: var(--mono); letter-spacing: 0.3em; }
select.field { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.btn.wide { width: 100%; }
.btn.ghost { background: none; border-color: transparent; }
.btn:disabled { opacity: 0.6; cursor: default; }
.close-x {
  position: absolute; top: 12px; right: 12px; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; border: none; background: var(--surface-2); color: var(--muted); cursor: pointer;
}
.close-x:hover { background: var(--hover); color: var(--text); }
.auth .hint { text-align: center; font-size: 0.8rem; color: var(--faint); margin: 12px 0 0; }
a.user-btn { text-decoration: none; }
a.user-btn.active { border-color: var(--border); color: var(--text); }

/* ---------- แจ้งเตือนเล็ก ๆ ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 0.9rem;
  box-shadow: 0 12px 32px rgba(24, 24, 27, 0.25); animation: toast-in 0.2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
@media (max-width: 760px) {
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
  body.focus .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }
  .fld-row { gap: 8px; }
}
