:root {
  color-scheme: dark;
  --bg: #050b12;
  --bg-soft: #08131f;
  --panel: rgba(9, 23, 36, .86);
  --panel-strong: rgba(12, 32, 49, .96);
  --line: rgba(123, 230, 255, .16);
  --line-strong: rgba(123, 230, 255, .32);
  --text: #effaff;
  --muted: #8eabb8;
  --cyan: #49f2ff;
  --green: #55ff9a;
  --yellow: #ffd66b;
  --red: #ff5d7d;
  --blue: #7698ff;
  --shadow: 0 22px 70px rgba(0, 0, 0, .42);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 12%, rgba(73, 242, 255, .16), transparent 28rem),
    radial-gradient(circle at 88% 5%, rgba(85, 255, 154, .12), transparent 26rem),
    radial-gradient(circle at 72% 92%, rgba(118, 152, 255, .12), transparent 26rem),
    linear-gradient(135deg, #050b12, #07111c 54%, #04080e);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

code {
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--cyan);
  background: rgba(255, 255, 255, .05);
}

.app-bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
}

.app-bg::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, .024) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .024) 1px, transparent 1px);
  background-size: 38px 38px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, .88), transparent 84%);
}

.app-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .22;
  background:
    repeating-linear-gradient(0deg, transparent 0 8px, rgba(73, 242, 255, .04) 9px),
    repeating-linear-gradient(90deg, transparent 0 13px, rgba(85, 255, 154, .03) 14px);
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.login-card {
  width: min(100%, 560px);
  padding: clamp(22px, 5vw, 40px);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(12, 32, 49, .94), rgba(5, 14, 23, .92)),
    var(--panel);
  box-shadow: var(--shadow);
}

.brand-row,
.brand,
.profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: #031018;
  background: linear-gradient(135deg, var(--cyan), var(--green));
  font-weight: 950;
  box-shadow: 0 0 0 5px rgba(73, 242, 255, .06);
}

.kicker {
  margin: 0 0 6px;
  color: var(--cyan);
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2.3rem, 9vw, 4.8rem);
}

h2 {
  font-size: clamp(1.35rem, 4vw, 2.2rem);
}

.login-copy {
  margin: 22px 0;
  color: #bfd4dd;
  font-size: 1.06rem;
}

.login-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: .94rem;
  font-weight: 750;
}

input,
select {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  color: var(--text);
  background: rgba(1, 8, 13, .72);
}

input:focus,
select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 4px rgba(73, 242, 255, .08);
}

select option {
  background: #07111c;
}

.login-note {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid rgba(255, 214, 107, .2);
  border-radius: var(--radius);
  color: #f2dfab;
  background: rgba(255, 214, 107, .06);
}

.shell {
  width: min(1500px, calc(100% - 24px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 280px minmax(360px, 1fr) minmax(360px, 520px);
  grid-template-rows: 76px 1fr;
  gap: 12px;
  padding: 12px 0 18px;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(5, 15, 24, .72);
  backdrop-filter: blur(16px);
}

.brand {
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand strong,
.profile-card strong {
  display: block;
  font-size: 1rem;
}

.brand small,
.profile-card span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: .82rem;
}

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

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(12, 32, 49, .82), rgba(5, 14, 23, .88)),
    var(--panel);
  box-shadow: 0 16px 52px rgba(0, 0, 0, .22);
}

.sidebar {
  display: grid;
  align-content: start;
  gap: 12px;
}

.profile-card {
  padding: 14px;
}

.avatar {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: var(--radius);
  color: #031018;
  background: var(--cyan);
  font-weight: 950;
  text-transform: uppercase;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
}

.panel-head h2 {
  font-size: 1.02rem;
}

.panel-head span {
  min-width: 28px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--cyan);
  text-align: center;
  background: rgba(255, 255, 255, .04);
  font-size: .78rem;
  font-weight: 900;
}

.room-list,
.online-list {
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
}

.room,
.user-pill {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid rgba(123, 230, 255, .1);
  border-radius: var(--radius);
  color: var(--text);
  background: rgba(255, 255, 255, .035);
}

.room {
  cursor: pointer;
  text-align: left;
  font-weight: 850;
}

.room span,
.user-pill span {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}

