/* เลข/ตัวอังกฤษสไตล์พิกเซล: Press Start 2P (OFL) — ย่อขนาดให้เท่าฟอนต์เดิม, รองรับเฉพาะตัวอังกฤษ+ตัวเลข ไทยจะใช้ Mitr */
@font-face { font-family: 'NoraPixel'; src: url('../fonts/press-start-2p.woff2') format('woff2'); font-weight: 100 900; font-display: swap; size-adjust: 72%; unicode-range: U+0000-00FF, U+2013-2014, U+2018-201D, U+2022, U+2026, U+20AC, U+2122; }
/* =========================================================
   Nora Kingdom — Pixel Fantasy 90s Design System
   ใช้ร่วมกันทั้งหน้าลูกค้าและหน้าแอดมิน
   ========================================================= */
:root {
  --ink: #2f2153;
  --ink-soft: #6a5c8a;
  --lav: #b9a3ef;
  --lav-d: #8b74c8;
  --lav-dd: #5f4b98;
  --lav-l: #dcd1f7;
  --lav-xl: #f1ecfc;
  --pink: #f7a8c8;
  --pink-d: #c9799f;
  --pink-l: #fcd9e8;
  --sky: #a9d4f5;
  --sky-l: #dcefff;
  --cream: #fff3dc;
  --cream-d: #fbd0c8;
  --gold: #ffd447;
  --ok: #6cc58f;
  --bad: #f2727f;
  --white: #ffffff;

  --font-th: 'Mitr', 'Sarabun', system-ui, sans-serif;
  --font-body: 'Sarabun', 'Mitr', system-ui, sans-serif;
  --font-px: 'NoraPixel', 'Mitr', monospace;

  --r: 12px;
  --bw: 3px;
  --shadow: 0 5px 0 rgba(47, 33, 83, .28);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--lav-xl);
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
img, svg { max-width: 100%; }
svg[shape-rendering] { image-rendering: pixelated; display: inline-block; vertical-align: middle; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { font-family: var(--font-th); font-weight: 500; margin: 0; line-height: 1.3; }
p { margin: 0 0 .6em; }
a { color: var(--lav-dd); }
.px { font-family: var(--font-px); letter-spacing: .02em; }
.center { text-align: center; }
.muted { color: var(--ink-soft); }
.small { font-size: .86rem; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px dashed var(--pink-d); outline-offset: 3px; }

/* ---------- หน้าต่างเกม ---------- */
.win {
  position: relative;
  background: linear-gradient(180deg, var(--lav-xl), var(--white) 160px);
  border: var(--bw) solid var(--ink);
  border-radius: 16px;
  box-shadow: inset 0 0 0 4px var(--lav), inset 0 0 0 6px var(--white), var(--shadow);
  padding: 22px 16px 18px;
}
.win-plain { box-shadow: inset 0 0 0 3px var(--lav-l), var(--shadow); }
.win-inner {
  background: var(--white);
  border: var(--bw) solid var(--ink);
  border-radius: 12px;
  box-shadow: inset 0 -4px 0 var(--lav-xl);
  padding: 12px;
}
.win > .ribbon:first-child { margin: -40px auto 14px; }

/* ---------- ริบบิ้นหัวข้อ ---------- */
.ribbon {
  --rib: var(--pink);
  display: table;
  margin: 0 auto 14px;
  padding: 3px;
  background: var(--ink);
  clip-path: polygon(0 0, 100% 0, calc(100% - 14px) 50%, 100% 100%, 0 100%, 14px 50%);
  filter: drop-shadow(0 4px 0 rgba(47, 33, 83, .25));
}
.ribbon > span {
  display: block;
  background: linear-gradient(180deg, var(--pink-l) 0 18%, var(--rib) 18% 82%, var(--pink-d) 82%);
  clip-path: polygon(0 0, 100% 0, calc(100% - 12px) 50%, 100% 100%, 0 100%, 12px 50%);
  padding: 6px 34px 7px;
  font-family: var(--font-th);
  font-weight: 500;
  font-size: 1.25rem;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(255, 255, 255, .6);
}
.ribbon-sm > span { font-size: 1.02rem; padding: 4px 28px 5px; }
.ribbon-lav { --rib: var(--lav); }
.ribbon-lav > span { background: linear-gradient(180deg, var(--lav-l) 0 18%, var(--lav) 18% 82%, var(--lav-d) 82%); }

/* ---------- ปุ่มนูน ---------- */
.btn {
  --bg: var(--cream-d);
  --bg-hi: color-mix(in srgb, var(--bg) 55%, white);
  --bg-lo: color-mix(in srgb, var(--bg) 80%, var(--ink));
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px;
  padding: 8px 18px;
  border: var(--bw) solid var(--ink);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--bg-hi) 0 14%, var(--bg) 14% 80%, var(--bg-lo) 80%);
  box-shadow: 0 4px 0 var(--ink);
  font-family: var(--font-th);
  font-weight: 500;
  font-size: 1rem;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  transition: transform .06s, box-shadow .06s, filter .15s;
  user-select: none;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.04) saturate(1.05); }
