:root {
  --ink: #24302b;
  --muted: #5c6b62;
  --paper: #fff8ee;
  --moss: #2f6a45;
  --clay: #b5524a;
  --line: rgba(36, 48, 43, 0.12);
  --shadow: 0 24px 70px rgba(36, 48, 43, 0.16);
  color: var(--ink);
  font-family: "Be Vietnam Pro", "Segoe UI", sans-serif;
  background:
    radial-gradient(900px 480px at 12% -10%, #f4e6c4 0%, transparent 55%),
    radial-gradient(700px 420px at 110% 90%, #efc7b6 0%, transparent 46%),
    #d5e3cc;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--clay);
  outline-offset: 2px;
}

#game {
  position: fixed;
  inset: 0;
  opacity: 0;
  transition: opacity 0.45s ease;
}

#game.ready { opacity: 1; }

#game canvas { touch-action: none; }

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(ellipse at center, transparent 52%, rgba(36, 48, 43, 0.16) 100%);
}

#lobby, #hud, #wish, #luck, #counsel, #english, #incense, #vang, #duyen, #thi, #toast { z-index: 2; }

#lobby {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  overflow: auto;
  background: rgba(213, 227, 204, 0.2);
}

.card {
  width: min(460px, 100%);
  background: rgba(255, 248, 238, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 28px 22px 22px;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--muted);
}

h1 {
  margin: 6px 0 8px;
  font-size: clamp(44px, 10vw, 68px);
  font-weight: 600;
  letter-spacing: -0.045em;
  line-height: 0.95;
}

.lead, .quiet, .label { color: var(--muted); }

.lead { margin: 0 0 18px; line-height: 1.5; }

label, .label {
  display: block;
  margin: 14px 0 8px;
  font-size: 14px;
}

input {
  width: 100%;
  height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 0 14px;
  font-size: 16px;
}

textarea {
  width: 100%;
  min-height: 96px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  line-height: 1.45;
  resize: vertical;
}

.counsel-source {
  margin: 0;
  text-align: left;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--moss);
}

.counsel-reply {
  margin: 8px 0 0;
  text-align: left;
  line-height: 1.55;
}

#join, #wish-form button, .chat button {
  width: 100%;
  height: 48px;
  margin-top: 16px;
  border: 0;
  border-radius: 999px;
  background: var(--moss);
  color: var(--paper);
  font-weight: 600;
}

#join:disabled { opacity: 0.55; cursor: progress; }

.quiet { min-height: 1.4em; font-size: 14px; text-align: center; }

