@font-face {
  font-family: 'Noto Sans Khmer';
  src: url('/fonts/NotoSansKhmer-400.woff') format('woff');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Noto Sans Khmer';
  src: url('/fonts/NotoSansKhmer-700.woff') format('woff');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #2a1c2e;
  --panel: rgba(37, 25, 36, 0.92);
  --panel-solid: #2b1d2a;
  --panel-2: rgba(255, 244, 228, 0.07);
  --line: rgba(255, 230, 200, 0.16);
  --text: #fbf3e6;
  --muted: #d9c7b4;
  --accent: #e9a23b;
  --accent-2: #c8553d;
  --gold: #e6c36a;
  --ok: #8cc79a;
  --danger: #ef7d6b;
  --radius: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --kb: 0px; /* virtual keyboard height, set from JS */
  --font: 'Noto Sans Khmer', 'Khmer OS', 'Khmer UI', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 16px;
  /* Khmer stacks subscript consonants and vowels above/below; give lines room. */
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
body { overflow: hidden; touch-action: manipulation; }
button, input, select, textarea { font: inherit; color: inherit; line-height: 1.6; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }

.screen { position: fixed; inset: 0; }
.muted { color: var(--muted); }
.tiny { font-size: 0.8rem; }
.error { color: var(--danger); }
.note { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.noscript { padding: 24px; }

/* ---------- boot & lobby ---------- */
#boot, #lobby {
  display: grid; place-items: center; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background:
    radial-gradient(120% 70% at 50% 110%, rgba(233, 162, 59, 0.45), transparent 60%),
    linear-gradient(180deg, #3b2342 0%, #6a3546 55%, #b9643f 100%);
  overflow-y: auto;
}
.boot-card, .lobby-card {
  width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 22px; padding: 22px 20px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); text-align: center;
}
.lobby-card { text-align: left; }
.game-name { font-size: 2rem; font-weight: 700; color: var(--gold); text-align: center; line-height: 1.9; letter-spacing: 0.02em; }
.lobby-title { font-size: 1.15rem; font-weight: 700; text-align: center; }
.lobby-card > .muted { text-align: center; }
.logo { display: grid; place-items: center; height: 56px; }
.logo-lotus { width: 48px; height: 48px; border-radius: 50% 50% 46% 46%; background: radial-gradient(circle at 50% 30%, #ffd9e6, #e58fb0 60%, #b9557e); box-shadow: 0 0 24px rgba(229, 143, 176, 0.6); }
.bar { height: 8px; background: rgba(255, 255, 255, 0.12); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; width: 5%; background: linear-gradient(90deg, var(--accent), var(--gold)); transition: width 0.3s; }

.lang-switch { display: flex; gap: 8px; justify-content: center; }
.chip {
  min-height: 40px; padding: 4px 16px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer;
}
.chip[aria-pressed='true'], .chip.on { background: var(--accent); color: #2b1606; border-color: transparent; font-weight: 700; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 700; font-size: 0.95rem; }
input[type='text'], textarea, select {
  width: 100%; min-height: 48px; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25); outline: none;
}
input[type='text']:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: none; min-height: 88px; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 44px; height: 44px; border-radius: 50%; border: 3px solid transparent; cursor: pointer;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25); position: relative;
}
.swatch[aria-checked='true'] { border-color: var(--gold); transform: scale(1.06); }
.swatch:disabled { opacity: 0.35; cursor: not-allowed; }
.swatch:disabled::after { content: '🔒'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 14px; }

.btn {
  min-height: 46px; padding: 6px 18px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; font-weight: 700;
}
.btn.primary { background: linear-gradient(180deg, #f0b04d, #d98a2b); color: #2b1606; border: none; }
.btn.danger { background: transparent; color: var(--danger); border-color: rgba(239, 125, 107, 0.5); }
.btn.big { min-height: 56px; font-size: 1.15rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }
.link { background: none; border: none; color: var(--gold); text-decoration: underline; cursor: pointer; padding: 6px 0; align-self: center; }

/* ---------- game HUD ---------- */
#game { overflow: hidden; background: #000; }
#view, #view canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.label {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -100%); white-space: nowrap;
  font-size: 13px; line-height: 1.6; padding: 0 8px; border-radius: 99px; background: rgba(30, 18, 28, 0.62);
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; will-change: transform; pointer-events: auto; cursor: pointer;
}
.label.me { background: rgba(233, 162, 59, 0.75); color: #2b1606; }
.label.npc { background: rgba(80, 80, 90, 0.6); font-style: italic; pointer-events: none; }
.label .npc-tag { font-size: 10px; opacity: 0.85; margin-left: 4px; }
/* activity icon (offering round) before the name */
.label[data-icon]:not([data-icon=""])::before { content: attr(data-icon); margin-right: 3px; font-size: 13px; }
/* far away or many people on screen: only the icon, or a small dot */
.label.compact { font-size: 0; padding: 0 3px; min-width: 8px; min-height: 8px; background: rgba(30, 18, 28, 0.45); }
.label.compact::before { margin-right: 0 !important; }
.label.compact:not([data-icon])::after, .label.compact[data-icon=""]::after { content: ""; display: block; width: 6px; height: 6px; margin: 1px 0; border-radius: 50%; background: rgba(255, 240, 220, 0.8); }
.bubble {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -100%); max-width: min(220px, 60vw);
  background: #fff8ec; color: #2a1a12; padding: 6px 12px; border-radius: 14px; font-size: 14px; line-height: 1.6;
  white-space: normal; overflow-wrap: anywhere; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25); pointer-events: none;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.bubble.emote { background: transparent; box-shadow: none; font-size: 28px; padding: 0; }

.hud-top {
  position: absolute; top: calc(8px + var(--safe-t)); left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r));
  display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none;
}
.pill {
  background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 2px 12px;
  font-size: 0.85rem; display: flex; align-items: center; gap: 6px; pointer-events: auto;
}
.pill.warn { background: rgba(180, 70, 40, 0.92); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }

