/* Thủ Thành, a darker fantasy look (the approved design canvas): dark woods,
   panels of dark metal with a bronze edge, carved titles (Alegreya SC) over a
   clear text face made for Vietnamese (Be Vietnam Pro). Both are bundled
   (fonts/, fonts.css), so it works offline and in the iOS app. A match is the
   field full screen (a canvas, or the native field under a see-through page)
   with the bar along the top and the command panel along the bottom. */
@import url('fonts.css');
:root {
  --ink: #f1e4c2;
  --muted: #c9b892;
  --faint: #a89670;
  --gold: #f6d98a;
  --bronze: #8a6d3b;
  --bronze-hi: #c9a35a;
  --well: #0d0b08;
  --edge: #4a3b22;
  --wood: #0f1d0b;
  --panel: linear-gradient(180deg, #2b241a, #120e09);
  --title: 'Alegreya SC', Georgia, serif;
  --text: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-family: var(--text);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { touch-action: manipulation; }
body {
  min-height: 100dvh;
  background: radial-gradient(120% 70% at 50% 18%, #233d17 0%, var(--wood) 55%, #070b05 100%) fixed;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  line-height: 1.4; /* (Vietnamese accents need the room) */
}
body[data-screen='game'] { background: var(--wood); }
/* The native field shows through the page while a match is on. */
html.native-field, html.native-field body { background: transparent !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
input { font: inherit; font-size: 16px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
h1, h2, h3 { font-family: var(--title); font-weight: 800; }

/* ---------- the menu, the rooms, the waiting room ---------- */
.menu, .lobby {
  max-width: 460px;
  margin: 0 auto;
  padding: calc(22px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.title { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 4px; }
.title .crest { display: block; width: 120px; height: 110px; }
.title h1 { margin: 0; font-size: 46px; line-height: 1.2; color: var(--gold); text-shadow: 0 2px 0 #3b2a10, 0 0 18px rgba(0, 0, 0, 0.8); }
.tagline { margin: 0; text-align: center; font-size: 14px; line-height: 1.45; color: #d8c79a; }
.card {
  padding: 14px 12px;
  border: 2px solid var(--bronze);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(43, 36, 26, 0.96), rgba(18, 14, 9, 0.96));
  box-shadow: inset 0 0 0 1px #000, 0 8px 20px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card h2 { margin: 0; font-size: 18px; color: var(--gold); }
.screen-title { margin: 0; text-align: center; font-size: 26px; color: var(--gold); }
.screen-sub { margin: 4px 0 0; font-size: 18px; color: var(--gold); }
.note { margin: 0; text-align: center; font-size: 13px; color: var(--muted); }
.btn {
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--bronze);
  border-radius: 5px;
  background: linear-gradient(180deg, #3d3324, #1d1710);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 3px 0 #000;
  font-family: var(--title);
  font-weight: 800;
  font-size: 17px;
}
.btn:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 1px 0 #000; }
.btn.primary { border-color: #e8c77a; background: linear-gradient(180deg, #4f7a2c, #2d4a18); color: #fff4d6; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 3px 0 #0b1207; }
.btn.bronze { border-color: #e8c77a; background: linear-gradient(180deg, var(--bronze), #5a4320); color: #fff4d6; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 3px 0 #000; }
.btn.danger { border-color: #a5432f; background: linear-gradient(180deg, #7a2a1c, #4a160d); color: #ffe4d6; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 15px; }
.btn.wide { width: 100%; }
.btn.big { min-height: 66px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 19px; }
.btn.big small { font-family: var(--text); font-weight: 500; font-size: 12px; color: var(--muted); }
.btn.primary.big small { color: #d7eabf; }
.btn:disabled { opacity: 0.5; filter: grayscale(0.5); }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper .btn { width: 44px; padding: 0; font-size: 18px; }
.stepper input { flex: 1; accent-color: var(--bronze-hi); }
.me { display: flex; align-items: center; gap: 10px; }
.avatar { width: 42px; height: 42px; border-radius: 4px; border: 2px solid var(--bronze-hi); display: grid; place-items: center; background: #3b2a10; color: var(--gold); font-family: var(--title); font-weight: 800; font-size: 22px; flex: none; }
.who { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.who small { font-size: 12px; color: var(--faint); }
.who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link { background: none; border: 0; padding: 6px; color: #e8c77a; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.link.muted { color: var(--faint); text-decoration: none; }
a.link { display: inline-block; }
.how summary { cursor: pointer; font-family: var(--title); font-weight: 800; font-size: 17px; color: var(--gold); }
.how ul { margin: 0; padding-left: 18px; font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.safety-card a, .safety-card button { color: #e8c77a; }
.foot { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; }
.join { flex-direction: row; gap: 8px; }
.join input { flex: 1; min-width: 0; height: 48px; padding: 0 14px; border: 2px solid var(--bronze); border-radius: 5px; background: var(--well); color: var(--ink); font-family: var(--title); font-size: 22px; letter-spacing: 6px; text-transform: uppercase; }
.players-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.players-list li { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 10px; border: 1px solid var(--edge); border-radius: 4px; background: var(--well); }
.players-list li.me { border-color: var(--bronze-hi); }
.players-list .dot { width: 14px; height: 14px; border-radius: 3px; border: 1px solid #000; flex: none; }
.players-list .name { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players-list small { color: var(--faint); }
.players-list .remove { width: 36px; height: 36px; border: 1px solid var(--edge); border-radius: 4px; background: none; color: var(--muted); }
.code { font-family: var(--title); letter-spacing: 4px; color: var(--gold); }
.lobby h2 { margin: 0; text-align: center; font-size: 26px; }
.row { display: flex; gap: 8px; }
.row .btn { flex: 1; }
.toggle { flex-direction: row; align-items: center; gap: 10px; font-weight: 600; }
.toggle input { width: 22px; height: 22px; accent-color: var(--bronze-hi); }

/* ---------- a match ---------- */
.game { position: fixed; inset: 0; overflow: hidden; touch-action: none; }
#field { position: absolute; inset: 0; display: block; touch-action: none; }
.hud {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  background: var(--panel);
  border-bottom: 2px solid var(--bronze);
  box-shadow: 0 2px 0 #2b2014, 0 6px 14px rgba(0, 0, 0, 0.55);
}
.stat { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; height: 38px; border-radius: 6px; background: var(--well); border: 1px solid var(--edge); white-space: nowrap; }
.stat svg { width: 18px; height: 18px; flex: none; }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; }
.stat small { font-size: 13px; color: #9c8b66; }
.stat .word { font-family: var(--title); font-weight: 800; font-size: 15px; color: #d8c79a; }
.stat.wave { flex: 1.3; }
.stat.gold b { color: var(--gold); }
.hud-btn { width: 44px; height: 38px; flex: none; border-radius: 6px; border: 1px solid var(--bronze); background: linear-gradient(180deg, #3d3324, #1d1710); color: #e8c77a; display: grid; place-items: center; padding: 0; }
.hud-btn svg { width: 16px; height: 16px; }
.lane-bar {
  position: absolute;
  left: 50%;
  top: calc(64px + env(safe-area-inset-top));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  border-radius: 4px;
  border: 1px solid var(--edge);
  background: rgba(13, 11, 8, 0.82);
  font-family: var(--title);
  font-weight: 800;
  font-size: 15px;
  white-space: nowrap;
}
.lane-step { width: 32px; height: 28px; border: 0; background: none; color: #e8c77a; font-size: 20px; line-height: 1; padding: 0; }
.lane-step:disabled { color: #5d5240; }
.banner {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 20px;
  border: 2px solid var(--bronze);
  border-radius: 4px;
  background: rgba(18, 14, 9, 0.9);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  text-align: center;
  will-change: transform, opacity;
}
.banner b { font-family: var(--title); font-weight: 800; font-size: 22px; color: var(--gold); }
.banner small { font-size: 13px; color: var(--muted); }
.banner.show { animation: banner 2.6s ease both; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  10% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  16% { transform: translate(-50%, -50%) scale(1); }
  85% { opacity: 1; }
  100% { opacity: 0; }
}
.build {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 10px calc(12px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 2px solid var(--bronze);
  box-shadow: 0 -2px 0 #2b2014, 0 -8px 18px rgba(0, 0, 0, 0.6);
}
.next-wave { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 38px; padding-bottom: 8px; border-bottom: 1px solid var(--edge); font-size: 14px; color: #d8c79a; }
.next-wave b { color: var(--ink); }
.hint { margin: 0; min-height: 96px; display: grid; place-items: center; text-align: center; font-family: var(--title); font-weight: 800; font-size: 16px; color: #d8c79a; }
.towers { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.tower-btn { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 0; border: 0; background: none; min-width: 0; }
.tower-btn .slot {
  width: 100%;
  max-width: 58px;
  aspect-ratio: 1;
  border-radius: 4px;
  border: 2px solid var(--bronze-hi);
  background: radial-gradient(circle at 50% 40%, #2b3a22, var(--well) 75%);
  box-shadow: inset 0 0 0 1px #000, 0 2px 0 #000;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.tower-btn[data-kind='frost'] .slot { background: radial-gradient(circle at 50% 40%, #1d2f3a, var(--well) 75%); }
.tower-btn[data-kind='bolt'] .slot { background: radial-gradient(circle at 50% 40%, #2c2440, var(--well) 75%); }
.tower-btn[data-kind='banner'] .slot { background: radial-gradient(circle at 50% 40%, #3a2020, var(--well) 75%); }
.tower-btn img { width: 92%; height: 92%; object-fit: contain; pointer-events: none; }
.tower-btn .cost { font-size: 12px; font-weight: 700; color: var(--gold); }
.tower-btn:disabled { opacity: 0.5; }
.tower-btn:disabled .slot { border-color: #5d5240; filter: grayscale(0.7); }
.picked { margin: 0; text-align: center; font-family: var(--title); font-weight: 800; font-size: 15px; color: #d8c79a; min-height: 1.4em; }
.picked span { font-family: var(--text); font-weight: 500; font-size: 13px; color: var(--faint); }
.tower-info { display: flex; flex-direction: column; gap: 10px; }
.info-top { display: flex; gap: 12px; align-items: stretch; }
.portrait { width: 84px; height: 84px; flex: none; border: 2px solid var(--bronze-hi); border-radius: 4px; background: radial-gradient(circle at 50% 40%, #3a4a2a, var(--well) 75%); box-shadow: inset 0 0 0 1px #000; display: grid; place-items: center; overflow: hidden; }
.portrait img { width: 90%; height: 90%; object-fit: contain; }
.info-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.info-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.info-head b { font-family: var(--title); font-weight: 800; font-size: 19px; color: var(--gold); }
.info-head span { font-size: 13px; color: var(--muted); }
.info-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.info-stats div { padding: 3px 6px; border-radius: 3px; background: var(--well); border: 1px solid #3a2f1c; }
.info-stats small { display: block; font-size: 11px; color: var(--faint); }
.info-stats b { font-size: 15px; }
.info-note { font-size: 12px; color: #9fd3ff; }
.info-actions { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; }

/* On a computer: the panels narrower, in the middle. */
@media (min-width: 720px) {
  .hud, .build { left: 50%; right: auto; width: 620px; transform: translateX(-50%); border: 2px solid var(--bronze); border-radius: 6px; }
  .hud { top: 8px; padding-top: 8px; }
  .build { bottom: 8px; padding-bottom: 12px; }
  .lane-bar { top: 70px; }
}

/* ---------- toasts, sheets, banners ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(230px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border: 1px solid var(--bronze);
  border-radius: 4px;
  background: rgba(13, 11, 8, 0.94);
  font-weight: 700;
  text-align: center;
  z-index: 30;
  pointer-events: none;
}
.sheet-wrap { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, 0.55); }
.sheet-wrap.fresh { pointer-events: none; }
.sheet {
  width: min(420px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 18px;
  border: 2px solid var(--bronze);
  border-radius: 4px;
  background: var(--panel);
  box-shadow: inset 0 0 0 1px #000, 0 12px 30px rgba(0, 0, 0, 0.6);
}
.sheet h2 { margin: 0 0 12px; text-align: center; color: var(--gold); }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.sheet-actions .btn { flex: 1 1 40%; }
.result { text-align: center; }
.result p { margin: 4px 0; }
.big-word { font-family: var(--title); font-size: 40px; color: var(--gold); }
.ask, .update {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100% - 20px);
  padding: 8px 10px;
  border: 1px solid var(--bronze);
  border-radius: 4px;
  background: rgba(13, 11, 8, 0.95);
  z-index: 45;
}
.ask { top: calc(10px + env(safe-area-inset-top)); }
.ask span { flex: 1; min-width: 0; font-weight: 700; }
.update { bottom: calc(14px + env(safe-area-inset-bottom)); white-space: nowrap; }
.meter { position: fixed; left: 6px; top: calc(env(safe-area-inset-top) + 110px); z-index: 99; padding: 4px 7px; border-radius: 6px; background: rgba(0, 0, 0, 0.65); color: #fff; font: 600 11px/1.35 ui-monospace, monospace; pointer-events: none; white-space: pre; }
.sheet input[type='range'] { width: 100%; accent-color: var(--bronze-hi); }
