* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Inter, Arial, sans-serif;
  background:
    radial-gradient(circle at 20% -10%, rgba(129, 80, 255, 0.32), transparent 30%),
    radial-gradient(circle at 90% 0%, rgba(255, 66, 128, 0.22), transparent 24%),
    linear-gradient(180deg, #0b0a14, #0f1020 45%, #0b0d17);
  color: #f3f3f9;
  min-height: 100vh;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 18px 34px;
}

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

.topbar-right {
  display: grid;
  gap: 8px;
  justify-items: end;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 34px);
  letter-spacing: 0.5px;
  text-shadow: 0 2px 18px rgba(123, 88, 255, 0.35);
}

h2 {
  margin: 0 0 12px;
}

.hint,
.subtle {
  color: #b8b7ce;
}

.status-badge {
  border: 1px solid #4a4f78;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  background: linear-gradient(180deg, #1e2742, #191f35);
  box-shadow: 0 8px 18px rgba(8, 10, 20, 0.35);
  display: flex;
  align-items: center;
  gap: 8px;
}

.stats-badge {
  border: 1px solid #3f456c;
  border-radius: 999px;
  padding: 7px 12px;
  font-weight: 600;
  font-size: 12px;
  color: #dce2ff;
  background: linear-gradient(180deg, #1b1f34, #151a2c);
  box-shadow: 0 6px 14px rgba(8, 10, 20, 0.3);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff4d4d;
  box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.7);
  animation: pulseRed 1.5s infinite;
}

.status-badge.online .status-dot {
  background: #45d97a;
  box-shadow: 0 0 0 0 rgba(69, 217, 122, 0.75);
  animation: pulseGreen 1.5s infinite;
}

@keyframes pulseRed {
  0% { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.7); }
  70% { box-shadow: 0 0 0 10px rgba(255, 77, 77, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0); }
}

@keyframes pulseGreen {
  0% { box-shadow: 0 0 0 0 rgba(69, 217, 122, 0.75); }
  70% { box-shadow: 0 0 0 10px rgba(69, 217, 122, 0); }
  100% { box-shadow: 0 0 0 0 rgba(69, 217, 122, 0); }
}