.round {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel);
  font-size: 20px; cursor: pointer; display: grid; place-items: center;
}
.round.small { width: 40px; height: 40px; font-size: 16px; }
.hud-side {
  position: absolute; right: calc(10px + var(--safe-r)); top: calc(56px + var(--safe-t));
  display: flex; flex-direction: column; gap: 10px;
}

.hud-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around;
  padding: 6px calc(8px + var(--safe-r)) calc(6px + var(--safe-b)) calc(8px + var(--safe-l));
  background: linear-gradient(180deg, transparent, rgba(20, 12, 20, 0.85) 40%);
}
.tab {
  flex: 1; max-width: 120px; min-height: 52px; background: none; border: none; display: flex; flex-direction: column;
  align-items: center; gap: 0; font-size: 0.78rem; cursor: pointer; position: relative; line-height: 1.5;
}
.tab .ico { font-size: 20px; line-height: 1.3; }
.badge { position: absolute; top: 4px; right: 28%; width: 10px; height: 10px; border-radius: 50%; background: var(--accent-2); }

.joy {
  position: absolute; left: 0; bottom: calc(64px + var(--safe-b)); width: 50%; height: 45%;
  touch-action: none;
}
.joy-base {
  position: absolute; left: calc(28px + var(--safe-l)); bottom: 24px; width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.1); border: 2px solid rgba(255, 255, 255, 0.22); pointer-events: none;
}
.joy-knob {
  position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%;
  background: rgba(255, 240, 220, 0.55); transition: transform 0.05s;
}
.joy.desktop .joy-base { display: none; }

.interact {
  position: absolute; left: 50%; bottom: calc(150px + var(--safe-b)); transform: translateX(-50%);
  min-height: 52px; padding: 6px 22px; border-radius: 99px; border: 2px solid var(--gold);
  background: rgba(43, 22, 6, 0.85); color: var(--gold); font-weight: 700; font-size: 1.05rem; cursor: pointer;
  box-shadow: 0 0 24px rgba(230, 195, 106, 0.4); max-width: 80vw;
}

.emote-bar {
  position: absolute; right: calc(66px + var(--safe-r)); top: calc(56px + var(--safe-t));
  display: flex; flex-direction: column; gap: 6px; background: var(--panel); padding: 8px; border-radius: 16px; border: 1px solid var(--line);
}
.emote-bar button { min-height: 42px; border-radius: 10px; border: none; background: var(--panel-2); padding: 2px 12px; text-align: left; cursor: pointer; }
.emote-bar button:disabled { opacity: 0.4; }

/* ---------- chat ---------- */
.chat {
  position: absolute; left: calc(8px + var(--safe-l)); bottom: calc(66px + var(--safe-b) + var(--kb));
  width: min(380px, calc(100% - 16px - var(--safe-l) - var(--safe-r))); display: flex; flex-direction: column; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px;
}
.chat.collapsed { display: none; }
.chat-log { max-height: 30vh; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; font-size: 0.92rem; overscroll-behavior: contain; }
.chat-log .msg { overflow-wrap: anywhere; }
.chat-log .msg .who { color: var(--gold); font-weight: 700; cursor: pointer; margin-right: 6px; }
.chat-log .msg.sys { color: var(--muted); font-size: 0.82rem; }
.chat-quick { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chat-quick button { flex: none; min-height: 36px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel-2); padding: 0 12px; cursor: pointer; font-size: 0.85rem; }
.chat-form { display: flex; gap: 6px; }
.chat-form input { flex: 1; min-height: 44px; }
.chat-tools { display: flex; justify-content: space-between; }
.chat-tools .link { padding: 0; }

