/* style.css - look and feel of the page. Colours are variables at the top. */

:root {
  --bg: #2b2118;
  --bg-soft: #3a2d21;
  --card: #fbf4e6;
  --card-edge: #e4d3b0;
  --ink: #2c2116;
  --muted: #7d6a52;
  --accent: #b5392b;
  --accent-ink: #ffffff;
  --good: #2e7d32;
  --warn: #c77700;
  --red-dot: #c62828;
  --black-dot: #1d1d1d;
  --radius: 12px;

  /* Login and lobby: red lacquer, gold and rice paper, like Chinese xiangqi apps. */
  --lacquer: #a3221c;
  --lacquer-deep: #6b1210;
  --lacquer-dark: #2e0807;
  --gold: #e9c46a;
  --gold-soft: #f8e6b0;
  --gold-deep: #a8792b;
  --paper: #fbf3de;
  --paper-low: #efdcb2;
  --paper-edge: #d4b26e;
  --ink-brown: #4a2511;
  --jade: #2f7d5b;
  --serif: "Noto Serif", Georgia, "Times New Roman", serif;
  --brush: "LXGW WenKai TC", "Kaiti SC", "STKaiti", "Songti SC", serif;
  --btn-red: linear-gradient(180deg, #d4473b 0%, #a3221c 55%, #7d1411 100%);
  --btn-gold: linear-gradient(180deg, #fdeab0 0%, #e5bb5e 58%, #c79233 100%);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }
/* No double-tap zoom; the page should feel like an app on phones. */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
/* An app, not a page: a long press or a swipe must not select text, pop up the
   "save image" menu, drag a picture or flash a grey tap box. Text boxes still
   select and paste as usual. */
html {
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
img, svg, canvas { -webkit-user-drag: none; user-drag: none; }
input, textarea, [contenteditable="true"] {
  -webkit-user-select: text; user-select: text;
  -webkit-touch-callout: default;
}

body {
  background: transparent; /* the app background is on html, see "app theme" */
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
  min-height: 100dvh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------------------------------------------------------------- top bar */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  /* Room for the iPhone status bar when opened from the home screen. */
  padding-top: calc(8px + env(safe-area-inset-top));
  background: linear-gradient(180deg, #7e1713 0%, #4d0d0b 100%);
  border-bottom: 2px solid var(--gold-deep);
  box-shadow: inset 0 -1px 0 rgba(233, 196, 106, .35), 0 2px 10px rgba(0, 0, 0, .35);
  color: var(--gold-soft);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; flex: none; }
.brand-seal {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(145deg, #cf3a2e, #861612);
  border: 1.5px solid var(--gold);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .18);
  color: var(--gold-soft);
  font-family: var(--brush);
  font-size: 21px;
  line-height: 1;
}
.topbar h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .5px;
  white-space: nowrap;
  text-shadow: 0 1px 0 #2a0505;
}
.spacer { flex: 1; }

.conn { font-size: 12px; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.conn-on { background: #1d5a3b; color: #d9f5e4; border: 1px solid #4f9c74; }
.conn-off { background: #7a3b12; color: #ffe2c9; border: 1px solid #b86a2e; }

.chip {
  background: rgba(0, 0, 0, .2);
  color: var(--gold-soft);
  border: 1px solid rgba(233, 196, 106, .55);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}
.chip:hover { background: rgba(233, 196, 106, .14); }

/* The player's name; guests tap it to rename themselves. */
.account-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  max-width: 45vw;
  padding: 3px 10px 3px 3px;
  background: rgba(0, 0, 0, .25);
  border: 1px solid rgba(233, 196, 106, .55);
  border-radius: 999px;
  color: var(--gold-soft);
  font-size: 14px;
  font-weight: 600;
}
.account-chip:hover { background: rgba(233, 196, 106, .14); }
.account-chip .avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffaf0, #e3c27c);
  border: 1.5px solid var(--gold);
  color: var(--lacquer-deep);
  font-family: var(--serif);
  font-weight: 700;
  font-size: 13px;
}
.account-chip .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-chip .chev { flex: none; width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: .75; }
.topbar .account-chip { max-width: 62vw; padding-right: 8px; font-size: 15px; }
.topbar .account-chip .avatar { width: 30px; height: 30px; font-size: 15px; }
/* ⚙ Settings */
.gear-btn {
  flex: none; display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .25); border: 1px solid rgba(233, 196, 106, .55); color: var(--gold-soft);
}
.gear-btn:hover { background: rgba(233, 196, 106, .14); }
.gear-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }

main { padding: 16px; }

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
.card h2 { margin: 0 0 12px; font-size: 20px; }

button {
  font: inherit;
  cursor: pointer;
}
.btn {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 600;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn-ghost {
  /* Solid background so the text stays readable on the dark page background too. */
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--card-edge);
}
.btn-ghost:hover { background: #f1e6cd; filter: none; }
.btn-good { background: var(--good); }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input:disabled { background: #f1e6cd; color: var(--muted); }
.field input {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--card-edge);
  background: #fff;
}

/* -------------------------------------------------------------- app theme */

/* Dark red lacquer with faint gold clouds behind every screen. It sits on html,
   not body: iOS paints the html background over the whole screen, while a
   home-screen app first sizes the page short of the home bar, which left a
   strip there without the clouds until the page was scrolled. Below the
   gradient the plain colour matches its dark end, and the clouds repeat. */
html {
  background-color: var(--lacquer-dark);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='120' viewBox='0 0 180 120'%3E%3Cg fill='none' stroke='%23e9c46a' stroke-opacity='.08' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M18 64a16 16 0 1 1 32 0c0 7-5 11-11 11s-9-4-9-8 3-6 6-6'/%3E%3Cpath d='M50 64a24 24 0 0 1 48 0'/%3E%3Cpath d='M98 64a12 12 0 1 1 24 0c0 5-4 8-8 8s-6-3-6-6 2-4 4-4'/%3E%3Cpath d='M8 78h124'/%3E%3C/g%3E%3C/svg%3E"),
    radial-gradient(ellipse at 50% -10%, #8e1d17 0%, #5a110e 42%, #2e0807 100%);
  background-size: 180px 120px, 100% 100%;
  background-repeat: repeat, no-repeat;
}

.themed { color: var(--gold-soft); }

/* A rice-paper panel with a gold double frame and a red ribbon title. */
.panel {
  position: relative;
  background: linear-gradient(180deg, var(--paper), var(--paper-low));
  border: 2px solid var(--gold-deep);
  border-radius: 14px;
  box-shadow: 0 0 0 4px rgba(233, 196, 106, .22), 0 12px 32px rgba(0, 0, 0, .5);
  padding: 26px 18px 16px;
  color: var(--ink-brown);
}
.panel::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(168, 121, 43, .45);
  border-radius: 10px;
  pointer-events: none;
}
.panel-title {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 26px;
  background: var(--btn-red);
  border: 1.5px solid var(--gold);
  border-radius: 6px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .35);
  color: var(--gold-soft);
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .35);
}

.themed .field span { color: #8a5a2b; font-weight: 600; }
.themed input {
  width: 100%;
  font: inherit;
  font-family: var(--serif); /* the same font as the titles and buttons */
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--paper-edge);
  background: #fffaf0;
  color: var(--ink-brown);
  box-shadow: inset 0 1px 3px rgba(74, 37, 17, .15);
}
.themed input:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold-deep); }

/* Red lacquer buttons with a gold edge; gold buttons for the second choice. */
.themed .btn {
  background: var(--btn-red);
  color: #fff4d6;
  border: 1.5px solid var(--gold);
  border-radius: 10px;
  padding: 10px 18px;
  font-family: var(--serif);
  font-weight: 700;
  letter-spacing: .4px;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3), 0 3px 0 #4a0d0b, 0 5px 10px rgba(0, 0, 0, .25);
}
.themed .btn-ghost {
  background: var(--btn-gold);
  color: var(--lacquer-deep);
  border-color: #8f6420;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), 0 3px 0 #7a5418, 0 5px 10px rgba(0, 0, 0, .22);
}
.themed .btn:hover:not(:disabled) { filter: brightness(1.07); }
.themed .btn-ghost:hover { background: var(--btn-gold); }
.themed .btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3), 0 1px 0 #4a0d0b;
}
.themed .btn-ghost:active:not(:disabled) { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), 0 1px 0 #7a5418; }
.btn-wide { width: 100%; }

/* ------------------------------------------------------------------ login */

.hero { text-align: center; margin: 26px auto 34px; }
.hero-seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 112px;
  height: 112px;
  border-radius: 22px;
  background: linear-gradient(145deg, #cf3a2e, #7d1411);
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 6px rgba(233, 196, 106, .16), 0 12px 30px rgba(0, 0, 0, .5), inset 0 0 0 3px rgba(0, 0, 0, .2);
  color: var(--gold-soft);
  font-family: var(--brush);
  font-size: 44px;
  line-height: 1.05;
  writing-mode: vertical-rl;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .3);
}
.hero-title {
  margin-top: 16px;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--gold-soft);
  text-shadow: 0 2px 0 #2a0505;
}

/* The login screen has no top bar: the big seal is the title. */
body.on-login .topbar { display: none; }
body.on-login main { padding-top: calc(16px + env(safe-area-inset-top)); }

/* Login and lobby fill the screen exactly and the page itself never scrolls
   (position: fixed also stops iOS from rubber-banding it). Only the room list
   scrolls, and the login form when the screen is too short for it. */
html:not(.in-room), body:not(.in-room) { height: 100%; overflow: hidden; overscroll-behavior: none; }
body:not(.in-room) { position: fixed; inset: 0; min-height: 0; display: flex; flex-direction: column; }

/* Home-screen app on iOS: when it opens, iOS reports a screen height short of
   the bottom edge until the page is scrolled, so "inset: 0" stopped above the
   home bar and the strip below showed no background. There, 100vh is the
   whole screen from the start, so size the page with it. (Safari is fine.) */