.room:hover,
.room.active {
  border-color: var(--line-strong);
  background: rgba(73, 242, 255, .09);
}

.chat-panel,
.game-panel {
  min-height: calc(100vh - 106px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.chat-head,
.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.status-pill,
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--cyan);
  background: rgba(73, 242, 255, .06);
  font-size: .84rem;
  font-weight: 850;
  white-space: nowrap;
}

.chip {
  cursor: pointer;
}

.chip.danger {
  color: #ffc2ce;
  border-color: rgba(255, 93, 125, .28);
  background: rgba(255, 93, 125, .08);
}

.messages {
  min-height: 340px;
  max-height: calc(100vh - 250px);
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.message.mine {
  grid-template-columns: minmax(0, 1fr) 42px;
}

.message.mine .bubble {
  order: 1;
  border-color: rgba(85, 255, 154, .24);
  background: rgba(85, 255, 154, .08);
}

.message.mine .mini-avatar {
  order: 2;
}

.mini-avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: #031018;
  font-weight: 950;
}

.bubble {
  padding: 11px 12px;
  border: 1px solid rgba(123, 230, 255, .12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .045);
}

.bubble-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.bubble-head strong {
  font-size: .92rem;
}

.bubble-head time {
  color: var(--muted);
  font-size: .76rem;
}

.bubble p {
  margin: 0;
  color: #d9edf4;
  word-wrap: break-word;
}

.system-message {
  align-self: center;
  max-width: 92%;
  padding: 8px 10px;
  border: 1px solid rgba(255, 214, 107, .18);
  border-radius: 999px;
  color: #f3dfab;
  background: rgba(255, 214, 107, .06);
  font-size: .84rem;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
}

.btn {
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 900;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.btn:hover,
.chip:hover,
.tab:hover {
  transform: translateY(-1px);
}

.btn.primary {
  color: #031018;
  background: linear-gradient(135deg, var(--cyan), var(--green));
  box-shadow: 0 12px 34px rgba(73, 242, 255, .16);
}

.btn.secondary {
  color: var(--text);
  border-color: var(--line);
  background: rgba(255, 255, 255, .05);
}

.score-box {
  display: grid;
  justify-items: end;
  gap: 3px;
}

.score-box span {
  color: var(--muted);
  font-size: .78rem;
}

.score-box strong {
  color: var(--green);
  font-size: 1.65rem;
}

.game-panel {
  grid-template-rows: auto auto 1fr auto auto auto;
}

.game-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--muted);
  background: rgba(255, 255, 255, .035);
  font-weight: 900;
}

.tab.active {
  color: #031018;
  border-color: transparent;
  background: linear-gradient(135deg, var(--yellow), var(--green));
}

.game-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 420px;
  padding: 14px;
}

canvas {
  width: min(100%, 420px);
  height: auto;
  max-height: 58vh;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #02070c;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .02), 0 18px 40px rgba(0, 0, 0, .35);
}

.game-overlay {
  position: absolute;
  inset: auto 28px 28px;
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(5, 12, 18, .78);
  backdrop-filter: blur(10px);
  text-align: center;
}

.game-overlay[hidden] {
  display: none;
}

.game-overlay strong {
  font-size: 1.02rem;
}

.game-overlay span {
  color: var(--muted);
  font-size: .9rem;
}

.game-controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.mobile-pad {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 12px 12px;
}

.mobile-pad button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: rgba(255, 255, 255, .055);
  font-weight: 850;
}

.tips {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 0 14px 14px;
  color: var(--muted);
  font-size: .8rem;
}

@media (max-width: 1160px) {
  .shell {
    grid-template-columns: 260px 1fr;
    grid-template-rows: 76px auto auto;
  }

  .game-panel {
    grid-column: 1 / -1;
    min-height: auto;
  }

  .game-stage {
    min-height: 380px;
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 16px, 760px);
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    padding-top: 8px;
  }

  .topbar,
  .top-actions,
  .composer,
  .game-controls {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .composer {
    display: grid;
  }

  .sidebar,
  .chat-panel,
  .game-panel {
    min-height: auto;
  }

  .messages {
    max-height: 58vh;
  }

  .mobile-pad {
    display: grid;
  }

  .tips {
    flex-direction: column;
  }
}
