:root {
  --ink: #fff8ea;
  --gold: #ffc857;
  --wood: #7a3e18;
  --line: rgba(255, 214, 140, 0.38);
  --card: rgba(255, 248, 234, 0.08);
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body.site {
  margin: 0;
  min-height: 100vh;
  font-family: "Baloo 2", "Nirmala UI", "Mangal", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 8% -10%, rgba(255, 186, 72, 0.34), transparent 52%),
    radial-gradient(ellipse 60% 42% at 110% 0%, rgba(255, 70, 110, 0.24), transparent 48%),
    linear-gradient(180deg, #2a1658 0%, #140c2e 56%, #0e1a36 100%);
}

body.site a { color: #ffe08a; }

.site-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(16, 8, 36, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.logo {
  font-weight: 800;
  text-decoration: none;
  color: white;
  font-size: 1.15rem;
  line-height: 1.2;
  white-space: nowrap;
}

.site-links {
  display: none;
  width: 100%;
  gap: 6px;
}

.site-links a,
.nav-pop a {
  text-decoration: none;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.92rem;
  font-weight: 700;
}

.site-links a.on,
.nav-pop a.on { background: var(--gold); color: #000; border-color: transparent; }

.nav-toggle {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  flex: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  min-height: 36px;
  padding: 0 12px;
  font-weight: 800;
}

.site-links.open {
  display: flex;
  flex-direction: column;
}

.site-links.open a { width: 100%; text-align: center; }

.nav-drawer-head { display: none; }

@media (max-width: 979px) {
  .site-bar { flex-wrap: nowrap; backdrop-filter: none; }
  body.nav-open .site-bar { z-index: 60; }
  body.nav-open,
  body.game-page.nav-open,
  body.game-page.nav-open:has(#board) { overflow: hidden; }
  .nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: block;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: rgba(6, 4, 16, 0.55);
    cursor: pointer;
  }
  .site-links {
    display: flex;
    flex-direction: column;
    position: fixed;
    z-index: 41;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(300px, 86vw);
    height: 100dvh;
    margin: 0;
    padding: 14px 14px 24px;
    gap: 8px;
    background: #160c30;
    border-left: 1px solid var(--line);
    box-shadow: -18px 0 40px rgba(0, 0, 0, 0.4);
    transform: translateX(105%);
    visibility: hidden;
    overflow: auto;
    transition: transform 0.28s ease;
  }
  .site-links.open {
    transform: translateX(0);
    visibility: visible;
  }
  .nav-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
  }
  .nav-drawer-head strong { font-size: 1.15rem; }
  .nav-close {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    border-radius: 999px;
    min-height: 36px;
    padding: 0 12px;
    font-weight: 800;
  }
  .site-links a,
  .site-links.open a {
    width: 100%;
    min-height: 46px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    padding: 0 14px;
    border-radius: 12px;
    box-sizing: border-box;
  }
}
@media (prefers-reduced-motion: reduce) {
  .site-links { transition: none; }
}

@media (min-width: 980px) {
  .nav-toggle { display: none; }
  .site-bar {
    width: min(1100px, calc(100% - 24px));
    height: 58px;
    min-height: 58px;
    margin-inline: auto;
    flex-wrap: nowrap;
    overflow: hidden;
    padding: 0 12px;
    top: 8px;
    border-radius: 16px;
  }
  body.game-page .site-bar {
    width: min(1100px, calc(100% - 24px));
    position: static;
    margin: 8px auto 0;
  }
  .nav-backdrop { display: none !important; }
  .nav-drawer-head { display: none; }
  .site-links,
  .site-links.open {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    position: static;
    top: auto;
    right: auto;
    bottom: auto;
    width: auto;
    height: auto;
    flex: 1;
    justify-content: flex-end;
    align-items: center;
    margin: 0;
    padding: 0;
    gap: 6px;
    background: transparent;
    border: 0;
    box-shadow: none;
    transform: none;
    visibility: visible;
    overflow: visible;
  }
  .site-links a,
  .site-links.open a {
    width: auto;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    padding: 0 10px;
    font-size: 0.8rem;
    box-sizing: border-box;
  }
}

.wrap {
  width: min(1100px, calc(100% - 24px));
  margin: 0 auto;
  padding: 18px 0 40px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
}

.hero h1 { margin: 0; font-size: clamp(1.7rem, 4vw, 2.5rem); line-height: 1.05; }
.hero p { margin: 6px 0 0; opacity: 0.86; }
.home-page { margin-top: 4px; }
.home-intro {
  margin: 0 0 14px;
  padding: 14px 16px 6px;
  background: rgba(8, 4, 20, 0.35);
  border: 1px solid var(--line);
  border-radius: 20px;
}
.home-intro h2 { margin: 0 0 8px; font-size: 1.55rem; }
.home-intro p { margin: 0 0 10px; line-height: 1.5; }
.home-topics {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}
.home-topics article {
  margin: 0;
  min-width: 0;
  padding: 14px 16px 6px;
  background: rgba(8, 4, 20, 0.35);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
}
.home-topics .home-art {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  min-width: 0;
  margin: 0 auto 12px;
}
.home-topics article.wide { grid-column: 1 / -1; }
.home-topics h2 { margin: 0 0 8px; font-size: 1.28rem; }
.home-topics h3 { margin: 0 0 6px; font-size: 1.05rem; }
.home-topics p, .home-topics li { line-height: 1.5; font-size: 1.02rem; }

.home-lists {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 28px;
}
.home-lists ul { margin: 0 0 10px; padding-left: 18px; }
@media (min-width: 801px) {
  .home-topics .home-art.art-right {
    float: right;
    width: min(360px, 38%);
    margin: 2px 0 12px 20px;
  }
  .home-topics .home-art.art-left {
    float: left;
    width: min(400px, 42%);
    margin: 4px 20px 12px 0;
  }
}
@media (max-width: 800px) {
  .home-topics, .home-lists { grid-template-columns: minmax(0, 1fr); }
  .home-topics .home-art,
  .home-topics .home-art.art-right,
  .home-topics .home-art.art-left {
    float: none;
    width: 100%;
    max-width: 100%;
    margin: 0 auto 12px;
  }
}
body.site.cookie-open { padding-bottom: 84px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin: 8px 0 22px;
}
@media (min-width: 900px) {
  .cards { grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); }
}

.player-card {
  position: relative;
  display: block;
  color: inherit;
  text-decoration: none;
  background: rgba(255, 248, 234, 0.08);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px 12px 14px;
  text-align: center;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  cursor: pointer;
}

.player-card:focus-visible {
  outline: 3px solid #ffe08a;
  outline-offset: 3px;
}

.player-card img {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid var(--gold);
}

.player-card h2 { margin: 8px 0 2px; font-size: 1.25rem; }
.player-card p { margin: 4px 0; }

.card-online {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0;
  padding: 2px 8px 2px 6px;
  border-radius: 999px;
  background: rgba(8, 20, 12, 0.88);
  color: #37d36e;
  font-weight: 800;
  font-size: 0.82rem;
  line-height: 1.2;
  letter-spacing: 0.02em;
}

.card-online i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #37d36e;
  box-shadow: 0 0 0 0 rgba(55, 211, 110, 0.7);
  animation: online-blink 1.15s ease-out infinite;
}

@keyframes online-blink {
  0% { opacity: 1; box-shadow: 0 0 0 0 rgba(55, 211, 110, 0.7); }
  55% { opacity: 0.25; box-shadow: 0 0 0 7px rgba(55, 211, 110, 0); }
  100% { opacity: 1; box-shadow: 0 0 0 0 rgba(55, 211, 110, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .card-online i { animation: none; opacity: 1; }
}

.play-link, .primary, .sheet button.primary, body.site a.play-link {
  display: inline-block;
  background: linear-gradient(180deg, #ffe08a, #f0a332);
  color: #000;
  text-decoration: none;
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 800;
}

.ghost {
  display: inline-block;
  margin-left: 6px;
  color: var(--ink);
  font-weight: 700;
}

.article {
  background: rgba(8, 4, 20, 0.35);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 8px 16px 18px;
}

.article h2 { margin: 18px 0 6px; font-size: 1.35rem; }
.article p, .article li { line-height: 1.45; font-size: 1.02rem; }

.site-foot {
  width: min(1100px, calc(100% - 24px));
  margin: 0 auto 24px;
  opacity: 0.8;
  font-size: 0.92rem;
}

.panel {
  background: rgba(8, 4, 20, 0.35);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  margin: 12px 0;
}

label { display: block; font-weight: 700; margin: 10px 0; }
input, textarea, select {
  width: 100%;
  margin-top: 4px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  padding: 10px 12px;
  font: inherit;
}

table { width: 100%; border-collapse: collapse; }
td, th { text-align: left; padding: 6px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.1); vertical-align: top; }

.nav-pop {
  position: fixed;
  z-index: 40;
  left: 8px;
  right: 8px;
  top: 8px;
  background: #241445;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
}

.nav-pop nav { display: flex; flex-wrap: wrap; gap: 6px; }

.chat-card {
  display: flex;
  flex-direction: column;
  background: #1b1036;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.chat-card header, .chat-card form { display: flex; gap: 8px; align-items: center; padding: 12px; }
.chat-card img { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; }
.chat-card header strong, .chat-card header small { display: block; }
.chat-card form input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  padding: 10px 14px;
}
.chat-log { overflow: auto; padding: 0 12px 12px; display: flex; flex-direction: column; gap: 8px; min-height: 280px; max-height: min(56vh, 520px); }
.bubble { margin: 0; max-width: 85%; padding: 8px 10px; border-radius: 12px; background: rgba(255, 255, 255, 0.08); }
.bubble.me { align-self: flex-end; background: rgba(255, 200, 87, 0.2); }
.bubble.typing { opacity: 0.72; font-style: italic; }
.chat-card .play-link { align-self: flex-start; }

.cookie-bar {
  position: fixed;
  z-index: 45;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-radius: 14px;
  background: #241445;
  border: 1px solid var(--line);
}
.cookie-bar p { margin: 0; flex: 1; }

.form-error { color: #ffb4c0; }

.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

@media (max-width: 860px) {
  .hero { flex-direction: column; align-items: stretch; }
}

body.game-page {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

body.game-page .site-bar { flex: none; position: static; }

body.game-page .app,
body.game-page .lobby {
  flex: 1;
  height: auto;
  min-height: 0;
}

body.game-page .app { margin-inline: auto; }

.lobby {
  display: grid;
  place-items: center;
  padding: 20px 16px;
  overflow: auto;
}

.lobby-card {
  width: min(440px, 100%);
  display: grid;
  gap: 12px;
  justify-items: center;
  text-align: center;
  padding: 22px 16px;
  border-radius: 18px;
  background: rgba(255, 248, 234, 0.08);
  border: 1px solid var(--line);
}

.lobby-card h1 { margin: 0; font-size: 1.6rem; }
.lobby-card p { margin: 0; }
.lobby-card img { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; }
.lobby-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; width: 100%; }
.lobby-actions button {
  min-height: 44px;
  border: 1px solid var(--line);
  background: rgba(255, 248, 234, 0.08);
  color: inherit;
  border-radius: 999px;
  padding: 0 16px;
  font-weight: 700;
}
.lobby-actions button.primary,
.lobby-actions a.play-link {
  background: linear-gradient(180deg, #ffe08a, #f0a332);
  color: #000;
  border-color: transparent;
}
.lobby-actions input { width: 100%; min-width: 0; padding: 8px 10px; border-radius: 10px; font-size: 0.82rem; }

.choose {
  width: min(520px, 100%);
  margin: 8px auto 24px;
  display: grid;
  justify-items: center;
  gap: 12px;
  text-align: center;
  padding: 18px 16px 22px;
  border-radius: 24px;
  background: rgba(255, 248, 234, 0.06);
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
}

.choose h1 { margin: 0; font-size: clamp(1.6rem, 4vw, 2.1rem); }
.choose p { margin: 0; line-height: 1.45; }
.choose-photo { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; border: 3px solid var(--gold); }

.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
.pick button {
  min-height: 52px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 248, 234, 0.06);
  color: inherit;
  font-weight: 800;
}
.pick button.on { background: var(--gold); color: #000; border-color: transparent; }

.article.narrow { width: min(460px, 100%); margin: 0 auto; }
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.admin-head h1 { margin: 8px 0; }
.notice { padding: 10px 12px; border-radius: 12px; background: rgba(55, 211, 110, 0.16); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 8px 0 16px; }
.stat-grid article {
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 248, 234, 0.08);
  border: 1px solid var(--line);
}
.stat-grid span, .stat-grid small { display: block; opacity: 0.8; }
.stat-grid strong { font-size: 1.7rem; line-height: 1.1; }
.analytics-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 4px 0 12px;
}
.analytics-bar p { margin: 0; }
.hint-line { display: block; font-weight: 500; opacity: 0.75; margin-top: 2px; }
.admin textarea { font-family: ui-monospace, Consolas, monospace; font-size: 0.86rem; }

.ad-slot, .game-ad-body, .game-bottom-ad, .ad-frame { max-width: 100%; }
.ad-slot iframe, .ad-slot img, .ad-slot video,
.game-ad-body iframe, .game-ad-body img, .game-ad-body video,
.game-bottom-ad iframe, .game-bottom-ad img,
.ad-frame iframe, .ad-frame img, .ad-frame video { max-width: 100%; height: auto; }
.ad-square { width: min(250px, 100%); }
.ad-square .ad-ph { aspect-ratio: 1; }
.ad-ph {
  display: grid;
  place-items: center;
  min-height: 72px;
  border: 1px dashed rgba(255, 214, 140, 0.45);
  border-radius: 14px;
  color: rgba(255, 248, 234, 0.72);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.85rem;
  font-weight: 700;
}
.chat-ad { margin: 6px 0; }

.game-ad {
  display: none;
  flex: none;
  background: #fff;
  color: #1c1c1c;
  border-bottom: 1px solid #e4e4e4;
  overflow: hidden;
}
.game-ad-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 22px;
  padding: 0 8px;
  background: #f4f4f4;
  color: #666;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.game-ad-bar button {
  border: 0;
  background: transparent;
  color: #333;
  min-height: 22px;
  min-width: 28px;
  padding: 0;
}
.game-ad-body { max-height: 0; overflow: hidden; transition: max-height 0.35s ease; background: #fff; }
.game-ad.open .game-ad-body { max-height: 92px; }
.game-ad .ad-ph { min-height: 64px; border: 0; border-radius: 0; background: #f7f7f7; color: #666; }

.game-bottom-ad {
  display: none;
  flex: none;
  min-height: 36px;
  max-height: 48px;
  overflow: hidden;
  background: #fff;
  color: #222;
}
.game-bottom-ad .ad-ph { min-height: 36px; border: 0; border-radius: 0; background: #f7f7f7; color: #666; }

body.game-page:has(#gameApp:not([hidden])) .game-ad,
body.game-page:has(#gameApp:not([hidden])) .game-bottom-ad { display: block; }

.ad-full:not([hidden]) {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(6, 4, 16, 0.82);
}
.ad-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  min-height: 40px;
  border-radius: 999px;
  border: 0;
  padding: 0 14px;
  background: #fff;
  color: #222;
  font-weight: 800;
}
.ad-frame {
  width: min(920px, 100%);
  max-height: calc(100dvh - 88px);
  overflow: auto;
  background: #fff;
  color: #111;
  border-radius: 16px;
}
.ad-frame.ad-video { width: min(720px, 100%); aspect-ratio: 16 / 9; background: #000; }
.ad-frame .ad-ph { min-height: 180px; color: #666; border-color: #ddd; }

body.site:has(.admin-shell) .site-foot { display: none; }

.admin-nav-check {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.admin-shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  align-items: stretch;
  min-height: 100dvh;
}

.admin-side {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100dvh;
  padding: 18px 12px 14px;
  overflow: auto;
  background: rgba(8, 4, 20, 0.72);
  border-right: 1px solid var(--line);
}

.admin-brand { display: grid; padding: 0 8px; }
.admin-brand strong { font-size: 1.35rem; line-height: 1.1; }
.admin-brand span { opacity: 0.72; font-size: 0.86rem; }

.admin-nav { display: grid; gap: 4px; }

body.site .admin-nav a,
body.site .admin-side a.view {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: 12px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
}

body.site .admin-nav a.on {
  background: var(--gold);
  color: #000;
}

.admin-nav .count {
  min-width: 1.6em;
  text-align: center;
  font-size: 0.78rem;
  opacity: 0.8;
}

.admin-side-foot { display: grid; gap: 8px; margin-top: auto; }
.admin-logout,
.admin-open,
.admin-close {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 248, 234, 0.08);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}
.admin-logout { width: 100%; }
.admin-open, .admin-close, .admin-backdrop { display: none; }

.admin-main {
  min-width: 0;
  padding: 18px 22px 40px;
}

.admin-top { display: flex; align-items: center; gap: 12px; }
.admin-top h1 { margin: 0; font-size: 1.7rem; }
.admin-lead { margin: 4px 0 0; opacity: 0.86; }
.table-scroll { overflow-x: auto; }
.admin-main .article { margin-top: 8px; }
.admin-main .notice { margin: 12px 0; }

@media (max-width: 860px) {
  .admin-shell { display: block; }
  .admin-side {
    position: fixed;
    z-index: 40;
    left: 0;
    top: 0;
    width: min(280px, 86vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .admin-nav-check:checked ~ .admin-shell .admin-side { transform: none; }
  .admin-open { display: inline-flex; align-items: center; padding: 0 14px; }
  .admin-close { display: inline-flex; align-items: center; justify-content: center; }
  .admin-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(6, 4, 16, 0.55);
    opacity: 0;
    pointer-events: none;
  }
  .admin-nav-check:checked ~ .admin-shell .admin-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .admin-main { padding: 14px 14px 32px; }
}