.setup {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mini-btn {
  padding: 4px 10px;
  font-size: 12px;
}

.field-span {
  grid-column: 1 / -1;
}

.avatar-picker {
  display: grid;
  grid-template-columns: repeat(6, minmax(46px, 1fr));
  gap: 8px;
}

.avatar-option {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid #4c537e;
  background: #161a2f;
  overflow: hidden;
  padding: 0;
}

.avatar-option img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-option.selected {
  border-color: #9c86ff;
  box-shadow: 0 0 0 2px rgba(140, 123, 255, 0.35);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.card {
  background: linear-gradient(180deg, rgba(35, 36, 56, 0.88), rgba(23, 25, 41, 0.9));
  border: 1px solid #363a5d;
  border-radius: 16px;
  padding: 15px;
  box-shadow:
    0 16px 36px rgba(8, 10, 24, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.me-card {
  margin-top: 12px;
}

#eventLogSection {
  margin-top: 12px;
}

.me-title {
  font-size: 12px;
  color: #bfc6ea;
  margin-bottom: 6px;
  letter-spacing: 0.4px;
}

.me-content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.me-avatar {
  width: 46px;
  height: 46px;
}

.me-name {
  font-size: 15px;
  font-weight: 700;
  color: #f0f2ff;
}

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

.lobby-actions {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.lobby-split {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
}

.lobby-pane {
  border: 1px solid #43496f;
  border-radius: 12px;
  background: linear-gradient(180deg, #1a1f35, #14182a);
  padding: 10px;
}

.lobby-pane-title {
  font-size: 12px;
  color: #c7c6dc;
  margin-bottom: 8px;
  letter-spacing: 0.3px;
}

.join-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input,
button {
  background: #1a1d33;
  color: #fff;
  border: 1px solid #494f7a;
  border-radius: 10px;
  padding: 10px 11px;
  transition: all 150ms ease;
}

input {
  min-width: 0;
  flex: 1;
}

button {
  cursor: pointer;
}

button:hover {
  border-color: #848cf7;
  transform: translateY(-1px);
}

.primary {
  background: linear-gradient(180deg, #8069ff, #5a42e0);
  border-color: #8c7bff;
  box-shadow: 0 10px 20px rgba(92, 71, 230, 0.35);
}

.large-btn {
  padding: 11px 12px;
  font-weight: 600;
}

.ghost {
  background: transparent;
}

.phase-box,
.role-card {
  border: 1px solid #454c7c;
  border-radius: 10px;
  padding: 11px;
  background: linear-gradient(180deg, #1b2038, #171a2c);
  margin-bottom: 8px;
}

.phase-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.2px;
}

.phase-icon {
  font-size: 24px;
}

#timerInfo {
  margin-top: 4px;
  font-size: 36px;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 1px;
  color: #e9eeff;
  text-align: center;
  text-shadow: 0 6px 20px rgba(91, 101, 255, 0.35);
}

#timerInfo.urgent {
  color: #ffd7d7;
  text-shadow: 0 6px 20px rgba(200, 62, 62, 0.45);
}

.role-card {
  color: #ffd79a;
  font-weight: 700;
}

.role-card-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.voice-panel {
  margin-top: 10px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #4a527d;
  background: linear-gradient(180deg, #182038, #151b30);
  display: grid;
  gap: 8px;
}

.voice-top-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

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

.voice-state {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #566080;
  background: #1b2138;
  font-size: 12px;
  font-weight: 700;
}

.voice-state.on {
  border-color: #38a56a;
  background: #123726;
  color: #c9ffe0;
}

.voice-state.off {
  border-color: #7b4c4c;
  background: #3a1717;
  color: #ffd8d8;
}

.role-help-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  padding: 0;
  font-weight: 700;
}

.players-list {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.player-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 1px solid #44496b;
  border-radius: 10px;
  background: linear-gradient(180deg, #1d2138, #171a2a);
  padding: 9px;
}

.player-item.selected-target {
  border-color: #8e84ff;
  box-shadow: 0 0 0 1px #8e84ff inset;
}

.player-item.speaking {
  border-color: #36c975;
  box-shadow:
    0 0 0 1px #36c975 inset,
    0 0 14px rgba(54, 201, 117, 0.35);
}

.player-item.dead {
  opacity: 0.55;
}

.player-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 30% 30%, #9f95ff, #4f45bb);
  border: 1px solid #8d83ff;
  box-shadow: 0 6px 16px rgba(114, 102, 255, 0.35);
  font-size: 20px;
  line-height: 1;
  overflow: hidden;
}

.player-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.player-meta {
  font-size: 12px;
  color: #acacbf;
}

.speaking-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid #34b56a;
  background: #133823;
  color: #ccffe0;
  font-size: 11px;
  font-weight: 700;
  animation: speakingPulse 0.9s ease-in-out infinite alternate;
}

@keyframes speakingPulse {
  from {
    box-shadow: 0 0 6px rgba(62, 220, 130, 0.35);
  }
  to {
    box-shadow: 0 0 12px rgba(62, 220, 130, 0.6);
  }
}

.life-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.life-tag.alive {
  border: 1px solid #2f8b57;
  background: linear-gradient(180deg, #15482f, #103425);
  color: #ccffe2;
}

.life-tag.eliminated {
  border: 1px solid #b44;
  background: linear-gradient(180deg, #5a1a1a, #3f1111);
  color: #ffd7d7;
}

.identity-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid #5d5f80;
  background: linear-gradient(180deg, #23253b, #1a1b2d);
  color: #d8dcff;
  font-size: 11px;
  font-weight: 600;
}

.identity-tag.revealed {
  border-color: #c7a229;
  background: linear-gradient(180deg, #5b4713, #42320d);
  color: #ffe7a3;
  box-shadow: 0 0 10px rgba(255, 214, 92, 0.5);
  animation: identityGlow 1.3s ease-in-out infinite alternate;
}

@keyframes identityGlow {
  from {
    box-shadow: 0 0 8px rgba(255, 214, 92, 0.35);
  }
  to {
    box-shadow: 0 0 14px rgba(255, 214, 92, 0.65);
  }
}

.vote-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid #5679d9;
  background: #1a2b57;
  color: #d7e4ff;
  font-size: 11px;
}

.day-target-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid #b44;
  background: linear-gradient(180deg, #5a1a1a, #3f1111);
  color: #ffd7d7;
  font-size: 11px;
  font-weight: 600;
}

.target-btn {
  padding: 6px 8px;
}

.action-feedback {
  margin: 8px 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: linear-gradient(180deg, #182844, #131d34);
  border: 1px solid #3b5489;
  color: #e1ebff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  border-color: #3a3a4e;
}

.chat-log,
#logArea {
  background: linear-gradient(180deg, #121526, #0f1120);
  border: 1px solid #343957;
  border-radius: 10px;
  padding: 10px;
  min-height: 180px;
  max-height: 320px;
  overflow: auto;
}

.chat-line {
  margin-bottom: 6px;
}

#logArea {
  white-space: pre-wrap;
}

.room-code-wrap {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
  color: #ecebff;
  background: #161a2f;
  border: 1px dashed #4a4f76;
  border-radius: 10px;
  padding: 8px 10px;
}

.room-code-wrap > * {
  min-width: 0;
}

.room-code-wrap strong {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.hidden-by-mode {
  display: none !important;
}

.invite-info {
  margin-bottom: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid #4b5a88;
  background: linear-gradient(180deg, #1a2742, #162038);
  color: #d8e4ff;
  font-size: 13px;
}

.role-modal {
  position: fixed;
  inset: 0;
  background: rgba(7, 9, 18, 0.72);
  display: grid;
  place-items: center;
  z-index: 999;
  padding: 14px;
}

.role-modal-panel {
  width: min(520px, 100%);
  border: 1px solid #4b5a88;
  border-radius: 14px;
  background: linear-gradient(180deg, #151d34, #11182c);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  padding: 12px;
}

.role-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.role-modal-body {
  color: #dce6ff;
  line-height: 1.5;
}

.role-modal-body p {
  margin: 0 0 8px;
}

.role-modal-body ul {
  margin: 0;
  padding-left: 18px;
}

@media (max-width: 860px) {
  .setup,
  .grid {
    grid-template-columns: 1fr;
  }

  .lobby-split {
    grid-template-columns: 1fr;
  }

  .join-box {
    grid-template-columns: 1fr;
  }

  .topbar-right {
    width: 100%;
    justify-items: stretch;
  }

  .topbar-right .status-badge,
  .topbar-right .stats-badge {
    justify-content: center;
    text-align: center;
  }
}