.genders {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.gender {
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f3ecdf;
  font-weight: 600;
}

.gender[aria-pressed="true"] {
  background: var(--moss);
  color: var(--paper);
  border-color: transparent;
}

.avatars {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.avatar {
  border: 1px solid transparent;
  background: #f3ecdf;
  border-radius: 16px;
  padding: 8px 2px 6px;
}

.avatar[aria-pressed="true"] {
  border-color: var(--clay);
  background: #fff;
}

.avatar small { display: block; color: var(--muted); font-size: 11px; }

.mini {
  width: 36px;
  height: 48px;
  margin: 0 auto;
  display: grid;
  justify-items: center;
  align-content: start;
}

.mini .hair {
  width: 22px;
  height: 16px;
  background: var(--hair);
  border-radius: 10px 10px 6px 6px;
}

.mini.nam .hair {
  width: 16px;
  height: 8px;
  margin-top: 4px;
  border-radius: 7px 7px 2px 2px;
}

.mini .face {
  width: 16px;
  height: 16px;
  margin-top: -6px;
  background: var(--skin);
  border-radius: 50%;
}

.mini .body {
  width: 16px;
  height: 18px;
  margin-top: 2px;
  background: var(--tunic);
  border-radius: 6px 6px 11px 11px;
}

.mini.nam .body {
  width: 24px;
  height: 15px;
  border-radius: 5px 5px 4px 4px;
}

#hud { pointer-events: none; }

#hud button, #hud form, #hud .stick { pointer-events: auto; }

.topbar {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.presence {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.skyline, .rank {
  color: var(--muted);
  white-space: normal;
  max-width: 260px;
}

.rank { color: var(--ink); }

.name-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.my-mark,
.pill.mark,
.wish-mark {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
  color: #8f1d1d;
}

.my-mark {
  margin: 8px 0 0;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
}

.pill.mark {
  border-color: rgba(143, 29, 29, 0.4);
  background: rgba(255, 232, 228, 0.96);
  font-weight: 600;
}

.wish-mark {
  display: inline-block;
  margin-left: 6px;
  font-size: 12px;
  font-weight: 600;
}

.pill, .top-actions button, .emotes button, .hint {
  background: rgba(255, 248, 238, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 8px 24px rgba(36, 48, 43, 0.08);
}

.pill {
  margin: 0;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  white-space: nowrap;
}

.top-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

.top-actions button, .emotes button {
  height: 36px;
  border-radius: 999px;
  padding: 0 12px;
  border: 1px solid var(--line);
}

#sound[aria-pressed="true"],
#voice[aria-pressed="true"],
#visit[aria-pressed="true"] { background: #e7f0df; }

.emotes button.paid {
  background: #f3c84a;
  border-color: #e0b02a;
  font-weight: 600;
}

.dock {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 640px;
}

.hint {
  margin: 0;
  align-self: flex-start;
  max-width: min(420px, 100%);
  border-radius: 16px;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.45;
}

.emotes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat { display: flex; gap: 8px; }

.chat input { flex: 1; background: rgba(255, 248, 238, 0.96); }

.chat button { width: auto; margin-top: 0; padding: 0 16px; }

.stick {
  display: none;
  position: fixed;
  left: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: rgba(255, 248, 238, 0.72);
  border: 1px solid var(--line);
  touch-action: none;
}

body.touch .stick { display: block; }

body.touch .dock { margin-left: 124px; }

.knob {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--moss);
  position: absolute;
  left: 32px;
  top: 32px;
}

#wish, #luck, #counsel, #english, #incense, #vang, #duyen, #thi {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: end center;
  padding: 16px;
  background: rgba(36, 48, 43, 0.28);
}

.luck-number {
  margin: 8px 0 0;
  text-align: center;
  font-size: clamp(56px, 12vw, 84px);
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1;
  color: #8a3b2a;
}

.luck-line {
  margin: 8px 0 0;
  text-align: center;
  line-height: 1.5;
}

.luck-praise {
  margin: 10px 0 0;
  text-align: center;
  line-height: 1.55;
  color: var(--moss);
}

.pill.luck {
  color: #8a3b2a;
  font-weight: 600;
  letter-spacing: 0.08em;
}

#counsel .wish-card,
#english .wish-card {
  max-height: calc(100dvh - 20px);
}

#counsel-ask {
  position: sticky;
  bottom: 0;
}

.incense-card { width: min(520px, 100%); }

.altar {
  display: grid;
  grid-template-columns: 78px 1fr 120px;
  align-items: end;
  gap: 8px;
  min-height: 230px;
  margin-top: 8px;
  padding: 16px 12px 8px;
  border-radius: 22px;
  background:
    radial-gradient(140px 90px at 50% 100%, rgba(224, 177, 90, 0.38), transparent 70%),
    linear-gradient(#4a3028, #241814);
}

.tablet {
  justify-self: center;
  width: 72px;
  min-height: 188px;
  padding: 12px 6px 10px;
  border-radius: 4px;
  background: linear-gradient(#8d3b2e, #5a221c);
  color: #f6e2a8;
  box-shadow: inset 0 0 0 3px #e0b15a;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.tablet-relation {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-align: center;
}

.tablet-name {
  margin: 0;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-weight: 600;
  letter-spacing: 0.14em;
  font-size: 16px;
  line-height: 1.15;
  max-height: 132px;
}

.incense-sticks {
  position: relative;
  height: 150px;
  align-self: end;
}

.incense-sticks span {
  position: absolute;
  bottom: 18px;
  width: 3px;
  height: 72px;
  border-radius: 2px;
  background: linear-gradient(#f2d48a, #6b3a28);
  transform-origin: bottom center;
}

.incense-sticks span:nth-child(1) { left: 42%; transform: rotate(-8deg); }
.incense-sticks span:nth-child(2) { left: 50%; }
.incense-sticks span:nth-child(3) { left: 58%; transform: rotate(8deg); }

.incense-sticks span::after {
  content: "";
  position: absolute;
  top: -3px;
  left: -1px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #ffb15a;
  box-shadow: 0 0 8px #ffb15a;
}

.incense-sticks i {
  position: absolute;
  bottom: 92px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 248, 238, 0.55);
  animation: incense-smoke 2.8s ease-in infinite;
}

.incense-sticks i:nth-of-type(1) { left: 40%; animation-delay: 0s; }
.incense-sticks i:nth-of-type(2) { left: 48%; animation-delay: 0.6s; }
.incense-sticks i:nth-of-type(3) { left: 56%; animation-delay: 1.2s; }

@keyframes incense-smoke {
  0% { transform: translateY(0) scale(0.6); opacity: 0; }
  20% { opacity: 0.7; }
  100% { transform: translateY(-46px) scale(1.5); opacity: 0; }
}

.bow-figure {
  justify-self: center;
  width: 120px;
  height: 150px;
}

.bow-svg { width: 100%; height: 100%; overflow: visible; }

.bow-figure.nam .figure-nu,
.pray-figure.nam .figure-nu,
.bow-figure:not(.nam) .figure-nam,
.pray-figure:not(.nam) .figure-nam { display: none; }

.bow-body {
  transform-box: view-box;
  transform-origin: 84px 124px;
  animation: incense-bow 3.6s ease-in-out infinite;
}

@keyframes incense-bow {
  0%, 16% { transform: rotate(0deg); }
  46%, 64% { transform: rotate(-62deg); }
  100% { transform: rotate(0deg); }
}

.incense-prayer {
  margin: 8px 0 0;
  white-space: pre-line;
  line-height: 1.55;
  text-align: left;
}

.rite-share {
  width: 100%;
  height: 48px;
  margin-top: 16px;
  border: 0;
  border-radius: 999px;
  background: var(--moss);
  color: var(--paper);
  font-weight: 600;
}

.rite-share:disabled { opacity: 0.6; cursor: progress; }

.rite-share-status { min-height: 1.2em; margin: 8px 0 0; }

#incense-again, #vang-again, #duyen-again, #thi-again {
  width: 100%;
  height: 44px;
  margin-top: 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--moss);
  font-weight: 600;
}

.duyen-altar {
  display: grid;
  grid-template-columns: 78px 1fr 120px;
  align-items: end;
  gap: 8px;
  min-height: 210px;
  margin-top: 8px;
  padding: 16px 12px;
  border-radius: 22px;
  background:
    radial-gradient(140px 90px at 50% 100%, rgba(224, 177, 90, 0.38), transparent 70%),
    linear-gradient(#4a3028, #241814);
}

.duyen-altar > img {
  justify-self: center;
  align-self: center;
  width: 72px;
  height: 96px;
  object-fit: cover;
  object-position: center center;
  border-radius: 8px;
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.35), inset 0 0 0 2px #e0b15a;
}

.incense-bowl {
  position: relative;
  height: 176px;
  align-self: end;
}

.incense-bowl .incense-sticks {
  position: absolute;
  inset: 0 0 6px;
  height: auto;
}

.incense-bowl .incense-sticks span { bottom: 34px; }
.incense-bowl .incense-sticks i { bottom: 112px; }

.bowl-body {
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 64px;
  height: 28px;
  margin-left: -32px;
  border-radius: 0 0 32px 32px;
  background: linear-gradient(#c47a32, #6e3b18);
  box-shadow: inset 0 -7px 0 #4e2810;
}

.bowl-lip {
  position: absolute;
  left: 50%;
  bottom: 24px;
  width: 74px;
  height: 14px;
  margin-left: -37px;
  border-radius: 40px;
  background: linear-gradient(#f2d48a, #b6843e);
  box-shadow: inset 0 3px 0 rgba(255, 248, 230, 0.45);
}

.pray-figure {
  justify-self: center;
  width: 120px;
  height: 156px;
}

.pray-svg { width: 100%; height: 100%; overflow: visible; }

.pray-body {
  transform-box: fill-box;
  transform-origin: center bottom;
  animation: pray-still 3.4s ease-in-out infinite;
}

@keyframes pray-still {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.offer-field {
  margin: 14px 0 0;
  padding: 0;
  border: 0;
}

.offer-field legend {
  margin-bottom: 8px;
  font-weight: 600;
}

.offer-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.offer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.offer-row span {
  line-height: 1.3;
}

.offer-amounts {
  display: flex;
  gap: 6px;
}

.offer-amounts button {
  min-width: 46px;
  height: 34px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  background: #f6efe4;
  color: inherit;
  font-weight: 600;
}

.offer-amounts button[aria-pressed="true"] {
  background: var(--moss);
  color: var(--paper);
}

.offer-burn {
  display: flex;
  flex-wrap: wrap;
  align-content: end;
  gap: 10px 8px;
  margin: 0;
  padding: 16px 4px 8px;
  list-style: none;
}

.offer-burn li {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0;
  background: transparent;
  color: #f6e2a8;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

.offer-burn img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.4);
}

.offer-burn li[data-tier="10"] img { width: 80px; height: 80px; }
.offer-burn li[data-tier="20"] img { width: 100px; height: 100px; }

.fruit-tray {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  align-items: end;
  gap: 6px;
  margin: 2px 0 0;
  padding: 6px 0 0;
  list-style: none;
}

.fruit-tray li {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 56px;
  color: #f6e2a8;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
}

.fruit-tray li[data-tier="10"] { width: 66px; }
.fruit-tray li[data-tier="20"] { width: 78px; }

.fruit-tray img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 10px;
  box-shadow: 0 6px 10px rgba(0, 0, 0, 0.35);
}

.fruit-tray li[data-tier="10"] img { width: 62px; height: 62px; }
.fruit-tray li[data-tier="20"] img { width: 74px; height: 74px; }

.offer-burn li::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -12px;
  width: 8px;
  height: 14px;
  margin-left: -4px;
  border-radius: 50% 50% 45% 45%;
  background: #ffb15a;
  box-shadow: 0 0 8px #ffb15a;
  animation: offer-flame 1.1s ease-in-out infinite;
}

@keyframes offer-flame {
  0%, 100% { transform: scale(1) translateY(0); opacity: 0.85; }
  50% { transform: scale(0.8, 1.15) translateY(-2px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .bow-body { animation: none; transform: rotate(-58deg); }
  .incense-sticks i { animation: none; opacity: 0.45; }
  .pray-body { animation: none; }
  .offer-burn li::before { animation: none; }
}

#luck-ask, #counsel-ask, #english-ask, #incense-ask, #vang-ask, #duyen-ask, #thi-ask {
  width: 100%;
  height: 48px;
  margin-top: 16px;
  border: 0;
  border-radius: 999px;
  background: var(--moss);
  color: var(--paper);
  font-weight: 600;
}

#luck-ask:disabled, #counsel-ask:disabled, #english-ask:disabled, #incense-ask:disabled, #vang-ask:disabled, #duyen-ask:disabled, #thi-ask:disabled { opacity: 0.6; cursor: progress; }

.lesson-word,
.lesson-en {
  margin: 0 0 12px;
  font-size: 22px;
  font-weight: 600;
}

.lesson-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.lesson-line p { margin: 0; line-height: 1.45; }

.lesson-en-line,
.lesson-vi-line { display: block; }

.lesson-vi-line {
  margin-top: 2px;
  color: var(--muted);
  font-size: 15px;
}

.lesson-line small {
  display: block;
  margin-bottom: 2px;
  color: var(--moss);
  font-weight: 600;
}

.lesson-line button {
  height: 40px;
  border: 0;
  border-radius: 999px;
  padding: 0 16px;
  background: var(--moss);
  color: var(--paper);
  font-weight: 600;
}

.lesson-line button:disabled { opacity: 0.55; }

.wish-card { max-height: min(640px, 100%); overflow: auto; }

.wish-head, .topbar { align-items: center; }

.wish-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.wish-head h2 { margin: 0; font-size: 28px; letter-spacing: -0.04em; }

#wish-close, #luck-close {
  border: 0;
  background: transparent;
  color: var(--muted);
}

#wish-list {
  list-style: none;
  margin: 12px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#wish-list li {
  background: #f6efe4;
  border-radius: 14px;
  padding: 10px 12px;
}