html.standalone:not(.in-room) { height: 100vh; }
html.standalone body:not(.in-room) { inset: 0 0 auto 0; height: 100vh; }
body:not(.in-room) .topbar { flex: none; }
body:not(.in-room) main { flex: 1; min-height: 0; overflow: hidden; padding-bottom: 0; }
body.on-login main { overflow-y: auto; overscroll-behavior: contain; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
#lobby, #history { height: 100%; }

.login-card { max-width: 380px; margin: 0 auto 24px; }
.login-or {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  font-size: 13px;
  color: #9b7448;
}
.login-or::before, .login-or::after { content: ""; flex: 1; height: 1px; background: var(--paper-edge); }
.login-error { color: var(--accent); min-height: 1.4em; margin: 0 0 10px; font-size: 14px; }
.register-note { margin: -6px 0 10px; font-size: 13px; color: #8a6a45; }
/* "Chưa có tài khoản? Đăng ký" under the login button. */
.link-btn {
  display: block; width: 100%; margin-top: 12px; padding: 6px; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 14px; color: #8a5a2b;
}
.link-btn b { color: var(--lacquer); text-decoration: underline; text-underline-offset: 3px; }

/* ------------------------------------------------------------------ lobby */

.lobby-wrap { max-width: 680px; height: 100%; margin: 0 auto; padding-top: 12px; display: flex; flex-direction: column; gap: 16px; }
.lobby-wrap { position: relative; }
/* Wide screens: room creation panel at the top with "Chơi với máy" beside it. */
.lobby-top { flex: none; display: flex; gap: 14px; align-items: center; }
.lobby-top .create-room { flex: 1; min-width: 0; }
.create-room { padding: 10px; }
.create-room-row { display: flex; gap: 8px; align-items: center; }
.create-room-row input { flex: 1; min-width: 0; }
.create-room-row .add-btn { flex: none; width: 44px; height: 44px; padding: 0; border-radius: 10px; display: grid; place-items: center; }
.vs-btn { flex: none; width: 70px; height: 70px; padding: 0; border-radius: 14px; overflow: hidden; cursor: pointer;
  border: 1.5px solid var(--gold); background: #3b4a66;
  box-shadow: 0 0 0 1px rgba(90, 50, 10, .35), 0 2px 6px rgba(0, 0, 0, .35), inset 0 0 0 1px rgba(255, 240, 200, .25); }
.vs-btn:active { transform: scale(.94); }
.vs-btn img { display: block; width: 100%; height: 100%; object-fit: cover; }
.lobby-fabs { display: none; }
/* Phones: the round buttons at the bottom right instead (+ opens openNewRoom). */
@media (max-width: 880px) {
  .lobby-top { display: none; }
  .lobby-fabs { display: flex; }
}
.lobby-wrap > .panel, .lobby-wrap > .section-head { flex: none; }
/* Round buttons at the bottom right of the lobby: "Chơi với máy" above, a new room below. */
.lobby-fabs { position: absolute; right: 4px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 5;
  flex-direction: column; align-items: center; gap: 14px; pointer-events: none; }
.fab { pointer-events: auto; width: 60px; height: 60px; padding: 0; border-radius: 50%; cursor: pointer; overflow: hidden;
  display: grid; place-items: center; border: 2px solid var(--gold);
  box-shadow: 0 0 0 1px rgba(90, 50, 10, .45), 0 4px 12px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 240, 200, .35); }
.fab:active { transform: scale(.93); }
.fab:disabled { opacity: .5; cursor: not-allowed; }
.fab-add { background: var(--btn-red); color: #fff4d6; }
.fab-vs { background: #3b4a66; }
.fab-vs img { display: block; width: 100%; height: 100%; object-fit: cover; }
.overlay .card.new-room-card { width: 100%; max-width: 340px; }
.new-room-card input { width: 100%; margin: 4px 0 16px; }
.create-info { margin: 8px 0 0; font-size: 13px; color: #8a6a45; }

/* Home: the two zones. */
.zone-list { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.zone-card {
  display: flex; align-items: center; gap: 16px; padding: 18px 18px; text-align: left; cursor: pointer;
  font: inherit; color: var(--ink-brown);
  background: linear-gradient(180deg, var(--paper), var(--paper-low));
  border: 2px solid var(--gold-deep); border-radius: 14px;
  box-shadow: 0 0 0 3px rgba(233, 196, 106, .18), 0 8px 20px rgba(0, 0, 0, .45);
  transition: transform .12s ease, box-shadow .12s ease;
}
.zone-card:hover { transform: translateY(-2px); box-shadow: 0 0 0 3px rgba(233, 196, 106, .4), 0 12px 26px rgba(0, 0, 0, .5); }
.zone-card:active { transform: translateY(0); }
.zone-art { flex: none; display: flex; width: 104px; }
.zone-art img { width: 58px; height: auto; }
.zone-art img + img { margin-left: -12px; }
.zone-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.zone-name { font-family: var(--serif); font-size: 22px; color: var(--lacquer-deep); }
.zone-desc { font-size: 14px; color: #6b4a2a; }
.zone-count { font-size: 13px; color: #8a6a45; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.section-head h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  color: var(--gold-soft);
  text-shadow: 0 2px 0 #2a0505;
}
.section-head h2::before, .section-head h2::after {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--gold);
  transform: rotate(45deg);
}
.head-tools { display: flex; align-items: center; gap: 8px; }
.share-list { display: flex; flex-direction: column; gap: 10px; margin: 10px 0 16px; text-align: left; }
.share-row { display: flex; align-items: center; gap: 10px; }
.share-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.share-text b { font-family: var(--serif); color: var(--lacquer-deep); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-text span { font-size: 13px; color: #8a6a45; overflow-wrap: anywhere; }
.share-row .btn { flex: none; }

.room-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* still scrolls, just no bar */
  display: grid;
  align-content: start;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  /* Room for the cards' shadows, and for the iPhone home bar under the last card. */
  margin: -6px -6px 0;
  padding: 6px 6px calc(20px + env(safe-area-inset-bottom));
}
/* Phones: the last card scrolls clear of the round buttons (.lobby-fabs) at the bottom right. */
@media (max-width: 880px) { .room-list { padding-bottom: calc(160px + env(safe-area-inset-bottom)); } }
.room-list::-webkit-scrollbar { display: none; }
.empty-lobby {
  grid-column: 1 / -1;
  margin: 0;
  padding: 26px 16px;
  text-align: center;
  border: 1px dashed rgba(233, 196, 106, .4);
  border-radius: 14px;
  background: rgba(0, 0, 0, .22);
  color: rgba(248, 230, 176, .85);
}
.empty-lobby p { margin: 10px 0 0; }
.empty-seal {
  display: inline-grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 2px solid rgba(233, 196, 106, .6);
  color: var(--gold);
  font-family: var(--brush);
  font-size: 28px;
  opacity: .8;
}

.room-card {
  background: linear-gradient(180deg, var(--paper), var(--paper-low));
  border: 2px solid var(--gold-deep);
  border-radius: 14px;
  padding: 12px 14px 14px;
  box-shadow: 0 0 0 3px rgba(233, 196, 106, .18), 0 8px 20px rgba(0, 0, 0, .45);
  color: var(--ink-brown);
}
.room-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.room-name {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--lacquer-deep);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  max-width: 100%;
}
.watchers { margin-left: auto; font-size: 12px; color: #8a6a45; }
.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-waiting { background: var(--jade); color: #eafff3; border: 1px solid #1f5a40; }
.badge-playing { background: var(--btn-red); color: #fff4d6; border: 1px solid var(--gold-deep); }
.badge-finished { background: #8a7a63; color: #fbf3de; border: 1px solid #6b5d48; }

/* Red seat, a little board, black seat: like a table in the game hall. */
.room-table {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin: 10px 0 12px;
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px dashed rgba(168, 121, 43, .5);
  background: rgba(168, 121, 43, .09);
}
.mini-board { width: 40px; height: 46px; filter: drop-shadow(0 2px 2px rgba(74, 37, 17, .3)); }
.seat { display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0; text-align: center; }
.seal {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid currentColor;
  background: radial-gradient(circle at 35% 30%, #fffaf0 0%, #f3dfb0 70%, #d8b46a 100%);
  box-shadow: inset 0 0 0 3px #f6e7c4, inset 0 0 0 4px currentColor, 0 3px 5px rgba(74, 37, 17, .35);
  font-family: var(--brush);
  font-size: 24px;
  line-height: 1;
}
.seal-r { color: #b3241c; }
.seal-b { color: #1f1a17; }
.seat.empty .seal { opacity: .35; box-shadow: inset 0 0 0 3px #f6e7c4, inset 0 0 0 4px currentColor; }
.seat-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 700;
}
.seat.empty .seat-name { font-weight: 500; font-style: italic; color: #9b8160; }
.room-actions { display: flex; gap: 10px; }
.room-actions .btn { flex: 1; }

/* "Đổi tên hiển thị" box. */
.rename-form input {
  width: 100%;
  font: inherit;
  font-family: var(--serif);
  padding: 10px 12px;
  margin-bottom: 14px;
  border-radius: 8px;
  border: 1px solid var(--card-edge);
  background: #fff;
}

.dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
}
.dot-r { background: var(--red-dot); }
.dot-b { background: var(--black-dot); }

/* ------------------------------------------------------------------- game */

.game-layout {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: flex-start;
}

/* The board column shrinks so that the whole board fits the window height. */
.board-col {
  display: grid;
  gap: 8px;
  flex: none;
  width: max(300px, min(100%, 600px, calc((100vh - 200px) * var(--board-ar, 0.9))));
}
.board-wrap { width: 100%; position: relative; }
.board-tilt { position: relative; }

/* The real 3D board (board3d.js, WebGL): its canvas fills the board's box,
   whose shape is --board-ar (ASPECT in board3d.js). The 2D canvas over it is
   for the checkmate slash. */
body.board-gl .board-wrap { aspect-ratio: var(--board-ar); }
.board-gl, .b3d { position: absolute; inset: 0; }
.b3d canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.b3d .b3d-fx { pointer-events: none; }
/* On computers the board (2D and 3D alike) is as big as the window lets it
   (its height sets its width), and the players' cards go beside it, between
   the board and the side column. 100px = top bar and margins; 240px + 12px =
   the cards' column; 360px + 16px = the side column; 32px = page margins.
   556 / 626 = the 2D board's shape (board.js), which sets no --board-ar. */
@media (min-width: 881px) {
  body.in-room .board-col {
    --bw: min(calc(100vw - 240px - 12px - 360px - 16px - 32px), calc((100vh - 100px) * var(--board-ar, 556 / 626)));
    width: auto;
    grid-template-columns: var(--bw) 240px;
    grid-template-rows: auto 1fr auto;
    column-gap: 12px;
  }
  body.in-room #boardWrap { grid-column: 1; grid-row: 1 / 4; }
  body.in-room #topPlayer { grid-column: 2; grid-row: 1; }
  body.in-room #bottomPlayer { grid-column: 2; grid-row: 3; align-self: end; }
}

/* 3D board (☰ menu "Bàn cờ" 3D, see applyBoardView in app.js): the board,
   in a wide mahogany frame, lies tilted away by --tilt (fixed) and is seen in
   perspective, like a board on a table. Its box (.board-wrap) gets the shape
   the tilted board takes on screen (--board-ar). The numbers (4.5cqw frame,
   4cqw front face, perspective 200cqw) must match FRAME_3D / EDGE_3D /
   PERSP_3D in app.js. */
body.board-3d .board-wrap { container-type: inline-size; aspect-ratio: var(--board-ar); }
body.board-3d .board-tilt {
  position: absolute; left: 0; right: 0; bottom: 4cqw;
  border: 4.5cqw solid transparent;
  border-radius: 1.8cqw;
  /* Mahogany: light from the far side, fine grain, base colour. */
  background:
    linear-gradient(180deg, rgba(255, 220, 180, .10), rgba(0, 0, 0, .22)) border-box,
    repeating-linear-gradient(91deg, transparent 0 .7cqw, rgba(30, 8, 0, .16) .7cqw .9cqw,
      rgba(255, 190, 140, .06) .9cqw 1.6cqw, rgba(30, 8, 0, .10) 1.6cqw 1.75cqw) border-box,
    repeating-linear-gradient(89deg, transparent 0 2.3cqw, rgba(20, 5, 0, .14) 2.3cqw 2.6cqw, transparent 2.6cqw 4.1cqw) border-box,
    linear-gradient(90deg, #6e2f14, #823d1b 28%, #64290f 55%, #7a3819 80%, #612810) border-box;
  box-shadow: 0 0 0 .25cqw #2a1006, 0 3cqw 5cqw rgba(0, 0, 0, .55);
  transform-origin: 50% 100%;
  transform: perspective(200cqw) rotateX(var(--tilt));
}
/* Over the board picture, under the pieces: the board sits a little lower
   than the frame (shadow along its edges) and is lit from the far side. */
body.board-3d .board-tilt::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 0 .2cqw rgba(40, 15, 0, .55), inset 0 .8cqw 1.6cqw rgba(0, 0, 0, .28), inset 0 -.3cqw .6cqw rgba(255, 230, 190, .18);
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(255, 246, 225, .22), transparent 60%),
    linear-gradient(180deg, transparent 55%, rgba(60, 30, 0, .10));
}
/* The board's front face, below the tilted top: the frame's wood, lit from
   above, with a light edge where it meets the top. */
body.board-3d .board-wrap::after {
  content: ''; position: absolute; left: -.25cqw; right: -.25cqw; bottom: 0; height: 4cqw;
  border-radius: 0 0 1.4cqw 1.4cqw;
  background:
    linear-gradient(180deg, #c07a45 0 .25cqw, rgba(0, 0, 0, 0) .25cqw, rgba(0, 0, 0, .45)),
    repeating-linear-gradient(90deg, transparent 0 1.1cqw, rgba(20, 5, 0, .14) 1.1cqw 1.3cqw, transparent 1.3cqw 2.9cqw),
    linear-gradient(90deg, #5a2410, #6e2f14 30%, #54220d 60%, #66290f);
  box-shadow: 0 0 0 .25cqw #2a1006, 0 2.5cqw 3.5cqw rgba(0, 0, 0, .55);
  pointer-events: none;
}
body.board-3d .board-tilt .board-svg { border-radius: 0; box-shadow: none; filter: none; }
/* The pieces stand up (stretched by --stand against the tilt) and may stick
   out of the top of the board. */
body.board-3d .board-pieces { overflow: visible; }
/* The pieces are flat discs (no rim): a tight contact shadow and a soft one
   cast towards the eye. */
body.board-3d .board-pieces .pc { scale: 1 var(--stand);
  filter: drop-shadow(0 .25cqw .2cqw rgba(30, 10, 0, .55)) drop-shadow(.3cqw .9cqw .8cqw rgba(0, 0, 0, .35)); }
body.board-3d .board-pieces .pc.lifted { filter: drop-shadow(.4cqw 2.2cqw 1.4cqw rgba(0, 0, 0, .35)); }
.board-svg {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .45);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
/* Layers over the board picture (see render in board.js): the pieces, the
   checkmate slash, the click targets. Same box as the board. */
.board-pieces, .board-marks, .board-fx, .board-hits {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
}
.board-pieces { pointer-events: none; overflow: hidden; }
.board-pieces .pc { position: absolute; display: block; height: auto; max-width: none; -webkit-user-drag: none; }
/* The selected piece is picked up: bigger, a little higher, with a longer
   shadow. Same transform as LIFT in board.js. */
.board-pieces .pc.lifted { z-index: 2; transform: translateY(-4%) scale(1.15);
  filter: drop-shadow(0 6px 5px rgba(0, 0, 0, .35)); animation: pc-lift .12s ease-out; }
@keyframes pc-lift { from { transform: translateY(0) scale(1); filter: none; } }
@media (prefers-reduced-motion: reduce) { .board-pieces .pc.lifted { animation: none; } }
/* A General in check is scared: it trembles a little for 5 s (25 x .2 s,
   continued across redraws by an animation-delay, see render in board.js;
   with "translate", so it adds to a lift) and sweats: drops thrown out to
   both sides that splash on the board, 3 times each (then it stops: an
   endless animation keeps the phone drawing, and warm). */
.board-pieces .pc.sweating { animation: pc-tremble .2s linear 25; }
.board-pieces .pc.sweating.lifted { animation: pc-lift .12s ease-out, pc-tremble .2s linear 25; }
@keyframes pc-tremble {
  0%, 100% { translate: 0 0; rotate: 0deg; }
  25% { translate: -.5% 0; rotate: -.8deg; }
  75% { translate: .5% 0; rotate: .8deg; }
}
.board-sweat { position: absolute; inset: 0; z-index: 3; }
.sweat-drop {
  position: absolute; width: 3%; aspect-ratio: 1; margin: -1.5% 0 0 -1.5%;
  /* A square with one sharp corner, turned so the corner points up: a drop. */
  border-radius: 50% 0 50% 50%; rotate: -45deg;
  background: radial-gradient(circle at 40% 60%, #fff 0 14%, #9be3ff 32%, #2f9ae0 100%);
  box-shadow: 0 1px 2px rgba(0, 40, 90, .35);
  opacity: 0; animation: sweat-fly 1.45s linear 3;
}
/* Thrown out sideways (--sx: -1 left, 1 right; --far: how far) in an arc
   (0-40%: x even, y a parabola, up then down past where it started), its
   point turning with it; then it splashes flat on the board and dries. */
@keyframes sweat-fly {
  0% { opacity: 0; scale: .4; translate: 0 0; rotate: calc(-45deg - var(--sx) * 35deg); }
  4% { opacity: 1; scale: 1; }
  8% { translate: calc(var(--sx) * var(--far) * 66%) -61%; }
  16% { translate: calc(var(--sx) * var(--far) * 132%) -83%; rotate: -45deg; }
  24% { translate: calc(var(--sx) * var(--far) * 198%) -67%; }
  32% { translate: calc(var(--sx) * var(--far) * 264%) -13%; }
  40% { opacity: 1; scale: 1; border-radius: 50% 0 50% 50%; translate: calc(var(--sx) * var(--far) * 330%) 80%;
    rotate: calc(-45deg + var(--sx) * 70deg); }
  46% { opacity: .85; scale: 1.5 .5; border-radius: 50%; rotate: 0deg; translate: calc(var(--sx) * var(--far) * 340%) 80%; }
  100% { opacity: 0; scale: 1.8 .45; border-radius: 50%; rotate: 0deg; translate: calc(var(--sx) * var(--far) * 340%) 80%; }
}
@media (prefers-reduced-motion: reduce) {
  .board-pieces .pc.sweating, .board-pieces .pc.sweating.lifted { animation: none; }
  .sweat-drop { animation: none; opacity: 1; }
}
.board-marks { display: block; pointer-events: none; }
.board-fx { pointer-events: none; }
.board-hits { display: block; touch-action: manipulation; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent; }
.board-hits .hit { cursor: pointer; }

.player-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 10px;
  min-height: 48px;
}
.pline { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 0 1 auto; min-width: 0; }
.ready-tag {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  color: #1e5a26;
  background: #d7efd9;
  border-radius: 999px;
  padding: 1px 8px;
}

/* Pieces this player has taken, on a line under the name: a group per kind,
   the pieces of one kind overlapping by half. */
.caps {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  /* One fixed line, also with nothing taken yet: the card never changes height.
     A very long row is cut off rather than wrapped. */
  height: 20px;
  flex-wrap: nowrap;
  overflow: hidden;
}
.cap-group { flex: none; }
.cap-group { display: inline-flex; align-items: center; }
.cap {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .35));
}
.cap-group .cap + .cap { margin-left: -10px; }

/* "Sẵn sàng" / "Chơi ván mới" in the middle of the board between games. */
.ready-box {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.ready-card {
  pointer-events: auto;
  display: grid;
  justify-items: center;
  gap: 10px;
  min-width: min(260px, 80%);
  max-width: 86%;
  padding: 18px 20px;
  background: rgba(251, 244, 230, .96);
  border: 1px solid var(--card-edge);
  border-radius: 14px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .4);
  text-align: center;
  animation: ready-in .2s ease-out;
}
@keyframes ready-in { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
.ready-title { font-size: 19px; font-weight: 700; }
.ready-note { font-size: 14px; color: var(--muted); }
.ready-note.ok { color: var(--good); font-weight: 600; }
.ready-sub { font-size: 12px; color: var(--muted); }
.btn-big { font-size: 18px; padding: 12px 34px; border-radius: 10px; }
.btn-small { padding: 5px 14px; font-size: 14px; font-weight: 500; }
.offline { color: var(--warn); font-size: 13px; }
.player-card .grow { flex: 1; min-width: 0; }
.clock {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 20px;
  background: #efe3c8;
  border-radius: 8px;
  padding: 3px 10px;
  min-width: 78px;
  text-align: center;
}
.clock.active { background: #ffe29a; }
.clock.low { background: #ffcdd2; color: #b71c1c; }

.side-col { display: grid; gap: 12px; width: 360px; max-width: 100%; flex: none; }
.room-title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.status { font-size: 17px; font-weight: 600; }
.status.alert { color: var(--accent); }
.status.over { color: #1e5a26; }

.offer {
  margin-top: 10px;
  padding: 10px;
  border-radius: 8px;
  background: #fff1cc;
  border: 1px solid #f1d58a;
}
.offer .row { display: flex; gap: 8px; margin-top: 8px; }

/* ------------------------------------------------------ replay + move list */

.replay-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 8px;
}
.replay-controls button {
  color: var(--ink);
  width: 44px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--card-edge);
  background: #fff;
  font-size: 15px;
}
.replay-controls button:hover:not(:disabled) { background: #f1e6cd; }
.replay-controls button:disabled { opacity: .35; cursor: default; }
.ply-label { flex: 1; text-align: center; font-size: 13px; color: var(--muted); }

.view-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #e3f0ff;
  border: 1px solid #b6d4f5;
  color: #14457a;
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 8px;
  font-size: 14px;
}
.view-banner button {
  border: 0;
  background: #1e6fc7;
  color: #fff;
  border-radius: 6px;
  padding: 4px 10px;
}

.move-list {
  position: relative;
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid var(--card-edge);
  border-radius: 8px;
  background: #fff;
}
.move-row {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  align-items: stretch;
}
.move-row:nth-child(even) { background: #faf3e3; }
.move-no { color: var(--muted); font-size: 13px; padding: 7px 0 7px 8px; }
.mv {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 7px 8px;
  font-size: 15px;
  border-radius: 6px;
  color: var(--ink);
}
.mv:hover { background: #f3e4bd; }
.mv.active { background: #1e6fc7; color: #fff; }
.mv .chk { color: var(--accent); font-weight: 700; }
.mv.active .chk { color: #ffd6d0; }
.empty-moves { padding: 14px; color: var(--muted); text-align: center; font-size: 14px; }

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

/* ------------------------------------------------------------ ☰ options menu */

.menu-btn { font-size: 16px; line-height: 1; padding: 6px 12px; }
.menu { position: fixed; inset: 0; z-index: 15; }
.menu-backdrop { position: absolute; inset: 0; background: rgba(20, 14, 8, .45); }
.menu-panel {
  position: absolute;
  top: 52px;
  right: 16px;
  width: 280px;
  max-width: calc(100% - 32px);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .45);
  padding: 6px;
  display: grid;
  gap: 6px;
}
.menu-group {
  display: grid;
  background: #fff9ec;
  border: 1px solid var(--card-edge);
  border-radius: 10px;
  overflow: hidden;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: 0;
  border-bottom: 1px solid var(--card-edge);
  padding: 12px 14px;
  font-size: 16px;
}
.menu-group .menu-item:last-child { border-bottom: 0; }
.menu-item:hover:not(:disabled) { background: #f1e6cd; }
.menu-item:disabled { color: var(--muted); cursor: not-allowed; }
.menu-item.danger, .menu-item[data-danger] { color: var(--accent); font-weight: 600; }
.menu-close { text-align: center; border: 0; color: var(--muted); }

/* "Cỡ quân cờ  [To] [Nhỏ]" */
.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  border-bottom: 1px solid var(--card-edge);
  font-size: 16px;
}
.menu-row-btn {
  width: 100%;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--card-edge);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu-row-btn:hover { background: #f3e0b4; }

/* Small pictures of the board looks (☰ > Nền and its picker). Pictures are the
   board top (556 x 616); the drawn board's thickness below is cut off. */
.board-thumb { display: block; width: 100%; aspect-ratio: 556 / 616; overflow: hidden; border-radius: 6px; }
.board-thumb img, body .board-thumb svg { display: block; width: 100%; height: auto; border-radius: 0; box-shadow: none; filter: none; }
.board-thumb-small { width: 40px; flex: none; box-shadow: 0 1px 4px rgba(0, 0, 0, .3); }
.piece-thumb { display: inline-flex; gap: 2px; flex: none; }
.piece-thumb img { width: 30px; height: auto; display: block; }
.piece-thumb-big { justify-content: center; gap: 8px; padding: 14px 0; width: 100%; }
.piece-thumb-big img { width: 56px; }
.board-picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 8px 0 16px; }
.board-choice {
  padding: 4px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: rgba(74, 37, 17, .06);
  cursor: pointer;
}
.board-choice:hover { background: rgba(74, 37, 17, .12); }
.board-choice.active { border-color: var(--lacquer); box-shadow: 0 0 0 2px var(--gold); }
/* ☰ > Thời gian: the times a player can pick for the next game. */
.time-picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 10px 0 16px; }
.time-choice {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px;
  border: 2px solid transparent; border-radius: 10px; background: rgba(74, 37, 17, .06);
  color: var(--ink-brown); font: inherit; cursor: pointer;
}
.time-choice:hover { background: rgba(74, 37, 17, .12); }
.time-choice b { font-size: 16px; }
.time-choice span { font-size: 12px; color: #8a6a45; }
.time-choice.active { border-color: var(--lacquer); box-shadow: 0 0 0 2px var(--gold); }
.ready-time {
  border: 0; background: none; padding: 2px 4px; font: inherit; font-size: 13px; color: #8a6a45; cursor: pointer;
}
.ready-time span { color: var(--lacquer); font-weight: 600; text-decoration: underline; }
/* ☰ > Xếp bàn cờ: a board to set up and the pieces to put on it. */
.overlay .card.setup-card { max-width: 460px; width: 100%; max-height: 100%; overflow-y: auto; padding: 14px; }
.setup-card h2 { margin: 0 0 8px; }
#overlay .setup-board { width: auto; max-width: 380px; margin: 8px auto; } /* not the room's board size */
.setup-tools { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 6px 0; }
.setup-palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin: 6px 0; }
.setup-piece {
  position: relative; display: flex; align-items: center; justify-content: center; aspect-ratio: 1;
  padding: 2px; border: 2px solid transparent; border-radius: 8px; background: rgba(74, 37, 17, .06); cursor: pointer;
}
.setup-piece img { width: 100%; height: auto; }
.setup-piece span {
  position: absolute; right: 0; bottom: 0; min-width: 16px; padding: 0 3px; border-radius: 8px;
  background: var(--lacquer); color: #fff; font-size: 11px; line-height: 16px;
}
.setup-piece:disabled { opacity: .35; cursor: default; }
.setup-piece.active { border-color: var(--lacquer); box-shadow: 0 0 0 2px var(--gold); }
.setup-erase { font-size: 20px; color: var(--lacquer); }
.setup-turn { display: flex; gap: 10px; align-items: center; justify-content: center; margin: 8px 0; }
.room-time { font-size: 12px; color: #8a6a45; }
.menu-group .menu-row:last-child { border-bottom: 0; }
.seg { display: inline-flex; border: 1px solid var(--card-edge); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button {
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 6px 16px;
  font-size: 15px;
}
.seg button + button { border-left: 1px solid var(--card-edge); }
.seg button.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* Phone-only pieces of the room screen (shown by the media query below). */
.bottom-bar { display: none; }

/* ---------------------------------------------------------- overlay, toast */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 8, .75);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.overlay .card { max-width: 420px; text-align: center; }
.overlay p { margin: 6px 0 14px; }
.confirm-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* A friend's invite to a game: at the top, with "Chơi" and "Bỏ qua". */
.invite-box { position: fixed; left: 50%; top: calc(10px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 40;
  width: min(92vw, 380px); padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--gold);
  background: linear-gradient(180deg, #fffaf0, #f3e3c0); color: var(--ink-brown);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45); display: flex; align-items: center; gap: 10px; animation: invite-in .25s ease-out; }
.invite-box .invite-text { flex: 1; min-width: 0; font-size: 14.5px; line-height: 1.35; }
.invite-box .btn { flex: none; padding: 8px 14px; }
@keyframes invite-in { from { transform: translate(-50%, -30px); opacity: 0; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #2c2116;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 30;
  max-width: 90vw;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
}

/* ------------------------------------------------------------- room theme */

/* Everything around the board in the same red lacquer, gold and rice paper as
   the lobby. The board and the pieces keep their own look (board.js). */
.card {
  background: linear-gradient(180deg, var(--paper), var(--paper-low));
  border: 2px solid var(--gold-deep);
  border-radius: 14px;
  box-shadow: 0 0 0 3px rgba(233, 196, 106, .18), 0 8px 20px rgba(0, 0, 0, .45);
  color: var(--ink-brown);
}

.player-card {
  /* Always the same height (name line + captured pieces line), no border. */
  height: 62px;
  background: linear-gradient(180deg, rgba(126, 23, 19, .94), rgba(62, 10, 9, .94));
  border: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 4px 10px rgba(0, 0, 0, .35);
  color: var(--gold-soft);
}
.player-card .pname { font-family: var(--serif); letter-spacing: .2px; }
.player-card .offline { flex: none; color: #ffb36b; }
.player-card .ready-tag { background: var(--jade); color: #eafff3; border: 1px solid #1f5a40; }
/* The side's dot becomes a small 帥 / 將 seal. */
.player-card .dot {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1.5px solid currentColor;
  background: radial-gradient(circle at 35% 30%, #fffaf0 0%, #f3dfb0 70%, #d8b46a 100%);
  box-shadow: inset 0 0 0 2px #f6e7c4, inset 0 0 0 3px currentColor, 0 2px 4px rgba(0, 0, 0, .4);
  font-family: var(--brush);
  font-size: 17px;
  line-height: 1;
}
.player-card .dot-r { color: #b3241c; }
.player-card .dot-b { color: #1f1a17; }
.player-card .dot-r::after { content: "帥"; }
.player-card .dot-b::after { content: "將"; }

.clock {
  background: #1e0605;
  color: var(--gold-soft);
  border: 1px solid rgba(233, 196, 106, .45);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .6);
}
.clock.active {
  background: var(--btn-gold);
  color: var(--lacquer-deep);
  border-color: #8f6420;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6);
}
.clock.low { background: #ffd7d0; color: var(--lacquer); border-color: var(--lacquer); }

/* "Sẵn sàng" box on the board: a small rice-paper panel. */
.ready-card {
  position: relative;
  background: linear-gradient(180deg, rgba(251, 243, 222, .97), rgba(239, 220, 178, .97));
  border: 2px solid var(--gold-deep);
  box-shadow: 0 0 0 3px rgba(233, 196, 106, .25), 0 10px 28px rgba(0, 0, 0, .5);
  color: var(--ink-brown);
}
.ready-card::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(168, 121, 43, .45);
  border-radius: 10px;
  pointer-events: none;
}
.ready-title { font-family: var(--serif); color: var(--lacquer-deep); letter-spacing: .5px; }
.ready-note, .ready-sub { color: #8a6a45; }
.ready-note.ok { color: var(--jade); }

/* Side column (computers and wide tablets). */
.room-title b { font-family: var(--serif); font-size: 17px; color: var(--lacquer-deep); }
.room-title .muted { color: #8a6a45; }
.status { color: var(--ink-brown); }
.status.alert { color: var(--lacquer); }
.status.over { color: var(--jade); }
.offer { background: #fff3d0; border-color: var(--paper-edge); color: var(--ink-brown); }

.replay-controls button {
  background: var(--btn-gold);
  border: 1px solid #8f6420;
  color: var(--lacquer-deep);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), 0 2px 0 #7a5418;
}
.replay-controls button:hover:not(:disabled) { background: var(--btn-gold); filter: brightness(1.06); }
.ply-label { color: #8a6a45; }
.view-banner { background: rgba(163, 34, 28, .08); border-color: rgba(163, 34, 28, .35); color: var(--lacquer-deep); }
.view-banner button { background: var(--btn-red); border: 1px solid var(--gold); color: #fff4d6; }
.move-list { background: #fffaf0; border-color: var(--paper-edge); }
.move-row:nth-child(even) { background: #f8ecd0; }
.move-no { color: #9b7448; }
.mv { color: var(--ink-brown); }
.mv:hover { background: #f3e0b4; }
.mv.active { background: var(--btn-red); color: #fff4d6; }
.empty-moves { color: #9b7448; }

/* ☰ menu, dialogs and toasts. */
.menu-backdrop { background: rgba(30, 5, 4, .55); }
.menu-panel {
  background: linear-gradient(180deg, var(--paper), var(--paper-low));
  border: 2px solid var(--gold-deep);
  color: var(--ink-brown);
}
.menu-group { background: #fffaf0; border-color: var(--paper-edge); }
.menu-item { color: var(--ink-brown); border-bottom-color: var(--paper-edge); }
.menu-item:hover:not(:disabled) { background: #f3e0b4; }
.menu-item.danger, .menu-item[data-danger] { color: var(--lacquer); }
.menu-close { color: #8a6a45; }
.menu-row { border-bottom-color: var(--paper-edge); }
.seg { border-color: var(--paper-edge); }
.seg button { color: var(--ink-brown); }
.seg button + button { border-left-color: var(--paper-edge); }
.seg button.active { background: var(--btn-red); color: #fff4d6; }

.overlay { background: rgba(30, 5, 4, .78); }
.overlay .card h2 { font-family: var(--serif); color: var(--lacquer-deep); }
.toast {
  background: linear-gradient(180deg, #7e1713, #4d0d0b);
  border: 1px solid var(--gold);
  color: var(--gold-soft);
}

/* Version line (☰ menu, login screen) and the admin's frame meter. */
.app-version { margin: 4px 0 2px; text-align: center; font-size: 12px; color: #9b7448; }
.login-version { color: var(--gold); font: 700 16px/1 var(--serif); letter-spacing: .5px; text-shadow: 0 1px 0 #2a0505; }
.frame-meter {
  position: fixed;
  z-index: 25;
  top: calc(env(safe-area-inset-top) + 6px);
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 16px);
  text-align: center;
  padding: 3px 9px;
  border-radius: 12px;
  background: rgba(20, 60, 35, .9);
  border: 1px solid #4f9c74;
  color: #d9f5e4;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.frame-meter.bad { background: rgba(120, 20, 15, .92); border-color: #ff8a7a; color: #ffe0da; }

/* ---------------------------------------------------------------- tablets */

/* Tablets wide enough for the side column: no room name or status either; the
   card only shows up for a draw offer or a lost connection. */
@media (pointer: coarse) and (min-width: 881px) {
  .info-card .room-title,
  .info-card .status:not(.status-offline) { display: none; }
  .info-card .offer { margin-top: 0; }
  .info-card .status-offline + .offer { margin-top: 10px; }
  .info-card:not(:has(.offer:not(.hidden), .status-offline)) { display: none; }
  .info-card:has(.status-review) { display: block; }
  .info-card .status.status-review { display: block; }
}

/* ----------------------------------------------------------------- mobile */

/* Narrow phones: the connection pill becomes a dot so the player's name fits. */
@media (max-width: 480px) {
  .conn { width: 10px; height: 10px; padding: 0; font-size: 0; border-radius: 50%; flex: none; }
  .conn-on { background: #3fcf86; border-color: #b9f3d3; box-shadow: 0 0 6px rgba(63, 207, 134, .7); }
  .conn-off { background: #f39a4a; border-color: #ffd9b5; }
}

@media (max-width: 880px) {
  main { padding: 10px; }
  .game-layout { flex-direction: column; align-items: center; gap: 8px; }
  .side-col { width: min(100%, 600px); }
  .move-list { max-height: 220px; }
  .topbar h1 { font-size: 17px; }
  .topbar { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .lobby-wrap { padding-top: 10px; }
  .hero { margin-top: 14px; }

  /* While playing on a phone: no top bar, the board as big as possible, and a
     bottom bar with ☰ ‹ › (like chess.com). */
  /* The whole room fits one screen: the board takes the space left over by the
     other rows and shrinks when needed, so the page never scrolls. */
  html.in-room { height: 100%; overflow: hidden; overscroll-behavior: none; }
  /* position: fixed is what stops iOS Safari from rubber-band scrolling the page. */
  body.in-room { position: fixed; inset: 0; height: auto; min-height: 0; overflow: hidden; overscroll-behavior: none; }
  html.standalone.in-room { height: 100vh; }
  html.standalone body.in-room { inset: 0 0 auto 0; height: 100vh; } /* see "Home-screen app" above */
  body.in-room .topbar { display: none; }
  body.in-room main { padding: 0; height: 100%; }
  body.in-room #room { display: flex; flex-direction: column; height: 100%;
    padding-top: env(safe-area-inset-top); }
  body.in-room .game-layout { flex: 1; min-height: 0; flex-wrap: nowrap; }
  /* The board column is a size container: the board is as wide as possible while
     it and the two player cards (2 x 58px fixed, plus the gaps: 136px) still fit its height. 556x626 = board.js size. */
  body.in-room .board-col {
    flex: 1; min-height: 0; display: flex; flex-direction: column;
    justify-content: center; align-items: center; container-type: size;
  }
  body.in-room .board-wrap,
  body.in-room .player-card { width: min(100cqw, calc((100cqh - 136px) * var(--board-ar, 556 / 626))); flex: none; }
  body.in-room .board-svg { box-shadow: none; border-radius: 0;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .45)); }
  /* Room name and status are not shown on phones; the draw offer and a lost
     connection float over the top of the screen instead, so
     they never push the board around or make it smaller. */
  body.in-room #room { position: relative; }
  body.in-room .side-col {
    position: absolute; z-index: 4; top: calc(env(safe-area-inset-top) + 6px); left: 6px; right: 6px;
    width: auto; pointer-events: none;
  }

  body.in-room .board-col { width: 100%; gap: 6px; padding: 6px 6px 0; }
  /* The real 3D board goes almost to the screen's edges (2px). */
  body.in-room.board-gl .board-wrap { width: calc(100% + 8px); margin: 0 -4px; }
  body.in-room .board-svg { border-radius: 8px; }
  body.in-room .player-card { height: 58px; min-height: 0; padding: 6px 10px; }
  body.in-room .player-card .dot { width: 26px; height: 26px; font-size: 15px; }
  body.in-room .clock { font-size: 17px; min-width: 64px; }
  body.in-room .info-card { display: grid; justify-items: center; gap: 6px; padding: 0; background: none; border: 0; box-shadow: none; }
  body.in-room .info-card > * { pointer-events: auto; margin: 0; box-shadow: 0 4px 14px rgba(0, 0, 0, .4); }
  body.in-room .room-title,
  body.in-room .status:not(.status-offline) { display: none; }
  body.in-room .status-offline { font-size: 14px; padding: 6px 10px; border-radius: 8px;
    background: #fff1cc; border: 1px solid #f1d58a; }
  body.in-room .status.status-review { display: block; font-size: 14px; padding: 6px 12px; border-radius: 8px;
    background: #fff1cc; border: 1px solid #f1d58a; color: var(--ink-brown); }
  .mb-ply { align-self: center; text-align: center; font-size: 15px; color: var(--gold-soft); font-variant-numeric: tabular-nums; }
  body.in-room .moves-card,
  body.in-room .actions { display: none; }

  body.in-room .bottom-bar {
    flex: none;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: linear-gradient(180deg, #5a0f0d, #2e0807);
    border-top: 1.5px solid var(--gold-deep);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-bar button {
    height: 56px;
    background: transparent;
    border: 0;
    color: var(--gold-soft);
    font-size: 30px;
    line-height: 1;
  }
  .bottom-bar svg {
    width: 28px; height: 28px; vertical-align: middle; fill: currentColor;
  }
  .bottom-bar button:active:not(:disabled) { background: rgba(233, 196, 106, .12); }
  .bottom-bar button:disabled { opacity: .25; }

  /* In a room the menu opens as a sheet from the bottom of the screen. */
  body.in-room .menu-panel { top: auto; bottom: 0; left: 0; right: 0; width: auto; max-width: none; max-height: 86vh;
    border-left: 0; border-top: 2px solid var(--gold-deep);
    border-radius: 16px 16px 0 0; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); transform: translateY(100%); }
  body.in-room .menu.open .menu-panel { transform: none; }
}

/* ------------------------------------------------------------- "Câu nói" */

.board-col { position: relative; }

/* The picker: a grid of lines, then "Câu nói đối thủ" Hiện / Ẩn. */
.taunt-panel { width: 320px; }
.taunt-head { display: flex; align-items: baseline; justify-content: space-between; padding: 4px 6px 0; }
.taunt-head b { font-family: var(--serif); color: var(--lacquer-deep); font-size: 17px; }
.taunt-wait { color: var(--lacquer); font-size: 14px; font-weight: 600; }
.taunt-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.taunt-choice {
  font-family: "Bangers", Impact, "Arial Black", sans-serif;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-size: 20px;
  line-height: 1.25;
  padding: 8px 6px 6px;
  border-radius: 10px;
  border: 2.5px solid #111;
  background: linear-gradient(180deg, #fff35c, #ffd400 50%, #ff9f0a);
  color: #111;
  box-shadow: 3px 3px 0 #111;
  cursor: pointer;
}
.taunt-choice:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #111; }
.taunt-choice:disabled { filter: grayscale(1); opacity: .4; cursor: not-allowed; }

/* The 💬 button of the phone bar: the seconds left before the next line. */
#mbTaunt { position: relative; }
.mb-badge {
  position: absolute; top: 8px; left: calc(50% + 8px);
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: var(--gold); color: var(--lacquer-dark);
  font: 700 12px/20px system-ui, sans-serif;
}

/* The line over the board, comic style (placed and sized by showTaunt in
   app.js): a comic burst picture, the words in yellow-to-orange with a thick black outline and a 3D block. It falls from
   the screen (huge, tilted) and hits the board at 52% of .55 s = 286 ms
   (TAUNT_HIT_MS): the burst pops, the board shakes, then. */
.taunt-fx { position: absolute; z-index: 5; pointer-events: none; display: none; overflow: visible; }
.taunt-fx.on { display: block; }
.taunt-word {
  position: absolute; left: 50%;
  display: grid; justify-items: center;
  white-space: nowrap;
  transform: translate(-50%, -50%) rotate(-5deg);
  animation: taunt-slam .55s both;
}
/* Landed (set by showTaunt once the slam is over): no transform animation left,
   so the browser draws the letters and the picture again at their real size,
   sharp; only the opacity moves when it goes away. */
.taunt-word.landed { animation: taunt-out .4s ease-in 1.6s both; }
.taunt-word.landed .taunt-burst { animation: none; }
@keyframes taunt-out { to { opacity: 0; } }
.taunt-word .t {
  position: relative;
  font-family: "Bangers", Impact, "Arial Black", sans-serif;
  text-transform: uppercase;
  line-height: 1.3;
  letter-spacing: .04em;
  padding: 0 .2em;
  color: transparent;
  background: linear-gradient(180deg, #fff86a 0%, #ffd400 42%, #ff9a00 78%, #ff7a00 100%);
  -webkit-background-clip: text;
  background-clip: text;
}
/* Behind the coloured letters: the black outline and the 3D block. */
.taunt-word .t::before {
  content: attr(data-text);
  position: absolute; inset: 0; z-index: -1;
  padding: inherit;
  color: #111;
  -webkit-text-stroke: .16em #111;
  text-shadow: .03em .03em 0 #111, .06em .06em 0 #111, .09em .09em 0 #111, .12em .12em 0 #111,
    .15em .17em .1em rgba(0, 0, 0, .45);
}
/* The burst behind the words: a picture from public/taunt (rays and stars included). */
.taunt-burst {
  position: absolute; left: 50%; top: 50%; z-index: -1;
  width: 160%; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  filter: drop-shadow(4px 6px 0 rgba(0, 0, 0, .3));
  animation: taunt-pop .5s cubic-bezier(.2, 1.6, .4, 1) .25s both;
}
@keyframes taunt-pop {
  0% { transform: translate(-50%, -50%) scale(.2) rotate(-20deg); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
}
@keyframes taunt-slam {
  0% { transform: translate(-50%, -50%) scale(4.2) rotate(-14deg); opacity: 0;
       animation-timing-function: cubic-bezier(.55, 0, 1, .55); }
  15% { opacity: .9; }
  52% { transform: translate(-50%, -50%) scale(.86) rotate(-5deg); opacity: 1;
        animation-timing-function: ease-out; }
  75% { transform: translate(-50%, -50%) scale(1.08) rotate(-5deg); }
  100% { transform: translate(-50%, -50%) scale(1) rotate(-5deg); opacity: 1; }
}
/* By the avatar of whoever said it (showTaunt): the words start at the
   avatar and go right, below the top card (or above the bottom one, .up),
   and pop in from a little bigger. */
.taunt-word.corner {
  --ty: 0%;
  justify-items: start;
  transform: translate(-1.1em, var(--ty)) rotate(-4deg);
  transform-origin: 1.1em 50%;
  animation: taunt-corner .45s both;
}
.taunt-word.corner.up { --ty: -100%; }
.taunt-word.corner .taunt-burst { width: 130%; left: 45%; }
.taunt-word.corner.landed { animation: taunt-out .4s ease-in 1.6s both; }
@keyframes taunt-corner {
  0% { transform: translate(-1.1em, var(--ty)) scale(2) rotate(-12deg); opacity: 0;
       animation-timing-function: cubic-bezier(.55, 0, 1, .55); }
  20% { opacity: 1; }
  60% { transform: translate(-1.1em, var(--ty)) scale(.9) rotate(-4deg); animation-timing-function: ease-out; }
  100% { transform: translate(-1.1em, var(--ty)) scale(1) rotate(-4deg); opacity: 1; }
}
/* The board, hit: pushed down into the table, then rattling. */
.board-wrap.taunt-shake { animation: taunt-shake .45s linear .286s; }
@keyframes taunt-shake {
  0% { transform: none; }
  10% { transform: translate(-5px, 7px) scale(.975); }
  25% { transform: translate(6px, -4px) scale(.99); }
  40% { transform: translate(-4px, 3px); }
  55% { transform: translate(3px, -2px); }
  70% { transform: translate(-2px, 1px); }
  85% { transform: translate(1px, 0); }
  100% { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .board-wrap.taunt-shake { animation: none; }
  .taunt-word { animation: taunt-in .2s both; }
  .taunt-word .taunt-burst { animation: none; }
}
@keyframes taunt-in { from { opacity: 0; } }

@media (max-width: 880px) {
  /* ☰ 💬 ◀ ▶ (💬 only for the players) */
  body.in-room .bottom-bar { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 1fr; }
  .taunt-panel { width: auto; }
}

/* ---------------------------------------------------------------- "Lịch sử" */

.history-filter { align-self: flex-start; flex: none; }
.history-filter button { padding: 7px 16px; font-size: 14px; }
.history-filter #starCount { font-weight: 400; }
.hist-card { cursor: pointer; display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; transition: transform .12s ease; }
.hist-card:active { transform: scale(.985); }
.hist-card.starred { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(233, 196, 106, .45), 0 8px 20px rgba(0, 0, 0, .45); }
.hist-card .room-head { flex-wrap: nowrap; }
.hist-card .room-name { flex: 1; }
.hist-win { background: var(--jade); color: #eafff3; border: 1px solid #1f5a40; }
.hist-loss { background: var(--btn-red); color: #fff4d6; border: 1px solid var(--gold-deep); }
.hist-draw { background: #8a7a63; color: #fbf3de; border: 1px solid #6b5d48; }
.hist-reason { font-size: 14px; color: #6b4a2a; }
.hist-meta { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #8a6a45; }
.hist-meta .dot { width: 9px; height: 9px; margin: 0; }
.star-btn {
  flex: none; width: 40px; height: 40px; margin: -8px -8px -8px 0; border: 0; background: none; cursor: pointer;
  font-size: 24px; line-height: 1; color: #b89a6a;
}
.star-btn.on { color: #e0a419; text-shadow: 0 1px 0 #7a5410; }
.hist-more { grid-column: 1 / -1; justify-self: center; }

/* Admin: "Nhật ký đăng ký" */
.reglog-sum { font-size: 14px; text-align: left; margin: 6px 0 10px; }
.reglog-list { max-height: 55vh; overflow-y: auto; overscroll-behavior: contain; text-align: left; display: grid; gap: 8px; margin-bottom: 14px; }
.reglog-row { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--paper-edge); border-left: 4px solid #b5392b; background: rgba(255, 255, 255, .5); }
.reglog-row.ok { border-left-color: var(--jade); }
.reglog-head { display: flex; justify-content: space-between; gap: 8px; font-size: 15px; }
.reglog-head span { font-size: 13px; color: #8a5a2b; white-space: nowrap; }
.reglog-row.ok .reglog-head span { color: var(--jade); }
.reglog-meta { font-size: 12.5px; color: #8a6a45; overflow-wrap: anywhere; }

/* Passwords: "Quên mật khẩu?", "Đổi mật khẩu" */
.link-small { margin-top: 2px; font-size: 13px; color: #9b7448; text-decoration: underline; text-underline-offset: 3px; }
.pass-form { text-align: left; }
.mail-link { color: var(--lacquer); font-weight: 600; overflow-wrap: anywhere; }

/* Login screen: the version with the "!" (about) button beside it. */
.login-foot { display: flex; align-items: center; justify-content: center; gap: 8px; }
.login-foot .app-version { margin: 0; }
.info-btn {
  width: 26px; height: 26px; padding: 0; border-radius: 50%; cursor: pointer; flex: none;
  background: var(--btn-gold); border: 1px solid #8f6420; color: var(--lacquer-deep);
  font: 700 15px/1 var(--serif); text-shadow: 0 1px 0 rgba(255, 255, 255, .45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), 0 2px 0 #7a5418, 0 3px 6px rgba(0, 0, 0, .25);
}
.info-btn:active { transform: translateY(1px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), 0 1px 0 #7a5418; }
/* The about popup: long on a phone, so it scrolls inside. */
.overlay .card.about-card { max-height: 100%; overflow-y: auto; overscroll-behavior: contain; text-align: left; }
.about-card h2 { text-align: center; }
.about-head { font-family: var(--serif); color: var(--lacquer-deep); font-size: 17px; margin: 14px 0 8px; }
.install-steps { border: 1px solid var(--paper-edge); border-radius: 10px; background: rgba(255, 255, 255, .45); margin-bottom: 8px; }
.install-steps summary { cursor: pointer; padding: 9px 12px; font-weight: 700; color: var(--ink-brown); }
.install-steps ol { margin: 0; padding: 0 14px 10px 32px; font-size: 14px; }
.install-steps li { margin: 4px 0; }
.install-note { font-size: 14px; padding: 8px 10px; border-radius: 8px; background: #fff1cc; border: 1px solid #f1d58a; }
.install-note.ok { background: #e3f4ea; border-color: #9fd2b4; }
.about-card .confirm-row { justify-content: center; }

/* Refused login / sign-up: a warning that drops down from the top. */
.drop-warn {
  position: fixed; z-index: 40; left: 50%; top: calc(env(safe-area-inset-top) + 12px);
  width: min(92vw, 420px); display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border-radius: 12px; border: 1.5px solid var(--gold); background: var(--btn-red); color: #fff4d6;
  font-weight: 600; font-size: 15px; box-shadow: 0 10px 28px rgba(0, 0, 0, .55); cursor: pointer;
  transform: translate(-50%, calc(-100% - 40px)); opacity: 0; pointer-events: none;
  transition: transform .35s cubic-bezier(.2, 1.3, .4, 1), opacity .2s ease;
}
.drop-warn.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; animation: drop-warn-shake .4s .3s ease; }
.drop-warn-icon {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--btn-gold); color: var(--lacquer-deep); font: 700 16px/1 var(--serif);
}
@keyframes drop-warn-shake {
  25% { transform: translate(calc(-50% - 6px), 0); }
  50% { transform: translate(calc(-50% + 6px), 0); }
  75% { transform: translate(calc(-50% - 3px), 0); }
}
@media (prefers-reduced-motion: reduce) { .drop-warn { transition: opacity .2s ease; } .drop-warn.show { animation: none; } }

/* A wrong box of the login form shakes (see loginWarn), and stays red until edited. */
.field input.shake { animation: box-shake .45s ease; border-color: #c0392b; box-shadow: 0 0 0 3px rgba(192, 57, 43, .18); }
@keyframes box-shake {
  15%, 55% { transform: translateX(-6px); }
  35%, 75% { transform: translateX(6px); }
  90% { transform: translateX(-2px); }
}
@media (prefers-reduced-motion: reduce) { .field input.shake { animation: none; } }

/* "Chơi với máy" */
.overlay .card.computer-card { max-height: 100%; overflow-y: auto; overscroll-behavior: contain; }
.pick-label { text-align: left; font-weight: 700; font-size: 14px; color: #8a5a2b; margin: 10px 0 6px; }
.level-grid { display: grid; gap: 6px; }
.level-btn {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px; cursor: pointer; text-align: left;
  border: 1px solid var(--paper-edge); border-radius: 10px; background: rgba(255, 255, 255, .6); color: var(--ink-brown); font: inherit;
}
.level-btn b { font: 700 18px/1 var(--serif); color: var(--lacquer-deep); }
.level-btn span { font-size: 15px; }
.level-btn.active { background: var(--btn-red); border-color: var(--gold); color: #fff4d6; }
.level-btn.active b { color: var(--gold-soft); }
.color-seg { display: flex; width: 100%; }
.color-seg button { flex: 1; padding: 8px 4px; font-size: 13px; }
.loading-dots::after { content: ""; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* ------------------------------------------------- settings menu (⚙ / ☰) */
/* Lacquer red and gold like the top bar. Slides in from the right, about half
   the screen wide (wide enough for its rows on a phone); in a room on a phone
   it is a sheet from the bottom (see the mobile part above). */
.menu-backdrop { opacity: 0; transition: opacity .25s ease; }
.menu.open .menu-backdrop { opacity: 1; }
.menu-panel {
  top: 0; right: 0; bottom: 0; left: auto; width: clamp(260px, 50vw, 380px); max-width: 100%;
  border-radius: 0; border: 0; border-left: 2px solid var(--gold-deep);
  background: linear-gradient(180deg, #6a1310 0%, #3a0a08 100%); color: var(--gold-soft);
  box-shadow: -10px 0 30px rgba(0, 0, 0, .5);
  padding: calc(10px + env(safe-area-inset-top)) 12px calc(14px + env(safe-area-inset-bottom));
  align-content: start; gap: 10px; overflow-y: auto; overscroll-behavior: contain;
  transform: translateX(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
}
.menu.open .menu-panel { transform: none; }
.menu-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 2px 2px 4px; }
.menu-head b { font: 700 19px/1.2 var(--serif); color: var(--gold); text-shadow: 0 1px 0 #2a0505; }
.menu-x { width: 34px; height: 34px; border-radius: 50%; border: 1px solid rgba(233, 196, 106, .45); background: rgba(0, 0, 0, .25); color: var(--gold-soft); font-size: 15px; }
.taunt-panel .menu-head { display: none; }
.menu-group { background: rgba(0, 0, 0, .22); border: 1px solid rgba(233, 196, 106, .32); border-radius: 12px; }
.menu-item { color: var(--gold-soft); border-bottom-color: rgba(233, 196, 106, .18); font-size: 15px; }
.menu-item:hover:not(:disabled) { background: rgba(233, 196, 106, .1); }
.menu-item.danger, .menu-item[data-danger] { color: #ff9e8c; }
.menu-item:disabled { color: rgba(248, 230, 176, .4); }
.menu-close { display: none; }
.menu-row { border-bottom-color: rgba(233, 196, 106, .18); font-size: 15px; flex-wrap: wrap; }
.menu-row-btn:hover { background: rgba(233, 196, 106, .1); }
.menu-panel .seg { background: rgba(0, 0, 0, .3); border-color: rgba(233, 196, 106, .45); }
.menu-panel .seg button { color: var(--gold-soft); padding: 5px 13px; font-size: 14px; }
.menu-panel .seg button + button { border-left-color: rgba(233, 196, 106, .35); }
.menu-panel .seg button.active { background: var(--btn-gold); color: var(--lacquer-deep); font-weight: 700; }
.menu-panel .app-version { color: rgba(248, 230, 176, .55); }
.menu-panel .taunt-head { color: var(--gold); }

/* ------------------------------------------------------- "Hồ sơ" (profile) */
/* A sheet presented from the bottom like on iOS, with pages pushed from the
   right ("Xem tất cả"). */
.sheet { position: fixed; inset: 0; z-index: 18; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20, 4, 3, .6); opacity: 0; transition: opacity .3s ease; }
.sheet.open .sheet-backdrop { opacity: 1; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; top: calc(env(safe-area-inset-top) + 18px);
  margin: 0 auto; max-width: 560px; overflow: hidden;
  border-radius: 16px 16px 0 0; border-top: 2px solid var(--gold-deep);
  background: linear-gradient(180deg, var(--paper), var(--paper-low)); color: var(--ink-brown);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, .5);
  transform: translateY(100%); transition: transform .32s cubic-bezier(.2, .8, .2, 1);
}
.sheet.open .sheet-panel { transform: none; }
.sheet-page { position: absolute; inset: 0; display: flex; flex-direction: column; background: inherit;
  transition: transform .3s cubic-bezier(.2, .8, .2, 1); }
.sheet-push { transform: translateX(100%); box-shadow: -8px 0 20px rgba(0, 0, 0, .15); }
.sheet:not([data-page="main"]) .sheet-page[data-page="main"] { transform: translateX(-25%); }
.sheet[data-page="history"] .sheet-page[data-page="history"],
.sheet[data-page="friends"] .sheet-page[data-page="friends"] { transform: none; }
.sheet-head {
  flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  height: 52px; padding: 0 12px; border-bottom: 1px solid var(--paper-edge);
  background: var(--btn-red); color: var(--gold-soft);
}
.sheet-head b { font: 700 17px/1 var(--serif); color: var(--gold-soft); text-shadow: 0 1px 0 #2a0505; white-space: nowrap; }
.sheet-close, .sheet-back { border: 0; background: none; color: var(--gold); font-size: 15px; font-weight: 600; padding: 8px 2px; }
.sheet-close { justify-self: end; }
.sheet-back { justify-self: start; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
.avatar {
  display: inline-grid; place-items: center; flex: none; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffaf0, #e3c27c); border: 1.5px solid var(--gold);
  color: var(--lacquer-deep); font-family: var(--serif); font-weight: 700;
}
.avatar-xl { width: 78px; height: 78px; font-size: 38px; border-width: 2.5px; box-shadow: 0 4px 12px rgba(0, 0, 0, .25); }
.avatar-sm { width: 36px; height: 36px; font-size: 16px; }
.profile-hero { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.profile-id { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.profile-name { display: flex; align-items: center; gap: 10px; }
.profile-name b { flex: 1; min-width: 0; }
.profile-id b { font: 700 24px/1.2 var(--serif); color: var(--lacquer-deep); overflow-wrap: anywhere; }
.profile-id span { font-size: 14px; color: #8a6a45; }
.profile-key { flex: none; display: grid; place-items: center; width: 36px; height: 36px; padding: 0;
  border-radius: 50%; border: 1.5px solid var(--gold-deep); background: rgba(42, 5, 5, .35); color: var(--gold-soft); cursor: pointer; }
.profile-key svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.profile-key:active { transform: scale(.94); }
.sheet-section-head { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 8px; }
.sheet-section-head h3 { margin: 0; font: 700 17px/1.2 var(--serif); color: var(--lacquer-deep); }
.see-all { border: 0; background: none; padding: 4px 0; color: var(--lacquer); font-weight: 600; font-size: 14px; }
.sheet-list { background: rgba(255, 255, 255, .55); border: 1px solid var(--paper-edge); border-radius: 12px; overflow: hidden; }
.game-row, .friend-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--paper-edge); }
.game-row:last-child, .friend-row:last-child { border-bottom: 0; }
.game-row { cursor: pointer; }
.game-row:active { background: rgba(168, 121, 43, .12); }
.game-row .badge { flex: none; min-width: 56px; text-align: center; }
.game-text, .friend-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.game-text b, .friend-text b { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-text span, .friend-text span { font-size: 12.5px; color: #8a6a45; }
.friend-text .online { color: var(--jade); font-weight: 600; }
.game-row .star-btn { margin: -8px -6px -8px 0; }
.friend-form { display: flex; gap: 8px; margin-bottom: 10px; }
.friend-form input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--paper-edge); background: #fffdf6; font: inherit; color: var(--ink-brown); }
.friend-form .btn { flex: none; }
.mini-btn { flex: none; border: 1px solid var(--paper-edge); background: #fffaf0; color: var(--ink-brown); border-radius: 999px; padding: 5px 11px; font-size: 13px; }
/* Friend list: invite an online friend (board icon), watch a friend's game (board with a live dot). */
.play-btn { position: relative; flex: none; width: 36px; height: 36px; padding: 0; border-radius: 50%; display: grid; place-items: center;
  border: 1.5px solid var(--gold); background: var(--btn-red); color: #fff4d6; cursor: pointer; }
.play-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.play-btn.watch { background: #2f5a45; }
.play-btn.watch::after { content: ""; position: absolute; top: 1px; right: 1px; width: 9px; height: 9px; border-radius: 50%;
  background: #ff3b30; border: 1.5px solid #fffaf0; animation: live-dot 1.4s ease-in-out infinite; }
@keyframes live-dot { 50% { opacity: .35; } }
.play-btn:active { transform: scale(.92); }
.friend-text .playing { color: #c0392b; font-weight: 600; }
.mini-btn.ok { background: var(--jade); border-color: #1f5a40; color: #eafff3; font-weight: 600; }
.sheet-sub { margin: 12px 0 6px; font-size: 13px; font-weight: 700; color: #8a5a2b; }
.sheet-empty { margin: 4px 0; padding: 14px; text-align: center; color: #8a6a45; font-size: 14px; }
.sheet-note { margin: 14px 0; padding: 12px 14px; border-radius: 12px; background: #fff1cc; border: 1px solid #f1d58a; font-size: 14px; }
.sheet-bottom { margin-top: 24px; }
.sheet-bottom + .sheet-bottom { margin-top: 10px; }
/* The whole profile on the app's red lacquer, with paper cards on it. */
.sheet-panel, .sheet-page {
  background-color: var(--lacquer-dark);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='120' viewBox='0 0 180 120'%3E%3Cg fill='none' stroke='%23e9c46a' stroke-opacity='.08' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M18 64a16 16 0 1 1 32 0c0 7-5 11-11 11s-9-4-9-8 3-6 6-6'/%3E%3Cpath d='M50 64a24 24 0 0 1 48 0'/%3E%3Cpath d='M98 64a12 12 0 1 1 24 0c0 5-4 8-8 8s-6-3-6-6 2-4 4-4'/%3E%3Cpath d='M8 78h124'/%3E%3C/g%3E%3C/svg%3E"),
    radial-gradient(ellipse at 50% -10%, #8e1d17 0%, #5a110e 42%, #2e0807 100%);
  background-size: 180px 120px, 100% 100%;
  background-repeat: repeat, no-repeat;
}
#historyBody .history-filter { display: inline-flex; margin-bottom: 16px; }
#historyList, .hist-cards { display: grid; gap: 8px; }
.hist-mini {
  display: flex; flex-direction: row; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer;
  background: linear-gradient(180deg, var(--paper), var(--paper-low)); color: var(--ink-brown);
  border: 1.5px solid var(--gold-deep); border-radius: 12px; box-shadow: 0 0 0 2px rgba(233, 196, 106, .15), 0 4px 10px rgba(0, 0, 0, .35);
}
.hist-mini .game-text b { color: var(--lacquer-deep); font-family: var(--serif); }
.hist-mini .star-btn { margin: -8px -6px -8px 0; }

/* Win / loss / draw as a picture (see resultIcon in app.js). */
.result-icon { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid; }
.result-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.res-win { background: var(--btn-gold); border-color: #8f6420; color: var(--lacquer-deep); }
.res-win svg { stroke-width: 1.9; }
.res-loss { background: var(--btn-red); border-color: var(--gold-deep); color: #fff4d6; }
.res-draw { background: #8a7a63; border-color: #6b5d48; color: #fbf3de; }

/* Profile texts on the red lacquer. */
.profile-id b { color: var(--gold-soft); text-shadow: 0 1px 0 #2a0505; }
.profile-id span { color: rgba(248, 230, 176, .7); }
.sheet-section-head h3 { color: var(--gold); text-shadow: 0 1px 0 #2a0505; }
.see-all { color: var(--gold-soft); }
.sheet-sub { color: var(--gold); }
.sheet-empty { color: rgba(248, 230, 176, .8); }
.sheet-list { background: linear-gradient(180deg, var(--paper), var(--paper-low)); border: 1.5px solid var(--gold-deep); }
.friend-form input { border-color: var(--gold-deep); }
.sheet-panel { border-top-color: var(--gold); }

/* "Câu nói" of an account: the lines in "Hồ sơ" and the editor
   (openEditTaunts in app.js). */
.taunt-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.taunt-chips span { padding: 5px 10px; border-radius: 999px; font-size: 13px; color: var(--ink-brown);
  background: linear-gradient(180deg, var(--paper), var(--paper-low)); border: 1px solid var(--gold-deep); }
.taunt-quick { display: flex; gap: 8px; margin-top: 10px; }
.taunt-quick-input { flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--card-edge); background: #fff; }
.taunt-quick .btn { flex: none; padding-left: 14px; padding-right: 14px; }
.taunt-quick-input.shake { animation: box-shake .45s ease; border-color: #c0392b; box-shadow: 0 0 0 3px rgba(192, 57, 43, .18); }
.taunt-quick-error { margin: 6px 0 0; color: #ffb4a8; }
.taunt-quick-error:empty { display: none; }
#tauntAdd .taunt-quick { margin-top: 0; }
.taunt-rows { display: grid; gap: 7px; }
.taunt-row { display: flex; gap: 6px; }
.taunt-del { flex: none; width: 40px; border-radius: 8px; border: 1px solid var(--card-edge); background: #fff;
  color: #8a5a2b; font-size: 22px; line-height: 1; cursor: pointer; }
.taunt-add { border: 1.5px dashed var(--card-edge); background: none; border-radius: 8px; padding: 9px; font: inherit;
  font-weight: 600; color: #8a5a2b; cursor: pointer; }
.taunts-card { max-height: calc(100dvh - 32px); overflow-y: auto; }
.taunts-help { font-size: 13px; text-align: left; }
.taunts-form { display: grid; gap: 7px; }
.taunt-input { flex: 1; min-width: 0; width: 100%; font: inherit; font-size: 16px; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--card-edge); background: #fff; }
.taunt-input.shake { animation: box-shake .45s ease; border-color: #c0392b; box-shadow: 0 0 0 3px rgba(192, 57, 43, .18); }
.taunts-form .confirm-row { margin-top: 6px; }
.taunts-form .login-error:empty { display: none; }
@media (prefers-reduced-motion: reduce) { .taunt-input.shake { animation: none; } }

/* "Hồ sơ" bottom: Đăng xuất button, then a small underlined Đổi mật khẩu link. */
.profile-pw {
  display: block;
  margin: 14px auto 4px;
  font-size: 13px;
  color: var(--gold-soft, #e8d3a0);
  text-decoration: underline;
  text-underline-offset: 3px;
  opacity: .85;
}
