:root {
  --bg: #f7f1e6;
  --surface: #fffaf2;
  --text: #2e2418;
  --muted: #7a6a55;
  --border: #e4d6bf;
  --accent: #c8742b;
  --shadow: 0 2px 8px rgba(60, 40, 10, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1712;
    --surface: #27211a;
    --text: #f2e8d8;
    --muted: #a89880;
    --border: #3a3127;
    --accent: #e08a3e;
    --shadow: 0 2px 8px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: inherit; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.logo { font-size: 1.6rem; }
.player-controls { display: flex; gap: 8px; flex-wrap: wrap; }
button, .btn {
  font: inherit; font-size: .9rem;
  padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  cursor: pointer; text-decoration: none;
}
button:hover, .btn:hover { border-color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; }

.hero { text-align: center; margin-bottom: 24px; }
.hero h1 { margin: 8px 0 4px; font-size: 2rem; }
.hero p { margin: 0 0 16px; color: var(--muted); }
#search {
  width: 100%; max-width: 420px;
  padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit;
}
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.card {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  overflow: hidden; text-decoration: none; box-shadow: var(--shadow);
  transition: transform .12s, border-color .12s;
}
.card:hover, .card:focus-visible { transform: translateY(-3px); border-color: var(--c, var(--accent)); outline: none; }
.card .art {
  height: 110px; display: grid; place-items: center; font-size: 3.2rem;
  background: color-mix(in srgb, var(--c, var(--accent)) 22%, transparent);
}
.card .body { padding: 12px 14px 14px; }
.card h3 { margin: 0 0 4px; font-size: 1.05rem; }
.card p { margin: 0; color: var(--muted); font-size: .9rem; line-height: 1.35; }
.empty { text-align: center; color: var(--muted); }

#player { max-width: 1200px; }
#player h2 { margin: 0 0 12px; }
.frame-wrap {
  background: #000; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border);
  height: calc(100vh - 170px); min-height: 360px;
}
#frame { width: 100%; height: 100%; border: 0; display: block; }
body { touch-action: manipulation; }   /* no double-tap zoom */

/* ---------- "Install app" (PWA) ---------- */
.install-btn { background: #2f6b2c; color: #fff; border-color: #2f6b2c; font-weight: 700; }
.install-btn[hidden] { display: none; }
.install-help { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(15, 10, 5, .55); }
.install-help[hidden] { display: none; }
.install-card { background: var(--surface); color: var(--text); border-radius: 16px; padding: 18px 20px; max-width: 380px; width: 100%; box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
.install-card h3 { margin: 0 0 8px; }
.install-card ol { margin: 0; padding-left: 20px; line-height: 1.6; }
.ios-share { display: inline-block; border: 1.5px solid currentColor; border-radius: 4px; padding: 0 4px; font-size: .8rem; }
.install-actions { display: flex; justify-content: flex-end; margin-top: 12px; }
.install-actions button { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }

/* ---------- phones & tablets: the game fills the whole screen ---------- */
.mobile-bar { display: none; }
body.mobile-play { overflow: hidden; background: #000; }
body.mobile-play .top, body.mobile-play #player-title { display: none; }
body.mobile-play #player { padding: 0; margin: 0; max-width: none; }
body.mobile-play .frame-wrap {
  position: fixed; inset: 0; z-index: 15;
  width: 100vw; height: 100vh; height: 100dvh; min-height: 0;
  border: 0; border-radius: 0; background: #000;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.mobile-play .mobile-bar {
  display: flex; flex-direction: column; gap: 10px;
  position: fixed; z-index: 16; top: 50%; transform: translateY(-50%);
  left: calc(6px + env(safe-area-inset-left));
}
.mobile-bar button {
  position: relative; width: 38px; height: 38px; padding: 0; border-radius: 50%;
  display: grid; place-items: center; font-size: 16px; line-height: 1;
  background: rgba(20, 15, 10, .45); color: #fff; border: 1.5px solid rgba(255, 255, 255, .55);
  opacity: .8; touch-action: manipulation;
}
.mobile-bar button:active { opacity: 1; background: rgba(200, 116, 43, .8); }
.m-dot { position: absolute; top: -2px; right: -2px; width: 11px; height: 11px; border-radius: 50%; background: #d9432f; border: 2px solid #fff; }
.m-dot[hidden] { display: none; }
body.mobile-play .chat { z-index: 20; }

/* ---------- header right side ---------- */
.top-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.player-controls[hidden] { display: none; }
.chat-btn { position: relative; font-weight: 700; }
.chat-count { font-weight: 400; color: var(--muted); }
.chat-unread {
  position: absolute; top: -7px; right: -7px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: #d9432f; color: #fff; font-size: .75rem; line-height: 20px; text-align: center;
}
.chat-unread[hidden] { display: none; }

/* ---------- chat panel ---------- */
.chat {
  position: fixed; top: 62px; right: 12px; bottom: 12px; width: 360px; max-width: calc(100vw - 24px);
  display: flex; flex-direction: column; z-index: 20;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25); overflow: hidden;
}
.chat[hidden] { display: none; }
@media (min-width: 1100px) { body.chat-open main { margin-right: 384px; } }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.chat-title { font-weight: 800; }
.chat-status { font-weight: 400; font-size: .8rem; color: var(--muted); margin-left: 6px; }
.chat-status[data-s="online"] { color: #3a9a4a; }
.icon-btn { padding: 4px 9px; }
.link-btn { border: 0; background: none; padding: 0 2px; color: var(--accent); text-decoration: underline; font-size: .82rem; }
.chat-me { padding: 6px 12px; font-size: .88rem; color: var(--muted); border-bottom: 1px solid var(--border); }
.chat-me b { color: var(--text); }
.name-edit { font: inherit; width: 150px; padding: 2px 6px; border-radius: 6px; border: 1px solid var(--accent); background: var(--bg); color: var(--text); }
.chat-hosting { padding: 8px 12px; font-size: .88rem; background: color-mix(in srgb, var(--accent) 16%, transparent); border-bottom: 1px solid var(--border); }
.chat-hosting[hidden] { display: none; }
.hosting-btns { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.chat-tabs { display: flex; border-bottom: 1px solid var(--border); }
.chat-tabs button { flex: 1; border: 0; border-radius: 0; background: none; padding: 8px 4px; font-size: .85rem; color: var(--muted); border-bottom: 3px solid transparent; }
.chat-tabs button.on { color: var(--text); font-weight: 700; border-bottom-color: var(--accent); }
.pill-count { font-size: .75rem; color: var(--accent); font-weight: 800; }
.chat-tab { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: auto; }
.chat-tab[hidden] { display: none; }
#tab-msgs { overflow: hidden; }
.chat-log { flex: 1; overflow-y: auto; padding: 8px 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { font-size: .9rem; line-height: 1.35; overflow-wrap: anywhere; }
.msg time { font-size: .72rem; color: var(--muted); margin-left: 4px; }
.msg .text { margin-top: 1px; }
.msg.mine .text { color: var(--text); }
.msg.sys { color: var(--muted); font-style: italic; font-size: .84rem; }
.msg.invite { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 10px; padding: 7px 9px; }
.who { color: hsl(var(--h) 55% 38%); }
@media (prefers-color-scheme: dark) { .who { color: hsl(var(--h) 70% 70%); } }
.join-btn { margin-top: 6px; background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
.join-btn:disabled { background: var(--bg); color: var(--muted); border-color: var(--border); cursor: default; }
.chat-form { display: flex; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--border); }
.chat-form input { flex: 1; min-width: 0; font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.chat-form input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.chat-form button { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
.chat-note { margin: 0; padding: 0 12px 10px; font-size: .76rem; color: var(--muted); }
.chat-empty { color: var(--muted); text-align: center; font-size: .9rem; margin: 18px 8px; }
.room-row, .person { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.room-game { font-weight: 700; }
.room-sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.person-btns { display: flex; gap: 6px; flex-shrink: 0; }
.person-btns button { font-size: .8rem; padding: 5px 8px; }
#tab-games .chat-note, #tab-people .chat-note { padding-top: 10px; }

/* ---------- invite pop-ups ---------- */
.toasts { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 24px)); }
.toast { background: var(--surface); color: var(--text); border: 2px solid var(--accent); border-radius: 12px; padding: 12px 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, .3); font-size: .95rem; }
.toast-btns { display: flex; gap: 8px; margin-top: 8px; justify-content: flex-end; }
.toast-btns .primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }

@media (max-width: 700px) {
  .top { padding: 10px 12px; flex-wrap: wrap; }
  .chat { top: auto; right: 0; left: 0; bottom: 0; width: 100%; max-width: none; height: 72vh; border-radius: 16px 16px 0 0; }
}