#wish-list p { margin: 4px 0 0; }

#wish-list .empty { color: var(--muted); background: transparent; padding-left: 0; }

#toast {
  position: fixed;
  top: calc(86px + env(safe-area-inset-top));
  left: 50%;
  z-index: 3;
  transform: translateX(-50%);
  max-width: min(420px, calc(100% - 24px));
  background: var(--ink);
  color: var(--paper);
  border-radius: 18px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
}

.support-garden {
  align-self: flex-start;
  height: 36px;
  border-radius: 999px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #fff8ee;
  color: var(--clay);
  font-weight: 600;
}

#support {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(36, 48, 43, 0.28);
}

.support-card {
  max-height: min(92vh, 820px);
  overflow: auto;
  text-align: center;
  background: #fff8ee;
}

.support-card .lead { margin-top: 12px; }

.support-card img {
  width: auto;
  max-width: min(280px, 100%);
  max-height: min(46vh, 340px);
  margin: 8px auto 0;
  border-radius: 18px;
}

.support-note {
  margin: 14px 0 2px;
  text-align: left;
  line-height: 1.55;
}

.support-note p { margin: 0 0 10px; }

#lobby[hidden],
#hud[hidden],
#wish[hidden],
#luck[hidden],
#counsel[hidden],
#english[hidden],
#incense[hidden],
#duyen[hidden],
#vang[hidden],
#thi[hidden],
#support[hidden],
#toast[hidden],
#hint[hidden] { display: none !important; }

@media (max-width: 720px) {
  #toast {
    top: calc(188px + env(safe-area-inset-top));
    width: calc(100% - 24px);
  }
  .support-card img { max-width: min(220px, 100%); max-height: 240px; }
  .duyen-altar { grid-template-columns: 64px 1fr 100px; }
  .duyen-altar > img { width: 60px; height: 80px; }
  .fruit-tray { gap: 4px; }
  .fruit-tray li { width: 48px; font-size: 9px; }
  .fruit-tray li[data-tier="10"] { width: 56px; }
  .fruit-tray li[data-tier="20"] { width: 64px; }
  .fruit-tray img { width: 44px; height: 44px; }
  .fruit-tray li[data-tier="10"] img { width: 52px; height: 52px; }
  .fruit-tray li[data-tier="20"] img { width: 60px; height: 60px; }
  .avatars { grid-template-columns: repeat(3, 1fr); }
  h1 { font-size: 48px; }
  .top-actions button,
  .emotes button { padding: 0 10px; font-size: 14px; }
  .dock { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  #game { transition: none; }
}