/* ---------- sheets (panels) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 5, 10, 0.45); z-index: 20; }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 21;
  width: min(520px, 100%); max-height: min(86vh, calc(100% - var(--safe-t) - 12px - var(--kb)));
  margin-bottom: var(--kb);
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 22px 22px 0 0;
  display: flex; flex-direction: column; padding-bottom: var(--safe-b);
}
@media (min-width: 700px) and (min-height: 500px) {
  .sheet { bottom: 50%; transform: translate(-50%, 50%); border-radius: 22px; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 4px 18px; gap: 8px; }
.sheet-head h2 { font-size: 1.15rem; }
.sheet-body { overflow-y: auto; padding: 8px 18px 18px; display: flex; flex-direction: column; gap: 12px; overscroll-behavior: contain; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.card h3 { font-size: 1.02rem; }
.card .row { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg .chip { flex: 1 1 auto; }
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.progress { height: 10px; background: rgba(255, 255, 255, 0.1); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--gold)); }
.blessing-text { font-size: 1.2rem; line-height: 1.9; text-align: center; padding: 8px 4px; }
.blessing-en { color: var(--muted); text-align: center; font-size: 0.9rem; }
.counter { text-align: right; font-size: 0.8rem; color: var(--muted); }
.counter.over { color: var(--danger); }
.photo-preview { width: 100%; max-width: 320px; align-self: center; border-radius: 12px; aspect-ratio: 1080 / 1350; background: #111; object-fit: contain; }
.seat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.qr-img { width: 160px; height: 160px; image-rendering: pixelated; align-self: center; background: #fff; border-radius: 8px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.sponsor { border-style: dashed; }
.sponsor .tag { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
input[type='range'] { width: 100%; accent-color: var(--accent); min-height: 32px; }

/* ---------- meditation overlay ---------- */
.med-overlay {
  position: absolute; left: 50%; bottom: calc(76px + var(--safe-b)); transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 14px 18px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; width: min(320px, 90vw); text-align: center;
}
.breath { position: relative; width: 120px; height: 120px; display: grid; place-items: center; }
.breath-ring {
  position: absolute; width: 100%; height: 100%; border-radius: 50%;
  background: radial-gradient(circle, rgba(230, 195, 106, 0.35), rgba(230, 195, 106, 0.08) 70%);
  border: 2px solid var(--gold); transform: scale(0.55); animation: breathe 10s ease-in-out infinite;
}
@keyframes breathe { 0%, 100% { transform: scale(0.55); } 45%, 55% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .breath-ring { animation-duration: 14s; } }
.breath-label { position: relative; font-weight: 700; }
.med-time { font-size: 1.3rem; font-weight: 700; }

/* ---------- toasts ---------- */
.toasts {
  position: absolute; left: 50%; top: calc(48px + var(--safe-t)); transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: min(420px, 92vw); z-index: 30;
}
.toast {
  background: rgba(30, 18, 28, 0.94); border: 1px solid var(--line); border-radius: 14px; padding: 6px 14px;
  font-size: 0.92rem; text-align: center; animation: toast-in 0.25s ease-out;
}
.toast.good { border-color: rgba(230, 195, 106, 0.6); color: var(--gold); }
.toast.bad { border-color: rgba(239, 125, 107, 0.6); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* Landscape phones: tighter HUD */
@media (orientation: landscape) and (max-height: 500px) {
  .med-overlay { bottom: auto; top: calc(8px + var(--safe-t)); right: calc(8px + var(--safe-r)); left: auto; transform: none; width: 240px; }
  .breath { width: 90px; height: 90px; }
  .hud-bottom { left: auto; width: min(420px, 60%); background: none; }
  .chat-log { max-height: 26vh; }
  .joy { height: 70%; bottom: 0; }
  .joy-base { bottom: 12px; width: 104px; height: 104px; }
  .joy-knob { left: 27px; top: 27px; }
  .interact { bottom: calc(76px + var(--safe-b)); }
  .chat { bottom: calc(64px + var(--safe-b) + var(--kb)); }
}

/* ---------- 3D Creative Corner ---------- */
.cc-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.cc-item {
  display: flex; flex-direction: column; gap: 2px; text-align: left; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 14px; padding: 8px; cursor: pointer; min-height: 44px;
}
.cc-item img, .cc-noimg { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: rgba(0, 0, 0, 0.25); }
.cc-name { font-weight: 700; font-size: 0.92rem; overflow-wrap: anywhere; }
.cc-price { color: var(--gold); font-size: 0.88rem; }
.cc-hero { width: 100%; max-height: 52vh; object-fit: contain; border-radius: 12px; background: rgba(0, 0, 0, 0.25); }
.cc-thumbs { display: flex; gap: 6px; overflow-x: auto; }
.cc-thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; cursor: pointer; flex: none; }
.cc-price-big { font-size: 1.3rem; font-weight: 700; color: var(--gold); }
.cc-spec { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; font-size: 0.9rem; }
.cc-spec dt { color: var(--muted); }
.cc-spec dd { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