.btn:active, .btn.is-pressed { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: 0 4px 0 var(--ink); }
.btn svg { width: 22px; height: 22px; flex: none; }
.btn-primary { --bg: var(--pink); }
.btn-lav { --bg: var(--lav); }
.btn-sky { --bg: var(--sky); }
.btn-white { --bg: var(--white); }
.btn-ok { --bg: var(--ok); }
.btn-danger { --bg: var(--bad); }
.btn-gold { --bg: var(--gold); }
.btn-block { display: flex; width: 100%; }
.btn-sm { min-height: 36px; padding: 4px 12px; font-size: .9rem; border-radius: 10px; box-shadow: 0 3px 0 var(--ink); }
.btn-sm:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn-icon { width: 40px; min-height: 40px; padding: 0; border-radius: 10px; font-size: 1.1rem; }
.btn-icon.btn-sm { width: 36px; min-height: 36px; }

/* ---------- แท็บ ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-bottom: 12px; }
.tab {
  flex: 1 1 auto;
  min-height: 40px;
  padding: 4px 14px;
  border: var(--bw) solid var(--ink);
  border-radius: 12px;
  background: var(--lav-l);
  box-shadow: inset 0 -3px 0 var(--lav-d);
  font-family: var(--font-th);
  font-size: .95rem;
  cursor: pointer;
  white-space: nowrap;
}
.tab.active { background: var(--cream); box-shadow: inset 0 -3px 0 var(--cream-d), inset 0 3px 0 var(--white); }
.tab .count { font-family: var(--font-px); }

/* ---------- ฟอร์ม ---------- */
.field { margin-bottom: 14px; }
.label { display: block; font-family: var(--font-th); font-weight: 500; margin-bottom: 6px; }
.label .req { color: var(--bad); }
.input, .select, .textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: var(--bw) solid var(--ink);
  border-radius: 12px;
  background: var(--white);
  box-shadow: inset 0 3px 0 var(--lav-xl);
  font-size: 16px; /* กันมือถือซูม */
}
.textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%); background-position: calc(100% - 20px) 20px, calc(100% - 14px) 20px; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--lav-dd); box-shadow: inset 0 3px 0 var(--lav-xl), 0 0 0 3px var(--pink-l); }
.hint { font-size: .85rem; color: var(--ink-soft); margin-top: 4px; }
.err { font-size: .88rem; color: #c43d56; margin-top: 4px; }

/* ---------- ดาว ---------- */
.stars { display: inline-flex; gap: 2px; vertical-align: middle; }
.stars .px-star { width: 18px; height: 18px; }
.star-pick { display: flex; gap: 6px; justify-content: center; }
.star-pick button { background: none; border: 0; padding: 4px; cursor: pointer; transition: transform .1s; }
.star-pick button svg { width: 42px; height: 42px; }
.star-pick button:hover, .star-pick button:focus-visible { transform: scale(1.15) rotate(-6deg); }
.star-pick button.on svg { animation: pop .25s; }

/* ---------- ป้าย / ชิป ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 10px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--lav-l);
  font-family: var(--font-th);
  font-size: .78rem;
  line-height: 1.5;
  white-space: nowrap;
}
.badge-pending { background: var(--gold); }
.badge-approved { background: #b7ecc9; }
.badge-rejected { background: #ffc2c8; }
.badge-hidden { background: #e2e0ea; }
.badge-pink { background: var(--pink-l); }
.badge-sky { background: var(--sky-l); }

/* ---------- แถบ EXP / HP ---------- */
.bar { height: 16px; border: var(--bw) solid var(--ink); border-radius: 8px; background: var(--white); overflow: hidden; box-shadow: inset 0 3px 0 var(--lav-xl); }
.bar > i { display: block; height: 100%; background: linear-gradient(180deg, #ffd1e2 0 30%, var(--pink) 30% 75%, var(--pink-d) 75%); border-right: 2px solid var(--ink); }
.bar-sky > i { background: linear-gradient(180deg, #e3f3ff 0 30%, var(--sky) 30% 75%, #6aa9d8 75%); }

/* ---------- สวิตช์ ---------- */
.switch { position: relative; display: inline-block; width: 62px; height: 32px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; cursor: pointer;
  border: var(--bw) solid var(--ink); border-radius: 999px; background: #e2dcef;
  transition: background .15s;
}
.switch span::before {
  content: 'OFF'; position: absolute; right: 7px; top: 3px; font: 600 10px/1 var(--font-px); color: var(--ink-soft); margin-top: 4px;
}
.switch span::after {
  content: ''; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 6px;
  background: var(--white); border: 2px solid var(--ink); transition: transform .15s;
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { content: 'ON'; left: 8px; right: auto; color: var(--ink); }
.switch input:checked + span::after { transform: translateX(29px); }
.switch input:focus-visible + span { outline: 3px dashed var(--pink-d); outline-offset: 3px; }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(47, 33, 83, .55);
  display: grid; place-items: center;
  padding: 44px 14px 20px;
  animation: fade .15s;
  overflow-y: auto;
}
.modal-back.out { animation: fade .15s reverse forwards; }
.modal { width: min(440px, 100%); padding-top: 26px; animation: popin .22s cubic-bezier(.3, 1.5, .6, 1); }
.modal-wide { width: min(640px, 100%); }
.modal-title { margin: -46px auto 12px !important; }
.modal-x {
  position: absolute; top: 8px; right: 8px; width: 34px; height: 34px;
  border: var(--bw) solid var(--ink); border-radius: 10px; background: var(--white); cursor: pointer; font-weight: 700;
}
.modal-body { max-height: 70vh; overflow-y: auto; padding: 2px 2px 4px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1 1 120px; }

/* ---------- Toast ---------- */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); top: 14px; z-index: 300; display: grid; gap: 8px; width: min(92vw, 380px); pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border: var(--bw) solid var(--ink); border-radius: 12px;
  background: var(--white); box-shadow: 0 4px 0 var(--ink);
  font-family: var(--font-th); font-size: .95rem;
  animation: slidein .25s cubic-bezier(.3, 1.4, .6, 1);
}
.toast.out { animation: fade .3s reverse forwards; }
.toast-ico svg { width: 22px; height: 22px; }
.toast-success { background: #e7f9ee; }
.toast-error { background: #ffe6ea; }

/* ---------- ฉากพื้นหลัง ---------- */
.scene { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none;
  background: linear-gradient(180deg, var(--lav-l) 0%, var(--lav-xl) 45%, var(--pink-l) 78%, var(--cream) 100%); }
.scene .tw { position: absolute; width: 10px; height: 10px; animation: twinkle 2.4s infinite steps(2); }
.scene .tw svg { width: 100%; height: 100%; }
.scene .moon { position: absolute; top: 46px; right: 9%; width: 44px; }
.scene .cloud { position: absolute; width: 120px; opacity: .95; animation: drift linear infinite; }
.scene .hills { position: absolute; left: 0; right: 0; bottom: 0; height: 120px;
  background:
    radial-gradient(60% 90px at 15% 100%, color-mix(in srgb, var(--lav) 70%, white) 98%, transparent 100%),
    radial-gradient(50% 110px at 70% 100%, color-mix(in srgb, var(--lav) 55%, white) 98%, transparent 100%);
  opacity: .8; }
.scene .grass { position: absolute; left: 0; right: 0; bottom: 0; height: 32px; background-repeat: repeat-x; background-size: 64px 32px; image-rendering: pixelated; }

/* ---------- Loading ---------- */
.loading-screen {
  position: fixed; inset: 0; z-index: 500;
  display: grid; place-items: center; align-content: center; gap: 14px;
  background: var(--ink); color: var(--white);
  transition: opacity .3s;
}
.loading-screen.out { opacity: 0; pointer-events: none; }
.loading-screen .ls-hero { width: 64px; animation: walk .4s steps(2) infinite; }
.loading-screen .ls-img { max-width: min(70vw, 320px); max-height: 40vh; image-rendering: pixelated; }
.loading-screen .ls-text { font-family: var(--font-px); font-size: 1.1rem; letter-spacing: .12em; }
.loading-screen .ls-bar { width: 200px; height: 18px; border: 3px solid var(--white); padding: 2px; display: flex; gap: 2px; }
.loading-screen .ls-bar i { flex: 1; background: var(--pink); opacity: 0; animation: fill .9s steps(1) forwards; }

/* ---------- Animations ---------- */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes popin { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pop { 50% { transform: scale(1.35); } }
@keyframes slidein { from { transform: translateY(-16px); opacity: 0; } }
@keyframes twinkle { 50% { opacity: .2; } }
@keyframes drift { from { transform: translateX(-160px); } to { transform: translateX(calc(100vw + 160px)); } }
@keyframes bob { 50% { transform: translateY(-4px); } }
@keyframes walk { 50% { transform: translateY(-3px); } }
@keyframes fill { to { opacity: 1; } }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
/* เชื่อมฐานข้อมูลไม่ได้ */
.db-down { position: fixed; inset: 0; z-index: 10000; display: grid; place-items: center; padding: 20px; background: rgba(47, 33, 83, .7); }
.db-down > div { max-width: 360px; padding: 20px; border: 3px solid #2f2153; border-radius: 14px; background: #fff; text-align: center; font-family: 'Mitr', sans-serif; color: #2f2153; }
.db-down p { font-size: .9rem; }
.db-down button { padding: 8px 18px; border: 2px solid #2f2153; border-radius: 10px; background: #f7a8c8; font: inherit; cursor: pointer; }
